Advertisement

Any example about glShaderBinary updating Uniform buffer on windows?

Started by July 28, 2018 05:30 PM
1 comment, last by Hurmuz 6 years, 6 months ago

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.

Not sure if you still have this problem, but I think you should take a look at this: https://www.khronos.org/opengl/wiki/Program_Introspection#Naming.

"The introspection APIs will often make a single "variable" definition in GLSL appear as though it were multiple variables. This is done for variables that are not basic types or arrays of basic types (note that in GLSL, "basic types" include vector and matrix types).

For example, consider the following:


struct A_Struct 
{ 
	vec4 first; 
	vec2 second; 
	vec2 third[3]; 
}; 

uniform A_Struct unif;

The struct itself cannot be queried via the introspection API; the struct is just a prototype, an aggregate type definition. The variable unif is a uniform, of type `A_Struct`.

However, if you try to get the uniform location, or any other property, of unif, you will be unable to do so. As far as the introspection API is concerned, there is no unif. Because the introspection API is built around basic types, struct aggregates of basic type are not directly visible.

Instead, each sub-element of the struct that is a basic type is visible. So there is a uniform named unif.first. There is a uniform named unif.second. And so forth."

 

This topic is closed to new replies.

Advertisement