Raftel Engine
 
Loading...
Searching...
No Matches
Raftel::Texture Class Reference

Represents an OpenGL texture object. More...

#include <texture.hpp>

Public Member Functions

 Texture ()
 Default constructor that initializes the texture ID to 0.
 
 Texture (const std::vector< std::string > &faces)
 Constructs a cubemap texture from six image files.
 
 Texture (TextureImage image)
 Constructor that creates an OpenGL texture from a TextureImage.
 
 ~Texture ()
 Destructor that deletes the OpenGL texture.
 
void bind (int unit) const
 Binds the texture to a texture unit.
 
const std::string & getLastError () const
 Gets the last error message generated by texture operations.
 
GLuint getID () const
 Move constructor.
 

Static Public Member Functions

static std::shared_ptr< TextureloadTexture (const std::string &texturePath)
 Loads a texture from a file and creates an OpenGL texture object.
 
static std::shared_ptr< TextureloadCubemap (const std::vector< std::string > &faces)
 Loads a cubemap texture from six image files.
 

Public Attributes

GLuint id
 OpenGL texture ID.
 
TextureType type
 Specifies the type of texture (2D or Cubemap)
 

Detailed Description

Represents an OpenGL texture object.

The Texture class wraps the OpenGL texture object, providing functions to load, bind, and manage textures. It also includes functionality for error handling related to texture loading.

Definition at line 88 of file texture.hpp.

Constructor & Destructor Documentation

◆ Texture() [1/3]

Raftel::Texture::Texture ( )
inline

Default constructor that initializes the texture ID to 0.

Definition at line 96 of file texture.hpp.

◆ Texture() [2/3]

Raftel::Texture::Texture ( const std::vector< std::string > & faces)

Constructs a cubemap texture from six image files.

This constructor loads a set of six images and creates a cubemap texture used for skyboxes or environment mapping.

The images must be provided in the following order:

  • Right (+X)
  • Left (-X)
  • Top (+Y)
  • Bottom (-Y)
  • Front (+Z)
  • Back (-Z)
Parameters
facesA vector containing the file paths of the six images.

◆ Texture() [3/3]

Raftel::Texture::Texture ( TextureImage image)

Constructor that creates an OpenGL texture from a TextureImage.

Parameters
imageThe TextureImage that contains the image data to create the texture.

Member Function Documentation

◆ bind()

void Raftel::Texture::bind ( int unit) const

Binds the texture to a texture unit.

This function binds the texture to the specified texture unit and sets the corresponding shader sampler to the texture unit.

Parameters
unitThe texture unit to bind the texture to (e.g., 0, 1, etc.).
sampleThe name of the sampler uniform in the shader.
shader_programThe shader program to which the texture is bound.

◆ getID()

GLuint Raftel::Texture::getID ( ) const
inline

Move constructor.

Transfers ownership of the OpenGL texture ID from another Texture.

Parameters
otherThe Texture to move from.

Gets the OpenGL texture ID.

Returns
GLuint The OpenGL texture ID.

Definition at line 188 of file texture.hpp.

◆ getLastError()

const std::string & Raftel::Texture::getLastError ( ) const
inline

Gets the last error message generated by texture operations.

Returns
A string containing the last error message.

Definition at line 173 of file texture.hpp.

◆ loadCubemap()

static std::shared_ptr< Texture > Raftel::Texture::loadCubemap ( const std::vector< std::string > & faces)
static

Loads a cubemap texture from six image files.

This function creates an OpenGL cubemap texture using the six provided images representing the faces of a cube. The order of the images must be:

  • Right
  • Left
  • Top
  • Bottom
  • Front
  • Back
Parameters
facesA vector containing the file paths of the six images.
Returns
std::shared_ptr<Texture> A shared pointer to the loaded cubemap texture.

◆ loadTexture()

static std::shared_ptr< Texture > Raftel::Texture::loadTexture ( const std::string & texturePath)
static

Loads a texture from a file and creates an OpenGL texture object.

This function uses the stb_image library to load an image from disk and then creates an OpenGL texture object with the image data.

Parameters
texturePathThe file path to the texture image.
Returns
A shared pointer to the loaded texture.

Member Data Documentation

◆ id

GLuint Raftel::Texture::id

OpenGL texture ID.

Definition at line 90 of file texture.hpp.

◆ type

TextureType Raftel::Texture::type

Specifies the type of texture (2D or Cubemap)

Definition at line 91 of file texture.hpp.


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