nCine  2025.04.r498-9d36345
A cross-platform 2D game engine
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
ncine::Texture Class Reference

Texture class. More...

#include <Texture.h>

Inheritance diagram for ncine::Texture:
Inheritance graph
[legend]
Collaboration diagram for ncine::Texture:
Collaboration graph
[legend]

Public Types

enum class  Format {
  R8 , RG8 , RGB8 , RGBA8 ,
  UNKNOWN
}
 Texture formats.
 
enum class  Filtering {
  NEAREST , LINEAR , NEAREST_MIPMAP_NEAREST , LINEAR_MIPMAP_NEAREST ,
  NEAREST_MIPMAP_LINEAR , LINEAR_MIPMAP_LINEAR
}
 Texture filtering modes.
 
enum class  Wrap { CLAMP_TO_EDGE , MIRRORED_REPEAT , REPEAT }
 Texture wrap modes.
 
- Public Types inherited from ncine::Object
enum class  ObjectType {
  BASE = 0 , TEXTURE , SHADER , SCENENODE ,
  SPRITE , MESH_SPRITE , ANIMATED_SPRITE , PARTICLE ,
  PARTICLE_SYSTEM , FONT , TEXTNODE , AUDIOBUFFER ,
  AUDIOBUFFER_PLAYER , AUDIOSTREAM_PLAYER
}
 Object types.
 

Public Member Functions

 Texture ()
 Creates an OpenGL texture name.
 
 Texture (const char *name, Format format, int mipMapCount, int width, int height)
 Creates an empty texture with the specified format, MIP levels, and size. More...
 
 Texture (const char *name, Format format, int mipMapCount, Vector2i size)
 Creates an empty texture with the specified format, MIP levels, and size using a vector. More...
 
 Texture (const char *name, Format format, int width, int height)
 Creates an empty texture with the specified format and size. More...
 
 Texture (const char *name, Format format, Vector2i size)
 Creates an empty texture with the specified format and size using a vector. More...
 
 Texture (const char *bufferName, const unsigned char *bufferPtr, unsigned long int bufferSize)
 Creates a texture from a named memory buffer. More...
 
 Texture (const char *filename)
 Creates a texture from an image file.
 
 Texture (Texture &&)
 Default move constructor.
 
Textureoperator= (Texture &&)
 Default move assignment operator.
 
void init (const char *name, Format format, int mipMapCount, int width, int height)
 Initializes an empty texture with the specified format, MIP levels, and size.
 
void init (const char *name, Format format, int mipMapCount, Vector2i size)
 Initializes an empty texture with the specified format, MIP levels, and size using a vector.
 
void init (const char *name, Format format, int width, int height)
 Initializes an empty texture with the specified format and size.
 
void init (const char *name, Format format, Vector2i size)
 Initializes an empty texture with the specified format and size using a vector.
 
bool loadFromMemory (const char *bufferName, const unsigned char *bufferPtr, unsigned long int bufferSize)
 
bool loadFromFile (const char *filename)
 
bool loadFromTexels (const unsigned char *bufferPtr)
 Loads all texture texels in raw format from a memory buffer in the first mip level. More...
 
bool loadFromTexels (const unsigned char *bufferPtr, unsigned int x, unsigned int y, unsigned int width, unsigned int height)
 Loads texels in raw format from a memory buffer to a texture sub-region in the first mip level. More...
 
bool loadFromTexels (const unsigned char *bufferPtr, Recti region)
 Loads texels in raw format from a memory buffer to a texture sub-region with a rectangle in the first mip level. More...
 
bool loadFromTexels (const unsigned char *bufferPtr, unsigned int level, unsigned int x, unsigned int y, unsigned int width, unsigned int height)
 Loads texels in raw format from a memory buffer to a specific texture mip level and sub-region. More...
 
bool loadFromTexels (const unsigned char *bufferPtr, unsigned int level, Recti region)
 Loads texels in raw format from a memory buffer to a specific texture mip level and sub-region with a rectangle. More...
 
bool saveToMemory (unsigned char *bufferPtr)
 Saves all texture texels in the first mip level in raw format to a memory buffer.
 
bool saveToMemory (unsigned char *bufferPtr, unsigned int level)
 Saves all texture texels in the specified texture mip level in raw format to a memory buffer.
 
int width () const
 Returns texture width.
 
int height () const
 Returns texture height.
 
int mipMapLevels () const
 Returns texture MIP map levels.
 
Vector2i size () const
 Returns texture size.
 
Recti rect () const
 Returns texture rectangle.
 
bool isCompressed () const
 Returns true if the texture holds compressed data.
 
Format format () const
 Returns the texture data format.
 
unsigned int numChannels () const
 Returns the number of color channels.
 
unsigned long dataSize () const
 Returns the amount of video memory needed to load the texture.
 
Filtering minFiltering () const
 Returns the texture filtering for minification.
 
Filtering magFiltering () const
 Returns the texture filtering for magnification.
 
Wrap wrap () const
 Returns texture wrap for both s and t coordinates.
 
void setMinFiltering (Filtering filter)
 Sets the texture filtering for minification.
 
void setMagFiltering (Filtering filter)
 Sets the texture filtering for magnification.
 
void setWrap (Wrap wrapMode)
 Sets texture wrap for both s and t coordinates.
 
bool isChromaKeyEnabled () const
 Returns true if chroma key transparency will be used when loading.
 
Color chromaKeyColor () const
 Returns the color treated as transparent when loading a texture.
 
void setChromaKeyEnabled (bool chromaKeyEnabled)
 Sets the chroma key transparency state to use when loading.
 
void setChromaKeyColor (const Color &chromaKeyColor)
 Sets the color to be treated as transparent when loading a texture.
 
void setChromaKeyColor (const Colorf &chromaKeyColor)
 Sets the color to be treated as transparent when loading a texture, using a Colorf
 
void setGLTextureLabel (const char *label)
 Sets the OpenGL object label for the texture.
 
void * guiTexId () const
 Returns the user data opaque pointer for ImGui's ImTextureID or Nuklear's texture handle. More...
 
- Public Member Functions inherited from ncine::Object
 Object (ObjectType type)
 Constructs an object with a specified type and adds it to the index.
 
 Object (ObjectType type, const char *name)
 Constructs an object with a specified type and name and adds it to the index.
 
virtual ~Object ()
 Removes an object from the index and then destroys it.
 
 Object (Object &&other)
 Move constructor.
 
Objectoperator= (Object &&other)
 Move assignment operator.
 
unsigned int id () const
 Returns the object identification number.
 
ObjectType type () const
 Returns the object type (RTTI)
 
const char * name () const
 Returns the object name.
 
void setName (const char *name)
 Sets the object name.
 

Static Public Member Functions

static ObjectType sType ()
 
- Static Public Member Functions inherited from ncine::Object
static ObjectType sType ()
 Static method to return class type.
 
template<class T >
static T * fromId (unsigned int id)
 Returns a casted pointer to the object with the specified id, if any exists.
 

Friends

class Material
 
class Viewport
 

Additional Inherited Members

- Static Public Attributes inherited from ncine::Object
static const unsigned int MaxNameLength = 128
 Maximum length for an object name.
 
- Protected Member Functions inherited from ncine::Object
 Object (const Object &other)
 Protected copy constructor used to clone objects.
 
- Protected Attributes inherited from ncine::Object
ObjectType type_
 Object type.
 

Detailed Description

Texture class.

Constructor & Destructor Documentation

◆ Texture() [1/5]

ncine::Texture::Texture ( const char *  name,
Format  format,
int  mipMapCount,
int  width,
int  height 
)

Creates an empty texture with the specified format, MIP levels, and size.

Note
It specifies a pixel format and it is intended to be used with loadFromTexels()

◆ Texture() [2/5]

ncine::Texture::Texture ( const char *  name,
Format  format,
int  mipMapCount,
Vector2i  size 
)

Creates an empty texture with the specified format, MIP levels, and size using a vector.

Note
It specifies a pixel format and it is intended to be used with loadFromTexels()

◆ Texture() [3/5]

ncine::Texture::Texture ( const char *  name,
Format  format,
int  width,
int  height 
)

Creates an empty texture with the specified format and size.

Note
It specifies a pixel format and it is intended to be used with loadFromTexels()

◆ Texture() [4/5]

ncine::Texture::Texture ( const char *  name,
Format  format,
Vector2i  size 
)

Creates an empty texture with the specified format and size using a vector.

Note
It specifies a pixel format and it is intended to be used with loadFromTexels()

◆ Texture() [5/5]

ncine::Texture::Texture ( const char *  bufferName,
const unsigned char *  bufferPtr,
unsigned long int  bufferSize 
)

Creates a texture from a named memory buffer.

Note
It needs a bufferName with a valid file extension as it loads compressed data from a file in memory

Member Function Documentation

◆ guiTexId()

void * ncine::Texture::guiTexId ( ) const

Returns the user data opaque pointer for ImGui's ImTextureID or Nuklear's texture handle.

The pointer is an opaque handle to be used only by ImGui or Nuklear. It is considered immutable from an user point of view and thus retrievable by a constant method.

◆ loadFromMemory()

bool ncine::Texture::loadFromMemory ( const char *  bufferName,
const unsigned char *  bufferPtr,
unsigned long int  bufferSize 
)
Note
It needs a bufferName with a valid file extension as it loads compressed data from a file in memory

◆ loadFromTexels() [1/5]

bool ncine::Texture::loadFromTexels ( const unsigned char *  bufferPtr)

Loads all texture texels in raw format from a memory buffer in the first mip level.

Note
It loads uncompressed pixel data from memory using the Format specified in the constructor

◆ loadFromTexels() [2/5]

bool ncine::Texture::loadFromTexels ( const unsigned char *  bufferPtr,
Recti  region 
)

Loads texels in raw format from a memory buffer to a texture sub-region with a rectangle in the first mip level.

Note
It loads uncompressed pixel data from memory using the Format specified in the constructor

◆ loadFromTexels() [3/5]

bool ncine::Texture::loadFromTexels ( const unsigned char *  bufferPtr,
unsigned int  level,
Recti  region 
)

Loads texels in raw format from a memory buffer to a specific texture mip level and sub-region with a rectangle.

It loads uncompressed pixel data from memory using the Format specified in the constructor

◆ loadFromTexels() [4/5]

bool ncine::Texture::loadFromTexels ( const unsigned char *  bufferPtr,
unsigned int  level,
unsigned int  x,
unsigned int  y,
unsigned int  width,
unsigned int  height 
)

Loads texels in raw format from a memory buffer to a specific texture mip level and sub-region.

Note
It loads uncompressed pixel data from memory using the Format specified in the constructor

◆ loadFromTexels() [5/5]

bool ncine::Texture::loadFromTexels ( const unsigned char *  bufferPtr,
unsigned int  x,
unsigned int  y,
unsigned int  width,
unsigned int  height 
)

Loads texels in raw format from a memory buffer to a texture sub-region in the first mip level.

Note
It loads uncompressed pixel data from memory using the Format specified in the constructor

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