lundi 13 juin 2016

Loss of data between the CPU and GPU when rendering with OpenGL


I have been writing some code for a basic rendering application.

The renderer code consists of setting up Vertex Array and Vertex Buffer Objects for rendering entities, and 3 texture units are created for use as the diffuse, specular and emission component respectively. I wrote a wrapper class for my shader, to create and set uniforms.

void Shader::SetVec3Uniform(const GLchar * name, vec3 data)
{
    glUniform3f(glGetUniformLocation(this->program, name), data);
}

When I set the uniforms using the above function, it doesn't render with the expected result. But when I find the location before I set the uniform, it renders correctly. I use the function below to set it.

void Shader::SetVec3Uniform(GLint loc, vec3 data)
{
    glUniform3f(loc, data.x, data.y, data.z);
}

So my question is, is data lost, is the data not reaching the shader on the GPU in time? I am honestly stumped. No idea why this subtle difference in the way the uniforms are set is causing such a difference in its render.

If anybody can shed any light on this, it would be greatly appreciated.

Thank you in advance.

Cheers!!


Aucun commentaire:

Enregistrer un commentaire