Radium Engine  1.5.0
Texture.hpp
1 #pragma once
2 
3 #include <Core/Tasks/TaskQueue.hpp>
4 #include <Core/Utils/Color.hpp>
5 #include <Engine/OpenGL.hpp>
6 #include <Engine/RaEngine.hpp>
7 
8 #include <memory>
9 #include <mutex>
10 #include <string>
11 
12 namespace globjects {
13 class Texture;
14 }
15 
16 namespace Ra {
17 namespace Engine {
18 namespace Data {
44  std::string name {};
46  GLenum target { GL_TEXTURE_2D };
48  size_t width { 1 };
50  size_t height { 1 };
52  size_t depth { 1 };
54  GLenum format { GL_RGB };
56  GLenum internalFormat { GL_RGB };
58  GLenum type { GL_UNSIGNED_BYTE };
60  GLenum wrapS { GL_CLAMP_TO_EDGE };
62  GLenum wrapT { GL_CLAMP_TO_EDGE };
64  GLenum wrapP { GL_CLAMP_TO_EDGE };
66  GLenum minFilter { GL_LINEAR };
68  GLenum magFilter { GL_LINEAR };
80  void* texels { nullptr };
81 };
82 
86 class RA_ENGINE_API Texture final
87 {
88  public:
91  Texture( const Texture& ) = delete;
92 
95  void operator=( const Texture& ) = delete;
96 
102  explicit Texture( const TextureParameters& texParameters );
103 
107  ~Texture();
108 
123  void initializeGL( bool linearize = false );
124 
132  void bind( int unit = -1 );
133 
146  void bindImageTexture( int unit, GLint level, GLboolean layered, GLint layer, GLenum access );
147 
151  inline std::string getName() const { return m_textureParameters.name; }
152 
161  void updateData( void* newData );
162 
172  void updateParameters();
173 
180  void linearize();
181 
185  GLenum format() const { return m_textureParameters.format; }
189  size_t width() const { return m_textureParameters.width; }
193  size_t height() const { return m_textureParameters.height; }
197  size_t depth() const { return m_textureParameters.depth; }
198 
199  void* texels() { return m_textureParameters.texels; }
203  globjects::Texture* texture() const { return m_texture.get(); }
204 
218  void resize( size_t w = 1, size_t h = 1, size_t d = 1, void* pix = nullptr );
219 
221  const TextureParameters& getParameters() const { return m_textureParameters; }
222 
226  TextureParameters& getParameters() { return m_textureParameters; }
227 
233  void setParameters( const TextureParameters& textureParameters ) {
234  std::lock_guard<std::mutex> lock( m_updateMutex );
235  m_textureParameters = textureParameters;
236  }
237 
238  private:
239  void updateGL();
240 
252  void sRGBToLinearRGB( uint8_t* texels, uint numComponent, bool hasAlphaChannel );
253 
255  void linearizeCubeMap( uint numComponent, bool hasAlphaChannel );
256 
259  TextureParameters m_textureParameters;
260 
262  std::unique_ptr<globjects::Texture> m_texture;
264  bool m_isMipMapped { false };
266  bool m_isLinear { false };
268  Core::TaskQueue::TaskId m_updateDataTaskId;
270  std::mutex m_updateMutex;
271 };
272 } // namespace Data
273 } // namespace Engine
274 } // namespace Ra
Utils::Index TaskId
Identifier for a task in the task queue.
Definition: TaskQueue.hpp:35
globjects::Texture * texture() const
Definition: Texture.hpp:203
GLenum format() const
Definition: Texture.hpp:185
size_t depth() const
Definition: Texture.hpp:197
void operator=(const Texture &)=delete
size_t height() const
Definition: Texture.hpp:193
TextureParameters & getParameters()
Definition: Texture.hpp:226
size_t width() const
Definition: Texture.hpp:189
void setParameters(const TextureParameters &textureParameters)
Definition: Texture.hpp:233
std::string getName() const
Definition: Texture.hpp:151
Texture(const Texture &)=delete
const TextureParameters & getParameters() const
get read access to texture parameters
Definition: Texture.hpp:221
Definition: Cage.cpp:3
GLenum wrapT
OpenGL wrap mode in the t direction.
Definition: Texture.hpp:62
GLenum magFilter
OpenGL magnification filter ( GL_LINEAR or GL_NEAREST )
Definition: Texture.hpp:68
GLenum wrapS
OpenGL wrap mode in the s direction.
Definition: Texture.hpp:60
size_t depth
width of the texture (p dimension)
Definition: Texture.hpp:52
GLenum wrapP
OpenGL wrap mode in the p direction.
Definition: Texture.hpp:64
size_t height
height of the texture (t dimension)
Definition: Texture.hpp:50
GLenum minFilter
OpenGL minification filter ( GL_LINEAR or GL_NEAREST or GL_XXX_MIPMAP_YYY )
Definition: Texture.hpp:66
GLenum format
Format of the external data.
Definition: Texture.hpp:54
size_t width
width of the texture (s dimension)
Definition: Texture.hpp:48
GLenum target
OpenGL target.
Definition: Texture.hpp:46
GLenum type
Type of the components in external data.
Definition: Texture.hpp:58
GLenum internalFormat
OpenGL internal format (WARNING, for Integer textures, must be GL_XXX_INTEGER)
Definition: Texture.hpp:56
std::string name
Name of the texture.
Definition: Texture.hpp:44