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
47 gTexture(int w, int h, int format = GL_RGBA, bool isFbo = false);
48 gTexture(const gTexture& other);
49 gTexture(gTexture&& other) noexcept;
50 gTexture& operator=(const gTexture& other);
51 gTexture& operator=(gTexture&& other) noexcept;
52 virtual ~gTexture();
53
54 virtual unsigned int load(const std::string& fullPath);
55 unsigned int loadTexture(const std::string& texturePath);
56
70 unsigned int loadMask(const std::string& fullPath);
71
86 unsigned int loadMaskTexture(const std::string& maskTexturePath);
87
88 void bind() const;
89 void bind(int textureSlotNo) const;
90 void unbind() const;
91
92 unsigned int getId() const;
93 bool isHDR() const;
94 unsigned int getInternalFormat() const;
95 unsigned int getFormat() const;
96 void setType(TextureType textureType);
98 void setWrapping(int wrapS, int wrapT);
99 void setFiltering(int minFilter, int magFilter);
100 int getWrapS() const;
101 int getWrapT() const;
102 int getFilterMin() const;
103 int getFilterMag() const;
104 const std::string& getTypeName() const;
105 const std::string& getFilename() const;
106 const std::string& getDir() const;
107 const std::string& getFullPath() const;
108
109 int getWidth() const;
110 int getHeight() const;
111 int getComponentNum() const;
112
113 void draw(int x, int y);
114 void draw(int x, int y, int w, int h);
115 void draw(int x, int y, int w, int h, float rotate);
116 void draw(int x, int y, int w, int h, int pivotx, int pivoty, float rotate);
117 void draw(int x, int y, int w, int h, int pivotx, int pivoty, float rotate, bool flipHorizontal);
118 void draw(glm::vec2 position, glm::vec2 size, float rotate = 0.0f);
119 void draw(glm::vec2 position, glm::vec2 size, glm::vec2 pivot, float rotate = 0.0f);
120
121 void drawSub(int x, int y, int sx, int sy, int sw, int sh);
122 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh);
123 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, float rotate);
124 void drawSub(int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate);
125 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);
126 void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, float rotate = 0.0f);
127 void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate = 0.0f);
128 void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate, bool flipHorizontal);
129 void drawSub(const gRect& src, const gRect& dst, float rotate = 0.f);
130 void drawSub(const gRect& src, const gRect& dst, int pivotx, int pivoty, float rotate = 0.f);
131 void drawSub(const gRect& src, const gRect& dst, glm::vec2 pivot, float rotate = 0.f);
132
133 unsigned int setData(unsigned char* textureData, int width, int height, int componentNum, bool isMutable = false, bool isStbImage = false);
134 unsigned int setDataHDR(float* textureData, int width, int height, int componentNum, bool isMutable = false, bool isStbImage = false);
135
137
140
141 void save(std::string fullpath);
142 void saveTexture(std::string fileName);
143
144 unsigned char* getData();
145
146 static const std::string& getTypeName(TextureType textureType);
147
148protected:
149 std::string fullpath, directory;
150 unsigned int id, internalformat, format;
152 std::string path;
154 unsigned char* data;
158
159 void setDataInternal(unsigned char* textureData, bool isMutable = false, bool isStbImage = false, bool clean = true);
160 void setDataInternalHDR(float* textureData, bool isMutable = false, bool isStbImage = false, bool clean = true);
161 bool isMutable();
162
163 void swap(gTexture& other) noexcept;
164 void copyFrom(const gTexture& other) noexcept;
165
166 std::string getDirName(const std::string& fname);
167 std::string getFileName(const std::string& fname);
168
169 bool ishdr;
170 float* datahdr;
174
175private:
176
177 unsigned int quadVAO, quadVBO;
178 glm::mat4 imagematrix;
179 void setupRenderData(int sx, int sy, int sw, int sh);
180 void beginDraw();
181 void endDraw();
182 bool isfbo;
183 bool isloaded;
184 bool issubpart;
185 glm::vec2 subpos;
186 glm::vec2 subscale;
187};
188
189#endif /* ENGINE_GRAPHICS_GTEXTURE_H_ */
Definition gRect.h:27
Definition gRenderObject.h:25
Definition gTexture.h:17
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:157
void setDataInternalHDR(float *textureData, bool isMutable=false, bool isStbImage=false, bool clean=true)
int componentnum
Definition gTexture.h:153
void drawSub(glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, float rotate=0.0f)
int filtermag
Definition gTexture.h:157
int wraps
Definition gTexture.h:157
bool isstbimage
Definition gTexture.h:156
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:151
bool ismutable
Definition gTexture.h:155
void setWrapping(int wrapS, int wrapT)
const std::string & getFullPath() const
bool ishdr
Definition gTexture.h:169
void drawSub(const gRect &src, const gRect &dst, float rotate=0.f)
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 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:150
unsigned int internalformat
Definition gTexture.h:150
int filtermin
Definition gTexture.h:157
gTexture(gTexture &&other) noexcept
int getWrapS() const
void drawSub(const gRect &src, const gRect &dst, int pivotx, int pivoty, float rotate=0.f)
TextureType getType() const
int width
Definition gTexture.h:153
std::string path
Definition gTexture.h:152
int height
Definition gTexture.h:153
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)
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:154
void unbind() const
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:149
unsigned int getInternalFormat() const
void setDataInternal(unsigned char *textureData, bool isMutable=false, bool isStbImage=false, bool clean=true)
float * datahdr
Definition gTexture.h:170
const std::string & getDir() const
bool istextureallocated
Definition gTexture.h:173
const std::string & getFilename() const
unsigned int loadMask(const std::string &fullPath)
gTexture & operator=(gTexture &&other) noexcept
void draw(int x, int y)
bool isHDR() const
bool ismaskloaded
Definition gTexture.h:171
std::string getDirName(const std::string &fname)
std::string fullpath
Definition gTexture.h:149
unsigned int getId() const
unsigned int getFormat() const
int getComponentNum() const
static const std::string & getTypeName(TextureType textureType)
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 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:172
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:150
void cleanupAll()