OpenGL glMapBuffer/glMapBufferRange

This entry is part 4 of 4 in the series Learning OpenGL

I’ve changed the last program a bit to use glMapBufferRange instead of glBufferSubData. For this specific example, there isn’t really any advantage in using glMapBufferRange over glBufferSubData, but in general, it has better performance than glBufferSubData.

I was actually going to change a bit more code, but I wasted quite a bit of time for a new laptop (from Santa) which turned out to have hardware issues (50% of laptops I’ve owned so far had defects when I got them – what a jinx I am).

You can find my latest OpenGL program as always on github.

Why glMapBuffer/glMapBufferRange?

The problem with glBufferData as well as with glBufferSubData is that you need to allocate some memory provided by your application before you can copy it to memory owned by OpenGL. Let’s assume you have a file with all vertex data. Wouldn’t it be nice to directly read that file into OpenGL memory? That’s exactly what glMapBuffer and glMapBufferRange is good for. You avoid wasting memory and copying operations. If you compare my code in ‘OpenGL – Beginner 4’ and ‘OpenGL – Beginner 5’, you’ll find that the usage of glMapBufferRange and glBufferSubData is very similar.

I suggest reading OpenGL’s wiki about mapping for a detailed explanation.

Series Navigation<< OpenGL glBufferSubData

Leave a Reply

Your email address will not be published. Required fields are marked *