Beginning with UBOs.

Hi there,

I am trying to teach myself how to use UBOs for a multitude of reasons. Right now, I’ve got a Context class that handles all the SDL stuff, an Object class which creates VBOs and initializes textures and such, and a Shader class for the obvious (all in C++). The Shader class has 2 methods, one that creates a UBO and one that fills the data. The shaders I’m using have 2 uniform blocks, called Projection and Model. Projection contains 2 matrices, vProjection and vCamera, while Model has 3: vTranslate, vRotate and vScale.

When an Object is initialized, it calls on Shader to return 2 UBOs for Project and Model. It then proceeds to stuff its own 5 matrices corresponding to the ones in the shader, into the buffer. After this, I can render and all is well.

However, here is my problem. Whenever I render, an Object gets translated to the location specified in its constructor. This means a call to a function that does the translation. If I render, say, 2 objects, next to each other, they both get created properly, and the Object::draw() function is happily drawing both items. Thing is, I can only see the last object drawn. I’m under the impression that after Object initialization, every Object uses those UBOs, and so each object gets rendered on top of the others (they’re all cubes with the same texture, for testing purposes). This would mean that although each Object has its own 2 UBOs, the class isn’t rebinding them to the shader program whenever it’s about to draw.

I’ve tried a the glBindBufferBase/Range and the glUniformBinding for both UBOs per object, and even reuploading the data to the UBO after rebinding, but all I get is that nothing gets rendered at all. gDEBugger does tell me the UBOs get created with the proper data in them, it just seems as if I’m not binding the UBOs to the shaderprogram per object properly. The documentation on the net is a bit sparse on UBOs, so I was wondering if someone could help me with this.

Thanks in advance.