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
5#include <glad/gl.h>
6
7#include <cstdint>
8
9namespace StevEngine::Visuals {
16 class Texture {
17 public:
23
28 Texture(const Texture& copy);
29
34 void operator=(const Texture& copy);
35
39 ~Texture();
40
45 void BindTexture(bool force = false);
46
51 void FreeTexture();
52
57 bool IsBound() const { return bound; };
58
63 GLuint GetGLLocation() const { return GLLocation; };
64
69 std::string GetPath() const { return path; }
70
72 const static Texture empty;
73
74 protected:
76 Texture() : bound(false), surface(nullptr), GLLocation(0) {};
77
78 std::string path;
79 SDL_Surface* surface;
80 GLuint GLLocation;
81 bool bound;
82 };
83
84 class ComputeTexture : public Texture {
85 public:
86 ComputeTexture(uint32_t width, uint32_t height, GLenum format = GL_RGBA32F);
87
92 ComputeTexture(const ComputeTexture& copy);
93
94 ~ComputeTexture();
95
100 void BindTexture(bool force = false);
101
108 bool AttachToFrameBuffer(uint32_t framebuffer, GLenum attachmentType = GL_COLOR_ATTACHMENT0);
109
117 void* RetrieveData(GLenum format, size_t dataSize = sizeof(float), GLenum pixel = GL_FLOAT) const;
118
119 const uint32_t width;
120 const uint32_t height;
121 const GLenum format;
122 };
123}
124#endif
Container for loaded resource data.
Definition ResourceManager.hpp:11
const GLenum format
OpenGL image storage format.
Definition Texture.hpp:121
const uint32_t height
Height of the texture.
Definition Texture.hpp:120
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:86
const uint32_t width
Width of the texture.
Definition Texture.hpp:119
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:73
void BindTexture(bool force=false)
Bind texture to OpenGL Generates and configures texture in GPU memory.
Definition Texture.cpp:59
SDL_Surface * surface
SDL surface containing image data.
Definition Texture.hpp:79
bool bound
Whether texture is bound to OpenGL.
Definition Texture.hpp:81
void operator=(const Texture &copy)
Assignment operator.
Definition Texture.cpp:17
void BindTexture(bool force=false)
Bind texture to OpenGL Generates and configures texture in GPU memory.
Definition Texture.cpp:25
bool IsBound() const
Check if texture is bound to OpenGL.
Definition Texture.hpp:57
void FreeTexture()
Free texture from OpenGL Releases texture from GPU memory.
Definition Texture.cpp:49
static const Texture empty
Empty texture singleton.
Definition Texture.hpp:72
std::string path
Path to texture file.
Definition Texture.hpp:78
GLuint GLLocation
OpenGL texture ID.
Definition Texture.hpp:80
Texture()
Create empty texture.
Definition Texture.hpp:76
std::string GetPath() const
Get texture file path.
Definition Texture.hpp:69
~Texture()
Clean up texture resources.
Definition Texture.cpp:24
GLuint GetGLLocation() const
Get OpenGL texture ID.
Definition Texture.hpp:63
Texture(Resources::Resource file)
Load texture from resource.
Definition Texture.cpp:13