Waste one day on this function and get nothing.
The only example I found on github is this example.
https://github.com/multiprecision/sph_opengl
It does work but lack of example about updating Uniform buffer.
When I got something like this
#version 460
uniform UniformBufferObject
{
mat4 model;
mat4 view;
mat4 proj;
}ubo;
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
layout (location = 0) out vec2 TexCoord;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(aPos, 1.0f);
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
}
I can not pass model,view,proj matrix to shader correctly in cpp.
The old version 330 from LearnOpengl will work for non binary shader,glShaderSource from text will work.
But I really want to try to use glShaderBinary
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
out vec2 TexCoord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0f);
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
}
This shader format does not compile with glslangValidator.
https://github.com/KhronosGroup/glslang
So I have to use that 460 version and don't know how to pass matrix to it correctly.
I tried to use Uniform buffer,map,unmap,not work.
glBindBuffer(GL_UNIFORM_BUFFER, UBO);
GLvoid* p = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
memcpy(p, &uboVS, sizeof(uboVS));
glUnmapBuffer(GL_UNIFORM_BUFFER);
and glGetUniformLocation always return -1,no matter what name I use
glGetUniformLocation(xxx,"ubo")
glGetUniformLocation(xxx,"UniformBufferObject")
glGetUniformLocation(xxx,"model")
All Fail.
if I change
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(aPos, 1.0f);
to
gl_Position = vec4(aPos, 1.0f);
Then the shader works,which means all the matrix not pass to shader correctly and they are all Zero I think.
So anybody know how to use glShaderBinary with glslangValidator updating Uniform buffer on OpenGL?
I am not sure if this 460 shader is correct,It just pass glslangValidator compile.