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 4 of 4

Thread: glFlushMappedBufferRange and GL_INVALID_VALUE

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    7

    glFlushMappedBufferRange and GL_INVALID_VALUE

    Hi!
    I'd like to upload a bunch of vertices of meshes (simple arrays of float values x,y,z) into a single vbo. I've created a unique buffer with the total ammount of bytes needed to contains all the vertices

    Code :
    glBufferData(buffer->glTarget, buffer->nTotalBytes, 0, buffer->glUsage);

    then reading each mesh vertices array i'd like to copy those bytes into the buffer, each at the right offset inside the VBO. to do that i calculate the offset and size of each array to copy then i call a function that simply do this

    Code :
    // Bind the buffer for use
    glBindBuffer(buffer->glTarget, buffer->glId);
     
    GLvoid* data_pointer = glMapBufferRange(
            buffer->glTarget,
            offset, // Offset
            size,    // Size,
            GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
     
    // copy the data
    uploadFunction(data_pointer);
     
    // flush the data
    glFlushMappedBufferRange(buffer->glTarget, offset, size);
     
    // release the buffer pointer
    glUnmapBuffer(buffer->glTarget);
     
    // Unbind the buffer
    glBindBuffer(buffer->glTarget, 0);

    offset is 0 at the begin, size is the size of the array in bytes, then the next mesh offset+= size, size = new_mesh_size. The problem is that at the second mesh copy, when i flush the data, OpenGL gives me a GL_INVALID_VALUE error. I checked all the ranges values and everything is ok (the buffer is like 2 Mbytes and the first mesh is like 3000 vertices, the second 1000) and if the ranges are wrong i'd assume glMapBufferRange would give me an error first, isn't it?

    If i remove the flush and let it do the operation automatically with glUnmapBuffer there's no error. Any ideas why i cannot flush the second slice?

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290
    If your drivers support debug-output, that can help you.
    http://www.opengl.org/wiki/Debug_Output

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    7
    Is it possible that the offset you need to specify for the flush command is relative to the interval set in glMapBufferRange itself?

    For example glMapBufferRange has 1000 as offset and 500 as size of the interval. The flush offset has to be between 0 and 500, not between 1000 and 1500.

    I've tried to flush with that in mind and it works. If i add +1 to the range the error returns, so...

    All the examples i've found just upload data from the begin of the buffer and flush everything so you cannot understand how it works.

    I'll check debug output too

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290
    You're right; from the spec:
    The specified subrange to flush is relative to the start of the currently mapped range of buffer

Posting Permissions

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