DarkRadiant GLTextureManager: Difference between revisions
No edit summary |
m categorize |
||
Line 28: | Line 28: | ||
Depending on the passed TextureType (which may be diffuse, bump, specular, lightfalloff, etc.) a default texture binding is returned if something goes wrong during image load (i.e. the returned Image* pointer is NULL). A default specularmap would be a pitch black texture. For diffusemaps the known "Shader Image Missing" texture is bound and returned. | Depending on the passed TextureType (which may be diffuse, bump, specular, lightfalloff, etc.) a default texture binding is returned if something goes wrong during image load (i.e. the returned Image* pointer is NULL). A default specularmap would be a pitch black texture. For diffusemaps the known "Shader Image Missing" texture is bound and returned. | ||
{{darkradiant-internal|sort=GLTextureManager}} | |||
Latest revision as of 23:17, 11 November 2007
The GLTextureManager has these tasks:
- Instantiate/Realise Textures and load them into OpenGL when requested.
- Deliver the fallback textures ("shader image missing", black specular, flat bump, etc.) if the load failed.
- Image Post-Processing like resampling, gamma-correction.
Realisation / Binding
To request a binding, the Shader objects call the GLTextureManager::getBinding method:
TexturePtr getBinding(const std::string& textureKey, TextureConstructorPtr constructor, eTextureType textureType);
The GLTextureManager does not load the textures itself, but requests them to be created/loaded from the passed TextureConstructor. This way the GLTextureManager doesn't need to take care of how the images are constructed (they may be the result of a addnormals() mapexpression).
The texture is post-processed (see below) and loaded into OpenGL. The according Texture structure is allocated, saved and its pointer returned to the Shader object (which itself returns the pointer to the Renderer, that originally requested the Texture from the Shader).
Post-Processing
- The image dimensions are checked to match a power of two. If the image dimensions do not match, the according image dimension is stretched to to match the next largest power of two. A 900x700 texture will be resampled into a 1024x1024 texture.
- The image is downsampled to match the maximum texture size supported by OpenGL. Additionally, the preferences setting Texture Quality may further reduce the maximum texture size (12.5% means that the image dimensions are cut down to 1/8).
- The gamma adjustment is applied after resampling according to an internally stored, precalculated gama value table. This will only be performed if the gamma setting is different from 1.0, which is equal to "no change".
- The texture is scanned and an average colour value is calculated (the mean value of all the visited pixels is taken). This is needed for the FlatShade rendering mode, otherwise all the rendered objects would be uniformly black. Every 20th pixel is taken into account for this integration.
- The Mipmaps are created. This is simply done by the according OpenGL call right after requesting the binding ID from OpenGL.
Fallback (default) Textures
Depending on the passed TextureType (which may be diffuse, bump, specular, lightfalloff, etc.) a default texture binding is returned if something goes wrong during image load (i.e. the returned Image* pointer is NULL). A default specularmap would be a pitch black texture. For diffusemaps the known "Shader Image Missing" texture is bound and returned.