GLSL shaders and multiple rendering contexts

Hello,

my app uses four different OpenGL views (rendering contexts). One of them is a 3D view and in this context I create some shader objects. The problem is that the shader objects don’t seem to persist after the contexts are switched to another one and then back to the 3D context: glUseProgramObjectARB generates GL_INVALID_VALUE error.

If remove all but the 3D view and run the app then shaders work okay, so obviously RC switching is the cause. Is there any workaround for this problem? I’ve tried wglShareLists already, but to no avail.

I have WinXP SP2 and ATI Radeon 9700 with Catalyst 4.8 drivers installed.

TIA.

wglShareList should work. Look at the restrictions of that function to see if you aren’t doing all allright:

You can only share display lists with rendering contexts within the same process

All rendering contexts of a shared display list must use an identical pixel format

BOOL wglShareLists(
HGLRC hglrc1, // OpenGL rendering context with which to share
// display lists
HGLRC hglrc2 // OpenGL rendering context to share display lists
);

hglrc2 Specifies the OpenGL rendering context to share display lists with hglrc1. The hglrc2 parameter should not contain any existing display lists when wglShareLists is called.
If this still doesn’t work, try this: you don’t really need 4 RC for 4 views. You can create one RC and use it in all windows, simply you must stablish the same pixel format for all windows and make current the one that you need (remember that wglMakeCurrent has two parameters)

wglMakeCurrent(DCview1,RC);
draw_in_window1();
SwapBuffers(DCview1);

wglMakeCurrent(DCview2,RC);
draw_in_window2();
SwapBuffers(DCview2);

wglMakeCurrent(DCview3,RC);
draw_in_window3();
SwapBuffers(DCview3);

wglMakeCurrent(DCview4,RC);
draw_in_window4();
SwapBuffers(DCview4);

I tried that in the past and worked perfectly for me, and has avoided me to the boring task of maintain 4 different OpenGL rendering contexts

Hello

Thanks for your help! Originally, I created the shader objects before calling wglShareLists. I changed it so that wglShareLists is called first and it started working!

I tried that in the past and worked perfectly for me, and has avoided me to the boring task of maintain 4 different OpenGL rendering contexts
There are some advantages to this. For example, separate GL state is automatically maintained for each view. This is useful especially if we have textured 3D view and wireframe 2D views.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.