PDA

View Full Version : glMapBuffer() returns NULL



SKoder
02-11-2005, 07:14 AM
I use dynamic draw buffer, and I'm trying to map the buffer, but glMapBuffer() returns NULL

How I can solve this problem?

yooyo
02-11-2005, 07:25 AM
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

SKoder
02-11-2005, 07:31 AM
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

Aeluned
02-11-2005, 08:12 AM
Do you have a current context?

SKoder
02-11-2005, 08:27 AM
yes

zeckensack
02-13-2005, 06:18 AM
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. 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.
<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.

zeckensack
02-13-2005, 06:25 AM
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?

SKoder
02-17-2005, 01:19 AM
I already solved the problem by using this:

glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);