Easy3D 2.6.1
Loading...
Searching...
No Matches
TextureManager Class Reference

Management of OpenGL textures. More...

#include <easy3d/renderer/texture_manager.h>

Static Public Member Functions

static Texturerequest (const std::string &image_file, Texture::WrapMode wrap=Texture::CLAMP_TO_EDGE, Texture::FilterMode filter=Texture::LINEAR)
 Request a texture from the image file.
 
static Texturerequest (const std::string &image_file, int num_stripes, Texture::WrapMode wrap=Texture::CLAMP_TO_EDGE, Texture::FilterMode filter=Texture::LINEAR)
 Request a texture for rendering scalar fields from a gradually varying (from left to right) color image given its file name.
 
static Texturerequest (int num_stripes, int stride, Texture::WrapMode wrap=Texture::CLAMP_TO_EDGE, Texture::FilterMode filter=Texture::LINEAR)
 Request a random color texture for rendering scalar fields. The texture will have a set of uniformly colored vertical stripes.
 
static void release (const Texture *texture)
 Release a texture (deallocate its memory).
 
static void terminate ()
 Destroy all textures and release their memory.
 

Detailed Description

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).

Member Function Documentation

◆ release()

void release ( const Texture * texture)
static

Release a texture (deallocate its memory).

Parameters
textureThe texture to be released.

◆ request() [1/3]

Texture * request ( const std::string & image_file,
int num_stripes,
Texture::WrapMode wrap = Texture::CLAMP_TO_EDGE,
Texture::FilterMode filter = Texture::LINEAR )
static

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_fileThe full path to the image file.
num_stripesThe number of stripes. If num_stripes == image_width, no sampling will occur.
wrapThe wrap mode.
filterThe filter mode.
Returns
The texture created from the image.

◆ request() [2/3]

Texture * request ( const std::string & image_file,
Texture::WrapMode wrap = Texture::CLAMP_TO_EDGE,
Texture::FilterMode filter = Texture::LINEAR )
static

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_fileThe full path to the image file.
wrapThe wrap mode.
filterThe filter mode.
Returns
The texture created from the image.
Examples
Tutorial_308_TexturedMesh/main.cpp.

◆ request() [3/3]

Texture * request ( int num_stripes,
int stride,
Texture::WrapMode wrap = Texture::CLAMP_TO_EDGE,
Texture::FilterMode filter = Texture::LINEAR )
static

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_stripesThe number of stripes in the texture.
strideThe width of each vertical strip. So the total width of the texture is: num_stripes * stride.
wrapThe wrap mode.
filterThe filter mode.
Returns
The texture created.

◆ terminate()

void terminate ( )
static

Destroy all textures and release their memory.

Note
This method should be called before the OpenGL context is deleted. It is typically called in the destructor of the viewer.
Examples
Tutorial_203_Viewer_wxWidgets/main.cpp, and Tutorial_204_Viewer_Qt/main.cpp.

The documentation for this class was generated from the following files: