X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexturecube.cpp;h=bfa63873b2e188f2f339940fc48bf09e4c38034e;hb=11a5d4f2a35dfdcf61e16d4fcfba22e20ea6a3db;hp=ff2b28755bb3e8e37c3dbadf57f6695b24e13d83;hpb=4365124bd39bd6edbda6eaef64ec72a1a10565f8;p=libs%2Fgl.git diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index ff2b2875..bfa63873 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -33,7 +33,7 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv) { if(size>0) { - if(fmt!=format || sz!=size || (lv && lv!=levels)) + if(fmt!=format || sz!=size || (lv && lv!=n_levels)) throw incompatible_data("TextureCube::storage"); return; } @@ -42,13 +42,21 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv) set_format(fmt); size = sz; - levels = get_n_levels(); + n_levels = count_levels(size); if(lv>0) - levels = min(levels, lv); + n_levels = min(n_levels, lv); allocate(); } +void TextureCube::image(unsigned level, const void *data) +{ + const char *pixels = static_cast(data); + unsigned face_size = size*size*get_pixel_size(storage_fmt); + for(unsigned i=0; i<6; ++i) + image(static_cast(i), level, pixels+i*face_size); +} + void TextureCube::image(TextureCubeFace face, unsigned level, const void *data) { unsigned lsz = get_level_size(level); @@ -59,7 +67,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, unsigned x, un { if(size==0) throw invalid_operation("TextureCube::sub_image"); - if(level>=levels || x>size || x+wd>size || y>size || y+ht>size) + if(level>=n_levels || x>size || x+wd>size || y>size || y+ht>size) throw out_of_range("TextureCube::sub_image"); TextureCubeBackend::sub_image(face, level, x, y, wd, ht, data); @@ -90,17 +98,7 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv) else if(w!=size || h!=size) throw incompatible_data("TextureCube::image"); - const char *pixels = reinterpret_cast(img.get_pixels()); - unsigned face_size = img.get_stride()*size; - for(unsigned i=0; i<6; ++i) - image(static_cast(i), 0, pixels+i*face_size); -} - -unsigned TextureCube::get_n_levels() const -{ - unsigned n = 0; - for(unsigned s=size; s; s>>=1, ++n) ; - return n; + image(0, img.get_pixels()); } unsigned TextureCube::get_level_size(unsigned level) const @@ -133,11 +131,6 @@ Vector3 TextureCube::get_texel_direction(TextureCubeFace face, unsigned u, unsig return fv+s*sv+t*tv; } -uint64_t TextureCube::get_data_size() const -{ - return id ? size*size*6*get_pixel_size(storage_fmt) : 0; -} - TextureCube::Loader::Loader(TextureCube &t): DataFile::DerivedObjectLoader(t)