X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fopengl%2Ftexture-gl.cc;h=2fbd05ebb8be1a9b683cf3553f20a1e097259e0f;hb=15cb9e608f3028a86ed878d726f1633bce9d6e04;hp=a2072e3088adddae7197cc5e8259206ce4f95e0e;hpb=0da7a98f74d00bfa6cf0d47fd7cf0f687eeba5f6;p=demo diff --git a/src/opengl/texture-gl.cc b/src/opengl/texture-gl.cc index a2072e3..2fbd05e 100644 --- a/src/opengl/texture-gl.cc +++ b/src/opengl/texture-gl.cc @@ -1,15 +1,13 @@ #include +#include #include "texture.h" #include "opengl/texture-gl.h" TextureGL::TextureGL() { - w = 0; - h = 0; - - pixels = 0; tex = 0; + target = GL_TEXTURE_2D; } TextureGL::~TextureGL() @@ -19,22 +17,47 @@ TextureGL::~TextureGL() void TextureGL::update() { + if(images.empty()) + return; + if(!tex) { + target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; + glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(target, tex); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { - glBindTexture(GL_TEXTURE_2D, tex); + glBindTexture(target, tex); } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); - glGenerateMipmap(GL_TEXTURE_2D); -} + static const unsigned int faces[] = { + GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + }; + + for(size_t i=0; i