Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::OpenGLTexture2D Class Reference

#include <OpenGLTexture.h>

Inheritance diagram for Vesper::OpenGLTexture2D:
Vesper::Texture2D Vesper::Texture

Public Member Functions

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

Private Attributes

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

Additional Inherited Members

Static Public Member Functions inherited from Vesper::Texture2D
static Ref< Texture2DCreate (uint32_t width, uint32_t height)
static Ref< Texture2DCreate (const std::string &path)

Constructor & Destructor Documentation

◆ OpenGLTexture2D() [1/2]

Vesper::OpenGLTexture2D::OpenGLTexture2D ( uint32_t width,
uint32_t height )
10 : m_Width(width), m_Height(height)
11 {
13 m_InternalFormat = GL_RGBA8;
14 m_DataFormat = GL_RGBA;
15
16 glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
17 glTextureStorage2D(m_RendererID, 1, m_InternalFormat, m_Width, m_Height);
18
19 glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
20 glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
21
22 glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT);
23 glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT);
24 }
#define VZ_PROFILE_FUNCTION()
Definition Instrumentor.h:240
GLenum m_DataFormat
Definition OpenGLTexture.h:34
uint32_t m_Height
Definition OpenGLTexture.h:32
uint32_t m_RendererID
Definition OpenGLTexture.h:33
uint32_t m_Width
Definition OpenGLTexture.h:32
GLenum m_InternalFormat
Definition OpenGLTexture.h:34

References m_Height, and m_Width.

◆ OpenGLTexture2D() [2/2]

Vesper::OpenGLTexture2D::OpenGLTexture2D ( const std::string & path)
27 : m_Path(path)
28 {
30 int width, height, channels;
31 stbi_set_flip_vertically_on_load(1);
32 stbi_uc* data = nullptr;
33 {
34 VZ_PROFILE_SCOPE("stbi_load - OpenGLTexture2D::OpenGLTexture2D(const std::string&)");
35 data = stbi_load(path.c_str(), (int*)&width, (int*)&height, &channels, 0);
36 }
37 VZ_CORE_ASSERT(data, "Failed to load image from: " + path);
38
39 m_Width = width;
40 m_Height = height;
41
42 GLenum internalFormat = 0, dataFormat = 0;
43 if (channels == 4)
44 {
45 internalFormat = GL_RGBA8;
46 dataFormat = GL_RGBA;
47 }
48 else if (channels == 3)
49 {
50 internalFormat = GL_RGB8;
51 dataFormat = GL_RGB;
52 }
53
54 m_InternalFormat = internalFormat;
55 m_DataFormat = dataFormat;
56
57
58 VZ_CORE_ASSERT(internalFormat & dataFormat, "Format not supported!");
59
60 glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
61 glTextureStorage2D(m_RendererID, 1, internalFormat, m_Width, m_Height);
62
63 glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
64 glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
65
66 glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT);
67 glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT);
68
69 glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, dataFormat, GL_UNSIGNED_BYTE, data);
70
71 stbi_image_free(data);
72 }
#define VZ_CORE_ASSERT(x,...)
Definition Asserts.h:20
#define VZ_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_RendererID, m_Width, and OpenGLTexture2D().

Referenced by OpenGLTexture2D().

◆ ~OpenGLTexture2D()

Vesper::OpenGLTexture2D::~OpenGLTexture2D ( )
virtual
75 {
77 glDeleteTextures(1, &m_RendererID);
78 }

References m_RendererID.

Member Function Documentation

◆ Bind()

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

Binds the texture to the specified slot for use.

Implements Vesper::Texture.

81 {
83 glBindTextureUnit(slot, m_RendererID);
84 }

References m_RendererID.

◆ GetHeight()

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

Returns the height of the texture.

Implements Vesper::Texture.

16{ return m_Height; }

References m_Height.

◆ GetName()

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

Implements Vesper::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 }

◆ GetRendererID()

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

Returns the renderer ID of the texture.

Implements Vesper::Texture.

17{ return m_RendererID; }

References m_RendererID.

◆ GetWidth()

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

Returns the width of the texture.

Implements Vesper::Texture.

15{ return m_Width; }

References m_Width.

◆ operator==()

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

Implements Vesper::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 Vesper::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 Vesper::Texture.

87 {
89 uint32_t bpp = (m_DataFormat == GL_RGBA ? 4 : 3);
90 VZ_CORE_ASSERT(size == m_Width * m_Height * bpp, "Data must be entire texture!");
91 glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, m_DataFormat, GL_UNSIGNED_BYTE, data);
92 }

Member Data Documentation

◆ m_DataFormat

GLenum Vesper::OpenGLTexture2D::m_DataFormat
private

◆ m_Height

uint32_t Vesper::OpenGLTexture2D::m_Height
private

◆ m_InternalFormat

GLenum Vesper::OpenGLTexture2D::m_InternalFormat
private

◆ m_Path

std::string Vesper::OpenGLTexture2D::m_Path
private

◆ m_RendererID

uint32_t Vesper::OpenGLTexture2D::m_RendererID
private

◆ m_Width

uint32_t Vesper::OpenGLTexture2D::m_Width
private

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