Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: glMapBuffer() returns NULL

  1. #1
    Intern Newbie
    Join Date
    Sep 2004
    Location
    Latvija, Riga
    Posts
    32

    glMapBuffer() returns NULL

    I use dynamic draw buffer, and I'm trying to map the buffer, but glMapBuffer() returns NULL

    How I can solve this problem?

  2. #2
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    872

    Re: glMapBuffer() returns NULL

    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

  3. #3
    Intern Newbie
    Join Date
    Sep 2004
    Location
    Latvija, Riga
    Posts
    32

    Re: glMapBuffer() returns NULL

    Yes I did all that.

    Creation code:
    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:
    Code :
    	void* PP;
    	glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexVBO);
    	PP = glMapBufferARB(VertexVBO, GL_WRITE_ONLY_ARB);
    	//PP is NULL

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    570

    Re: glMapBuffer() returns NULL

    Do you have a current context?

  5. #5
    Intern Newbie
    Join Date
    Sep 2004
    Location
    Latvija, Riga
    Posts
    32

    Re: glMapBuffer() returns NULL

    yes

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,633

    Re: glMapBuffer() returns NULL

    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.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,633

    Re: glMapBuffer() returns NULL

    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?

  8. #8
    Intern Newbie
    Join Date
    Sep 2004
    Location
    Latvija, Riga
    Posts
    32

    Re: glMapBuffer() returns NULL

    I already solved the problem by using this:

    glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •