Ticket #520 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Vsync is not implemented in Linux

Reported by: lubosz Owned by:
Priority: Nice to Have Milestone:
Component: Core engine Keywords: vsync opengl glext glxext glx
Cc:

Description

I use glXSwapIntervalSGI to activate vsync in Linux. This is found in GL/glxext.h. Which needs GL/glx.h. I put those inlcudes to the according places where i found the wgl.h and wglext.h Windows ones.

More information about this extension: http://www.opengl.org/registry/specs/SGI/swap_control.txt

The problem is that glx.h inludes X11/X.h which defines Cursor. So i replaced the Cursor stuff in cursor.cpp with GameCursor?... I have no other idea how to solve this. Maybe using namespaces?

The other mystery is that ogl_HaveExtension("GLX_SGI_swap_control") returns false. Do I have to register it somewhere? I did not get the magic of ogl_HaveExtension in ogl.cpp. But it runs without checking for me. This should be temporary.

The ifdefs are confusing with OS_WIN, OS_MACOSX and OS_MAC. Is there OS_UNIX or OS_LINUX? So I could ensure a better separation. Maybe this extension could be usefull in OS X too, but I can't test it.

Attachments

vsync_linux.diff (3.4 KB) - added by lubosz 3 years ago.
Vsync idea patch for Linux. diffed in source folder.
vsync_linux_sdl.diff (537 bytes) - added by lubosz 3 years ago.
VSync done with sdl. This also should work with OS X and windows. But WGL vsyn should be removed before removing the OS_UNIX ifdef

Change History

Changed 3 years ago by lubosz

Vsync idea patch for Linux. diffed in source folder.

comment:1 Changed 3 years ago by Philip

The Cursor problem could probably be solved by not including glx*.h since the patch doesn't seem to be using anything defined in that file.

The most useful OS defines are OS_WIN, OS_LINUX, OS_MACOSX, and OS_UNIX (which is OS_LINUX || OS_MACOSX) - those cover all the supported platforms.

GLX_SGI_swap_control is a GLX extension, not a GL extension, so I believe it needs to use a separate set of APIs for detecting and loading the function, which would probably need a lot of changes to ogl.cpp.

It looks like SDL actually provides this functionality already - use SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1) in ps/VideoMode.cpp, and then we wouldn't have to worry about any platform-specific details. Does that work? (I haven't tried it.)

(If so, it would be good to use that consistently across platforms. On Windows, that means moving the vsync call from ps/GameSetup.cpp to lib/sysdep/os/win/wsdl.cpp. But that's not necessary yet - it'd be fine to add just the non-Windows code first.)

Changed 3 years ago by lubosz

VSync done with sdl. This also should work with OS X and windows. But WGL vsyn should be removed before removing the OS_UNIX ifdef

comment:2 Changed 3 years ago by philip

  • Status changed from new to closed
  • Resolution set to fixed

(In [7845]) Use SDL_GL_SWAP_CONTROL to control vsync on non-Windows. Fixes #520.

comment:3 Changed 3 years ago by Philip

I changed this to not be OS-specific, and added #523 about properly implementing that functionality on Windows.

I can't test this myself on Linux (I always seem to get clamped to 60fps regardless) so I'll trust that it works for people with more proper graphics setups :-)

comment:4 Changed 3 years ago by anonymous

  • Milestone Unclassified deleted

Milestone Unclassified deleted

Note: See TracTickets for help on using tickets.