KGLLib
Public Member Functions | Protected Member Functions | Protected Attributes
KGLLib::TextureBase Class Reference

Abstract base class for all textures. More...

#include <texture.h>

Inheritance diagram for KGLLib::TextureBase:
KGLLib::Texture KGLLib::Texture3D

List of all members.

Public Member Functions

 TextureBase ()
 TextureBase (const QString &name)
virtual ~TextureBase ()
bool isValid () const
virtual void bind () const
virtual void unbind () const
virtual void enable (bool bind=true) const
virtual void disable (bool unbind=true) const
virtual void setFilter (GLenum filter)
virtual void setWrapMode (GLenum coordinate, GLenum mode)
virtual void setWrapMode (GLenum mode)=0
QString name () const
void setName (const QString &name)
virtual QString debugString () const
virtual GLenum glTarget () const =0
virtual GLuint glId () const

Protected Member Functions

void setValid (bool valid)

Protected Attributes

bool mValid
GLuint mGLId
QString mName
GLenum mFormat
GLenum mInternalFormat

Detailed Description

Abstract base class for all textures.

This class includes basic functionality such as bind/unbind and enable/disable methods which all textures have.

See Texture class documentation for more detailed introduction and examples.

See also:
Texture

Constructor & Destructor Documentation

KGLLib::TextureBase::TextureBase ( )

Creates new invalid texture. It is up to subclasses to actually initialize the texture. TODO: should we do glGenTextures() here or in subclasses? Probably latter.

KGLLib::TextureBase::TextureBase ( const QString &  name)

Same as above but also sets texture name to name.

References setName().

KGLLib::TextureBase::~TextureBase ( ) [virtual]

Deletes the OpenGL texture associated with this object.


Member Function Documentation

void KGLLib::TextureBase::bind ( ) const [virtual]

Binds the texture onto currently active texture unit.

References KGLLib::renderer.

Referenced by enable().

void KGLLib::TextureBase::disable ( bool  unbind = true) const [virtual]

Disables texturing with this texture type for currently active texture unit.

Parameters:
unbindif true then unbind() is called before disabling texturing

References KGLLib::renderer, and unbind().

Referenced by KGLLib::HdrGLWidget::render().

void KGLLib::TextureBase::enable ( bool  bind = true) const [virtual]

Enables texturing with this texture type for currently active texture unit.

Parameters:
bindif true then bind() is called after enabling texturing

References bind(), and KGLLib::renderer.

Referenced by KGLLib::HdrGLWidget::render().

virtual GLuint KGLLib::TextureBase::glId ( ) const [inline, virtual]
Returns:
internal OpenGL texture id of this texture.
virtual GLenum KGLLib::TextureBase::glTarget ( ) const [pure virtual]

TODO: maybe rename to glType()

Returns:
type of this texture (e.g. GL_TEXTURE_2D)

Implemented in KGLLib::Texture, and KGLLib::Texture3D.

Referenced by setFilter(), and setWrapMode().

bool KGLLib::TextureBase::isValid ( ) const [inline]
Returns:
whether the texture is valid
QString KGLLib::TextureBase::name ( ) const [inline]
Returns:
name of this texture. It can be used to identify textures e.g. to ease debugging.

Referenced by setName().

void KGLLib::TextureBase::setFilter ( GLenum  filter) [virtual]

Sets texture's filter to filter. filter is minification filter, magnification filter is set to GL_NEAREST if filter is GL_NEAREST and to GL_LINEAR otherwise.

Common values are:

  • GL_NEAREST - return nearest pixel. Usually you don't want this.
  • GL_LINEAR - return weighed average of neighboring pixels.
  • GL_NEAREST_MIPMAP_LINEAR - same as GL_LINEAR but uses nearest MIPMAP (aka bilinear).
  • GL_LINEAR_MIPMAP_LINEAR - uses GL_LINEAR on two neighboring mipmaps and then takes weighed average of them (aka trilinear) TODO: some better wording here GL_LINEAR_MIPMAP_LINEAR usually gives best quality but uses a third more memory and has a bit lower performance.

TODO: maybe set filter to GL_CLAMP by default because it seems to suit smaller apps better. OTOH I really don't like having defaults differ from OpenGL ones. Maybe add Renderer::setDefaultTextureFilter() method???

References glTarget().

Referenced by KGLLib::HdrGLWidget::render().

void KGLLib::TextureBase::setName ( const QString &  name)

Sets texture's name to name. The name doesn't have any connection with OpenGL but it can be used to identify textures when debugging.

References name().

Referenced by TextureBase().

virtual void KGLLib::TextureBase::setWrapMode ( GLenum  mode) [pure virtual]

Sets wrap mode for all coordinates of this texture. Subclasses need to reimplement this, calling setWrapMode() for every possible coordinate.

Implemented in KGLLib::Texture, and KGLLib::Texture3D.

void KGLLib::TextureBase::setWrapMode ( GLenum  coordinate,
GLenum  mode 
) [virtual]

Sets texture wrap mode for given coordinate. Wrap mode controls how exactly the texture coordinates are interpreted:

  • GL_REPEAT is default and ignores integer part of the texture coordinate, causing the texture to be repeated.
  • GL_CLAMP clamps coordinates to range [0; 1]. TODO: explain other modes as well

Usually you should use GL_REPEAT when you want texture to repeat across surfaces (e.g. for terrain with repeating texture) and GL_CLAMP when you want just one instance of the texture (e.g. for a logo).

References glTarget().

void KGLLib::TextureBase::unbind ( ) const [virtual]

Unbinds the texture. After calling this, no texture is bound but texturing may still be enabled (in which case texturing results are undefined). TODO: is this meanful or should it be removed (as users usually want to either disable() texturing or just bind() another texture)?

References KGLLib::renderer.

Referenced by disable().


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