PDA

View Full Version : wglCreateBufferRegionARB returns NULL on NVIDIA



JSB888
04-19-2010, 01:57 AM
I recently added support for buffer regions in my software. It works perfectly on ATI but the call to wglCreateBufferRegionARB returns NULL on NVIDIA H/W and I haven't been able to figure out why.

The "WGL_ARB_buffer_region" extension string is present and wglGetProcAddress() works fine. GetLastError() returns the error code 0xC00705AA and FormatMessage() with that error code returns a NULL string.

These are the attributes I'm using for the pixel format:

PIXELFORMATDESCRIPTOR pFd;
memset(&pFd,0,sizeof(pFd));
pFd.nSize = sizeof(pFd);
pFd.nVersion = 1;
pFd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_STEREO | PFD_DOUBLEBUFFER;
pFd.iPixelType = PFD_TYPE_RGBA;
pFd.iLayerType = PFD_MAIN_PLANE;
pFd.cDepthBits = 32;
pFd.cColorBits = 24;

(I tried with and without PFD_STEREO, which is the only thing that seems remotely unusual, and that didn't help. Neither did using 16 bits for depth.)

The call looks like this, but any combination of front and back buffer with and without depth makes no difference:

UINT ColourBuffer = m_DoubleBuffer ? WGL_BACK_COLOR_BUFFER_BIT_ARB : WGL_FRONT_COLOR_BUFFER_BIT_ARB;

m_Buffer = wglCreateBufferRegionARB(pDC->m_hDC, 0, ColourBuffer | WGL_DEPTH_BUFFER_BIT_ARB);

This is such an old extension that I'm completely at a loss. It doesn't work on any GeForce or Quadro card I've tried, with any driver version, but works fine on all ATI cards. What am I doing wrong?

Piers Daniell
04-19-2010, 01:28 PM
What driver version? Which OS? Which GPU(s)? Also, if possible, could you submit a simple repro app source. Thanks.

JSB888
04-20-2010, 04:09 AM
I put together a simple Win32 test program so I could post it and found it actually worked correctly, despite the OpenGL code being almost line-for-line identical.

After much mucking about I finally figured out what the difference was between the two versions -- in the original code all the OpenGL initialisation is done during the CView-derived OnCreate() method, which occurs after the window has been created but before it becomes visible, while the test program did the initialisation after the window was visible.

OnCreate() is the canonical OpenGL setup location in every example I've seen. We've been using it for about 15 years.

For ATI using OnCreate() doesn't cause any problems, and for all the other OpenGL initialisation that occurs this doesn't cause any problems, but apparently NVIDIA requires the window to be visible before wglCreateBufferRegionARB can be called successfully.

It would have been nice if calling FormatMessage() with the error code returned by GetLastError() had said something to that effect. :-)

I couldn't find anything in the specification that said the window has to be visible before this can be used. Now it looks like I'll need to put a once-off initialisation in OnDraw() because I'm not aware of a message that's sent in between.