PDA

View Full Version : Regarding glMapBuffferRange



debonair
01-21-2013, 10:05 AM
GLfloat vertices4[]={-0.9,0.6, -0.9,0.2, -0.6,0.2, -0.6,0.6,
-0.4,0.6, -0.4,0.2, 0.1,0.2, 0.1,0.6,
0.3,0.6, 0.3,0.2, 0.6,0.2, 0.6,0.6 };

GLushort indices[]={0,1,2,3, 120, 4,5,6,7, 120, 8,9,10,11};
GLenum *value=GL_STREAM_DRAW;
GLfloat temp_err;
glEnable(GL_PRIMITIVE_RESTART);
nResult =GL_ERROR_CHECK((GL_NO_ERROR,"glEnable(GL_PRIMITIVE_RESTART)"));

glPrimitiveRestartIndex(120);
nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glPrimitiveRestartIndex(120);"));

glGenBuffers(1,&bufferid1);
nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGenBuffers(1,&bufferid1)"));

glGenBuffers(1,bufferid);

glBindBuffer(GL_TEXTURE_BUFFER,bufferid);

glBufferData(GL_TEXTURE_BUFFER,sizeof(vertices4),v ertices4,*value);

temp_err=(GLfloat*)glMapBufferRange(GL_TEXTURE_BUF FER,0,8*sizeof(GLfloat),GL_MAP_READ_BIT);


glBindBuffer(GL_ARRAY_BUFFER,bufferid1);
nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glBindBuffer(GL_ARRAY_BUFFER,bufferid1);"));

glBufferData(GL_ARRAY_BUFFER,8*sizeof(GLfloat),tem p_err,*value);


*attr_vertex = glGetAttribLocation(shader_data.psId, "a_position");
nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGetAttribLocation(shader_data.psId, \"a_position\");"));

glVertexAttribPointer(*attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);
nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glVertexAttribPointer(attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);"));

glEnableVertexAttribArray(*attr_vertex);
nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glEnableVertexAttribArray(attr_vertex);"));

glUniform1f(glGetUniformLocation(shader_data.psId,"offset_x"),x);
glUniform1f(glGetUniformLocation(shader_data.psId,"offset_y"),y);
glDrawElements(GL_TRIANGLE_FAN, 14,GL_UNSIGNED_SHORT,indices);



Here i am expecting it would render 1 quad as i am passing vertex data of first quad in "bufferid1" but it renders all the 3 quads in vertices4. Please point me where i am going wrong here.

tonyo_au
01-21-2013, 04:54 PM
glDrawElements(GL_TRIANGLE_FAN, 14,GL_UNSIGNED_SHORT,indices);
I am unclear what you would expect to get when you draw past the end of you buffer.

Try

glDrawElements(GL_TRIANGLE_FAN, 4,GL_UNSIGNED_SHORT,indices);