TheMax3131's picture

Shader modification for differents vbos and gl controls troubleshoutings

Hi everyone,

Here is my problem. I have a VBO class (VBOGL) that also initialize shader programs, then i have a View class, containing a GL_Control to render the VBO.
I need to have 2 views, and thus i create two objects of my View class. Consequently, i have two independent vbos and shader programs. But it occurs that when i make the same modification of the vertex shader in both objects, the modification is only taken into account in the second object, the first view do not change.
I found a "weak solution" solution for this problem, that is copying the VBOGL that take into account the change into my other view ... But i don't understand why i have this result.

If someone has an idea, that would be greate for my understanding in opengl/glsl !



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mOfl's picture
TheMax3131 wrote:

Consequently, i have two independent vbos and shader programs.

Why is this? I'm not familiar with your architecture, but is this an architecture constraint or did you just choose to do it this way? Anyways, you should change this. As I think you already thought of, you can of course share almost (*) every resource between all contexts. This means for you that you maintain only one VBO and one shader. You can use both resources for both contexts. For this, you need to provide access to the VBO's and shader's handle for both of your View class objects. Then, you make the first context the current context, bind your VBO and shader, render to the first control, unbind shader and VBO, make the second control's context current, bind VBO and shader again, render for the second control and unbind shader and VBO again.

(*) You cannot share state objects such as the Vertex Array Object, which are context-bound.

I'm actually not even sure if you need to do the unbinding for the shader and VBO all the time, you can try to leave it out. I'm quite sure, however, that you cannot bind a texture to your second context as long as it is bound to the first one, so I can only guess that the behavior for other resources is the same.

This does not really answer your original question which was why the buffer changes are not applied, but I think as it would be better to use only one buffer anyways, I'd recommend you to first try this idea. If it doesn't work out or if you really need two separate buffers with the same content, you should provide the source code of the content-changing part.

Hope that helps.

lid6j86's picture

if you are going to use a particular Vertex Array very often, would it make sense to have one VBO for that, then have the others in a second VBO? or would you still swap them out in the same VBO? For instance, say I want to make cube world so I have the VBO loaded with a cube, but there are random pyramids and spheres in it too. would I swap out and plug in the pyramid and sphere arrays into that one VBO to render, or would it make sense (and be faster) to give them a separate VBO since they are drawn less frequently?

not sure if that made sense or not.