Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
jop::Texture Class Referenceabstract

#include <Texture.hpp>

Inheritance diagram for jop::Texture:
jop::Resource jop::SafeReferenceable< Resource > jop::SerializeInfo jop::Cubemap jop::Texture2D

Classes

struct  Flag
 
class  FormatBundle
 

Public Types

enum  Format {
  Format::None, Format::Alpha_UB_8, Format::RGB_UB_8, Format::RGBA_UB_8,
  Format::RGB_F_16, Format::RGBA_F_16, Format::Depth_US_16, Format::Depth_UI_24,
  Format::Stencil_UB_8, Format::DepthStencil_UI_24_B_8
}
 

Public Member Functions

 Texture (const std::string &name, const unsigned int glTarget)
 Constructor. More...
 
virtual ~Texture () override=0
 Virtual destructor. More...
 
void destroy ()
 Destroy this texture, erasing it from video memory. More...
 
bool bind (const unsigned int texUnit=0) const
 Bind this texture. More...
 
void unbind (const unsigned int texUnit=0) const
 Unbind a current texture. More...
 
bool isValid () const
 Check if this texture is valid. More...
 
void setSampler (const TextureSampler &sampler)
 Set a texture sampler. More...
 
void removeSampler ()
 Remove the bound texture sampler. More...
 
const TextureSamplergetSampler () const
 Get the currently bound sampler. More...
 
virtual glm::uvec2 getSize () const =0
 Get the texture size. More...
 
virtual unsigned int getPixelDepth () const =0
 Get the texture pixel depth. More...
 
TexturesetFilterMode (const TextureSampler::Filter mode, const float param=1.f)
 Set the filtering mode. More...
 
TexturesetRepeatMode (const TextureSampler::Repeat repeat)
 Set the repeating mode. More...
 
TexturesetBorderColor (const Color &color)
 Set the border color. More...
 
TextureSampler::Filter getFilterMode () const
 Get the filtering mode. More...
 
TextureSampler::Repeat getRepeatMode () const
 Get the repeating mode. More...
 
float getAnisotropyLevel () const
 Get the anisotropy level. More...
 
const ColorgetBorderColor () const
 Get the border color. More...
 
unsigned int getHandle () const
 Get the OpenGL handle for this texture. More...
 
- Public Member Functions inherited from jop::Resource
 Resource (const std::string &name)
 Constructor. More...
 
virtual ~Resource ()=0
 Virtual destructor. More...
 
const std::string & getName () const
 Get the name of this resource. More...
 
void setPersistence (const unsigned short level)
 Set the persistence level. More...
 
unsigned short getPersistence () const
 Get the persistence level. More...
 
- Public Member Functions inherited from jop::SafeReferenceable< Resource >
WeakReference< ResourcegetReference () const
 Get a weak reference to the bound object. More...
 
- Public Member Functions inherited from jop::SerializeInfo
 SerializeInfo ()
 
void setSerializePackage (const uint16 package)
 
uint16 getSerializePackage () const
 
void setShouldSerialize (const bool set)
 
bool shouldSerialize () const
 
void setLightSerializeable (const bool set)
 
bool isLightSerializeable () const
 

Static Public Member Functions

static unsigned int getMaxTextureUnits ()
 Get the maximum texture units. More...
 
static void setUnpackAlignment (const Format format)
 Set the pixel store alignment. More...
 
static bool allowSRGB ()
 Check is the sRGB color space is allowed. More...
 
static bool allowGenMipmaps (const glm::uvec2 &size, const bool srgb)
 Check is automatic mipmap generation is allowed. More...
 

Protected Member Functions

void setAlphaSwizzle (const Format format)
 Set the swizzle mask for 8 bit textures. More...
 
- Protected Member Functions inherited from jop::Resource
 Resource (const Resource &other, const std::string &newName)
 Copy constructor. More...
 
- Protected Member Functions inherited from jop::SafeReferenceable< Resource >
 SafeReferenceable (Resource *ref)
 Constructor. More...
 
 SafeReferenceable (SafeReferenceable< Resource > &&other)
 Move constructor. More...
 
SafeReferenceableoperator= (SafeReferenceable< Resource > &&other)
 Move assignment operator. More...
 
 ~SafeReferenceable ()
 Protected destructor. More...
 

Static Protected Member Functions

static Format getFormatFromDepth (const uint32 depth)
 Get the texture format from pixel depth. More...
 
static unsigned int getDepthFromFormat (const Format format)
 Get the texture pixel depth from format. More...
 

Protected Attributes

Format m_format
 Must be filled by derived classes during load() More...
 

Detailed Description

Definition at line 37 of file Texture.hpp.

Member Enumeration Documentation

enum jop::Texture::Format
strong

Texture format

Enumerator
None 

For internal functionality, do not use (except with RenderTexture)

Alpha_UB_8 

8 bit alpha texture

RGB_UB_8 

24 bit RGB texture

RGBA_UB_8 

32 bit RGBA texture

RGB_F_16 

48 bit floating point RGB texture

        \warning On GLES 2.0, supported only with the extension GL_OES_texture_half_float
RGBA_F_16 

64 bit floating point RGBA texture

        \warning On GLES 2.0, supported only with the extension GL_OES_texture_half_float
Depth_US_16 

16 bit depth texture

        \warning On GLES 2.0, supported only with the extension OES_depth_texture
Depth_UI_24 

24 bit depth texture

        \warning On GLES 2.0, supported only with the extension OES_depth_texture
Stencil_UB_8 

8 bit stencil texture

        \warning Not supported on GLES 3.0 or lesser. On GLES 3.1 supported with the extension OES_texture_stencil8
DepthStencil_UI_24_B_8 

24 bit depth, 8 bit stencil

        \warning On GLES 2.0, supported only with the extension OES_packed_depth_stencil

Definition at line 59 of file Texture.hpp.

Constructor & Destructor Documentation

jop::Texture::Texture ( const std::string &  name,
const unsigned int  glTarget 
)

Constructor.

Parameters
nameName of the resource
glTargetThe OpenGL texture target, e.g. GL_TEXTURE_2D
virtual jop::Texture::~Texture ( )
overridepure virtual

Virtual destructor.

Member Function Documentation

static bool jop::Texture::allowGenMipmaps ( const glm::uvec2 &  size,
const bool  srgb 
)
static

Check is automatic mipmap generation is allowed.

Returns
True if allowed
static bool jop::Texture::allowSRGB ( )
static

Check is the sRGB color space is allowed.

Returns
True if allowed
bool jop::Texture::bind ( const unsigned int  texUnit = 0) const

Bind this texture.

Parameters
texUnitThe texture unit to bind this texture to
Returns
True if successful
void jop::Texture::destroy ( )

Destroy this texture, erasing it from video memory.

float jop::Texture::getAnisotropyLevel ( ) const

Get the anisotropy level.

Returns
The anisotropy level
const Color& jop::Texture::getBorderColor ( ) const

Get the border color.

Returns
The border color
static unsigned int jop::Texture::getDepthFromFormat ( const Format  format)
staticprotected

Get the texture pixel depth from format.

Parameters
formatThe format
Returns
The pixel depth in bytes
TextureSampler::Filter jop::Texture::getFilterMode ( ) const

Get the filtering mode.

Returns
The filtering mode
static Format jop::Texture::getFormatFromDepth ( const uint32  depth)
staticprotected

Get the texture format from pixel depth.

Parameters
depthThe pixel depth value in bytes
Returns
The format
unsigned int jop::Texture::getHandle ( ) const

Get the OpenGL handle for this texture.

Returns
The OpenGL handle
static unsigned int jop::Texture::getMaxTextureUnits ( )
static

Get the maximum texture units.

Returns
The maximum texture units. Sampler cannot be bound to texture units which have equal or greater number than this
virtual unsigned int jop::Texture::getPixelDepth ( ) const
pure virtual

Get the texture pixel depth.

Returns
The texture pixel depth in bytes

Implemented in jop::Cubemap, and jop::Texture2D.

TextureSampler::Repeat jop::Texture::getRepeatMode ( ) const

Get the repeating mode.

Returns
The repeating mode
const TextureSampler* jop::Texture::getSampler ( ) const

Get the currently bound sampler.

Returns
Pointer to the sampler. nullptr if none is bound
virtual glm::uvec2 jop::Texture::getSize ( ) const
pure virtual

Get the texture size.

Returns
The texture size

Implemented in jop::Cubemap, and jop::Texture2D.

bool jop::Texture::isValid ( ) const

Check if this texture is valid.

Returns
True if a valid texture handle exists
void jop::Texture::removeSampler ( )

Remove the bound texture sampler.

After this call, the texture-specific sampling parameters will be used.

See also
setSampler()
void jop::Texture::setAlphaSwizzle ( const Format  format)
protected

Set the swizzle mask for 8 bit textures.

By default Texture2D and Cubemap swizzle the R component to the A component. This way the alpha component can be referenced via the a component in shaders, maintaining the same functionality across GLES 2.0 and 3.0.

Parameters
formatThe format. If this is not Alpha_UB_8, nothing happens
Texture& jop::Texture::setBorderColor ( const Color color)

Set the border color.

Warning
On GLES 3.1 and lesser, only supported with one of these extensions: EXT_texture_border_clamp, OES_texture_border_clamp
Parameters
colorThe border color
Returns
Reference to self
Texture& jop::Texture::setFilterMode ( const TextureSampler::Filter  mode,
const float  param = 1.f 
)

Set the filtering mode.

Parameters
modeThe filtering mode
paramPossible anisotropic filtering level
Returns
Reference to self
Texture& jop::Texture::setRepeatMode ( const TextureSampler::Repeat  repeat)

Set the repeating mode.

Parameters
repeatThe repeating mode
Returns
Reference to self
void jop::Texture::setSampler ( const TextureSampler sampler)

Set a texture sampler.

After this call, this texture will use the sampling parameters defined by the sampler object until it is removed.

Parameters
samplerThe texture sampler to set
See also
removeSampler()
static void jop::Texture::setUnpackAlignment ( const Format  format)
static

Set the pixel store alignment.

This set the OpenGL UNPACK_ALIGNMENT parameter appropriately.

Parameters
formatThe texture format
void jop::Texture::unbind ( const unsigned int  texUnit = 0) const

Unbind a current texture.

Parameters
texUnitThe texture unit to unbind a texture from

Member Data Documentation

Format jop::Texture::m_format
protected

Must be filled by derived classes during load()

Definition at line 313 of file Texture.hpp.


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