]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texturecube.cpp
Throw an exception if Texture*::allocate is called before storage
[libs/gl.git] / source / texturecube.cpp
index 833ef28f0ebd78add08ccfae4c8555df87dff288..b9a8f5dd02b8cacb73f63df7bce028a5920035cd 100644 (file)
@@ -45,7 +45,6 @@ unsigned TextureCube::orientations[12] =
 
 TextureCube::TextureCube():
        Texture(GL_TEXTURE_CUBE_MAP),
-       ifmt(RGB),
        size(0),
        allocated(0)
 {
@@ -59,16 +58,14 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz)
        if(sz==0)
                throw invalid_argument("TextureCube::storage");
 
-       if(MSP_sized_internal_formats)
-               fmt = get_sized_pixelformat(fmt);
-       require_pixelformat(fmt);
-
-       ifmt = fmt;
+       set_internal_format(fmt);
        size = sz;
 }
 
 void TextureCube::allocate(unsigned level)
 {
+       if(size==0)
+               throw invalid_operation("TextureCube::allocate");
        if(allocated&(1<<level))
                return;
 
@@ -101,7 +98,7 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
                return sub_image(face, level, 0, 0, s, s, fmt, type, data);
 
        BindRestore _bind(this);
-       glTexImage2D(face, level, ifmt, s, s, 0, fmt, type, data);
+       glTexImage2D(face, level, ifmt, s, s, 0, get_upload_format(fmt), type, data);
 
        // XXX Allocation should be tracked per-face, but we'll run out of bits
        allocated |= 1<<level;
@@ -121,7 +118,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
        BindRestore _bind(this);
        allocate(level);
 
-       glTexSubImage2D(face, level, x, y, wd, ht, fmt, type, data);
+       glTexSubImage2D(face, level, x, y, wd, ht, get_upload_format(fmt), type, data);
 
        if(gen_mipmap && level==0)
                auto_generate_mipmap();