Radium Engine
1.5.20
|
Represent a Texture of the engine. More...
#include <Engine/Data/Texture.hpp>
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 TextureParameters & | getParameters () const |
get read access to texture parameters | |
TextureParameters & | getParameters () |
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. | |
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.
|
explicit |
Texture constructor. No GPU initialization is done there.
texParameters | Name of the texture |
Definition at line 18 of file Texture.cpp.
Ra::Engine::Data::Texture::~Texture | ( | ) |
Texture destructor. Both internal data and GPU representation are deleted.
Definition at line 40 of file Texture.cpp.
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.
unit | Index of the texture to be bound. If -1 (default) only calls glBindTexture. |
Definition at line 129 of file Texture.cpp.
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.
Definition at line 134 of file Texture.cpp.
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.
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.
|
inline |
Definition at line 185 of file Texture.hpp.
|
inline |
Definition at line 176 of file Texture.hpp.
|
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.
Definition at line 197 of file Texture.hpp.
|
inline |
Definition at line 182 of file Texture.hpp.
|
inline |
Definition at line 171 of file Texture.hpp.
|
inline |
read/write access to texture parameters
Definition at line 202 of file Texture.hpp.
|
inline |
get read access to texture parameters
Definition at line 200 of file Texture.hpp.
|
inline |
Definition at line 188 of file Texture.hpp.
|
inline |
Definition at line 179 of file Texture.hpp.
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.
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.
|
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.
void Ra::Engine::Data::Texture::readFromGpu | ( | int | level = 0 | ) |
Definition at line 302 of file Texture.cpp.
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.
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.
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.
w | width of the texture |
h | height of the texture |
d | depth of the texture |
pix | the new texels array corresponding the the new texture dimension |
Definition at line 99 of file Texture.cpp.
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.
void Ra::Engine::Data::Texture::sendSamplerParametersToGpu | ( | ) |
Send sampler parameters to the GPU.
Definition at line 316 of file Texture.cpp.
void Ra::Engine::Data::Texture::setImageParameters | ( | const ImageParameters & | imageParameters | ) |
set TextureParameters.image
Definition at line 117 of file Texture.cpp.
|
inline |
Sets the name of the texture.
Definition at line 173 of file Texture.hpp.
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.
void Ra::Engine::Data::Texture::setSamplerParameters | ( | const SamplerParameters & | samplerParameters | ) |
set TerctureParameters.samples
Definition at line 123 of file Texture.cpp.
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()
newData | user image pointer to wrap |
Definition at line 92 of file Texture.cpp.