OpenGL Direct State Access (DSA)



GPU Caps Viewer, OpenGL GL_EXT_direct_state_access extension
GPU Caps Viewer 1.9.5, GL_EXT_direct_state_access extension on a GTX 470


Direct State Access or DSA is an useful OpenGL extension that allows to update (or query) OpenGL states in a direct way without using an OpenGL state selector. GL_EXT_direct_state_access is available for AMD Radeon cards since Catalyst 10.7 (July 2010) and since ForceWare 180.42 (October 2008) for NVIDIA GeForce boards. This extension should be supported (partially) by any OpenGL 2.1 compliant implementation and complete support should be available in any OpenGL 3.0 compliant implementation (please, correct me if I’m wrong).

DSA introduces new OpenGL functions like glProgramUniform_XXX_EXT() for setting GPU program uniform variables, or glFramebufferTexture2DEXT() for attaching a logical buffer to a FBO. All new functions and complete specification can be found here: GL_EXT_direct_state_access @ OpenGL registry.

Here are some simple examples with and without DSA:


GLSL Uniform Variables

Without DSA:

glUseProgram(progId);
glUniform1f(loc, x); 

With DSA:

glProgramUniform1fEXT(progId, loc, x); 

As you can see, DSA is really handy for updating uniform variables.


2D Texture Uploading

Without DSA:

glGenTextures(1, &tid);
glBindTexture(GL_TEXTURE_2D, tid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, \
             w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixmap);

With DSA:

glGenTextures(1, &tid);
glTextureImage2DEXT(tid, GL_TEXTURE_2D, 0, GL_RGBA8, \
                    w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixmap);


Simple FBO Creation

Without DSA:

glGenTextures(1, &tid);
glBindTexture(GL_TEXTURE_2D, tid);
glTextureImage2DEXT(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, \
                    GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);

glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, \ 
                       GL_TEXTURE_2D, tid, 0);

With DSA:

glGenTextures(1, &tid);
glTextureImage2DEXT(tid, GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, \ 
                    GL_RGBA, GL_UNSIGNED_BYTE, 0);

glGenFramebuffers(1, &fbo);
glNamedFramebufferTexture2DEXT(fbo, GL_COLOR_ATTACHMENT0, \ 
                               GL_TEXTURE_2D, tid, 0);


Modelview Matrix

Not really useful in modern OpenGL 3 or 4 code but still useful in OpenGL 2 code:

Without DSA:

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(matrix);

With DSA:

glMatrixLoadfEXT(GL_MODELVIEW, matrix);



I’ll try to use DSA in my OpenGL codes (GeeXLab, MSI Kombustor, FurMark, TessMark, etc.).

G-Truc has updated its OpenGL code samples pack with several code samples about DSA. You can download the code samples pack and read additional information about DSA here: OpenGL Samples Pack 4.1.4.0 released, focus on DSA





[ Subscribe to Geeks3D latest news by email ]

Geeks3D.com

↑ Grab this Headline Animator