static Require _req(MSP_texture1D);
}
-void Texture1D::storage(PixelFormat fmt, unsigned wd)
+void Texture1D::storage(PixelFormat fmt, unsigned wd, unsigned lv)
{
if(width>0)
throw invalid_operation("Texture1D::storage");
set_internal_format(fmt);
width = wd;
+ levels = get_n_levels();
+ if(lv)
+ levels = min(levels, lv);
}
void Texture1D::allocate(unsigned level)
{
if(width==0)
throw invalid_operation("Texture1D::allocate");
+ if(level>=levels)
+ throw invalid_argument("Texture1D::allocate");
if(allocated&(1<<level))
return;
if(ARB_texture_storage)
{
- unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
if(ARB_direct_state_access)
- glTextureStorage1D(id, n_levels, ifmt, width);
+ glTextureStorage1D(id, levels, ifmt, width);
else
{
BindRestore _bind(this);
- glTexStorage1D(target, n_levels, ifmt, width);
+ glTexStorage1D(target, levels, ifmt, width);
}
- allocated |= (1<<n_levels)-1;
+ allocated |= (1<<levels)-1;
}
else
{
unsigned w = img.get_width();
PixelFormat fmt = pixelformat_from_graphics(img.get_format());
if(width==0)
- storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
+ {
+ unsigned l = (is_mipmapped(min_filter) ? 0 : 1);
+ storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l);
+ }
else if(w!=width)
throw incompatible_data("Texture1D::image");
private:
unsigned width;
+ unsigned levels;
unsigned allocated;
public:
Texture1D();
- void storage(PixelFormat, unsigned);
+ void storage(PixelFormat, unsigned, unsigned = 0);
void allocate(unsigned);
void image(unsigned, PixelFormat, DataType, const void *);
void sub_image(unsigned, int, unsigned, PixelFormat, DataType, const void *);
set_manager(0);
}
-void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht)
+void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
{
if(width>0)
throw invalid_operation("Texture2D::storage");
set_internal_format(fmt);
width = wd;
height = ht;
+ levels = get_n_levels();
+ if(lv>0)
+ levels = min(levels, lv);
}
void Texture2D::allocate(unsigned level)
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::allocate");
+ if(level>=levels)
+ throw invalid_argument("Texture2D::allocate");
if(allocated&(1<<level))
return;
if(ARB_texture_storage)
{
- unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
if(ARB_direct_state_access)
- glTextureStorage2D(id, n_levels, ifmt, width, height);
+ glTextureStorage2D(id, levels, ifmt, width, height);
else
{
BindRestore _bind(this);
- glTexStorage2D(target, n_levels, ifmt, width, height);
+ glTexStorage2D(target, levels, ifmt, width, height);
}
- allocated |= (1<<n_levels)-1;
+ allocated |= (1<<levels)-1;
}
else
{
unsigned h = img.get_height();
PixelFormat fmt = pixelformat_from_graphics(img.get_format());
if(width==0)
- storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h);
+ {
+ unsigned l = (is_mipmapped(min_filter) ? 0 : 1);
+ storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, l);
+ }
else if(w!=width || h!=height)
throw incompatible_data("Texture2D::image");
unsigned width;
unsigned height;
+ unsigned levels;
unsigned allocated;
public:
Texture2D(ResourceManager * = 0);
virtual ~Texture2D();
- /** Defines storage structure for the texture. Must be called before an
- image can be uploaded. Once storage is defined, it can't be changed. */
- void storage(PixelFormat fmt, unsigned wd, unsigned ht);
+ /** Defines storage structure for the texture. If lv is zero, the number
+ of mipmap levels is automatically determined from storage dimensions.
+
+ Must be called before an image can be uploaded. Once storage is defined,
+ it can't be changed. */
+ void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv = 0);
/** Allocates storage for the texture. The contents are initially
undefined. If storage has already been allocated, does nothing. */
static Require _req(EXT_texture3D);
}
-void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp)
+void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv)
{
if(width>0)
throw invalid_operation("Texture3D::storage");
width = wd;
height = ht;
depth = dp;
+ levels = get_n_levels();
+ if(lv>0)
+ levels = min(levels, lv);
}
void Texture3D::allocate(unsigned level)
{
if(width==0 || height==0 || depth==0)
throw invalid_operation("Texture3D::allocate");
+ if(level>=levels)
+ throw invalid_argument("Texture3D::allocate");
if(allocated&(1<<level))
return;
if(ARB_texture_storage)
{
- unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
if(ARB_direct_state_access)
- glTextureStorage3D(id, n_levels, ifmt, width, height, depth);
+ glTextureStorage3D(id, levels, ifmt, width, height, depth);
else
{
BindRestore _bind(this);
- glTexStorage3D(target, n_levels, ifmt, width, height, depth);
+ glTexStorage3D(target, levels, ifmt, width, height, depth);
}
- allocated |= (1<<n_levels)-1;
+ allocated |= (1<<levels)-1;
}
else
{
PixelFormat fmt = pixelformat_from_graphics(img.get_format());
if(width==0)
- storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d);
+ {
+ unsigned l = (is_mipmapped(min_filter) ? 0 : 1);
+ storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d, l);
+ }
else if(w!=width || h!=height || d!=depth)
throw incompatible_data("Texture3D::load_image");
unsigned width;
unsigned height;
unsigned depth;
+ unsigned levels;
unsigned allocated;
protected:
public:
Texture3D();
- /** Defines storage structure for the texture. Must be called before an
- image can be uploaded. Once storage is defined, it can't be changed. */
- void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp);
+ /** Defines storage structure for the texture. If lv is zero, the number
+ of mipmap levels is automatically determined from storage dimensions.
+
+ Must be called before an image can be uploaded. Once storage is defined,
+ it can't be changed. */
+ void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
/** Allocates storage for the texture. The contents are initially
undefined. If storage has already been allocated, does nothing. */
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");
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
{
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) ? 0 : 1);
+ storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l);
+ }
else if(w!=size || h!=size)
throw incompatible_data("TextureCube::image");
private:
unsigned size;
+ unsigned levels;
unsigned allocated;
static TextureCubeFace face_order[6];
public:
TextureCube();
- /** Defines storage structure for the texture. Must be called before an
- image can be uploaded. Once storage is defined, it can't be changed. */
- void storage(PixelFormat fmt, unsigned size);
+ /** Defines storage structure for the texture. If lv is zero, the number
+ of mipmap levels is automatically determined from storage dimensions.
+
+ Must be called before an image can be uploaded. Once storage is defined,
+ it can't be changed. */
+ void storage(PixelFormat fmt, unsigned size, unsigned lv = 0);
/** Allocates storage for the cube faces. The contents are initially
undefined. If storage has already been allocated, does nothing. */