ajith.mk

12-21-2015, 10:00 AM

Hi everyone,

The below code draws a triangle..

int m_loc=glGetUniformLocation(program,"model_marrix);

Int v_loc=glGetUniformLocation(program,"view_matrix);

int p_loc=glGetUniformLocation(program,"proj_matrix);

glUniformMatrix4fv(m_location,1,GL_FALSE,my_model) ;

glUniformMatrix4fv(v_location,1,GL_FALSE,my_view);

glUniformMatrix4fv(p_location,1,GL_FALSE,my_proj);

//Vertex shader

uniform mat4 proj_matrix;

uniform mat4 view_matrix;

uniform mat4 model_matrix;

void main()

{

const vec4 position[3]=blah blah blah;

gl_Position=proj_matrix*view_matrix*model_matrix*p osition[gl_VertexID];

}

while the below one doesn't

GLuint uboHandle;

glGenBuffer(1,&uboHandle);

glBindBufferBase(GL_UNIFORM_BUFFER,4,uboHandle);

GLfloat my_data[48]={xxxxx....};

glBufferData(GL_UNIFORM_BUFFER,48*sizeof(GLfloat), my_data,GL_DYNAMIC_DRAW);

//Vertex shader

layout(std140,binding=4) uniform matrices

{

mat4 model_matrix;

mat4 view_matrix;

mat4 proj_matrix;

};

void main()

{

const vec4 position[3]=blah blah blah;

gl_Position=proj_matrix*view_matrix*model_matrix*p osition[gl_VertexID];

}

Data in the buffer is the same data sent in first code. I checked it using glGetBufferSubData. Anyway they are all mat4s. So layout is trivial. So data and matrices are all fine since the first code worked.Matrices declaration order is not the same but I took care of it while filling the buffer. Somehow my shader fails to access data from named uniform block. Wondering what might be the problem.

The below code draws a triangle..

int m_loc=glGetUniformLocation(program,"model_marrix);

Int v_loc=glGetUniformLocation(program,"view_matrix);

int p_loc=glGetUniformLocation(program,"proj_matrix);

glUniformMatrix4fv(m_location,1,GL_FALSE,my_model) ;

glUniformMatrix4fv(v_location,1,GL_FALSE,my_view);

glUniformMatrix4fv(p_location,1,GL_FALSE,my_proj);

//Vertex shader

uniform mat4 proj_matrix;

uniform mat4 view_matrix;

uniform mat4 model_matrix;

void main()

{

const vec4 position[3]=blah blah blah;

gl_Position=proj_matrix*view_matrix*model_matrix*p osition[gl_VertexID];

}

while the below one doesn't

GLuint uboHandle;

glGenBuffer(1,&uboHandle);

glBindBufferBase(GL_UNIFORM_BUFFER,4,uboHandle);

GLfloat my_data[48]={xxxxx....};

glBufferData(GL_UNIFORM_BUFFER,48*sizeof(GLfloat), my_data,GL_DYNAMIC_DRAW);

//Vertex shader

layout(std140,binding=4) uniform matrices

{

mat4 model_matrix;

mat4 view_matrix;

mat4 proj_matrix;

};

void main()

{

const vec4 position[3]=blah blah blah;

gl_Position=proj_matrix*view_matrix*model_matrix*p osition[gl_VertexID];

}

Data in the buffer is the same data sent in first code. I checked it using glGetBufferSubData. Anyway they are all mat4s. So layout is trivial. So data and matrices are all fine since the first code worked.Matrices declaration order is not the same but I took care of it while filling the buffer. Somehow my shader fails to access data from named uniform block. Wondering what might be the problem.