All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Luminous::Texture Class Reference

A GPU texture. More...

#include <Luminous/Texture.hpp>

Inheritance diagram for Luminous::Texture:
Luminous::RenderResource

Public Types

enum  Filter {
  FILTER_NEAREST = GL_NEAREST, FILTER_LINEAR = GL_LINEAR, FILTER_NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST, FILTER_NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
  FILTER_LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST, FILTER_LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
}
 Texture filter mode. More...
 
enum  Wrap { WRAP_REPEAT, WRAP_MIRROR, WRAP_CLAMP, WRAP_BORDER }
 Texture wrap mode. More...
 
- Public Types inherited from Luminous::RenderResource
typedef uint64_t Id
 Id of a resource.
 
enum  Type {
  VertexArray, Buffer, Program, Texture,
  RenderBuffer, FrameBuffer
}
 Different types of render resources. More...
 

Public Member Functions

LUMINOUS_API void addDirtyRect (const QRect &rect)
 Mark a region of the texture as dirty. More...
 
LUMINOUS_API const Radiant::ColorborderColor () const
 Get the texture border color. More...
 
LUMINOUS_API const void * data () const
 Get the raw pointer to texture data. More...
 
LUMINOUS_API const PixelFormatdataFormat () const
 Get the pixel format of the texture data. More...
 
LUMINOUS_API std::size_t dataSize () const
 Get the size of the texture data in bytes. More...
 
LUMINOUS_API unsigned int depth () const
 Get the depth of the texture. More...
 
LUMINOUS_API uint8_t dimensions () const
 Get texture dimension. More...
 
LUMINOUS_API QRegion dirtyRegion (unsigned int threadIndex) const
 Get the texture dirty region for the given thread. More...
 
LUMINOUS_API Filter getMagFilter () const
 Get texture magnification filter mode. More...
 
LUMINOUS_API Filter getMinFilter () const
 Get the texture minification filter mode. More...
 
LUMINOUS_API void getWrap (Wrap &s, Wrap &t, Wrap &r) const
 Get the texture wrap mode. More...
 
LUMINOUS_API unsigned int height () const
 Get the height of the texture. More...
 
LUMINOUS_API int internalFormat () const
 Get the number of color components in the texture. More...
 
LUMINOUS_API bool isValid () const
 Check if the texture is valid. More...
 
LUMINOUS_API unsigned int lineSizePixels () const
 Get the texture line size in pixels. More...
 
LUMINOUS_API bool mipmapsEnabled () const
 True if automatic GPU mipmap generation is enabled.
 
LUMINOUS_API Textureoperator= (const Texture &tex)
 Copy a texture. More...
 
LUMINOUS_API Textureoperator= (Texture &&tex)
 Move a texture. More...
 
LUMINOUS_API int paramsGeneration () const
 Get the generation number for texture parameters. More...
 
LUMINOUS_API void reset ()
 Reset the texture to invalid state.
 
LUMINOUS_API unsigned int samples () const
 Get the sample count of the texture. More...
 
LUMINOUS_API void setBorderColor (const Radiant::Color &color)
 Set the texture border color. More...
 
LUMINOUS_API void setData (unsigned int width, const PixelFormat &dataFormat, const void *data)
 Set 1D texture data from memory. More...
 
LUMINOUS_API void setData (unsigned int width, unsigned int height, const PixelFormat &dataFormat, const void *data)
 Set 2D texture data from memory. More...
 
LUMINOUS_API void setData (unsigned int width, unsigned int height, unsigned int depth, const PixelFormat &dataFormat, const void *data)
 Set 3D texture data from memory. More...
 
LUMINOUS_API void setInternalFormat (int format)
 Specify the number of color components in the texture. More...
 
LUMINOUS_API void setLineSizePixels (std::size_t size)
 Set the texture line size in pixels. More...
 
LUMINOUS_API void setMagFilter (Filter filter)
 Set texture magnification filtering. More...
 
LUMINOUS_API void setMinFilter (Filter filter)
 Set texture minification filtering. More...
 
LUMINOUS_API void setMipmapsEnabled (bool enabled)
 Enables or disables automatic GPU mipmap generation.
 
LUMINOUS_API void setSamples (unsigned int samples)
 Set the number of samples for the texture. More...
 
LUMINOUS_API void setTranslucency (bool translucency)
 Set translucency flag to the texture. More...
 
LUMINOUS_API void setWrap (Wrap s, Wrap t, Wrap r)
 Set the texture wrap mode. More...
 
LUMINOUS_API QRegion takeDirtyRegion (unsigned int threadIndex) const
 Get the dirty region for the given thread and clear the dirty region. More...
 
LUMINOUS_API Texture ()
 Construct a new texture.
 
LUMINOUS_API Texture (const Texture &tex)
 Construct a copy. More...
 
LUMINOUS_API Texture (Texture &&tex)
 Construct texture by moving. More...
 
LUMINOUS_API bool translucent () const
 Check if the texture is translucent. More...
 
LUMINOUS_API unsigned int width () const
 Get the width of the texture. More...
 
LUMINOUS_API ~Texture ()
 Destructor.
 
- Public Member Functions inherited from Luminous::RenderResource
unsigned int expiration () const
 Returns resource expiration time. More...
 
int generation () const
 Returns generation of this resource. More...
 
void invalidate ()
 Invalidates correspondent GPU objects and forces uploading of data to GPU.
 
RenderResourceoperator= (RenderResource &&rr)
 Move assignment operator. More...
 
 RenderResource (Type type)
 Constructor of RenderResource. More...
 
 RenderResource (RenderResource &&rr)
 Move constructor. More...
 
Id resourceId () const
 Returns identifier of resource. More...
 
Type resourceType () const
 Returns type of the resource. More...
 
void setExpiration (unsigned int seconds)
 Set resource expiration time. More...
 
void setGeneration (int generation)
 Sets generation for this resource. More...
 
virtual ~RenderResource ()
 Destructor of RenderResource.
 

Additional Inherited Members

- Protected Member Functions inherited from Luminous::RenderResource
RenderResourceoperator= (const RenderResource &rr)
 Assignment operator. More...
 
 RenderResource (const RenderResource &rr)
 Copy constructor. More...
 

Detailed Description

A GPU texture.

This class contains the necessary CPU-side information about a texture. This class does not own the memory it handles. All pointers given to this class must remain valid during the lifetime of this object. GPU correspondent of this class is TextureGL

Member Enumeration Documentation

Texture filter mode.

Enumerator
FILTER_NEAREST 

Point-sampled filtering.

FILTER_LINEAR 

Linear filtering.

FILTER_NEAREST_MIPMAP_NEAREST 

Point-sampled filtering, nearest mipmap level.

FILTER_NEAREST_MIPMAP_LINEAR 

Point-sampled filtering, linear filtering between mipmap levels.

FILTER_LINEAR_MIPMAP_NEAREST 

Linear filtering, nearest mipmap level.

FILTER_LINEAR_MIPMAP_LINEAR 

Linear filtering, linear filtering between mipmap levels (trilinear filtering)

Texture wrap mode.

Enumerator
WRAP_REPEAT 

Repeat texture.

WRAP_MIRROR 

Mirror texture.

WRAP_CLAMP 

Clamp texture.

WRAP_BORDER 

Clamp-to-border.

Constructor & Destructor Documentation

LUMINOUS_API Luminous::Texture::Texture ( const Texture tex)

Construct a copy.

Parameters
textexture to copy
LUMINOUS_API Luminous::Texture::Texture ( Texture &&  tex)

Construct texture by moving.

Parameters
textexture to move

Member Function Documentation

LUMINOUS_API void Luminous::Texture::addDirtyRect ( const QRect &  rect)

Mark a region of the texture as dirty.

Dirty regions are used to determine which parts of the texture data must be uploaded to GPU memory. Use this function if you want to optimize texture uploads to GPU. For example, if you only update a small region of a large texture, you can just mark the changed region as dirty and Cornerstone will only upload that part of the texture to the GPU.

Parameters
rectdirty region define in pixel coordinates
LUMINOUS_API const Radiant::Color& Luminous::Texture::borderColor ( ) const

Get the texture border color.

Returns
border color
LUMINOUS_API const void* Luminous::Texture::data ( ) const

Get the raw pointer to texture data.

Returns
pointer to texture data
LUMINOUS_API const PixelFormat& Luminous::Texture::dataFormat ( ) const

Get the pixel format of the texture data.

Returns
data format
LUMINOUS_API std::size_t Luminous::Texture::dataSize ( ) const

Get the size of the texture data in bytes.

Returns
texture size in bytes
LUMINOUS_API unsigned int Luminous::Texture::depth ( ) const

Get the depth of the texture.

Returns
texture depth in pixels
LUMINOUS_API uint8_t Luminous::Texture::dimensions ( ) const

Get texture dimension.

2D textures will have dimension 2 and 3D textures 3.

Returns
texture dimension
LUMINOUS_API QRegion Luminous::Texture::dirtyRegion ( unsigned int  threadIndex) const

Get the texture dirty region for the given thread.

This functions returns the dirty region of the texture for the given thread. This function is used by Cornerstone internally. There should be no reason to call this function manually.

Parameters
threadIndexindex of the thread to query the region for
Returns
dirty region for the given thread
LUMINOUS_API Filter Luminous::Texture::getMagFilter ( ) const

Get texture magnification filter mode.

Returns
filtering used for texture magnification
LUMINOUS_API Filter Luminous::Texture::getMinFilter ( ) const

Get the texture minification filter mode.

Returns
filtering used for texture minification
LUMINOUS_API void Luminous::Texture::getWrap ( Wrap s,
Wrap t,
Wrap r 
) const

Get the texture wrap mode.

Parameters
[out]swrap mode for s coordinate
[out]twrap mode for t coordinate
[out]rwrap mode for r coordinate
LUMINOUS_API unsigned int Luminous::Texture::height ( ) const

Get the height of the texture.

Returns
texture height in pixels
LUMINOUS_API int Luminous::Texture::internalFormat ( ) const

Get the number of color components in the texture.

Returns
number of color components
LUMINOUS_API bool Luminous::Texture::isValid ( ) const

Check if the texture is valid.

Texture is considered valid, if its dimension has been defined.

Returns
true if the texture is valid; otherwise false
See Also
dimensions
LUMINOUS_API unsigned int Luminous::Texture::lineSizePixels ( ) const

Get the texture line size in pixels.

Returns
line size in pixels
LUMINOUS_API Texture& Luminous::Texture::operator= ( const Texture tex)

Copy a texture.

Parameters
textexture to copy
LUMINOUS_API Texture& Luminous::Texture::operator= ( Texture &&  tex)

Move a texture.

Parameters
textexture to move
LUMINOUS_API int Luminous::Texture::paramsGeneration ( ) const

Get the generation number for texture parameters.

This is increased every time border color, wrap mode or min/mag filters are changed

Returns
generation number, starting from 0
LUMINOUS_API unsigned int Luminous::Texture::samples ( ) const

Get the sample count of the texture.

By default, the sample count is zero for textures that are not multi-sampled.

Returns
sample count
LUMINOUS_API void Luminous::Texture::setBorderColor ( const Radiant::Color color)

Set the texture border color.

Parameters
colorborder color
LUMINOUS_API void Luminous::Texture::setData ( unsigned int  width,
const PixelFormat dataFormat,
const void *  data 
)

Set 1D texture data from memory.

Parameters
widthwidth of the texture
dataFormatdata format
datadata pointer
LUMINOUS_API void Luminous::Texture::setData ( unsigned int  width,
unsigned int  height,
const PixelFormat dataFormat,
const void *  data 
)

Set 2D texture data from memory.

Parameters
widthwidth of the texture
heightheight of the texture
dataFormatdata format
datadata pointer
LUMINOUS_API void Luminous::Texture::setData ( unsigned int  width,
unsigned int  height,
unsigned int  depth,
const PixelFormat dataFormat,
const void *  data 
)

Set 3D texture data from memory.

Parameters
widthwidth of the texture
heightheight of the texture
depthdepth of the texture
dataFormatdata format
datadata pointer
LUMINOUS_API void Luminous::Texture::setInternalFormat ( int  format)

Specify the number of color components in the texture.

Use 0 to let Cornerstone select the default format. See "internalFormat" parameter description in http://www.opengl.org/sdk/docs/man3/xhtml/glTexImage2D.xml

Parameters
formatnumber of color components
LUMINOUS_API void Luminous::Texture::setLineSizePixels ( std::size_t  size)

Set the texture line size in pixels.

Use 0 to use width of the texture.

Parameters
sizesize of one line in pixels
LUMINOUS_API void Luminous::Texture::setMagFilter ( Filter  filter)

Set texture magnification filtering.

Parameters
filterfiltering used
LUMINOUS_API void Luminous::Texture::setMinFilter ( Filter  filter)

Set texture minification filtering.

Parameters
filterfiltering used
LUMINOUS_API void Luminous::Texture::setSamples ( unsigned int  samples)

Set the number of samples for the texture.

This function can be used to define multi-sampled textures.

Parameters
samplessample count
LUMINOUS_API void Luminous::Texture::setTranslucency ( bool  translucency)

Set translucency flag to the texture.

This flag is used by Cornerstone to optimize rendering. Rendering opaque textures can be sorted for optimal performance. Rendering translucent textures can not be sorted. A texture must be marked as translucent if it has an alpha channel and any pixel in the texture has an alpha component other than one. Failure to do so may cause rendering artifacts as incorrect blending.

Parameters
translucencytexture translucency
See Also
translucent
LUMINOUS_API void Luminous::Texture::setWrap ( Wrap  s,
Wrap  t,
Wrap  r 
)

Set the texture wrap mode.

Parameters
swrap mode for s texture coordinate
twrap mode for t texture coordinate
rwrap mode for r texture coordinate
LUMINOUS_API QRegion Luminous::Texture::takeDirtyRegion ( unsigned int  threadIndex) const

Get the dirty region for the given thread and clear the dirty region.

This functions returns the dirty region of the texture and simultaneously clears it to empty. This function is used by Cornerstone internally and there should be no reason to call this function manually.

Parameters
threadIndexindex of the thread to query
Returns
dirty region for the given thread
LUMINOUS_API bool Luminous::Texture::translucent ( ) const

Check if the texture is translucent.

See Also
setTranslucency
LUMINOUS_API unsigned int Luminous::Texture::width ( ) const

Get the width of the texture.

Returns
texture width in pixels