2D_Game_Engine
Loading...
Searching...
No Matches
texture.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <vertexbuffer.hpp>
4
5class Renderer;
6class Entity;
7class Scene;
8
9class Texture{
10public:
11 Texture(): m_ID(std::numeric_limits<unsigned int>::max()),m_TexID(std::numeric_limits<uint32_t>::max()),m_FilePath(100,'\0'),m_LocalBuffer(nullptr),
12 m_Width(0),m_Height(0),m_BPP(0){}
13 Texture(const std::string &path,int mag_filter,int min_filter,uint32_t texID);
14 Texture(Texture &other);
15 ~Texture();
16
17 void Bind(unsigned int slot=0) const;
18 void Unbind() const;
19
20 inline int GetWidth() const{ return m_Width; }
21 inline int GetHeight() const{ return m_Height; }
22 inline unsigned int GetTexID() const{ return m_ID; }
23
25 m_ID=other.m_ID;
26 other.m_ID=std::numeric_limits<unsigned int>::max();
27 m_TexID=other.m_TexID;
35 m_Width=other.m_Width;
36 m_Height=other.m_Height;
37 m_BPP=other.m_BPP;
38 return *this;
39 }
40
42 if(this!=&other){
43 m_ID=other.m_ID;
44 other.m_ID=std::numeric_limits<unsigned int>::max();
45 m_TexID=other.m_TexID;
46 m_MagFilter=other.m_MagFilter;
47 m_MinFilter=other.m_MinFilter;
48 m_FilePath=other.m_FilePath;
49 m_LoadedFilePath=other.m_LoadedFilePath;
50 m_LoadedMagFilter=other.m_LoadedMagFilter;
51 m_LoadedMinFilter=other.m_LoadedMinFilter;
52 m_LocalBuffer=other.m_LocalBuffer;
53 m_Width=other.m_Width;
54 m_Height=other.m_Height;
55 m_BPP=other.m_BPP;
56 }
57 return *this;
58 }
59
60 inline void FreeTexture(){
61 if(m_ID!=std::numeric_limits<unsigned int>::max()){
62 glDeleteTextures(1,&m_ID);
63 if(m_LocalBuffer!=nullptr)
64 free(m_LocalBuffer);
65 }
66 }
67protected:
68 friend class Renderer;
69 friend class TexturesManager;
70 friend class SceneSerializer;
71
72 #ifdef EDITOR
73 friend class Editor;
74 #endif
75
76 unsigned int m_ID;
77 uint32_t m_TexID;
80 unsigned char *m_LocalBuffer;
82};
83
84class SpriteSheet : public Texture{
85public:
86 SpriteSheet(const std::string &path,unsigned int tile_width,unsigned int tile_height,int mag_filter,int min_filter,uint32_t tex_id)
87 :Texture(path,mag_filter,min_filter,tex_id),m_TileWidth(tile_width),m_TileHeight(tile_height){}
88 SpriteSheet(): Texture(),m_TileWidth(0),m_TileHeight(0){}
90
92 m_ID=other.m_ID;
93 other.m_ID=std::numeric_limits<unsigned int>::max();
94 m_TexID=other.m_TexID;
102 m_Width=other.m_Width;
103 m_Height=other.m_Height;
104 m_BPP=other.m_BPP;
105 m_TileWidth=other.m_TileWidth;
106 m_TileHeight=other.m_TileHeight;
107 return *this;
108 }
109
111 if(this!=&other){
112 m_ID=other.m_ID;
113 other.m_ID=std::numeric_limits<unsigned int>::max();
114 m_TexID=other.m_TexID;
115 m_MagFilter=other.m_MagFilter;
116 m_MinFilter=other.m_MinFilter;
117 m_FilePath=other.m_FilePath;
118 m_LoadedFilePath=other.m_LoadedFilePath;
119 m_LoadedMagFilter=other.m_LoadedMagFilter;
120 m_LoadedMinFilter=other.m_LoadedMinFilter;
121 m_LocalBuffer=other.m_LocalBuffer;
122 m_Width=other.m_Width;
123 m_Height=other.m_Height;
124 m_BPP=other.m_BPP;
125 m_TileWidth=other.m_TileWidth;
126 m_TileHeight=other.m_TileHeight;
127 }
128 return *this;
129 }
130
131 inline int GetTileWidth() const{ return m_TileWidth; }
132 inline int GetTileHeight() const{ return m_TileHeight; }
133
134 std::array<Vertex,4> CreateQuadSpriteSheet(float x,float y,float width,float height,float row,float col,int layer,float texID);
135
136private:
137 friend class Renderer;
138 friend class TexturesManager;
139 friend class SceneSerializer;
140 #if defined(EDITOR) || defined(APPLICATION)
141 friend class Editor;
142 #endif
143
144 #ifdef EDITOR
145 friend class Editor;
146 #endif
147
148 int m_TileWidth;
149 int m_TileHeight;
150};
Definition scene.hpp:6
SpriteSheet & operator=(SpriteSheet &&other)
Definition texture.hpp:110
std::array< Vertex, 4 > CreateQuadSpriteSheet(float x, float y, float width, float height, float row, float col, int layer, float texID)
Definition texture.cpp:89
int GetTileHeight() const
Definition texture.hpp:132
int GetTileWidth() const
Definition texture.hpp:131
SpriteSheet & operator=(SpriteSheet &other)
Definition texture.hpp:91
SpriteSheet(const std::string &path, unsigned int tile_width, unsigned int tile_height, int mag_filter, int min_filter, uint32_t tex_id)
Definition texture.hpp:86
~Texture()
Definition texture.cpp:52
void Unbind() const
Definition texture.cpp:67
unsigned int GetTexID() const
Definition texture.hpp:22
void Bind(unsigned int slot=0) const
Definition texture.cpp:62
int m_LoadedMinFilter
Definition texture.hpp:79
int GetHeight() const
Definition texture.hpp:21
uint32_t m_TexID
Definition texture.hpp:77
std::string m_LoadedFilePath
Definition texture.hpp:78
int m_LoadedMagFilter
Definition texture.hpp:79
Texture()
Definition texture.hpp:11
int m_BPP
Definition texture.hpp:81
int m_MinFilter
Definition texture.hpp:79
int GetWidth() const
Definition texture.hpp:20
int m_Height
Definition texture.hpp:81
void FreeTexture()
Definition texture.hpp:60
std::string m_FilePath
Definition texture.hpp:78
int m_MagFilter
Definition texture.hpp:79
unsigned char * m_LocalBuffer
Definition texture.hpp:80
int m_Width
Definition texture.hpp:81
unsigned int m_ID
Definition texture.hpp:76
Texture & operator=(Texture &other)
Definition texture.hpp:24
Texture & operator=(Texture &&other)
Definition texture.hpp:41