Jump to content
  • Advertisement
Sign in to follow this  
noodleBowl

Help on glMapBuffer*** Calls

This topic is 1427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Edited ignore everything, I spoke too soon smile.png

 

Final code just in case it help someone

GLvoid *p = glMapBufferRange(GL_ARRAY_BUFFER, 0, FLOATS_PER_QUAD * sizeof(GLfloat), GL_MAP_WRITE_BIT);
 
if (p == NULL)
{
std::cout << "Null ptr: " << glGetError()<< std::endl;
glUnmapBuffer(GL_ARRAY_BUFFER);
return;
}
 
((GLfloat*)p)[0] = 0.0f;
((GLfloat*)p)[1] = 0.0f;
((GLfloat*)p)[2] = 0.0f;
 
((GLfloat*)p)[3] = 0.0f;
((GLfloat*)p)[4] = 32.0f;
((GLfloat*)p)[5] = 0.0f;
 
((GLfloat*)p)[6] = 32.0f;
((GLfloat*)p)[7] = 32.0f;
((GLfloat*)p)[8] = 0.0f;
 
((GLfloat*)p)[9] = 32.0f;
((GLfloat*)p)[10] = 0.0f;
((GLfloat*)p)[11] = 0.0f;
 
glUnmapBuffer(GL_ARRAY_BUFFER);
 
glUseProgram(shaderProgramID);
glUniformMatrix4fv(matrixUniform, 1, GL_FALSE, uniformMatrix->matrix);
 
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);
glBindVertexArray(NULL);
 
glUseProgram(NULL);
 

---------------------------------------------------------------

 

Edit2:

 

My real question:

What am I doing wrong here? I keep getting back a NULL pointer to my buffer. glGetError() gives me back a 1282 error code [ GL_INVALID_OPERATION ]

 
glBindBuffer(GL_ARRAY_BUFFER, vbo);
GLvoid *p = glMapBufferRange(GL_ARRAY_BUFFER, 0, FLOATS_PER_QUAD * sizeof(GLfloat), GL_WRITE_ONLY);
 
if (p == NULL)
{
std::cout << "Null ptr: " << glGetError()<< std::endl;
glUnmapBuffer(GL_ARRAY_BUFFER);
return;
}
 
((GLfloat*)p)[0] = 0.0f;
((GLfloat*)p)[1] = 0.0f;
((GLfloat*)p)[2] = 0.0f;
 
((GLfloat*)p)[3] = 0.0f;
((GLfloat*)p)[4] = 32.0f;
((GLfloat*)p)[5] = 0.0f;
 
((GLfloat*)p)[6] = 32.0f;
((GLfloat*)p)[7] = 32.0f;
((GLfloat*)p)[8] = 0.0f;
 
((GLfloat*)p)[9] = 32.0f;
((GLfloat*)p)[10] = 0.0f;
((GLfloat*)p)[11] = 0.0f;
 
glUnmapBuffer(GL_ARRAY_BUFFER);
 

-------------------------------------------------------------------------------------
 

Hey everyone, I was wondering if someone could better explain the glMapBuffer*** calls.

 

I understand that glMapBuffers*** returns a void pointer to the buffer, but the thing I don't understand is how do I map the buffer?

All the examples I see do a memcpy of sorts to place data into it.

EG:

void * vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy(vbo_buffer, vertexs, vertex_size);
glUnmapBuffer(GL_ARRAY_BUFFER);

But is there way to directly place data into the buffer? Through pointer arithmetic or something?

EG [I know this is wrong, but somehting like]:

void * vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
 
*(vbo+1) = 0.0f;
*(vbo+2) = 0.0f;
*(vbo+3) = 0.0f;
*(vbo+4) = 32.0f;
*(vbo+4) = 0.0f;
//etc....
 
glUnmapBuffer(GL_ARRAY_BUFFER);
Edited by noodleBowl

Share this post


Link to post
Share on other sites
Advertisement

The glMapBufferRange function has slightly different access flags from glMapBuffer to allow more fine-grained control. You should be using GL_MAP_WRITE_BIT instead of GL_WRITE_ONLY. See https://www.opengl.org/sdk/docs/man/html/glMapBufferRange.xhtml :)

 

You should consider using the debug output functions if you're able to use it, which should give you more specific error messages in actual text and makes debugging a hell of a lot easier!

Share this post


Link to post
Share on other sites

Xycaleth already mentioned you are using the flags wrong, check out his links.

To increase readability you can also static-cast the returned pointer only once, and access him like a float-array.

 

For advanced information about buffer transfers I can recommend this GL 4.2 article:
http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf

Edited by Maus

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!