Management of OpenGL textures.
More...
#include <easy3d/renderer/texture_manager.h>
Management of OpenGL textures.
A texture can be shared by multiple models, so it is wise to have a single instance of a texture. TextureManager manages the texture creation and memories. It ensures no duplication.
- Note
- Make sure to call terminate() to destroy existing textures before the OpenGL context is deleted.
- Todo:
- Allow to change the wrap/filter mode (i.e., multiple textures of different parameters from the same image).
◆ release()
| void release |
( |
const Texture * |
texture | ) |
|
|
static |
Release a texture (deallocate its memory).
- Parameters
-
| texture | The texture to be released. |
◆ request() [1/3]
Request a texture for rendering scalar fields from a gradually varying (from left to right) color image given its file name.
This method allows to sample the original image into a specified number of vertical stripes. The generated texture has a unique identifier in the format: "file_name|num_stripes". If a texture with the same identifier is requested again, no new texture will be generated and the existing one is returned.
- Parameters
-
| image_file | The full path to the image file. |
| num_stripes | The number of stripes. If num_stripes == image_width, no sampling will occur. |
| wrap | The wrap mode. |
| filter | The filter mode. |
- Returns
- The texture created from the image.
◆ request() [2/3]
Request a texture from the image file.
The generated texture has a unique identifier of its full-path file name. If a texture with the same identifier is requested again, no new texture will be generated and the existing texture is returned.
- Parameters
-
| image_file | The full path to the image file. |
| wrap | The wrap mode. |
| filter | The filter mode. |
- Returns
- The texture created from the image.
- Examples
- Tutorial_308_TexturedMesh/main.cpp.
◆ request() [3/3]
Request a random color texture for rendering scalar fields. The texture will have a set of uniformly colored vertical stripes.
It first generates a random-colored image, where each row has "num_colors" color and each color repeat "stride" times. Then, a texture is created from this image data. The generated texture has a unique identifier in the format: "random|num_stripes|stride", where num_stripes and stride are integer numbers. If the requested number of stripes and the stride match a previously generated texture, no new texture will be generated and the existing texture is returned.
- Parameters
-
| num_stripes | The number of stripes in the texture. |
| stride | The width of each vertical strip. So the total width of the texture is: num_stripes * stride. |
| wrap | The wrap mode. |
| filter | The filter mode. |
- Returns
- The texture created.
◆ request_white()
Request a cached 1x1 white texture for inactive surface samplers.
Some drivers validate samplers even when their shader branches are disabled. The texture is released by terminate(), like other cached textures.
- Returns
- The texture, or nullptr if allocation fails. Requires a current context.
◆ terminate()
The documentation for this class was generated from the following files: