X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexturecube.cpp;h=2db1b63b92162c358618c7c3d7a6a0831ce3cb5e;hb=e92de029768eef5f0fd744329e589161b46d0762;hp=d006e383cc998af09fa478b18bb8bc4ce047ecfc;hpb=efb45a6851563cdb8077b6aad3ab92d4006d8790;p=libs%2Fgl.git diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index d006e383..2db1b63b 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -1,11 +1,11 @@ #include +#include +#include #include #include #include #include -#include "bindable.h" #include "error.h" -#include "pixelstore.h" #include "texturecube.h" using namespace std; @@ -49,12 +49,18 @@ TextureCube::TextureCube(): allocated(0) { static Require _req(ARB_texture_cube_map); + if(ARB_seamless_cube_map) + glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); } void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv) { if(size>0) - throw invalid_operation("TextureCube::storage"); + { + if(fmt!=format || sz!=size || (lv && lv!=levels)) + throw incompatible_data("TextureCube::storage"); + return; + } if(sz==0) throw invalid_argument("TextureCube::storage"); @@ -71,20 +77,39 @@ void TextureCube::allocate(unsigned level) throw invalid_operation("TextureCube::allocate"); if(level>=levels) throw invalid_argument("TextureCube::allocate"); + + bool direct = ARB_texture_storage && ARB_direct_state_access; + if(!direct) + { + glActiveTexture(GL_TEXTURE0); + glBindTexture(target, id); + } + + allocate_(level); + + if(!direct) + glBindTexture(target, 0); +} + +void TextureCube::allocate_(unsigned level) +{ if(allocated&(64<=levels) throw out_of_range("TextureCube::image"); if(ARB_texture_storage) - return sub_image(face, level, 0, 0, s, s, data); + { + unsigned lsz = get_level_size(level); + return sub_image(face, level, 0, 0, lsz, lsz, data); + } + + glActiveTexture(GL_TEXTURE0); + glBindTexture(target, id); + + image_(face, level, data); + + if(auto_gen_mipmap && level==0 && (allocated&63)==63) + { + generate_mipmap_(); + allocated |= (64<=levels) + throw out_of_range("TextureCube::sub_image"); - BindRestore _bind(this); - allocate(level); + bool direct = (ARB_direct_state_access && (ARB_texture_storage || (allocated&(1<(img.get_pixels()); unsigned face_size = img.get_stride()*size; for(unsigned i=0; i<6; ++i)