X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexture2d.cpp;fp=source%2Ftexture2d.cpp;h=fa92f1c97e52b3c980485827280def8e1c0057c2;hp=8846a555d6437f6554c46e316a6f40be0b1c9728;hb=2ba5af95fb7341b0e6b212e28d03208c6747aae5;hpb=2edfcf08707c3627b6b27289ba607a7183d63b01 diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 8846a555..fa92f1c9 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -53,7 +53,7 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv) 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(); @@ -74,17 +74,17 @@ void Texture2D::allocate(unsigned level) { Conditional _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< _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 @@ -131,6 +142,13 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht 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); @@ -141,17 +159,15 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb, bool f 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 @@ -182,7 +198,7 @@ Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *res) 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() @@ -215,7 +231,7 @@ void Texture2D::Loader::init() 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)