RunicVTT Open Source Virtual Tabletop for TTRPG using P2P
Loading...
Searching...
No Matches
Texture Class Reference

#include <Texture.h>

Collaboration diagram for Texture:

Public Member Functions

 Texture (const std::string &path)
 
 ~Texture ()
 
unsigned int GetRendererID ()
 
void SetFilePath (const std::string &path)
 
void Bind (unsigned int slot=0) const
 
void Unbind () const
 
int GetWidth () const
 
int GetHeight () const
 

Public Attributes

std::string m_FilePath
 

Private Attributes

unsigned char * m_LocalBuffer
 
int m_Width
 
int m_Height
 
int m_BPP
 
unsigned int m_RendererID
 

Detailed Description

Definition at line 5 of file Texture.h.

Constructor & Destructor Documentation

◆ Texture()

Texture::Texture ( const std::string & path)

Definition at line 5 of file Texture.cpp.

5 :
6 m_RendererID(0), m_FilePath(path), m_LocalBuffer(nullptr), m_Width(0), m_Height(0), m_BPP(0)
7{
8
9 stbi_set_flip_vertically_on_load(1);
10 m_LocalBuffer = stbi_load(path.c_str(), &m_Width, &m_Height, &m_BPP, 4);
11 if (m_LocalBuffer == NULL)
12 {
13 std::cout << stbi_failure_reason();
14 }
15 GLCall(glGenTextures(1, &m_RendererID));
16 GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
17
18 GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer));
19 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
20 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
21 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
22 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
23
24 GLCall(glBindTexture(GL_TEXTURE_2D, 0));
25
26 if (m_LocalBuffer)
27 stbi_image_free(m_LocalBuffer);
28 stbi_set_flip_vertically_on_load(0);
29}
#define GLCall(x)
Definition Renderer.h:12
int m_BPP
Definition Texture.h:9
int m_Height
Definition Texture.h:9
std::string m_FilePath
Definition Texture.h:13
unsigned int m_RendererID
Definition Texture.h:10
unsigned char * m_LocalBuffer
Definition Texture.h:8
int m_Width
Definition Texture.h:9

◆ ~Texture()

Texture::~Texture ( )

Definition at line 31 of file Texture.cpp.

32{
33 GLCall(glDeleteTextures(1, &m_RendererID));
34}

Member Function Documentation

◆ Bind()

void Texture::Bind ( unsigned int slot = 0) const

Definition at line 46 of file Texture.cpp.

47{
48
49 GLCall(glActiveTexture(GL_TEXTURE0 + slot));
50 GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
51}

◆ GetHeight()

int Texture::GetHeight ( ) const
inline

Definition at line 26 of file Texture.h.

27 {
28 return m_Height;
29 };

◆ GetRendererID()

unsigned int Texture::GetRendererID ( )

Definition at line 36 of file Texture.cpp.

37{
38 return m_RendererID;
39}

◆ GetWidth()

int Texture::GetWidth ( ) const
inline

Definition at line 22 of file Texture.h.

23 {
24 return m_Width;
25 };

◆ SetFilePath()

void Texture::SetFilePath ( const std::string & path)

Definition at line 41 of file Texture.cpp.

42{
43 m_FilePath = path;
44}

◆ Unbind()

void Texture::Unbind ( ) const

Definition at line 53 of file Texture.cpp.

54{
55 GLCall(glBindTexture(GL_TEXTURE_2D, 0));
56}

Member Data Documentation

◆ m_BPP

int Texture::m_BPP
private

Definition at line 9 of file Texture.h.

◆ m_FilePath

std::string Texture::m_FilePath

Definition at line 13 of file Texture.h.

◆ m_Height

int Texture::m_Height
private

Definition at line 9 of file Texture.h.

◆ m_LocalBuffer

unsigned char* Texture::m_LocalBuffer
private

Definition at line 8 of file Texture.h.

◆ m_RendererID

unsigned int Texture::m_RendererID
private

Definition at line 10 of file Texture.h.

◆ m_Width

int Texture::m_Width
private

Definition at line 9 of file Texture.h.


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