12#ifndef TEXTURE_H_6014714286
13#define TEXTURE_H_6014714286
15#include <Carna/Carna.h>
41template<
unsigned int dimension >
44 static_assert(
dimension >= 1 &&
dimension <= 3,
"Texture dimension must be 1, 2 or 3." );
87 const unsigned int id;
98 const static unsigned int SETUP_UNIT = 0;
111 (
const Eigen::Matrix< unsigned int, 1, 1 >& size
115 ,
const void* bufferPtr );
125 ,
const void* bufferPtr );
135 ,
const void* bufferPtr );
151template<
unsigned int dimension >
159 typedef Eigen::Matrix< unsigned int, dimension, 1 >
Resolution;
203 void bind(
unsigned int unit )
const;
230 std::unique_ptr< Resolution > mySize;
235template<
unsigned int dimension >
237 : internalFormat( internalFormat )
238 , pixelFormat( pixelFormat )
240 static_assert(
dimension >= 1 &&
dimension <= 3,
"Texture dimension must be 1, 2 or 3." );
245template<
unsigned int dimension >
252template<
unsigned int dimension >
255 return mySize.
get() !=
nullptr;
259template<
unsigned int dimension >
267template<
unsigned int dimension >
274 CARNA_ASSERT_EX( size(
i, 0 ) >= 1,
"Texture only supports positive sizes!" );
281 CARNA_ASSERT_EX( size( 2, 0 ) % 2 == 0,
"3D textures must have even depth!" );
286 this->bind( SETUP_UNIT );
287 uploadGLTextureData( size, internalFormat, pixelFormat, bufferType, bufferPtr );
291template<
unsigned int dimension >
294 update( size, 0,
nullptr );
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
#define CARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Represents an association.
AssociatedObjectType * get() const
Returns raw pointer to the referenced object.
Texture base class with dimension-independent definitions.
void uploadGLTextureData(const Eigen::Matrix< unsigned int, 1, 1 > &size, int internalFormat, int pixelFormat, int bufferType, const void *bufferPtr)
Wraps glTexImage1d.
const unsigned int id
Holds the ID of the represented OpenGL texture object.
TextureBase()
Creates OpenGL texture object.
virtual ~TextureBase()
Deletes the maintained OpenGL texture object.
void bindGLTextureObject(unsigned int unit, unsigned int id)
Binds OpenGL texture object id to texture unit. For internal usage only, use Texture::bind instead.
void uploadGLTextureData(const math::Vector3ui &size, int internalFormat, int pixelFormat, int bufferType, const void *bufferPtr)
Wraps glTexImage3d.
void uploadGLTextureData(const math::Vector2ui &size, int internalFormat, int pixelFormat, int bufferType, const void *bufferPtr)
Wraps glTexImage2d.
Represents an OpenGL texture object. This class realizes the RAII-idiom.
bool isValid() const
Tells whether the texture has been initialized, i.e. it has a size.
void update(const Resolution &size)
Eigen::Matrix< unsigned int, dimension, 1 > Resolution
Texture(int internalFormat, int pixelFormat)
Creates OpenGL texture object.
static const unsigned int DIMENSION
Holds the dimension of this texture.
const int internalFormat
Holds the number of color components in the texture, e.g. GL_RGBA8UI or GL_INTENSITY16.
void update(const Resolution &size, int bufferType, const void *bufferPtr)
const int pixelFormat
Holds the format of the pixel data, e.g. GL_RED, GL_RGB or GL_RGBA.
const Resolution & size() const
Tells the resolution of this texture.
void bind(unsigned int unit) const
Binds this texture to unit. Consider using TextureBase::SETUP_UNIT if you're binding the texture temp...
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Eigen::Matrix< unsigned int, 2, 1 > Vector2ui
Defines vector.
void bindGLTextureObject< 1 >(unsigned int unit, unsigned int id)
void bindGLTextureObject< 3 >(unsigned int unit, unsigned int id)
void bindGLTextureObject< 2 >(unsigned int unit, unsigned int id)
#define NON_COPYABLE
Features class it is placed in as non-copyable.