Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::OpenGLTexture2D Class Reference

#include <OpenGLTexture.h>

Inheritance diagram for Muto::OpenGLTexture2D:
Muto::Texture2D Muto::Texture

Public Member Functions

virtual void Bind (uint32_t slot) const override
 Binds the texture to the specified slot for use.
 
virtual uint32_t GetHeight () const override
 Returns the height of the texture.
 
virtual std::string GetName () const override
 
virtual uint32_t GetRendererID () const override
 Returns the renderer ID of the texture.
 
virtual uint32_t GetWidth () const override
 Returns the width of the texture.
 
 OpenGLTexture2D (const std::string &path)
 
 OpenGLTexture2D (uint32_t width, uint32_t height)
 
virtual bool operator== (const Texture2D &other) const override
 
virtual void SetData (void *data, uint32_t size) override
 Sets the data of the texture.
 
virtual ~OpenGLTexture2D ()
 
- Public Member Functions inherited from Muto::Texture
virtual ~Texture ()=default
 

Private Attributes

GLenum m_DataFormat
 
uint32_t m_Height
 
GLenum m_InternalFormat
 
std::string m_Path
 
uint32_t m_RendererID
 
uint32_t m_Width
 

Additional Inherited Members

- Static Public Member Functions inherited from Muto::Texture2D
static Ref< Texture2D > Create (const std::string &path)
 
static Ref< Texture2D > Create (uint32_t width, uint32_t height)
 

Constructor & Destructor Documentation

◆ OpenGLTexture2D() [1/2]

Muto::OpenGLTexture2D::OpenGLTexture2D ( uint32_t  width,
uint32_t  height 
)
11 {
15
18
21
24 }
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
GLenum m_InternalFormat
Definition OpenGLTexture.h:34
GLenum m_DataFormat
Definition OpenGLTexture.h:34
uint32_t m_RendererID
Definition OpenGLTexture.h:33
uint32_t m_Height
Definition OpenGLTexture.h:32
uint32_t m_Width
Definition OpenGLTexture.h:32
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References m_Height, and m_Width.

◆ OpenGLTexture2D() [2/2]

Muto::OpenGLTexture2D::OpenGLTexture2D ( const std::string &  path)
27 : m_Path(path)
28 {
30 int width, height, channels;
32 stbi_uc* data = nullptr;
33 {
34 MU_PROFILE_SCOPE("stbi_load - OpenGLTexture2D::OpenGLTexture2D(const std::string&)");
35 data = stbi_load(path.c_str(), (int*)&width, (int*)&height, &channels, 0);
36 }
37 MU_CORE_ASSERT(data, "Failed to load image from: " + path);
38
39 m_Width = width;
41
43 if (channels == 4)
44 {
47 }
48 else if (channels == 3)
49 {
52 }
53
56
57
58 MU_CORE_ASSERT(internalFormat & dataFormat, "Format not supported!");
59
62
65
68
70
72 }
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
unsigned int GLenum
Definition OpenGLShader.h:7
std::string m_Path
Definition OpenGLTexture.h:31

References m_Height, m_Path, m_RendererID, and m_Width.

◆ ~OpenGLTexture2D()

Muto::OpenGLTexture2D::~OpenGLTexture2D ( )
virtual

References m_RendererID.

Member Function Documentation

◆ Bind()

void Muto::OpenGLTexture2D::Bind ( uint32_t  slot) const
overridevirtual

Binds the texture to the specified slot for use.

Implements Muto::Texture.

References m_RendererID.

◆ GetHeight()

virtual uint32_t Muto::OpenGLTexture2D::GetHeight ( ) const
inlineoverridevirtual

Returns the height of the texture.

Implements Muto::Texture.

16{ return m_Height; }

References m_Height.

◆ GetName()

std::string Muto::OpenGLTexture2D::GetName ( ) const
overridevirtual

Implements Muto::Texture.

95 {
96 // Extract filename from path
97 size_t lastSlash = m_Path.find_last_of("/\\");
98 if (lastSlash == std::string::npos)
99 return m_Path; // No directory part
100 else
101 return m_Path.substr(lastSlash + 1);
102
103 }

References m_Path.

◆ GetRendererID()

virtual uint32_t Muto::OpenGLTexture2D::GetRendererID ( ) const
inlineoverridevirtual

Returns the renderer ID of the texture.

Implements Muto::Texture.

17{ return m_RendererID; }

References m_RendererID.

◆ GetWidth()

virtual uint32_t Muto::OpenGLTexture2D::GetWidth ( ) const
inlineoverridevirtual

Returns the width of the texture.

Implements Muto::Texture.

15{ return m_Width; }

References m_Width.

◆ operator==()

virtual bool Muto::OpenGLTexture2D::operator== ( const Texture2D &  other) const
inlineoverridevirtual

Implements Muto::Texture.

24 {
25 return m_RendererID == ((OpenGLTexture2D&)other).m_RendererID;
26 }
OpenGLTexture2D(uint32_t width, uint32_t height)
Definition OpenGLTexture.cpp:9

References m_RendererID.

◆ SetData()

void Muto::OpenGLTexture2D::SetData ( void *  data,
uint32_t  size 
)
overridevirtual

Sets the data of the texture.

Parameters
dataPointer to the data to be set.
sizeSize of the data in bytes.

Implements Muto::Texture.

87 {
89 uint32_t bpp = (m_DataFormat == GL_RGBA ? 4 : 3);
90 MU_CORE_ASSERT(size == m_Width * m_Height * bpp, "Data must be entire texture!");
92 }

Member Data Documentation

◆ m_DataFormat

GLenum Muto::OpenGLTexture2D::m_DataFormat
private

◆ m_Height

uint32_t Muto::OpenGLTexture2D::m_Height
private

◆ m_InternalFormat

GLenum Muto::OpenGLTexture2D::m_InternalFormat
private

◆ m_Path

std::string Muto::OpenGLTexture2D::m_Path
private

Referenced by GetName(), and OpenGLTexture2D().

◆ m_RendererID

uint32_t Muto::OpenGLTexture2D::m_RendererID
private

◆ m_Width

uint32_t Muto::OpenGLTexture2D::m_Width
private

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