Things about glMapBufferRange

I have been looking into using glMapBufferRange and attempting to understand a few things. And I’m hoping you guys could answer a few questions I got.
If you could explain things to me like I’m 5 too that would greatly appreciated :slight_smile:

Ok question time!

  1. What is the purpose of GL_INVALIDATE_BUFFER_BIT? I thought this flag was to say everything in the current bound VBO is junk so get rid of it. Basically it is used to orphan the current bound VBO. But then I see people saying no use glBufferData and NULL right after you bind the current buffer to map to. Then I see people implying they use all both, the GL_INVALIDATE_BUFFER_BIT flag and glBufferData with NULL

  2. I have read this http://www.java-gaming.org/index.php?topic=28209.0 multiple times and I’m still kind of unsure how this even works with out a Fence backup. I understand that we are trying to write to a buffer that is 6 frames in the past (so it should be fine to write to), but when I attempt this implementation with texture swaps I get garbage on the screen if my buffer count is not just right. EG: I want to render only 3 quads, all of which use a different texture. If I use 6 VBOs everything is good, change that VBO count to 8 and everything on screen looks really gross :frowning:

  1. GL_INVALIDATE_BUFFER_BIT is the same as glBufferData with NULL. They both orphan the current buffer. Just use that bit flag instead of the latter function to cut down on GL calls.

  2. How are you unsure it could work without a Fence when you understand that it’s 6 frames in the past therefore it should be fine? Your issue sounds like something else rather than the VBO count. How are you rendering with texture swaps, 3 glDraw* calls?

I’m doing batching them based on texture. There is no sort or anything etc. Just plain and simple:

Map current buffer
Draw X quads using texture 1
Draw X quads using texture 2
Here is where I unmap the current buffer, use the current bound texture (in this case texture 1), and call my render code for all the quads I need to draw for texture q.
Then change the texture to be bound to texture 2. Map the buffer and continue the fill
Draw X quads of anything else. Repeat the above if the texture changes
After all draw calls render anything else left

Based on the example I gave, yeah we are talking 3 glDraw*** calls per frame

Also GL_MAP_UNSYNCHRONIZED_BIT and GL_INVALIDATE_BUFFER_BIT just give me garbage when I swap texture