]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texturecube.cpp
Add support for integer vertex attributes
[libs/gl.git] / source / core / texturecube.cpp
index 5c7f61029c3c736eb3245e99b559b29c7e79f2aa..2db1b63b92162c358618c7c3d7a6a0831ce3cb5e 100644 (file)
@@ -5,7 +5,6 @@
 #include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/io/memory.h>
 #include <msp/strings/format.h>
-#include "bindable.h"
 #include "error.h"
 #include "texturecube.h"
 
@@ -78,8 +77,6 @@ void TextureCube::allocate(unsigned level)
                throw invalid_operation("TextureCube::allocate");
        if(level>=levels)
                throw invalid_argument("TextureCube::allocate");
-       if(allocated&(64<<level))
-               return;
 
        bool direct = ARB_texture_storage && ARB_direct_state_access;
        if(!direct)
@@ -96,12 +93,16 @@ void TextureCube::allocate(unsigned level)
 
 void TextureCube::allocate_(unsigned level)
 {
+       if(allocated&(64<<level))
+               return;
+
        if(ARB_texture_storage)
        {
+               GLenum fmt = get_gl_pixelformat(storage_fmt);
                if(ARB_direct_state_access)
-                       glTextureStorage2D(id, levels, storage_fmt, size, size);
+                       glTextureStorage2D(id, levels, fmt, size, size);
                else
-                       glTexStorage2D(target, levels, storage_fmt, size, size);
+                       glTexStorage2D(target, levels, fmt, size, size);
                apply_swizzle();
                allocated |= (64<<levels)-1;
        }
@@ -148,9 +149,10 @@ void TextureCube::image_(TextureCubeFace face, unsigned level, const void *data)
        }
 
        unsigned lsz = get_level_size(level);
-       PixelComponents comp = get_components(storage_fmt);
+       GLenum fmt = get_gl_pixelformat(storage_fmt);
+       GLenum comp = get_gl_components(get_components(storage_fmt));
        GLenum type = get_gl_type(get_component_type(storage_fmt));
-       glTexImage2D(face, level, storage_fmt, lsz, lsz, 0, comp, type, data);
+       glTexImage2D(face, level, fmt, lsz, lsz, 0, comp, type, data);
 
        if(level==0)
        {
@@ -162,7 +164,7 @@ void TextureCube::image_(TextureCubeFace face, unsigned level, const void *data)
        {
                for(unsigned i=0; i<6; ++i)
                        if(enumerate_faces(i)!=face)
-                               glTexImage2D(enumerate_faces(i), level, storage_fmt, lsz, lsz, 0, comp, type, 0);
+                               glTexImage2D(enumerate_faces(i), level, fmt, lsz, lsz, 0, comp, type, 0);
 
                allocated |= 64<<level;
        }
@@ -191,7 +193,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
 
        allocate_(level);
 
-       PixelComponents comp = get_components(storage_fmt);
+       GLenum comp = get_gl_components(get_components(storage_fmt));
        GLenum type = get_gl_type(get_component_type(storage_fmt));
        if(ARB_direct_state_access)
                glTextureSubImage3D(id, level, x, y, get_face_index(face), wd, ht, 1, comp, type, data);