Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glMapBuffer Returns 0x00000000 constantly

I have initialized glewInit( ) and any other openGL stuff. all before i do any of these calls.

  glGenBuffers( 1, &m_uiVertBufferHandle );
  glBindBuffer( GL_ARRAY_BUFFER, m_uiVertBufferHandle );
  glBufferData( GL_ARRAY_BUFFER, 0, 0, GL_READ_WRITE );
  glBindBuffer( GL_ARRAY_BUFFER, 0 );

this is how i create my buffer object i i did the glBufferData because i have read in openGL articles that you do not have any storage space at all if you do not call it at least once which would make glMapBuffer always give you 0x00000000.

later on i call glMapBuffer to get my storage location to start saving data when i use glMapBuffer i call it like this

void* buffer1; 
glBindBuffer( GL_ARRAY_BUFFER, m_uiVertBufferHandle );

//make sure our buffer excists
buffer1 = glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE );

i always get 0x00000000 in my buffer1. Why is this? the only 2 causes i have found at all were that i didn't initialize glewInit properly which i have done and that i wasnt calling glBindBufferData at least once.

like image 668
Franky Rivera Avatar asked Dec 30 '25 23:12

Franky Rivera


2 Answers

glBufferData( GL_ARRAY_BUFFER, 0, 0, GL_READ_WRITE );

GL_READ_WRITE is not a valid usage for buffer objects. You use that for mapping, not the buffer object's usage. Usage parameters are stuff like GL_STATIC_DRAW, or more reasonably for your "read/write" case, GL_DYNAMIC_READ.

Because you passed an invalid enum, OpenGL gave you a GL_INVALID_ENUM error and failed to execute this command. Also, 0 length buffer object is not a reasonable size for the buffer's storage. Try new int[0] or malloc(0) sometime and see what happens.

Please stop allocating miniscule or non-existent sizes of data. Allocate 4096 bytes or something if you really want to test this.

like image 56
Nicol Bolas Avatar answered Jan 01 '26 13:01

Nicol Bolas


You pass 0 as the size of the buffer into glBufferData. This means that OpenGL implementation does not know the size (even theoretical) of your buffer and does not know how to map this zero-sized buffer.

Use non-zero value as the size and NULL as the data pointer, i.e:

glBufferData( GL_ARRAY_BUFFER, SizeOfTheBuffer, NULL, GL_READ_WRITE );

P.S. GL_READ_WRITE is not a valid usage for buffer objects.

like image 21
Sergey K. Avatar answered Jan 01 '26 15:01

Sergey K.