TextureCube::TextureCube():
Texture(GL_TEXTURE_CUBE_MAP),
- ifmt(RGB),
size(0),
allocated(0)
{
static Require _req(ARB_texture_cube_map);
}
-void TextureCube::storage(PixelFormat fmt, unsigned sz)
+void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv)
{
if(size>0)
throw invalid_operation("TextureCube::storage");
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;
+ levels = get_n_levels();
+ if(lv>0)
+ levels = min(levels, lv);
}
void TextureCube::allocate(unsigned level)
{
+ if(size==0)
+ throw invalid_operation("TextureCube::allocate");
+ if(level>=levels)
+ throw invalid_argument("TextureCube::allocate");
if(allocated&(1<<level))
return;
if(ARB_texture_storage)
{
BindRestore _bind(this);
- unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
- glTexStorage2D(target, n_levels, ifmt, size, size);
- allocated |= (1<<n_levels)-1;
+ glTexStorage2D(target, levels, ifmt, size, size);
+ allocated |= (1<<levels)-1;
}
else
{
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;
- if(gen_mipmap && level==0)
+ if(auto_gen_mipmap && level==0)
{
// TODO Only do this once all faces are created
- auto_generate_mipmap();
+ generate_mipmap();
allocated |= (1<<get_n_levels())-1;
}
}
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();
+ if(auto_gen_mipmap && level==0)
+ generate_mipmap();
}
void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool srgb)
PixelFormat fmt = pixelformat_from_graphics(img.get_format());
if(size==0)
- storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
+ {
+ unsigned l = (is_mipmapped(min_filter) ? mipmap_levels ? mipmap_levels : 0 : 1);
+ storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l);
+ }
else if(w!=size || h!=size)
throw incompatible_data("TextureCube::image");
void TextureCube::Loader::storage(PixelFormat fmt, unsigned s)
{
- if(srgb)
- fmt = get_srgb_pixelformat(fmt);
obj.storage(fmt, s);
}