|
@@ -0,0 +1,47 @@
|
|
|
+#include "gl/Texture.h"
|
|
|
+
|
|
|
+Texture::Texture(Mode mode) : texture(0) {
|
|
|
+ glGenTextures(1, &texture);
|
|
|
+ glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
+ switch(mode) {
|
|
|
+ case NEAREST:
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
+ break;
|
|
|
+ case LINEAR:
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
+}
|
|
|
+
|
|
|
+Texture::~Texture() {
|
|
|
+ glDeleteTextures(1, &texture);
|
|
|
+}
|
|
|
+
|
|
|
+void Texture::setColorData(int width, int height, const Color4* data) {
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
|
|
+}
|
|
|
+
|
|
|
+void Texture::setColorData(int width, int height, const Color3* data) {
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
|
|
+}
|
|
|
+
|
|
|
+void Texture::setColorData(int width, int height, const Color2* data) {
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, data);
|
|
|
+}
|
|
|
+
|
|
|
+void Texture::setColorData(int width, int height, const Color1* data) {
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data);
|
|
|
+}
|
|
|
+
|
|
|
+void Texture::setRGBFloatData(int width, int height, const float* data) {
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, data);
|
|
|
+}
|
|
|
+
|
|
|
+void Texture::bind(int index) const {
|
|
|
+ glActiveTexture(GL_TEXTURE0 + index);
|
|
|
+ glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
+}
|