#include <SDL2\SDL.h>
#include "Graphix\Graphix.h"
+#include "Graphix\Textures\Texture.h"
#include "Game.h"
#include "GLM.h"
void message(std::string title, bool onoff);
+unsigned int toggle_MIPMAP = 0;
+
+
void Events::processEvents()
{
SDL_Event sdl_event;
message("WireFrame", !key_toggle[SDLK_F3]);
break;
case SDLK_F4:
- //TEXTURE SAMPLING QUALITY
+ //TEXTURE SAMPLING QUALITY: Nearest Neighbor/Bilinear
+ if (key_toggle[SDLK_F4])
+ Texture::setMaxSamplingQuality(TSQ_LINEAR);
+ else
+ Texture::setMaxSamplingQuality(TSQ_NEAREST_NEIGHBOR);
+ Message::info((string)"Texture Sampling Quality: " + ((!key_toggle[SDLK_F4]) ? "Nearest Neighbor" : "Bilinear"));
+
break;
case SDLK_F5:
- //MIPMAP QUALITY
+ //MIPMAP QUALITY: Off/Nearest Neighbor/Linear
+ switch (toggle_MIPMAP)
+ {
+ default:
+ case 0:
+ Texture::setMaxSamplingQuality(MMQ_OFF);
+ Message::info("MipMap Quality: Off");
+ toggle_MIPMAP = 0;
+ break;
+ case 1:
+ Texture::setMaxSamplingQuality(MMQ_NEAREST_NEIGHBOR);
+ Message::info("MipMap Quality: Nearest Neighbor");
+ break;
+ case 2:
+ Texture::setMaxSamplingQuality(MMQ_LINEAR);
+ Message::info("MipMap Quality: Linear");
+ break;
+ }
+ toggle_MIPMAP++;
break;
case SDLK_F6:
//??? BoundingBox
using std::string;
using std::unordered_map;
+using std::unordered_set;
string bindTargets[] = {"uColorTexture", "uBlendTexture", "uPointLightXP", "uPointLightXM", "uPointLightYP", "uPointLightYM", "uPointLightZP", "uPointLightZM", "uBlurVec" };
+
Texture::Texture(texTarget _target, unsigned int _type)
- : texture_target(_type)
+ : texture_target(_type), texture_MMQ(MMQ_OFF), texture_TSQ(TSQ_LINEAR)
{
glGenTextures(1, &handle);
+
+ texture_List.insert(this);
switch (_target)
{
Texture::~Texture()
{
glDeleteTextures(1, &handle);
+ texture_List.erase(this);
}
Texture* Texture::newTImage(const string& _path, const vec4& _material)
return texture_target;
}
+void Texture::setMaxSamplingQuality(sampTarget _mTSQ, bool _bind)
+{
+ if (max_tex_TSQ == _mTSQ)
+ return;
+
+ max_tex_TSQ = _mTSQ;
+
+ for (auto i = texture_List.begin(); i != texture_List.end(); i++)
+ (*i)->setSamplingQuality(_bind);
+}
+
+void Texture::setMaxSamplingQuality(mmTarget _mMMQ, bool _bind)
+{
+ if (max_tex_MMQ == _mMMQ)
+ return;
+
+ max_tex_MMQ = _mMMQ;
+
+ for (auto i = texture_List.begin(); i != texture_List.end(); i++)
+ (*i)->setSamplingQuality(_bind);
+}
+
+void Texture::updateMxSamplingQuality()
+{
+ switch (getMxMmTarget())
+ {
+ case MMQ_OFF:
+ if(getMxSampTarget())
+ texture_quality = GL_LINEAR;
+ else
+ texture_quality = GL_NEAREST;
+ break;
+ default:
+ case MMQ_NEAREST_NEIGHBOR:
+ if (getMxSampTarget())
+ texture_quality = GL_NEAREST_MIPMAP_LINEAR;
+ else
+ texture_quality = GL_NEAREST_MIPMAP_NEAREST;
+ break;
+ case MMQ_LINEAR:
+ if (getMxSampTarget())
+ texture_quality = GL_LINEAR_MIPMAP_LINEAR;
+ else
+ texture_quality = GL_LINEAR_MIPMAP_NEAREST;
+ break;
+ }
+}
+
Texture::operator unsigned int() const
{
height = _height;
}
+ updateMxSamplingQuality();
+
glBindTexture(texture_target, handle);
- if(data!=nullptr)
- glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- else
- glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, texture_quality);
glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//else
glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
+ if (getMxMmTarget())
+ glGenerateMipmap(texture_target);
}
void Texture::unbindTexture()
glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
}
-void Texture::downscale(unsigned int _lvl)
+void Texture::setSamplingQuality(sampTarget _TSQ, mmTarget _MMQ, bool _bind)
+{
+ texture_TSQ = _TSQ;
+ texture_MMQ = _MMQ;
+ updateMxSamplingQuality();
+
+ if (_bind)
+ glBindTexture(texture_target, handle);
+
+ if (getMxMmTarget())
+ glGenerateMipmap(texture_target);
+
+ glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, texture_quality);
+}
+void Texture::setSamplingQuality(mmTarget _MMQ, bool _bind)
+{
+ texture_MMQ = _MMQ;
+ updateMxSamplingQuality();
+
+ if (_bind)
+ glBindTexture(texture_target, handle);
+
+ if (getMxMmTarget())
+ glGenerateMipmap(texture_target);
+
+ glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, texture_quality);
+}
+void Texture::setSamplingQuality(sampTarget _TSQ, bool _bind)
+{
+ texture_TSQ = _TSQ;
+ updateMxSamplingQuality();
+
+ if (_bind)
+ glBindTexture(texture_target, handle);
+
+ glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, texture_quality);
+}
+void Texture::setSamplingQuality(bool _bind)
+{
+ updateMxSamplingQuality();
+
+ if (_bind)
+ glBindTexture(texture_target, handle);
+
+ if (getMxMmTarget())
+ glGenerateMipmap(texture_target);
+
+ glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, texture_quality);
+}
+
+void Texture::setMipMapLVL(unsigned int _lvl)
{
glBindTexture(texture_target, handle);
+
+ glTexParameteri(texture_target, GL_TEXTURE_BASE_LEVEL, mipmap_lvl);
+}
+
+void Texture::updateMipMap(bool _bind)
+{
+ if (!getMxMmTarget())
+ return;
+
+ if (_bind)
+ glBindTexture(texture_target, handle);
+
glGenerateMipmap(texture_target);
- glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- //glTexParameteri(texture_target, GL_TEXTURE_BASE_LEVEL, _lvl);
}
unordered_map<string, Texture::texHandle> Texture::texture_Map;
-unordered_map<unsigned int, Texture::texHandle*> Texture::handle_Map;
\ No newline at end of file
+unordered_map<unsigned int, Texture::texHandle*> Texture::handle_Map;
+
+unordered_set<Texture*> Texture::texture_List;
+
+sampTarget Texture::max_tex_TSQ = TSQ_LINEAR;
+mmTarget Texture::max_tex_MMQ = MMQ_LINEAR;
\ No newline at end of file
#include <string>
#include <unordered_map>
+#include <unordered_set>
class tImage;
uBLURVEC = 8
}; //Don't forget to assign the correct name in bindTargets at the beginning of Texture.cpp!
+#define BIT(x) (1<<(x))
+#define BIT0(x) (0<<(x))
+
+enum sampTarget {
+ TSQ_NEAREST_NEIGHBOR = 0,
+ TSQ_LINEAR = 1
+};
+
+enum mmTarget {
+ MMQ_OFF = 0,
+ MMQ_NEAREST_NEIGHBOR = 1,
+ MMQ_LINEAR = 2
+};
+
class Texture
{
public:
static void leaveTexture(bindTarget = uCOLOR);
virtual void updateSize(unsigned int width = 0, unsigned int height = 0);
- virtual void downscale(unsigned int lvl);
+
+ virtual void setMipMapLVL(unsigned int lvl=0);
+ virtual void updateMipMap(bool = true);
+
+ virtual void setSamplingQuality(sampTarget, mmTarget, bool = true);
+ virtual void setSamplingQuality(mmTarget, bool = true);
+ virtual void setSamplingQuality(sampTarget, bool = true);
+ virtual void setSamplingQuality(bool = true);
virtual operator unsigned int() const;
unsigned int getTTarget() const;
+ static void setMaxSamplingQuality(sampTarget, bool = true);
+ static void setMaxSamplingQuality(mmTarget, bool = true);
+
protected:
+
+ static sampTarget max_tex_TSQ;
+ static mmTarget max_tex_MMQ;
+
+
unsigned int handle;
unsigned int texture_target;
unsigned int texture_format;
unsigned int texture_type;
+
+ sampTarget texture_TSQ;
+ mmTarget texture_MMQ;
+ unsigned int texture_quality;
+
+ inline sampTarget getMxSampTarget()
+ {
+ return max_tex_TSQ<texture_TSQ ? max_tex_TSQ : texture_TSQ;
+ }
+
+ inline mmTarget getMxMmTarget()
+ {
+ return max_tex_MMQ<texture_MMQ ? max_tex_MMQ : texture_MMQ;
+ }
+
+ void updateMxSamplingQuality();
+
+ unsigned int mipmap_lvl = 0;
+
void* data = NULL;
unsigned int width = 0, height = 0;
-
typedef struct texStruct
{
unsigned int count=0;
static std::unordered_map<std::string, texHandle> texture_Map;
static std::unordered_map<unsigned int, texHandle*> handle_Map;
+
+ static std::unordered_set<Texture*> texture_List;
};
\ No newline at end of file