• Advertisement
Sign in to follow this  

glMapBufferRange and a offset

This topic is 1215 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

EDIT: If it helps I figured out they are drawing right on top of each other, but I don't know why sad.png Maybe my glDraw*** call is messed up? When ever I need to render I use: glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_SHORT, NULL). Also I'm using a VAO, which says that my VBO is interleaved and the IBO attached to it


I was wondering if someone could tell me what I'm doing wrong. I can't seem to understand why I'm only able to draw 2 of my 4 quads
So for testing purposes, I have a large VBO that can fit a total of 4 quads in it. I have then split it in half, so each half of the VBO can fit 2 quads (I only lock down one half of the buffer). My problem comes in when try to change the currently bound texture or if I know I'm going to go over the current map range.
My problem is I can only get the last 2 quads to show. The first two do not show at all, I think I might be the way I map my data.
My basic run down is like this:

void MapBuffer()
        offset = 0;
        data = glMapBufferRange(GL_ARRAY_BUFFER, offset, bufferSlice, GL_MAP_WRITE_BIT | GL_INVALIDATE_BUFFER_BIT)
        data = glMapBufferRange(GL_ARRAY_BUFFER, offset, bufferSlice, GL_MAP_WRITE_BIT)

void Draw(GLuint texture, float x, float y, float width, float height)
    if(currTexture != texture || mapIndex+1 > maxMapIndex)
        Render(); // In here I'm using glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_SHORT, NULL);
        mapIndex = 0;
        indicesCount = 0;
    //The quads are dynamic so fill the buffer like so:
    ((GLfloat*)data)[mapIndex] = x;
    ((GLfloat*)data)[mapIndex+1] = x;
    ((GLfloat*)data)[mapIndex+2] = z;
    ((GLfloat*)data)[mapIndex+3] = u1;
    ((GLfloat*)data)[mapIndex+4] = v1;
    // Repeat for the remaining vertex data. All the way to ((GLfloat*)data)[mapIndex+19]

    offset += DATA_SIZE_PER_QUAD
    mapIndex += 20;
    indicesCount += 6;

void main()
    const GLfloat DATA_SIZE_PER_QUAD = sizeof(GLfloat) * (3 + 2) * 4; //XYZ and the UV cords for each vertex. Times GLfloat for each corner. So 80 bytes
    int mapIndex = 0;
    int maxQuadCount = 4;
    int maxMapIndex = ((3 + 2) * 4) * maxQuadCount;
    int maxDataSize = maxQuadCount * DATA_SIZE_PER_QUAD;
    int BufferSlice = maxDataSize/2;
    int offset = 0;
    //... Other init code

//... polling event code
MapBuffer(); //Starting map
     Draw(text1, 0, 0, 32, 32);
     Draw(text1, 50, 50, 32, 32);
     Draw(text2, 100, 100, 32, 32);
     Draw(text2, 150, 150, 32, 32);
     UnmapBuffer(); //ending unmap
     Render(); //Draw whatever else needed

Can anyone tell me where I'm messing up?

Edited by noodleBowl

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement