This is part of a tutorial series teaching advanced modern OpenGL. To use all features to their fullest you will need to target OpenGL 4.6. These articles assume you have familiarity with OpenGL.
Modern OpenGL is all about improving performance and making the API much easier to use compared to older versions. This article is going to cover the simplest addition to the modern API: Direct State Access (DSA).
What is Direct State Access (DSA)?
DSA is a replacement of the old [bind resource –> edit resource –> unbind resource] model. It meant that if you wanted to update a texture, frame buffer, or storage object, you first had to bind it to a target, then perform some edit that referenced the target, then unbind. Not only was this less than ideal for ease of use and understanding, it also meant a global GL state change was needed every time a resource needed to be edited. DSA gets rid of that.
DSA Examples
This section will provide examples that walk through the old way of doing things, then show the new DSA way of doing things.
For example, here is the old way of copying one framebuffer to another:
With DSA, the above code can be simplified to the following:
Notice that glBlitNamedFramebuffer takes handles to the read and write buffers so that we don’t need to explicitly bind them to read and write points before performing the copy.
Here is an example of the old vs new method of transferring data to a shader storage buffer object (other buffer types supported as well):
Old:
New:
There are also other parts of the API that have received new DSA variants of older functions. Below are a few more examples to show the DSA pattern.
Old:
New:
Old:
New:
Conclusion
The general pattern is that anytime you find yourself using the older method of bind, edit, unbind, consider checking the documentation to see if a DSA version of the function is available so that you can avoid state changes and use the objects more directly instead.