X-Git-Url: https://eleni.mutantstargoat.com/git/?p=demo;a=blobdiff_plain;f=src%2Fopengl%2Ftexture-gl.cc;h=2fbd05ebb8be1a9b683cf3553f20a1e097259e0f;hp=607d0147f73ba39255c9a4542a53643155a16b2a;hb=15cb9e608f3028a86ed878d726f1633bce9d6e04;hpb=77e44c5424bd5e6e7c6a706151fa786a56270e12 diff --git a/src/opengl/texture-gl.cc b/src/opengl/texture-gl.cc index 607d014..2fbd05e 100644 --- a/src/opengl/texture-gl.cc +++ b/src/opengl/texture-gl.cc @@ -1,4 +1,5 @@ #include +#include #include "texture.h" #include "opengl/texture-gl.h" @@ -40,9 +41,16 @@ 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); @@ -50,5 +58,6 @@ void TextureGL::update() void TextureGL::bind() { - glBindTexture(GL_TEXTURE_2D, tex); + unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; + glBindTexture(target, tex); } \ No newline at end of file