Re: wglSwapLayerBuffers versus SwapBuffers

2,207 views
Skip to first unread message

Taylor Gordon

unread,
Jul 29, 2012, 1:26:54 PM7/29/12
to pyglet...@googlegroups.com
Ping! Should we switch from wglSwapLayerBuffers to SwapBuffers.

On Thursday, July 26, 2012 11:10:02 AM UTC-7, Taylor Gordon wrote:
I just started using Pyglet and came across an issue with the Win32 method of swapping front and back buffers. Pyglet uses the wglSwapLayerBuffers Win32 API call do this swap. On my machine (Windows 7, AMD Radeon HD 7-series graphics card) this method doesn't work with vsync enabled. My display has a 60Hz refresh rate, and yet the wglSwapLayerBuffers call blocks to make a 30fps rate. With vsync disabled the frame rate is > 500 so it is certainly not the case that each frame is to slow to achieve 60fps with vsync enabled. Moreover, if I replace the wglSwapLayerBuffers call with the more standard SwapBuffers call, everything works correctly (60fps).

I've heard reports of other people experiencing the same thing. Why does Pyglet use the wglSwapLayerBuffers call? This flat out doesn't work on some configurations with vsync enabled. Useful resources:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd374391(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd368815(v=vs.85).aspx

Andre D

unread,
Jul 29, 2012, 2:18:48 PM7/29/12
to pyglet...@googlegroups.com
This is likely why it is used used:
http://www.opengl.org/discussion_boards/showthread.php/141384-SwapBuffers-or-wglSwapBuffers

"since GDI and the ICD share function names like SwapBuffers, a
wglSwapBuffers is needed to avoid ambiguity when loading the proc
dynamically."
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pyglet-users/-/vol_It4XyLsJ.
> To post to this group, send email to pyglet...@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.

Andre D

unread,
Jul 29, 2012, 2:20:22 PM7/29/12
to pyglet...@googlegroups.com
http://www.opengl.org/wiki/Platform_specifics:_Windows#When_do_I_render_my_scene.3F
states "To swap buffers, use SwapBuffers instead of wglSwapBuffers."

Tristam MacDonald

unread,
Jul 29, 2012, 2:36:40 PM7/29/12
to pyglet...@googlegroups.com
On Sun, Jul 29, 2012 at 2:20 PM, Andre D <an...@andred.ca> wrote:
http://www.opengl.org/wiki/Platform_specifics:_Windows#When_do_I_render_my_scene.3F
states "To swap buffers, use SwapBuffers instead of wglSwapBuffers."

Sadly, that page doesn't offer any justification for it's assertion. Does anyone have a suitable reference to back it up?

--
Tristam MacDonald

Andreas Schiefer

unread,
Jul 30, 2012, 3:03:12 AM7/30/12
to pyglet...@googlegroups.com
On Thu, Jul 26, 2012 at 8:10 PM, Taylor Gordon <taylorg...@gmail.com> wrote:
> Moreover, if I replace the wglSwapLayerBuffers call with the
> more standard SwapBuffers call, everything works correctly (60fps).

What have you changed exactly to get it working with SwapBuffers?
I tried replacing the line
wgl.wglSwapLayerBuffers(self.canvas.hdc, wgl.WGL_SWAP_MAIN_PLANE)
with
wgl.SwapBuffers(self.canvas.hdc)

But I always get the error
pyglet.gl.lib.MissingFunctionException: SwapBuffers is not
exported by the available OpenGL driver.
with current Nvidia and Intel drivers.

This may of course be a bug in pyglets wrapper or be related to the
dynamic linking issue Andre pointed out, but I'm curious how you got
it working?

Taylor Gordon

unread,
Aug 11, 2012, 4:00:16 PM8/11/12
to pyglet...@googlegroups.com
You have to link the SwapBuffers method in the wgl module. Add the line:

SwapBuffers = _link_function('SwapBuffers', BOOL, [HDC], None)

claudio canepa

unread,
Aug 11, 2012, 4:44:52 PM8/11/12
to pyglet...@googlegroups.com
--
 

Ah, but there is more fun for this issue:

1. There's also a GDI function SwapBuffers, which seems to be the recomended way, see



It is not currently binded in pyglet, but you can use this GDI flavor by:

1.  En pyglet\libs\win32\__init__.py , near the line 99, add the lines

     _gdi32.SwapBuffers.restype = BOOL
     _gdi32.SwapBuffers.argtypes = [HDC]

2. in pyglet\gl\win32.py, class Win32Context, method .flip(), replace the line

     wgl.wglSwapLayerBuffers(self.canvas.hdc, wgl.WGL_SWAP_MAIN_PLANE)
by
     _gdi32.SwapBuffers(self.canvas.hdc)

Now, If there were a small script demoing the defect it would be easier to evalute solutions.

Note also that the first link does some remarks about vsync issues.

claudio

--


Reply all
Reply to author
Forward
0 new messages