That’s good news! EXT_bindable_uniform is already really good to me.
V-man, I can give you a code sample, it’s not really a big deal … even if it took me a will to figure it out XD. [/QUOTE]
Go ahead. Where is it? [/QUOTE]
Here, just sample code next, at the end, all the final to build and run in on Windows with VC8 (through CMake) buut first some commnet on it:
- This code purpose is just to show the feature.
- In a real software, the idea of sharing the uniform buffer between a vertex and fragment shader … Maybe not.
- The uniform buffer data should be considered as raw data, like any buffer. In the sample I use an array of vec4 just to keep it simple.
The vertex shader:
#version 120
#extension GL_EXT_bindable_uniform : enable
struct common
{
mat4 MVP;
vec4 Color;
};
bindable uniform common Common;
attribute vec2 Position;
void main()
{
gl_Position = Common.MVP * vec4(Position, 0.0, 1.0);
}
The fragment shader:
#version 120
#extension GL_EXT_bindable_uniform : enable
struct common
{
mat4 MVP;
vec4 Color;
};
bindable uniform common Common;
void main()
{
gl_FragColor = Common.Color;
}
Uniform buffer init:
bool CMain::initBindableBuffer()
{
std::size_t const BindableBufferSize = glGetUniformBufferSizeEXT(programName, uniformLocation);
bindableData[4] = glm::vec4(1.0f, 0.5f, 0.0f, 1.0f);
glGenBuffers(1, &bindableBufferName);
glBindBuffer(GL_UNIFORM_BUFFER_EXT, bindableBufferName);
glBufferData(GL_UNIFORM_BUFFER_EXT, BindableBufferSize, &bindableData[0][0], GL_STATIC_READ);
glBindBuffer(GL_UNIFORM_BUFFER_EXT, 0);
return true;
}
Get uniform buffer structure location:
uniformLocation = glGetUniformLocation(programName, "Common");
Uniform buffer use:
glBindBuffer(GL_UNIFORM_BUFFER_EXT, bindableBufferName);
glBufferSubData(GL_UNIFORM_BUFFER_EXT, 0, sizeof(glm::mat4), &bindableData[0][0]);
glUniformBufferEXT(programName, uniformLocation, bindableBufferName);
glBindBuffer(GL_UNIFORM_BUFFER_EXT, 0);
The working code is here:
http://groove.g-truc.net/g-tut-pack-ogl-dev.7z
Look at the sample called “ogl2x-buffer-bindable”
It uses CMake but have been tested only on VC8 … There is a lot more that just this bindable uniform samples but first it’s still under development and second it’s not really easy to extra an single sample the way its design.