StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
Texture.hpp
1#pragma once
2#ifdef StevEngine_RENDERER_GL
3#include "main/ResourceManager.hpp"
4#include "glad/gl.h"
5#include <cstdint>
6
7namespace StevEngine::Visuals {
14 class Texture {
15 public:
21
26 Texture(const Texture& copy);
27
32 void operator=(const Texture& copy);
33
37 ~Texture();
38
43 void BindTexture(bool force = false);
44
49 void FreeTexture();
50
55 bool IsBound() const { return bound; };
56
61 GLuint GetGLLocation() const { return GLLocation; };
62
67 std::string GetPath() const { return path; }
68
70 const static Texture empty;
71
72 protected:
74 Texture() : bound(false), surface(nullptr), GLLocation(0) {};
75
76 std::string path;
77 SDL_Surface* surface;
78 GLuint GLLocation;
79 bool bound;
80 };
81
82 class ComputeTexture : public Texture {
83 public:
84 ComputeTexture(uint32_t width, uint32_t height, GLenum format = GL_RGBA32F);
85
90 ComputeTexture(const ComputeTexture& copy);
91
92 ~ComputeTexture();
93
98 void BindTexture(bool force = false);
99
106 bool AttachToFrameBuffer(uint32_t framebuffer, GLenum attachmentType = GL_COLOR_ATTACHMENT0);
107
115 void* RetrieveData(GLenum format, size_t dataSize = sizeof(float), GLenum pixel = GL_FLOAT) const;
116
117 const uint32_t width;
118 const uint32_t height;
119 const GLenum format;
120 };
121}
122#endif
Container for loaded resource data.
Definition ResourceManager.hpp:11
const GLenum format
OpenGL image storage format.
Definition Texture.hpp:119
const uint32_t height
Height of the texture.
Definition Texture.hpp:118
void * RetrieveData(GLenum format, size_t dataSize=sizeof(float), GLenum pixel=GL_FLOAT) const
Retrieve pointer to the data from the texture.
Definition Texture.cpp:87
const uint32_t width
Width of the texture.
Definition Texture.hpp:117
bool AttachToFrameBuffer(uint32_t framebuffer, GLenum attachmentType=GL_COLOR_ATTACHMENT0)
Attach to an OpenGL framebuffer Generates and configures texture in GPU memory.
Definition Texture.cpp:74
void BindTexture(bool force=false)
Bind texture to OpenGL Generates and configures texture in GPU memory.
Definition Texture.cpp:60
SDL_Surface * surface
SDL surface containing image data.
Definition Texture.hpp:77
bool bound
Whether texture is bound to OpenGL.
Definition Texture.hpp:79
void operator=(const Texture &copy)
Assignment operator.
Definition Texture.cpp:18
void BindTexture(bool force=false)
Bind texture to OpenGL Generates and configures texture in GPU memory.
Definition Texture.cpp:26
bool IsBound() const
Check if texture is bound to OpenGL.
Definition Texture.hpp:55
void FreeTexture()
Free texture from OpenGL Releases texture from GPU memory.
Definition Texture.cpp:50
static const Texture empty
Empty texture singleton.
Definition Texture.hpp:70
std::string path
Path to texture file.
Definition Texture.hpp:76
GLuint GLLocation
OpenGL texture ID.
Definition Texture.hpp:78
Texture()
Create empty texture.
Definition Texture.hpp:74
std::string GetPath() const
Get texture file path.
Definition Texture.hpp:67
~Texture()
Clean up texture resources.
Definition Texture.cpp:25
GLuint GetGLLocation() const
Get OpenGL texture ID.
Definition Texture.hpp:61
Texture(Resources::Resource file)
Load texture from resource.
Definition Texture.cpp:14