//IDs for the buffer objects holding the uniform block data
GLuintscene_ubo=-1;
GLuintlight_ubo=-1;
GLuintmaterial_ubo=-1;
namespaceUboBinding
{
//These values come from the binding value specified in the shader block layout
intscene=0;
intlight=1;
intmaterial=2;
};
//Locations for the uniforms which are not in uniform blocks
namespaceUniformLocs
{
intM=0;//model matrix
inttime=1;
};
voidInit()
{
//Create and initialize uniform buffers
glGenBuffers(1,&Uniforms::scene_ubo);
glBindBuffer(GL_UNIFORM_BUFFER,scene_ubo);
glBufferData(GL_UNIFORM_BUFFER,sizeof(SceneUniforms),nullptr,GL_STREAM_DRAW);//Allocate memory for the buffer, but don't copy (since pointer is null).
glBindBufferBase(GL_UNIFORM_BUFFER,UboBinding::scene,scene_ubo);//Associate this uniform buffer with the uniform block in the shader that has the same binding.
glGenBuffers(1,&light_ubo);
glBindBuffer(GL_UNIFORM_BUFFER,light_ubo);
glBufferData(GL_UNIFORM_BUFFER,sizeof(LightUniforms),&LightData,GL_STREAM_DRAW);//Allocate memory for the buffer, but don't copy (since pointer is null).
glBindBufferBase(GL_UNIFORM_BUFFER,UboBinding::light,light_ubo);//Associate this uniform buffer with the uniform block in the shader that has the same binding.
glGenBuffers(1,&material_ubo);
glBindBuffer(GL_UNIFORM_BUFFER,material_ubo);
glBufferData(GL_UNIFORM_BUFFER,sizeof(MaterialUniforms),&MaterialData,GL_STREAM_DRAW);//Allocate memory for the buffer, but don't copy (since pointer is null).
glBindBufferBase(GL_UNIFORM_BUFFER,UboBinding::material,material_ubo);//Associate this uniform buffer with the uniform block in the shader that has the same binding.
glBindBuffer(GL_UNIFORM_BUFFER,0);
}
voidBufferSceneData()
{
glBindBuffer(GL_UNIFORM_BUFFER,scene_ubo);//Bind the OpenGL UBO before we update the data.
glBufferSubData(GL_UNIFORM_BUFFER,0,sizeof(SceneData),&SceneData);//Upload the new uniform values.
glBindBuffer(GL_UNIFORM_BUFFER,0);//unbind the ubo