ImFusion SDK 4.3
Texture Class Reference

#include <ImFusion/Core/GL/Texture.h>

Wrapper of an OpenGL Texture to store image data on the GPU. More...

+ Inheritance diagram for Texture:

Detailed Description

Wrapper of an OpenGL Texture to store image data on the GPU.

A texture is defined by its size and an internal format. Optionally, you can define a custom OpenGL texture Target type if you don't want to rely on the automatic deduction from the size.

The following default texture parameters will be set:

  • Filtering: Linear for normalized textures, Nearest for integer textures
  • Wrapping: ClampToBorder for all dimensions
  • Swizzling: {R, R, R, 1} for single channel textures, {R, G, B, A} for all other textures
Note
Be aware that most member functions will implicitly change the OpenGL texture binding state as they will bind the texture to texture unit 0 and unbind it again at the end. However, no binding state of any other texture unit than 0 will be touched implicitly.
See also
https://www.khronos.org/opengl/wiki/Texture

Public Types

enum class  Target {
  Tex1D = 0x0DE0 , Tex1DArray = 0x8C18 , Tex2D = 0x0DE1 , Tex2DArray = 0x8C1A ,
  Tex3D = 0x806F
}
 Enumeration of supported target types. More...
 

Public Member Functions

 Texture (Target type, const vec3i &size, InternalFormat internalFormat)
 Creates a new OpenGL texture of given type, size and internal format.
 
 Texture (const vec3i &size, InternalFormat internalFormat)
 Creates a new OpenGL texture of given size and internal format.
 
 Texture (Texture &&rhs) noexcept
 
void bind (int unit=0) const
 Binds the image to a texture unit.
 
template<typename T>
void upload (const T *data, PixelFormat pixelFormat)
 Uploads pixel data to the OpenGL texture.
 
template<typename T>
void download (T *outData, PixelFormat pixelFormat) const
 Downloads pixel data from the OpenGL texture into an existing buffer.
 
template<typename T>
std::unique_ptr< T[]> download (PixelFormat pixelFormat, size_t *outNumElementsInReturnValue=nullptr) const
 Downloads pixel data from the OpenGL texture into a newly allocated buffer.
 
template<typename T>
void clear (const Eigen::Matrix< T, 4, 1 > &color)
 Fills the entire texture with a constant value.
 
void generateMipmaps ()
 Generates mipmaps for this texture.
 
void setFiltering (Sampler::MinFilter min, Sampler::MagFilter mag)
 Sets the minification and magnification filters.
 
void setWrapping (Sampler::Wrap s, Sampler::Wrap t, Sampler::Wrap r)
 Sets the wrapping parameters for each dimension.
 
void setWrapping (Sampler::Wrap all)
 Sets all wrapping parameters for all dimensions to the same value.
 
void setBorderColor (const vec4f &color)
 Sets the border color that is used for ClampToBorder.
 
uint32_t id () const
 Returns the internal OpenGL texture ID.
 
const vec3i & size () const
 Returns the dimensions (number of pixels) of this texture.
 
int width () const
 Returns the width (number of pixels) of this texture.
 
int height () const
 Returns the height (number of pixels) of this texture.
 
int slices () const
 Returns the depth (number of slices) of this texture.
 
const vec3i & dimensions () const
 Returns the dimensions of this texture.
 
Target target () const
 Returns the target type this texture is bound to.
 
InternalFormat internalFormat () const
 Returns the requested internal format of this texture.
 

Static Public Member Functions

static void unbind (uint32_t textureUnit, Target target)
 Unbinds any potentially bound texture from the specified texture unit (binds 0).
 
static std::unique_ptr< TexturecreateFromExisting (Target type, uint32_t glTexId)
 Creates a new Texture instance wrapping around an already existing OpenGL texture object and taking ownership.
 
static std::unique_ptr< TexturecreateFromExisting (Target type, uint32_t glTexId, InternalFormat internalFormat)
 Creates a new Texture instance wrapping around an already existing OpenGL texture object with specified internal format and taking ownership.
 

Member Enumeration Documentation

◆ Target

enum class Target
strong

Enumeration of supported target types.

See also
https://www.khronos.org/opengl/wiki/Texture#Theory
Enumerator
Tex1D 

1D texture

Tex1DArray 

Array of 1D textures.

Tex2D 

2D texture

Tex2DArray 

Array of 2D textures.

Tex3D 

3D texture

Constructor & Destructor Documentation

◆ Texture() [1/2]

Texture ( Target type,
const vec3i & size,
InternalFormat internalFormat )

Creates a new OpenGL texture of given type, size and internal format.

Exceptions
std::runtime_errorif the corresponding OpenGL texture object could not be created.

◆ Texture() [2/2]

Texture ( const vec3i & size,
InternalFormat internalFormat )

Creates a new OpenGL texture of given size and internal format.

The texture's target type will Tex1D, Tex2D, or Tex3D based on the dimensionality of size.

Exceptions
std::runtime_errorif the corresponding OpenGL texture object could not be created.

Member Function Documentation

◆ createFromExisting() [1/2]

static std::unique_ptr< Texture > createFromExisting ( Target type,
uint32_t glTexId )
static

Creates a new Texture instance wrapping around an already existing OpenGL texture object and taking ownership.

glTexId must point to a valid OpenGL texture object matching the provided target type.

◆ createFromExisting() [2/2]

static std::unique_ptr< Texture > createFromExisting ( Target type,
uint32_t glTexId,
InternalFormat internalFormat )
static

Creates a new Texture instance wrapping around an already existing OpenGL texture object with specified internal format and taking ownership.

glTexId must point to a valid OpenGL texture object matching the provided target type.

◆ upload()

template<typename T>
void upload ( const T * data,
PixelFormat pixelFormat )

Uploads pixel data to the OpenGL texture.

Format conversion will operated as specified by OpenGL.

See also
https://www.khronos.org/opengl/wiki/Pixel_Transfer#Format_conversion
Parameters
dataPointer to the raw pixel data, must match the given pixel format and type and be of sufficient size
pixelFormatPixel format of the raw pixel buffer in data.

◆ download() [1/2]

template<typename T>
void download ( T * outData,
PixelFormat pixelFormat ) const

Downloads pixel data from the OpenGL texture into an existing buffer.

Format conversion will operated as specified by OpenGL.

Warning
Only texture where InternalFormat::isColorRenderable is true can be downloaded.
See also
https://www.khronos.org/opengl/wiki/Pixel_Transfer#Format_conversion
Parameters
outDataPointer to the raw pixel data, must match the given pixel format and type and be of sufficient size
pixelFormatPixel format of the raw pixel buffer in data.

◆ download() [2/2]

template<typename T>
std::unique_ptr< T[]> download ( PixelFormat pixelFormat,
size_t * outNumElementsInReturnValue = nullptr ) const

Downloads pixel data from the OpenGL texture into a newly allocated buffer.

Format conversion will operated as specified by OpenGL.

Parameters
outNumElementsInReturnValueOptional output value returning the number of elements in the return value.
Warning
OpenGL ES cannot download 3 channel texture directly, but only into a 4 channel buffer.
See also
https://www.khronos.org/opengl/wiki/Pixel_Transfer#Format_conversion
Parameters
pixelFormatPixel format of the raw pixel buffer in data.

◆ clear()

template<typename T>
void clear ( const Eigen::Matrix< T, 4, 1 > & color)

Fills the entire texture with a constant value.

Format conversion will be operated as specified by OpenGL.

See also
https://www.khronos.org/opengl/wiki/Pixel_Transfer#Format_conversion
Parameters
colorRGBA pixel value to assign to all pixels, extra channels will be ignored.

◆ setFiltering()

void setFiltering ( Sampler::MinFilter min,
Sampler::MagFilter mag )

Sets the minification and magnification filters.

Mipmap types will only work when the texture has mipmap levels (see generateMipmaps()).

Note
Texture parameters are global for all usages of this texture, prefer using a Sampler instead.

◆ setWrapping() [1/2]

void setWrapping ( Sampler::Wrap s,
Sampler::Wrap t,
Sampler::Wrap r )

Sets the wrapping parameters for each dimension.

Note
Texture parameters are global for all usages of this texture, prefer using a Sampler instead.

◆ setWrapping() [2/2]

void setWrapping ( Sampler::Wrap all)

Sets all wrapping parameters for all dimensions to the same value.

Note
Texture parameters are global for all usages of this texture, prefer using a Sampler instead.

◆ setBorderColor()

void setBorderColor ( const vec4f & color)

Sets the border color that is used for ClampToBorder.

Note
Texture parameters are global for all usages of this texture, prefer using a Sampler instead.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close