data[i*4+2] = 255-s;
data[i*4+3] = ((i+i/4)%2)*255;
}
- rotate_lookup.image(0, RGBA, UNSIGNED_BYTE, data);
+ rotate_lookup.image(0, data);
texturing.attach(3, rotate_lookup);
unsigned char curve_data[256];
for(unsigned i=0; i<256; ++i)
curve_data[i] = pow(i/255.0f, 1/g)*255+0.5f;
- curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
+ curve.image(0, curve_data);
}
void ColorCurve::set_srgb()
curve_data[0] = 0;
for(unsigned i=1; i<256; ++i)
curve_data[i] = to_srgb(i/255.0f)*255+0.5f;
- curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
+ curve.image(0, curve_data);
}
void ColorCurve::set_linear()
unsigned char curve_data[256];
for(unsigned i=0; i<256; ++i)
curve_data[i] = i;
- curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data);
+ curve.image(0, curve_data);
}
void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
Texture::Texture(GLenum t, ResourceManager *m):
id(0),
target(t),
- ifmt(RGB8),
+ format(RGB8),
+ storage_fmt(RGB8),
swizzle(NO_SWIZZLE),
auto_gen_mipmap(false),
default_sampler(*this)
glDeleteTextures(1, &id);
}
-void Texture::set_internal_format(PixelFormat fmt)
+void Texture::set_format(PixelFormat fmt)
{
PixelComponents comp = get_components(fmt);
+ PixelComponents st_comp = comp;
FormatSwizzle swiz = NO_SWIZZLE;
switch(comp)
{
case LUMINANCE:
- comp = RED;
+ st_comp = RED;
swiz = R_TO_LUMINANCE;
break;
case LUMINANCE_ALPHA:
- comp = RG;
+ st_comp = RG;
swiz = RG_TO_LUMINANCE_ALPHA;
break;
case BGR:
- comp = RGB;
+ st_comp = RGB;
swiz = RGB_TO_BGR;
break;
case BGRA:
- comp = RGBA;
+ st_comp = RGBA;
swiz = RGB_TO_BGR;
break;
default:;
}
- fmt = make_pixelformat(comp, get_component_type(fmt));
- require_pixelformat(fmt);
+ PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt));
+ require_pixelformat(st_fmt);
if(swiz!=NO_SWIZZLE)
static Require _req(ARB_texture_swizzle);
- ifmt = fmt;
- swizzle = swiz;
-}
-PixelComponents Texture::get_upload_components(PixelComponents comp) const
-{
- if(comp==LUMINANCE || comp==LUMINANCE_ALPHA || comp==BGR || comp==BGRA)
- return get_components(ifmt);
- else
- return comp;
+ format = fmt;
+ storage_fmt = st_fmt;
+ swizzle = swiz;
}
void Texture::apply_swizzle()
unsigned id;
GLenum target;
- PixelFormat ifmt;
+ PixelFormat format;
+ PixelFormat storage_fmt;
FormatSwizzle swizzle;
bool auto_gen_mipmap;
Sampler default_sampler;
~Texture();
protected:
- void set_internal_format(PixelFormat);
- PixelComponents get_upload_components(PixelComponents) const;
+ void set_format(PixelFormat);
void apply_swizzle();
void set_parameter_i(GLenum, int) const;
if(wd==0)
throw invalid_argument("Texture1D::storage");
- set_internal_format(fmt);
+ set_format(fmt);
width = wd;
levels = get_n_levels();
if(lv)
{
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
- glTextureStorage1D(id, levels, ifmt, width);
+ glTextureStorage1D(id, levels, storage_fmt, width);
else
- glTexStorage1D(target, levels, ifmt, width);
+ glTexStorage1D(target, levels, storage_fmt, width);
apply_swizzle();
allocated |= (1<<levels)-1;
}
else
- image(level, get_components(ifmt), get_component_type(ifmt), 0);
+ image(level, 0);
}
-void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
+void Texture1D::image(unsigned level, const void *data)
{
if(width==0)
throw invalid_operation("Texture1D::image");
unsigned w = get_level_size(level);
if(ARB_texture_storage)
- return sub_image(level, 0, w, comp, type, data);
+ return sub_image(level, 0, w, data);
BindRestore _bind(this);
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
apply_swizzle();
}
- glTexImage1D(target, level, ifmt, w, 0, get_upload_components(comp), type, data);
+
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
+ glTexImage1D(target, level, storage_fmt, w, 0, comp, type, data);
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
}
}
-void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
+void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture1D::image");
+ image(level, data);
+}
+
+void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
{
if(width==0)
throw invalid_operation("Texture3D::image");
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
- comp = get_upload_components(comp);
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
if(ARB_direct_state_access)
glTextureSubImage1D(id, level, x, wd, comp, type, data);
else
generate_mipmap();
}
+void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture1D::sub_image");
+ sub_image(level, x, wd, data);
+}
+
void Texture1D::image(const Graphics::Image &img, unsigned lv, bool srgb)
{
if(img.get_height()!=1)
unsigned w = img.get_width();
PixelFormat fmt = pixelformat_from_image(img);
- PixelComponents comp = get_components(fmt);
- DataType type = get_component_type(fmt);
if(width==0)
- storage(make_pixelformat(comp, type, srgb), w, lv);
+ storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, lv);
else if(w!=width)
throw incompatible_data("Texture1D::image");
- image(0, comp, type, img.get_data());
+ image(0, img.get_data());
}
unsigned Texture1D::get_n_levels() const
UInt64 Texture1D::get_data_size() const
{
- return id ? width*get_pixel_size(ifmt) : 0;
+ return id ? width*get_pixel_size(storage_fmt) : 0;
}
void Texture1D::Loader::raw_data(const string &data)
{
- obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
+ obj.image(0, data.data());
}
void Texture1D::Loader::storage(PixelFormat fmt, unsigned w)
{ storage(make_pixelformat(c, UNSIGNED_BYTE), w, l); }
void allocate(unsigned);
- void image(unsigned, PixelComponents, DataType, const void *);
- void sub_image(unsigned, int, unsigned, PixelComponents, DataType, const void *);
+ void image(unsigned, const void *);
+ DEPRECATED void image(unsigned, PixelComponents, DataType, const void *);
+ void sub_image(unsigned, int, unsigned, const void *);
+ DEPRECATED void sub_image(unsigned, int, unsigned, PixelComponents, DataType, const void *);
virtual void image(const Graphics::Image &, unsigned, bool = false);
using Texture::image;
unsigned get_width() const { return width; }
if(wd==0 || ht==0)
throw invalid_argument("Texture2D::storage");
- set_internal_format(fmt);
+ set_format(fmt);
width = wd;
height = ht;
levels = get_n_levels();
{
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
- glTextureStorage2D(id, levels, ifmt, width, height);
+ glTextureStorage2D(id, levels, storage_fmt, width, height);
else
- glTexStorage2D(target, levels, ifmt, width, height);
+ glTexStorage2D(target, levels, storage_fmt, width, height);
apply_swizzle();
allocated |= (1<<levels)-1;
}
else
- image(level, get_components(ifmt), get_component_type(ifmt), 0);
+ image(level, 0);
}
-void Texture2D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
+void Texture2D::image(unsigned level, const void *data)
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::image");
get_level_size(level, w, h);
if(ARB_texture_storage)
- return sub_image(level, 0, 0, w, h, comp, type, data);
+ return sub_image(level, 0, 0, w, h, data);
BindRestore _bind(this);
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
apply_swizzle();
}
- glTexImage2D(target, level, ifmt, w, h, 0, get_upload_components(comp), type, data);
+
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
+ glTexImage2D(target, level, storage_fmt, w, h, 0, comp, type, data);
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
}
}
-void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
+void Texture2D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture2D::image");
+ image(level, data);
+}
+
+void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::sub_image");
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
- comp = get_upload_components(comp);
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
if(ARB_direct_state_access)
glTextureSubImage2D(id, level, x, y, wd, ht, comp, type, data);
else
generate_mipmap();
}
+void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture2D::sub_image");
+ sub_image(level, x, y, wd, ht, data);
+}
+
void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb)
{
image(img, lv, srgb, false);
unsigned w = img.get_width();
unsigned h = img.get_height();
PixelFormat fmt = pixelformat_from_image(img);
- PixelComponents comp = get_components(fmt);
- DataType type = get_component_type(fmt);
if(width==0)
- storage(make_pixelformat(comp, type, srgb), w, h, lv);
+ storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, h, lv);
else if(w!=width || h!=height || (lv && lv!=levels))
throw incompatible_data("Texture2D::image");
PixelStore pstore = PixelStore::from_image(img);
BindRestore _bind_ps(pstore);
- image(0, comp, type, from_buffer ? 0 : img.get_data());
+ image(0, from_buffer ? 0 : img.get_data());
}
unsigned Texture2D::get_n_levels() const
UInt64 Texture2D::get_data_size() const
{
- return id ? width*height*get_pixel_size(ifmt) : 0;
+ return id ? width*height*get_pixel_size(format) : 0;
}
void Texture2D::unload()
void Texture2D::Loader::raw_data(const string &data)
{
- obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
+ obj.image(0, data.data());
}
void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
undefined. If storage has already been allocated, does nothing. */
void allocate(unsigned level);
- /** Uploads an image to the texture. Storage must be defined beforehand.
- The image data must have dimensions and format compatible with the defined
- storage. */
- void image(unsigned level, PixelComponents fmt, DataType type, const void *data);
+ /** Updates the contents of the entire texture. Storage must be defined
+ beforehand. The image data must have dimensions and format matching the
+ defined storage. */
+ virtual void image(unsigned level, const void *data);
+
+ DEPRECATED void image(unsigned level, PixelComponents fmt, DataType type, const void *data);
/** Updates a rectangular region of the texture. Storage must be defined
- and allocated beforehand. The update region must be fully inside the
- texture. */
- void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
+ beforehand. The image data must be in a format mathing the defined storage
+ and the update region must be fully inside the texture. */
+ void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data);
+
+ DEPRECATED void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
PixelComponents fmt, DataType type, const void *data);
- /** Uploads an image to the texture. If storage has not been defined, it
- will be set to match the image. Otherwise the image must be compatible with
- the defined storage.
+ /** Updates the contents of the entire texture from an image. If storage
+ has not been defined, it will be set to match the image. Otherwise the
+ image must match the defined storage.
If srgb is true and storage is determined by this call, then an sRGB pixel
format will be used. */
static Require _req(EXT_texture_array);
}
-void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
+void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
{
unsigned w = get_width();
unsigned h = get_height();
unsigned d = get_depth();
get_level_size(level, w, h, d);
- sub_image(level, 0, 0, z, w, h, 1, comp, type, data);
+ sub_image(level, 0, 0, z, w, h, 1, data);
+}
+
+void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture2DArray::layer_image");
+ layer_image(level, z, data);
}
void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
unsigned w = img.get_width();
unsigned h = img.get_height();
- PixelFormat fmt = pixelformat_from_image(img);
if(w!=get_width() || h!=get_height())
throw incompatible_data("Texture2DArray::layer_image");
+ PixelFormat fmt = pixelformat_from_image(img);
+ if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
+ throw incompatible_data("Texture2DArray::layer_image");
PixelStore pstore = PixelStore::from_image(img);
BindRestore _bind_ps(pstore);
- layer_image(level, z, get_components(fmt), get_component_type(fmt), img.get_data());
+ layer_image(level, z, img.get_data());
}
Texture2DArray();
- void layer_image(unsigned, unsigned, PixelComponents, DataType, const void *);
+ void layer_image(unsigned, unsigned, const void *);
+ DEPRECATED void layer_image(unsigned, unsigned, PixelComponents, DataType, const void *);
void layer_image(unsigned, unsigned, const Graphics::Image &);
unsigned get_layers() const { return get_depth(); }
if(wd==0 || ht==0 || dp==0)
throw invalid_argument("Texture3D::storage");
- set_internal_format(fmt);
+ set_format(fmt);
width = wd;
height = ht;
depth = dp;
{
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
- glTextureStorage3D(id, levels, ifmt, width, height, depth);
+ glTextureStorage3D(id, levels, storage_fmt, width, height, depth);
else
- glTexStorage3D(target, levels, ifmt, width, height, depth);
+ glTexStorage3D(target, levels, storage_fmt, width, height, depth);
apply_swizzle();
allocated |= (1<<levels)-1;
}
else
- image(level, get_components(ifmt), get_component_type(ifmt), 0);
+ image(level, 0);
}
-void Texture3D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
+void Texture3D::image(unsigned level, const void *data)
{
if(width==0 || height==0 || depth==0)
throw invalid_operation("Texture3D::image");
get_level_size(level, w, h, d);
if(ARB_texture_storage)
- return sub_image(level, 0, 0, 0, w, h, d, comp, type, data);
+ return sub_image(level, 0, 0, 0, w, h, d, data);
BindRestore _bind(this);
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
apply_swizzle();
}
- glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_components(comp), type, data);
+
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
+ glTexImage3D(target, level, storage_fmt, width, height, depth, 0, comp, type, data);
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
}
}
-void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelComponents comp, DataType type, const void *data)
+void Texture3D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture3D::image");
+ image(level, data);
+}
+
+void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
{
if(width==0 || height==0 || depth==0)
throw invalid_operation("Texture3D::image");
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
- comp = get_upload_components(comp);
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
if(ARB_direct_state_access)
glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, comp, type, data);
else
generate_mipmap();
}
+void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("Texture3D::sub_image");
+ sub_image(level, x, y, z, wd, ht, dp, data);
+}
+
void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb)
{
unsigned w = img.get_width();
}
PixelFormat fmt = pixelformat_from_image(img);
- PixelComponents comp = get_components(fmt);
- DataType type = get_component_type(fmt);
if(width==0)
- storage(make_pixelformat(comp, type, srgb), w, h, d, lv);
+ storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, h, d, lv);
else if(w!=width || h!=height || d!=depth)
throw incompatible_data("Texture3D::load_image");
PixelStore pstore = PixelStore::from_image(img);
BindRestore _bind_ps(pstore);
- image(0, comp, type, img.get_data());
+ image(0, img.get_data());
}
unsigned Texture3D::get_n_levels() const
UInt64 Texture3D::get_data_size() const
{
- return id ? width*height*depth*get_pixel_size(ifmt) : 0;
+ return id ? width*height*depth*get_pixel_size(storage_fmt) : 0;
}
void Texture3D::Loader::raw_data(const string &data)
{
- obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
+ obj.image(0, data.data());
}
void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)
undefined. If storage has already been allocated, does nothing. */
void allocate(unsigned level);
- /** Uploads an image to the texture. Storage must be defined beforehand.
- The image data must have dimensions and format compatible with the defined
- storage. */
- void image(unsigned level, PixelComponents, DataType type, const void *data);
+ /** Updates the contents of the entire texture. Storage must be defined
+ beforehand. The image data must have dimensions and format matching the
+ defined storage. */
+ void image(unsigned level, const void *data);
+
+ DEPRECATED void image(unsigned level, PixelComponents comp, DataType type, const void *data);
/** Updates a cuboid-shaped region of the texture. Storage must be defined
- and allocated beforehand. The update region must be fully inside the
- texture. */
- void sub_image(unsigned level,
+ beforehand. The image data must be in a format mathing the defined storage
+ and the update region must be fully inside the texture. */
+ void sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data);
+
+ DEPRECATED void sub_image(unsigned level,
int x, int y, int z, unsigned wd, unsigned ht, unsigned dp,
PixelComponents comp, DataType type, const void *data);
- /** Uploads an image to the texture. If storage has not been defined, it
- will be set to match the image. In this case the image will be treated as
- a stack of square layers and its height must be divisible by its width.
- Otherwise the image must be compatible with the defined storage.
+ /** Updates the contents of the entire texture from an image. If storage
+ has not been defined, it will be set to match the image. In this case the
+ image will be treated as a stack of square layers and its height must be
+ divisible by its width. Otherwise the image must match the defined storage.
If srgb is true and storage is determined by this call, then an sRGB pixel
format will be used. */
if(sz==0)
throw invalid_argument("TextureCube::storage");
- set_internal_format(fmt);
+ set_format(fmt);
size = sz;
levels = get_n_levels();
if(lv>0)
if(ARB_texture_storage)
{
BindRestore _bind(this);
- glTexStorage2D(target, levels, ifmt, size, size);
+ glTexStorage2D(target, levels, storage_fmt, size, size);
apply_swizzle();
allocated |= (1<<levels)-1;
}
else
{
- PixelComponents comp = get_components(ifmt);
- DataType type = get_component_type(ifmt);
for(unsigned i=0; i<6; ++i)
- image(enumerate_faces(i), level, comp, type, 0);
+ image(enumerate_faces(i), level, 0);
}
}
-void TextureCube::image(TextureCubeFace face, unsigned level, PixelComponents comp, DataType type, const void *data)
+void TextureCube::image(TextureCubeFace face, unsigned level, const void *data)
{
if(size==0)
throw invalid_operation("TextureCube::image");
throw out_of_range("TextureCube::image");
if(ARB_texture_storage)
- return sub_image(face, level, 0, 0, s, s, comp, type, data);
+ return sub_image(face, level, 0, 0, s, s, data);
BindRestore _bind(this);
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
apply_swizzle();
}
- glTexImage2D(face, level, ifmt, s, s, 0, get_upload_components(comp), type, data);
+
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
+ glTexImage2D(face, level, storage_fmt, s, s, 0, comp, type, data);
if(level==0)
{
{
for(unsigned i=0; i<6; ++i)
if(enumerate_faces(i)!=face)
- glTexImage2D(enumerate_faces(i), level, ifmt, s, s, 0, comp, type, 0);
+ glTexImage2D(enumerate_faces(i), level, storage_fmt, s, s, 0, comp, type, 0);
allocated |= 64<<level;
}
}
-void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
+void TextureCube::image(TextureCubeFace face, unsigned level, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("TextureCube::image");
+ image(face, level, data);
+}
+
+void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
{
if(size==0)
throw invalid_operation("TextureCube::sub_image");
BindRestore _bind(this);
allocate(level);
- glTexSubImage2D(face, level, x, y, wd, ht, get_upload_components(comp), type, data);
+ PixelComponents comp = get_components(storage_fmt);
+ DataType type = get_component_type(storage_fmt);
+ glTexSubImage2D(face, level, x, y, wd, ht, comp, type, data);
if(auto_gen_mipmap && level==0)
generate_mipmap();
}
+void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
+{
+ if(comp!=get_components(format) || type!=get_component_type(format))
+ throw incompatible_data("TextureCube::subimage");
+ sub_image(face, level, x, y, wd, ht, data);
+}
+
void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool srgb)
{
unsigned w = img.get_width();
PixelStore pstore = PixelStore::from_image(img);
BindRestore _bind_ps(pstore);
- image(face, 0, get_components(fmt), get_component_type(fmt), img.get_data());
+ image(face, 0, img.get_data());
}
void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb)
h /= 6;
PixelFormat fmt = pixelformat_from_image(img);
- PixelComponents comp = get_components(fmt);
- DataType type = get_component_type(fmt);
if(size==0)
- storage(make_pixelformat(comp, type, srgb), w, lv);
+ storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, lv);
else if(w!=size || h!=size)
throw incompatible_data("TextureCube::image");
const char *cdata = reinterpret_cast<const char *>(img.get_data());
unsigned face_size = img.get_stride()*size;
for(unsigned i=0; i<6; ++i)
- image(enumerate_faces(i), 0, comp, type, cdata+i*face_size);
+ image(enumerate_faces(i), 0, cdata+i*face_size);
}
unsigned TextureCube::get_n_levels() const
UInt64 TextureCube::get_data_size() const
{
- return id ? size*size*6*get_pixel_size(ifmt) : 0;
+ return id ? size*size*6*get_pixel_size(storage_fmt) : 0;
}
void TextureCube::Loader::raw_data(TextureCubeFace face, const string &data)
{
- obj.image(face, 0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
+ obj.image(face, 0, data.data());
}
void TextureCube::Loader::storage(PixelFormat fmt, unsigned s)
undefined. If storage has already been allocated, does nothing. */
void allocate(unsigned level);
- /** Uploads image data to a face. Storage must be defined beforehand. The
- image data must have dimensions and format compatible with the defined
+ /** Updates the contents of a face. Storage must be defined beforehand.
+ The image data must have dimensions and format matching the defined
storage. */
- void image(TextureCubeFace face, unsigned level,
+ void image(TextureCubeFace face, unsigned level, const void *data);
+
+ DEPRECATED void image(TextureCubeFace face, unsigned level,
PixelComponents comp, DataType type, const void *data);
- /** Updates a rectangular region of a face. Storage must be defined and
- allocated beforehand. The update region must be fully inside the texture.
- The data format must be compatible with the defined storage. */
- void sub_image(TextureCubeFace face, unsigned level,
+ /** Updates a rectangular region of a face. Storage must be defined
+ beforehand. The image data must be in a format mathing the defined storage
+ and the update region must be fully inside the face. */
+ void sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned w, unsigned h, const void *data);
+
+ DEPRECATED void sub_image(TextureCubeFace face, unsigned level,
int x, int y, unsigned w, unsigned h,
PixelComponents comp, DataType type, const void *data);