PDA

View Full Version : Uniform Buffer debugging



CaptainSnugglebottom
05-05-2017, 09:46 AM
Hello,


In my project I am using the uniform buffers in order to pass scene-wide variables such as camera and projection matrices. Both matrices are loaded before the frame is drawn. Unfortunately, when I got back to working on this project after some time, the uniform buffers stopped updating. They load just fine in the beginning, and the update function is called before each new frame, however, no change takes place.

At first I thought it was my driver, which I updated while I was not working on the thing. I updated it to the newest version, and a new bug appeared, so I rolled it back (I don't want to deal with 2 major bugs at the same time). So I know it's not the driver issue. On my application side everything is functioning as well, every array/matrix gets updated as it's supposed to. I tried to narrow the issue down, and it is in fact the uniform buffer.

Question: How does one debug this issue? I know there's no direct way to extract the values from GLSL when the application is running, so what would my alternative options be?

This is my matrix definitions and usage in the shader (the short version)


#version 430

...

// CAMERA SPACE
layout(std140, binding = 2) uniform cameraVars
{
mat4 projectionMat; // 64 bytes
mat4 cameraMat; // 128 bytes
};

...

void main() {
...
mat4 transformMat = cameraMat*objectPosMat*objectRotZMat*objectRotYMat *objectRotXMat; //cameraMat
...

gl_Position = projectionMat*transformMat*vec4(vertexPos, 1.0); //projectionMat
}



The buffer is created using:


// CAMERA MATRICES BUFFER OBJECT
glGenBuffers(1, &(this->subSceneUniformBufferObject));
glBindBuffer(GL_UNIFORM_BUFFER, this->subSceneUniformBufferObject);
glBufferData(GL_UNIFORM_BUFFER, 128, NULL, GL_STATIC_DRAW); // allocate 128 bytes of memory, point 2
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glBindBufferRange(GL_UNIFORM_BUFFER, 2, this->subSceneUniformBufferObject, 0, 128);



... And loaded/updated using:


// LOADING INTO BUFFER ///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
glBindBuffer(GL_UNIFORM_BUFFER, this->subSceneUniformBufferObject);
glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, this->projectionMat);
glBindBuffer(GL_UNIFORM_BUFFER, 0);

// LOADING INTO BUFFER ///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

glBindBuffer(GL_UNIFORM_BUFFER, this->subSceneUniformBufferObject);
glBufferSubData(GL_UNIFORM_BUFFER, 64, 64, this->cameraMat);
glBindBuffer(GL_UNIFORM_BUFFER, 0);


Any ideas?

UPDATE:

I have narrowed it down further. Apparently the issue is caused by me creating 2 different layers (I use layers, each containing its own objects to render, the layers then get stacked to make the final output). While all my objects are in the first layer, once I make a new empty layer the camera on the first layer stops updating. Both layers are using the same shader to render things.

Could it be that, when 2nd layer is being created, and creates its own buffer for camera values, it somehow affects the first layer's uniform buffer object?

Can this be fixed without using new binding point for each layer? Instead, I want to make each layer rewrite the uniform at the same binding point before the layer draws objects. I think I am missing rebinding the buffer object to specific point after each new layer starts rendering.