Radium Engine  1.5.20
Loading...
Searching...
No Matches
Ra::Engine::Data::Texture Class Referencefinal

Represent a Texture of the engine. More...

#include <Engine/Data/Texture.hpp>

+ Collaboration diagram for Ra::Engine::Data::Texture:

Public Member Functions

 Texture (const Texture &)=delete
 Textures are not copyable, delete copy constructor.
 
void operator= (const Texture &)=delete
 Textures are not copyable, delete operator =.
 
 Texture (const TextureParameters &texParameters)
 Texture constructor. No GPU initialization is done there.
 
 ~Texture ()
 Texture destructor. Both internal data and GPU representation are deleted.
 
void initialize ()
 Generate the OpenGL representation of the texture according to the stored TextureData (delayed).
 
void initializeNow ()
 Generate the GPU representation of the texture right now. Need an active OpenGL context.
 
void destroy ()
 destroy the GPU texture representation.
 
void destroyNow ()
 Generate the GPU representation of the texture right now. Need an active OpenGL context.
 
std::string getName () const
 
void setName (const std::string &name)
 
GLenum getFormat () const
 
size_t getWidth () const
 
size_t getHeight () const
 
size_t getDepth () const
 
const void * getTexels ()
 
globjects::Texture * getGpuTexture () const
 Get ptr to the managed globjects::Texture.
 
const TextureParametersgetParameters () const
 get read access to texture parameters
 
TextureParametersgetParameters ()
 read/write access to texture parameters
 
void updateData (std::shared_ptr< void > newData)
 Update the cpu representation of data contained by the texture.
 
void resize (size_t w=1, size_t h=1, size_t d=1, std::shared_ptr< void > pix=nullptr)
 Resize the texture. Need active OpenGL context.
 
void setParameters (const TextureParameters &textureParameters)
 set TextureParameters.
 
void setImageParameters (const ImageParameters &imageParameters)
 set TextureParameters.image
 
void setSamplerParameters (const SamplerParameters &samplerParameters)
 set TerctureParameters.samples
 
void bind (int unit=-1)
 Bind the texture to GPU texture unit to enable its use in a shader. Need active OpenGL context.
 
void bindImageTexture (int unit, GLint level, GLboolean layered, GLint layer, GLenum access)
 Bind the texture to an image unit for the purpose of reading and writing it from shaders. Need active OpenGL context.
 
void registerUpdateImageDataTask ()
 Regiter gpu task to RadiumEngine. Will call sendImageDataToGpu during next RadiumEngine::runGpuTasks() call.
 
void registerUpdateSamplerParametersTask ()
 Regiter gpu task to RadiumEngine. Will call sendSamplerParametersToGpu during next RadiumEngine::runGpuTasks() call.
 
void sendImageDataToGpu ()
 Send image data to the GPU and generate mipmap if needed.
 
void readFromGpu (int level=0)
 
void sendSamplerParametersToGpu ()
 Send sampler parameters to the GPU.
 

Static Public Member Functions

static void linearize (ImageParameters &image)
 Convert a color texture from sRGB to Linear RGB spaces.
 

Detailed Description

Represent a Texture of the engine.

When one wants to create a texture, the first thing to do is to create and fill a TextureParameters to describe the Texture.

The Texture creation could be done either using the TextureManager or directly on the client class/function.

When a texture is created, no GPU initialisation is realized. The user must first call either initialize() to register delayed initialisation by RadiumEngine using RadiumEngine::runGpuTasks() or intializeNow() to peform GPU initialization directly, with an active bound context. See TextureManager for information about how unique texture are defined.

Definition at line 119 of file Texture.hpp.

Constructor & Destructor Documentation

◆ Texture()

Ra::Engine::Data::Texture::Texture ( const TextureParameters & texParameters)
explicit

Texture constructor. No GPU initialization is done there.

Parameters
texParametersName of the texture

Definition at line 18 of file Texture.cpp.

◆ ~Texture()

Ra::Engine::Data::Texture::~Texture ( )

Texture destructor. Both internal data and GPU representation are deleted.

Definition at line 40 of file Texture.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ bind()

void Ra::Engine::Data::Texture::bind ( int unit = -1)

Bind the texture to GPU texture unit to enable its use in a shader. Need active OpenGL context.

Parameters
unitIndex of the texture to be bound. If -1 (default) only calls glBindTexture.

Definition at line 129 of file Texture.cpp.

◆ bindImageTexture()

void Ra::Engine::Data::Texture::bindImageTexture ( int unit,
GLint level,
GLboolean layered,
GLint layer,
GLenum access )

Bind the texture to an image unit for the purpose of reading and writing it from shaders. Need active OpenGL context.

Note
, only available since openGL 4.2, not available on MacOs uses m_parameters.internalFormat as format. see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml for documentation

Definition at line 134 of file Texture.cpp.

◆ destroy()

void Ra::Engine::Data::Texture::destroy ( )

destroy the GPU texture representation.

It creates gpu tasks the engine will run during next draw call, so it can be called without active opengl context.

Definition at line 75 of file Texture.cpp.

+ Here is the call graph for this function:

◆ destroyNow()

void Ra::Engine::Data::Texture::destroyNow ( )

Generate the GPU representation of the texture right now. Need an active OpenGL context.

see destroy() which is the same method, but delay gpu stuff to engine gpu tasks.

Definition at line 87 of file Texture.cpp.

+ Here is the call graph for this function:

◆ getDepth()

size_t Ra::Engine::Data::Texture::getDepth ( ) const
inline
Returns
the depth of the texture

Definition at line 185 of file Texture.hpp.

◆ getFormat()

GLenum Ra::Engine::Data::Texture::getFormat ( ) const
inline
Returns
the pixel format of the texture

Definition at line 176 of file Texture.hpp.

◆ getGpuTexture()

globjects::Texture * Ra::Engine::Data::Texture::getGpuTexture ( ) const
inline

Get ptr to the managed globjects::Texture.

Please unsure do keep data consistent between Texture's TextureParameters and the globjects::Texture and prefer using Textue methods to change texture representation if avaiable.

Returns
ptr to globjects::Texture associated with the Texture.

Definition at line 197 of file Texture.hpp.

◆ getHeight()

size_t Ra::Engine::Data::Texture::getHeight ( ) const
inline
Returns
the height of the texture

Definition at line 182 of file Texture.hpp.

◆ getName()

std::string Ra::Engine::Data::Texture::getName ( ) const
inline
Returns
Name of the texture.

Definition at line 171 of file Texture.hpp.

◆ getParameters() [1/2]

TextureParameters & Ra::Engine::Data::Texture::getParameters ( )
inline

read/write access to texture parameters

Definition at line 202 of file Texture.hpp.

◆ getParameters() [2/2]

const TextureParameters & Ra::Engine::Data::Texture::getParameters ( ) const
inline

get read access to texture parameters

Definition at line 200 of file Texture.hpp.

◆ getTexels()

const void * Ra::Engine::Data::Texture::getTexels ( )
inline
Returns
raw pointer to texels (or nullptr if cubeMap or no cpu side representation).

Definition at line 188 of file Texture.hpp.

◆ getWidth()

size_t Ra::Engine::Data::Texture::getWidth ( ) const
inline
Returns
the width of the texture

Definition at line 179 of file Texture.hpp.

◆ initialize()

void Ra::Engine::Data::Texture::initialize ( )

Generate the OpenGL representation of the texture according to the stored TextureData (delayed).

This method use the stored TextureParameters to generate and configure OpenGL texture. It creates gpu tasks the engine will run during next draw call, so it can be called without active opengl context.

Definition at line 53 of file Texture.cpp.

+ Here is the call graph for this function:

◆ initializeNow()

void Ra::Engine::Data::Texture::initializeNow ( )

Generate the GPU representation of the texture right now. Need an active OpenGL context.

see initialze() which is the same method, but delay gpu stuff to engine gpu tasks.

Definition at line 66 of file Texture.cpp.

+ Here is the call graph for this function:

◆ linearize()

void Ra::Engine::Data::Texture::linearize ( ImageParameters & image)
static

Convert a color texture from sRGB to Linear RGB spaces.

This will transform the internal representation of the texture to GL_SCALAR (GL_FLOAT). Only GL_RGB[8, 16, 16F, 32F] and GL_RGBA[8, 16, 16F, 32F] are managed. Full transformation as described at https://en.wikipedia.org/wiki/SRGB

Definition at line 143 of file Texture.cpp.

◆ readFromGpu()

void Ra::Engine::Data::Texture::readFromGpu ( int level = 0)

Definition at line 302 of file Texture.cpp.

◆ registerUpdateImageDataTask()

void Ra::Engine::Data::Texture::registerUpdateImageDataTask ( )

Regiter gpu task to RadiumEngine. Will call sendImageDataToGpu during next RadiumEngine::runGpuTasks() call.

Definition at line 205 of file Texture.cpp.

+ Here is the call graph for this function:

◆ registerUpdateSamplerParametersTask()

void Ra::Engine::Data::Texture::registerUpdateSamplerParametersTask ( )

Regiter gpu task to RadiumEngine. Will call sendSamplerParametersToGpu during next RadiumEngine::runGpuTasks() call.

Definition at line 220 of file Texture.cpp.

+ Here is the call graph for this function:

◆ resize()

void Ra::Engine::Data::Texture::resize ( size_t w = 1,
size_t h = 1,
size_t d = 1,
std::shared_ptr< void > pix = nullptr )

Resize the texture. Need active OpenGL context.

This allocate GPU memory to store the new resized texture and, if texels are not nullptr, upload the new content.

Note
If texels are not nullptr, user must ensure the texels array is correctly dimensioned.
Parameters
wwidth of the texture
hheight of the texture
ddepth of the texture
pixthe new texels array corresponding the the new texture dimension

Definition at line 99 of file Texture.cpp.

+ Here is the call graph for this function:

◆ sendImageDataToGpu()

void Ra::Engine::Data::Texture::sendImageDataToGpu ( )

Send image data to the GPU and generate mipmap if needed.

Definition at line 234 of file Texture.cpp.

+ Here is the call graph for this function:

◆ sendSamplerParametersToGpu()

void Ra::Engine::Data::Texture::sendSamplerParametersToGpu ( )

Send sampler parameters to the GPU.

Definition at line 316 of file Texture.cpp.

◆ setImageParameters()

void Ra::Engine::Data::Texture::setImageParameters ( const ImageParameters & imageParameters)

set TextureParameters.image

Definition at line 117 of file Texture.cpp.

+ Here is the call graph for this function:

◆ setName()

void Ra::Engine::Data::Texture::setName ( const std::string & name)
inline

Sets the name of the texture.

Definition at line 173 of file Texture.hpp.

◆ setParameters()

void Ra::Engine::Data::Texture::setParameters ( const TextureParameters & textureParameters)

set TextureParameters.

Call setImageParameters() and setSamplerParameters() to register update GPU sample task. No check is peformed to see if data need to be updated, gpu update is triggered inconditionnally.

Definition at line 112 of file Texture.cpp.

+ Here is the call graph for this function:

◆ setSamplerParameters()

void Ra::Engine::Data::Texture::setSamplerParameters ( const SamplerParameters & samplerParameters)

set TerctureParameters.samples

Definition at line 123 of file Texture.cpp.

+ Here is the call graph for this function:

◆ updateData()

void Ra::Engine::Data::Texture::updateData ( std::shared_ptr< void > newData)

Update the cpu representation of data contained by the texture.

newData must contain the same number (of the same type) of elements than old data (not checked). Element count can be obtained with getWidth() * getHeight() Element type can be obtained with getFormat()

Parameters
newDatauser image pointer to wrap

Definition at line 92 of file Texture.cpp.

+ Here is the call graph for this function:

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