One feature I think will be good to have for opengl to progress is to allow for baking of resources into memory and then load them for later use. Lets say for instance you want to load a png into a texture and use mip mapping and DXT1 compression, which is common. You would have to decode the png then opengl would have to compress it as DXT1 then create mip maps for the texture. This in total would take for instance would take 300 milliseconds for a 1024x1024 texture(rough estimates). What if there was a function which takes the texture as it is in memory and stored it as a memory stream and have it loaded later directly into memory as is with out any pre processing. This would allow it to load in 3 milliseconds using glCompressedTexImage2D for each level, but then you still have to make additional calls to set the state for that texture. What if there was one call that would load a texture with all its mip map levels if mip mapped and loaded all its previous states. This would allow for 10-20 calls to be reduced to a single call. This can also be used to improve loading speeds for geometry.
Here’s an example for baking a resource.
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)bitmap->bits());
if (generateMipmaps)
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap?GL_WRAP:GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap?GL_WRAP:GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, generateMipmaps?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR);
GLbyte *bakedTexture;
GLuint size;
glBake(GL_TEXTURE_2D, bakedTexture, &size);
glDeleteTextures(1, &tex);
Here’s an example for loading a baked resource.
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
GLbyte *bakedTexture; // has a preloaded baked resource
glTexBaked(GL_TEXTURE_2D, bakedTexture);
The other benefit is that it will encourage development of texture tools to handle the pre-baking of a resource which have multiple benefits to an application. Since some of the work is handled by the driver making these tools will be simpler. To list a few:
- No need to use libraries like FreeImage in your application because resources are already decoded.
- Simplifies texture creation for new users.
There are some problems like other people stealing your resources since it’s in an easy to read format but tool developers can through garbage into a baked resource and remove them before they are loaded, this can even be done by the texture tool developers. The tool develops can also use additional compression on a pre-baked resource to reduce space of resources.
This will benefit both high end and low end users. Easy texture creation for low end developers and fast resource loading for high end developers. Making things easier for low end developers will mean less time spent learning the API which can help with motivation to stick with it.