I use dynamic draw buffer, and I’m trying to map the buffer, but glMapBuffer() returns NULL
How I can solve this problem?
I use dynamic draw buffer, and I’m trying to map the buffer, but glMapBuffer() returns NULL
How I can solve this problem?
Did you call glBindBuffer before glMapBuffer?
Did you call glBufferData first time after glGenBuffers call. You can’t map buffer before buffer initialization with glBufferData call.
yooyo
Yes I did all that.
Creation code:
glGenBuffersARB(1, &VertexVBO);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexVBO);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, x, data, GL_DYNAMIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
Mapping the buffer:
void* PP;
glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexVBO);
PP = glMapBufferARB(VertexVBO, GL_WRITE_ONLY_ARB);
//PP is NULL
Do you have a current context?
yes
Check for errors. Implementations return NULL from MapBuffer to indicate failure to map. The spec does not mandate that any mappings succeed, so it would be legal for an implementation to always fail a map. In this case Buffer(Sub)Data must be used to fill in the object data.
What should the error behavior of BufferDataARB and MapBufferARB be?
RESOLVED: BufferDataARB returns no value and sets OUT_OF_MEMORY if the buffer could not be created, whereas MapBufferARB returns NULL and also sets OUT_OF_MEMORY if the buffer could not be mapped.
The entire data store of a buffer object can be mapped into the client's address space by calling
void *MapBufferARB(enum target, enum access);
with <target> set to ARRAY_BUFFER_ARB. [b]If the GL is able to map the buffer object's data store into the client's address space, MapBufferARB returns the pointer value to the data store. Otherwise MapBufferARB returns NULL, and the error OUT_OF_MEMORY is generated.[/b] <access> is specified as one of READ_ONLY_ARB, WRITE_ONLY_ARB, or READ_WRITE_ARB, indicating the operations that the client may perform on the data store through the pointer while the data store is mapped.
I must add that this is very unlikely to be the explanation …
1)What’s the value of “x” in your BufferData call?
The driver might refuse to allocate a very large buffer object. This call would then generate an error, there would be no buffer and it would be only logical for MapBuffer to fail then.
Obviously values <=0 won’t work either.
2)What hardware and driver version are you using?
I already solved the problem by using this:
glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);