X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexturecube.cpp;h=6ec3662523dea02903e024bb9113b91125e4b711;hp=db679cf9e1259cb4feb0e087c0f3e066c40921c3;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=1955e583d7eeeb0a2ff054d90c3694f575d9a08d diff --git a/source/texturecube.cpp b/source/texturecube.cpp index db679cf9..6ec36625 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -51,39 +51,44 @@ TextureCube::TextureCube(): 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"); - set_internal_format(fmt); + set_format(fmt); size = sz; + levels = get_n_levels(); + if(lv>0) + levels = min(levels, lv); } void TextureCube::allocate(unsigned level) { - if(allocated&(1<=levels) + throw invalid_argument("TextureCube::allocate"); + if(allocated&(64<(img.get_data()); + const char *pixels = reinterpret_cast(img.get_pixels()); unsigned face_size = img.get_stride()*size; for(unsigned i=0; i<6; ++i) - image(enumerate_faces(i), 0, fmt, UNSIGNED_BYTE, cdata+i*face_size); + image(enumerate_faces(i), 0, pixels+i*face_size); } unsigned TextureCube::get_n_levels() const @@ -227,7 +275,7 @@ Vector3 TextureCube::get_texel_direction(TextureCubeFace face, unsigned u, unsig 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; } @@ -249,6 +297,7 @@ void TextureCube::Loader::init() add("image_data", &Loader::image_data); add("raw_data", &Loader::raw_data); add("storage", &Loader::storage); + add("storage", &Loader::storage_levels); } void TextureCube::Loader::external_image(TextureCubeFace face, const string &fn) @@ -257,7 +306,7 @@ void TextureCube::Loader::external_image(TextureCubeFace face, const string &fn) RefPtr io = get_collection().open_raw(fn); img.load_io(*io); - obj.image(face, img, srgb); + obj.image(face, img); } void TextureCube::Loader::image_data(TextureCubeFace face, const string &data) @@ -266,21 +315,24 @@ void TextureCube::Loader::image_data(TextureCubeFace face, const string &data) IO::Memory mem(data.data(), data.size()); img.load_io(mem); - obj.image(face, img, srgb); + obj.image(face, img); } void TextureCube::Loader::raw_data(TextureCubeFace face, const string &data) { - obj.image(face, 0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data()); + obj.image(face, 0, data.data()); } void TextureCube::Loader::storage(PixelFormat fmt, unsigned s) { - if(srgb) - fmt = get_srgb_pixelformat(fmt); obj.storage(fmt, s); } +void TextureCube::Loader::storage_levels(PixelFormat fmt, unsigned s, unsigned l) +{ + obj.storage(fmt, s, l); +} + void operator>>(const LexicalConverter &conv, TextureCubeFace &face) {