added fog (need to set the fog params)
[demo] / src / opengl / texture-gl.cc
index 607d014..80db3ad 100644 (file)
@@ -1,4 +1,5 @@
 #include <GL/glew.h>
+#include <stdlib.h>
 
 #include "texture.h"
 #include "opengl/texture-gl.h"
@@ -40,15 +41,34 @@ void TextureGL::update()
                int w = images[i].w;
                int h = images[i].h;
 
-               unsigned char *pixels = images[i].pixels;
+               /* target */
                unsigned int t = is_cubemap() ? faces[i] : GL_TEXTURE_2D;
-               glTexImage2D(t, 0, GL_SRGB_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+               /* internal format */
+               unsigned int ifmt = images[i].is_float ? GL_RGBA16F : GL_SRGB_ALPHA;
+
+               /* data type of pixel data */
+               unsigned int type = images[i].is_float ? GL_FLOAT : GL_UNSIGNED_BYTE;
+
+               glTexImage2D(t, 0, ifmt, w, h, 0, GL_RGBA, type, images[i].pixels);
        }
 
        glGenerateMipmap(target);
 }
 
-void TextureGL::bind()
+void TextureGL::bind(int texture_unit)
+{
+       glActiveTexture(GL_TEXTURE0 + texture_unit);
+
+       unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
+       glBindTexture(target, tex);
+
+       //TODO: (not needed for now) if I ever use textures outside the Texture class
+       //glActiveTexture(GL_TEXTURE0);
+}
+
+void TextureGL::unbind()
 {
-       glBindTexture(GL_TEXTURE_2D, tex);
+       unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
+       glBindTexture(target, 0);
 }
\ No newline at end of file