Created
November 25, 2013 10:57
-
-
Save Groovounet/7639664 to your computer and use it in GitHub Desktop.
Ah twitter!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenGL is thread-safe which is actually pretty annoying and expective. | |
OpenGL traditionally uses the "Bind to Edit" model. An alternative is called "Direct State Access" (DSA). | |
Bind to Edit: | |
GLuint Texture(0); | |
glGenTextures(1, &Texture); | |
glBindTexture(GL_TEXTURE_2D, Texture); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
Direct State Access: | |
GLuint Texture(0); | |
glGenTextures(1, &Texture); | |
glTextureParameteriEXT(Texture, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
glTextureParameteriEXT(Texture, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
DSA looks nicer but it's slower because OpenGL is thread safe. Each time an OpenGL texture object is accessed an OpenGL implementation need one mutex to access the table that map OpenGL names to OpenGL objects and one mutex to access the object state modified by the API call. | |
This is because: any thread can create or delete an OpenGL object and any thread can modify an OpenGL object. | |
But DSA remains a better design because there are three approaches to manage OpenGL states: | |
1/ States overwrite (We just set all the states necessarilly) | |
2/ States tracking (We keep a copy of every states) | |
3/ Assumption (We know how the state should at a logical point of the rendering execution.) | |
An OpenGL renderer uses a bit of all that but because every OpenGL call is quite expensive we prefer to avoid 1. | |
DSA is a better approach even if it's more expensive because it's design to provide some garantees to the OpenGL states so that we can use assumption a lot more. We affect the rendering states only when rendering, not when creating objects or do memory transfer. With bind to edit, we need to invalidate some states hence relying on 2 or 1 but in practice more 1 than 2 hence traver the code to reset the OpenGL state because we don't know anymore where we are. | |
So in my opinion glTextureParameteriEXT(Texture, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); or glTextureWrapS(Texture, GL_CLAMP_TO_EDGE), this is proportionally to the problem, quite decorative. | |
If I had to got to decorativeness, I'll rather have real enums starting by 0 for GL_TEXTURE_WRAP_S so that behind a simple table access could allow to access the object state and that would give the same performance that glTextureWrapS without an API number explosion. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using opaque pointers as names should have happened a long time ago. RIP Longs Peak.