GlistEngine
Loading...
Searching...
No Matches
gTexture.h
Go to the documentation of this file.
1/*
2* gTexture.h
3*
4* Created on: May 10, 2020
5* Author: noyan
6*/
7
8#pragma once
9
10#ifndef ENGINE_GRAPHICS_GTEXTURE_H_
11#define ENGINE_GRAPHICS_GTEXTURE_H_
12
13#include <string>
14#include "gRenderObject.h"
15#include "gRect.h"
16
17class gTexture : public gRenderObject {
18public:
31
38
45
52
54 gTexture(int w, int h, int format = GL_RGBA, bool isFbo = false);
55 gTexture(const gTexture& other);
56 gTexture(gTexture&& other) noexcept;
57 gTexture(int w, int h, int miplevels, int format, bool isFbo);
58 gTexture& operator=(const gTexture& other);
59 gTexture& operator=(gTexture&& other) noexcept;
60 virtual ~gTexture();
61
62 virtual unsigned int load(const std::string& fullPath);
63 unsigned int loadTexture(const std::string& texturePath);
64
78 unsigned int loadMask(const std::string& fullPath);
79
94 unsigned int loadMaskTexture(const std::string& maskTexturePath);
95
96 void setMaskMode(int maskMode);
97
98 void setMaskRotation(float angle);
99 void setImageRotation(float angle);
100 void setObjectRotation(float angle);
101
102 void setAlphaMasking(int maskMode);
104 bool getAlphaMasking() const;
105
106 void bind() const;
107 void bind(int textureSlotNo) const;
108 void unbind() const;
109
110 unsigned int getId() const;
111 bool isHDR() const;
112 unsigned int getInternalFormat() const;
113 unsigned int getFormat() const;
114 void setType(TextureType textureType);
116 void setWrapping(int wrapS, int wrapT);
117 void setFiltering(int minFilter, int magFilter);
118 int getWrapS() const;
119 int getWrapT() const;
120 int getFilterMin() const;
121 int getFilterMag() const;
122 const std::string& getTypeName() const;
123 const std::string& getFilename() const;
124 const std::string& getDir() const;
125 const std::string& getFullPath() const;
126
127 int getWidth() const;
128 int getHeight() const;
129 int getComponentNum() const;
130
131 void draw(int x, int y);
132 void draw(int x, int y, int w, int h);
133 void draw(int x, int y, int w, int h, float rotate);
134 void draw(int x, int y, int w, int h, int pivotx, int pivoty, float rotate);
135 void draw(int x, int y, int w, int h, int pivotx, int pivoty, float rotate, bool flipHorizontal);
136 void draw(glm::vec2 position, glm::vec2 size, float rotate = 0.0f);
137 void draw(glm::vec2 position, glm::vec2 size, glm::vec2 pivot, float rotate = 0.0f);
138
139 void drawSub(int x, int y, int sx, int sy, int sw, int sh);
140 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh);
141 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, float rotate);
142 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate);
143 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate, bool flipHorizontal);
144 void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, float rotate = 0.0f);
145 void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate = 0.0f);
146 void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate, bool flipHorizontal);
147 void drawSub(const gRect& src, const gRect& dst, float rotate = 0.f);
148 void drawSub(const gRect& src, const gRect& dst, int pivotx, int pivoty, float rotate = 0.f);
149 void drawSub(const gRect& src, const gRect& dst, glm::vec2 pivot, float rotate = 0.f);
150
151 unsigned int setData(unsigned char* textureData, int width, int height, int componentNum, bool isMutable = false, bool isStbImage = false);
152 unsigned int setDataHDR(float* textureData, int width, int height, int componentNum, bool isMutable = false, bool isStbImage = false);
153
155
158
159 void save(std::string fullpath);
160 void saveTexture(std::string fileName);
161
162 unsigned char* getData();
163
164 static const std::string& getTypeName(TextureType textureType);
165
166protected:
167 std::string fullpath, directory;
168 unsigned int id, internalformat, format;
170 std::string path;
172 unsigned char* data;
176
177 void setDataInternal(unsigned char* textureData, bool isMutable = false, bool isStbImage = false, bool clean = true);
178 void setDataInternalHDR(float* textureData, bool isMutable = false, bool isStbImage = false, bool clean = true);
179 bool isMutable();
180
181 void swap(gTexture& other) noexcept;
182 void copyFrom(const gTexture& other) noexcept;
183
184 std::string getDirName(const std::string& fname);
185 std::string getFileName(const std::string& fname);
186
187 bool ishdr;
188 float* datahdr;
192
194
195 float maskRotation = 0.0f;
196 float imageRotation = 0.0f;
197 float objectRotation = 0.0f;
198
199 bool isalphamasking = false;
200
201private:
202
203 unsigned int quadVAO, quadVBO;
204 glm::mat4 imagematrix;
205 void setupRenderData(int sx, int sy, int sw, int sh);
206 void beginDraw();
207 void endDraw();
208 bool isfbo;
209 bool isloaded;
210 bool issubpart;
211 glm::vec2 subpos;
212 glm::vec2 subscale;
213};
214
215#endif /* ENGINE_GRAPHICS_GTEXTURE_H_ */
Definition gRect.h:27
void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate, bool flipHorizontal)
void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate, bool flipHorizontal)
gTexture & operator=(const gTexture &other)
bool isMutable()
int wrapt
Definition gTexture.h:175
float objectRotation
Definition gTexture.h:197
void setDataInternalHDR(float *textureData, bool isMutable=false, bool isStbImage=false, bool clean=true)
int componentnum
Definition gTexture.h:171
void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, float rotate=0.0f)
int filtermag
Definition gTexture.h:175
int wraps
Definition gTexture.h:175
bool isstbimage
Definition gTexture.h:174
int getWidth() const
void copyFrom(const gTexture &other) noexcept
int getFilterMin() const
void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, float rotate)
void setFiltering(int minFilter, int magFilter)
gTexture(const gTexture &other)
TextureType type
Definition gTexture.h:169
bool ismutable
Definition gTexture.h:173
void setWrapping(int wrapS, int wrapT)
const std::string & getFullPath() const
bool ishdr
Definition gTexture.h:187
void drawSub(const gRect &src, const gRect &dst, float rotate=0.f)
void setMaskMode(int maskMode)
gTexture(int w, int h, int miplevels, int format, bool isFbo)
void draw(int x, int y, int w, int h, float rotate)
unsigned int loadTexture(const std::string &texturePath)
unsigned int setData(unsigned char *textureData, int width, int height, int componentNum, bool isMutable=false, bool isStbImage=false)
int getHeight() const
void draw(glm::vec2 position, glm::vec2 size, float rotate=0.0f)
TextureMagFilter
Definition gTexture.h:39
@ TEXTUREMINMAGFILTER_CLAMP
Definition gTexture.h:43
@ TEXTUREMINMAGFILTER_LINEAR
Definition gTexture.h:40
@ TEXTUREMINMAGFILTER_NEAREST
Definition gTexture.h:42
@ TEXTUREMINMAGFILTER_MIPMAPLINEAR
Definition gTexture.h:41
void disableAlphaMasking()
void swap(gTexture &other) noexcept
void draw(int x, int y, int w, int h, int pivotx, int pivoty, float rotate)
void setType(TextureType textureType)
unsigned int format
Definition gTexture.h:168
unsigned int internalformat
Definition gTexture.h:168
int filtermin
Definition gTexture.h:175
gTexture(gTexture &&other) noexcept
bool getAlphaMasking() const
int getWrapS() const
MaskMode
Definition gTexture.h:46
@ MASKMODE_MASK
Definition gTexture.h:49
@ MASKMODE_PICTURE
Definition gTexture.h:48
@ MASKMODE_BOTH_FREE_ROTATE
Definition gTexture.h:50
@ MASKMODE_BOTH
Definition gTexture.h:47
void drawSub(const gRect &src, const gRect &dst, int pivotx, int pivoty, float rotate=0.f)
TextureType getType() const
int width
Definition gTexture.h:171
std::string path
Definition gTexture.h:170
int height
Definition gTexture.h:171
void draw(int x, int y, int w, int h)
void draw(int x, int y, int w, int h, int pivotx, int pivoty, float rotate, bool flipHorizontal)
unsigned int loadMaskTexture(const std::string &maskTexturePath)
void bind() const
int getFilterMag() const
const std::string & getTypeName() const
void cleanupData()
TextureWrap
Definition gTexture.h:32
@ TEXTUREWRAP_CLAMP
Definition gTexture.h:34
@ TEXTUREWRAP_CLAMPTOEDGE
Definition gTexture.h:35
@ TEXTUREWRAP_NEAREST
Definition gTexture.h:36
@ TEXTUREWRAP_REPEAT
Definition gTexture.h:33
gTexture(int w, int h, int format=GL_RGBA, bool isFbo=false)
bool isalphamasking
Definition gTexture.h:199
void saveTexture(std::string fileName)
void drawSub(int x, int y, int sx, int sy, int sw, int sh)
unsigned char * data
Definition gTexture.h:172
void setObjectRotation(float angle)
void unbind() const
float imageRotation
Definition gTexture.h:196
virtual ~gTexture()
unsigned int setDataHDR(float *textureData, int width, int height, int componentNum, bool isMutable=false, bool isStbImage=false)
std::string directory
Definition gTexture.h:167
unsigned int getInternalFormat() const
void setDataInternal(unsigned char *textureData, bool isMutable=false, bool isStbImage=false, bool clean=true)
float maskRotation
Definition gTexture.h:195
float * datahdr
Definition gTexture.h:188
const std::string & getDir() const
bool istextureallocated
Definition gTexture.h:191
const std::string & getFilename() const
unsigned int loadMask(const std::string &fullPath)
gTexture & operator=(gTexture &&other) noexcept
int maskmode
Definition gTexture.h:193
void draw(int x, int y)
bool isHDR() const
bool ismaskloaded
Definition gTexture.h:189
std::string getDirName(const std::string &fname)
void setMaskRotation(float angle)
std::string fullpath
Definition gTexture.h:167
unsigned int getId() const
unsigned int getFormat() const
int getComponentNum() const
static const std::string & getTypeName(TextureType textureType)
void setImageRotation(float angle)
void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate=0.0f)
unsigned char * getData()
TextureType
Definition gTexture.h:19
@ TEXTURETYPE_PBR_AO
Definition gTexture.h:28
@ TEXTURETYPE_COUNT
Definition gTexture.h:29
@ TEXTURETYPE_HEIGHT
Definition gTexture.h:23
@ TEXTURETYPE_NORMAL
Definition gTexture.h:22
@ TEXTURETYPE_PBR_ALBEDO
Definition gTexture.h:24
@ TEXTURETYPE_PBR_METALNESS
Definition gTexture.h:26
@ TEXTURETYPE_DIFFUSE
Definition gTexture.h:20
@ TEXTURETYPE_PBR_ROUGHNESS
Definition gTexture.h:25
@ TEXTURETYPE_PBR_NORMAL
Definition gTexture.h:27
@ TEXTURETYPE_SPECULAR
Definition gTexture.h:21
std::string getFileName(const std::string &fname)
void setAlphaMasking(int maskMode)
void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate)
void bind(int textureSlotNo) const
void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh)
void draw(glm::vec2 position, glm::vec2 size, glm::vec2 pivot, float rotate=0.0f)
gTexture * masktexture
Definition gTexture.h:190
void setupRenderData()
void save(std::string fullpath)
int getWrapT() const
void drawSub(const gRect &src, const gRect &dst, glm::vec2 pivot, float rotate=0.f)
virtual unsigned int load(const std::string &fullPath)
unsigned int id
Definition gTexture.h:168
void cleanupAll()