X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Ftexturecube.cpp;h=c56094c9cb0bd36e837db1df0c1c115fc38ad876;hp=6ec3662523dea02903e024bb9113b91125e4b711;hb=3a1b9cbe2441ae670a97541dc8ccb0a2860c8302;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 6ec36625..c56094c9 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"); @@ -76,10 +82,16 @@ void TextureCube::allocate(unsigned level) if(ARB_texture_storage) { - BindRestore _bind(this); - glTexStorage2D(target, levels, storage_fmt, size, size); + GLenum fmt = get_gl_pixelformat(storage_fmt); + if(ARB_direct_state_access) + glTextureStorage2D(id, levels, fmt, size, size); + else + { + bind_scratch(); + glTexStorage2D(target, levels, fmt, size, size); + } apply_swizzle(); - allocated |= (1<=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); - BindRestore _bind(this); + if(ARB_texture_storage) + return sub_image(face, level, 0, 0, lsz, lsz, data); if(!allocated) { @@ -108,28 +118,22 @@ void TextureCube::image(TextureCubeFace face, unsigned level, const void *data) apply_swizzle(); } - PixelComponents comp = get_components(storage_fmt); - DataType type = get_component_type(storage_fmt); - glTexImage2D(face, level, storage_fmt, s, s, 0, comp, type, data); + GLenum fmt = get_gl_pixelformat(storage_fmt); + GLenum comp = get_gl_components(get_components(storage_fmt)); + GLenum type = get_gl_type(get_component_type(storage_fmt)); + glTexImage2D(face, level, fmt, lsz, lsz, 0, comp, type, data); if(level==0) { allocated |= 1<=levels) + throw out_of_range("TextureCube::sub_image"); - BindRestore _bind(this); allocate(level); - 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(); + GLenum comp = get_gl_components(get_components(storage_fmt)); + GLenum type = get_gl_type(get_component_type(storage_fmt)); + if(ARB_direct_state_access) + glTextureSubImage3D(id, level, x, y, get_face_index(face), wd, ht, 1, comp, type, data); + else + { + bind_scratch(); + glTexSubImage2D(face, level, x, y, wd, ht, comp, type, data); + } } void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data) @@ -169,19 +177,11 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img) { unsigned w = img.get_width(); unsigned h = img.get_height(); - PixelFormat fmt = pixelformat_from_image(img); - if(size==0) - { - if(w!=h) - throw incompatible_data("TextureCube::image"); - - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w); - } - else if(w!=size || h!=size) + if(w!=h) throw incompatible_data("TextureCube::image"); - PixelStore pstore = PixelStore::from_image(img); - BindRestore _bind_ps(pstore); + PixelFormat fmt = pixelformat_from_image(img); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w); image(face, 0, img.get_pixels()); } @@ -206,9 +206,6 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv) else if(w!=size || h!=size) throw incompatible_data("TextureCube::image"); - PixelStore pstore = PixelStore::from_image(img); - BindRestore _bind_ps(pstore); - const char *pixels = reinterpret_cast(img.get_pixels()); unsigned face_size = img.get_stride()*size; for(unsigned i=0; i<6; ++i) @@ -273,7 +270,7 @@ Vector3 TextureCube::get_texel_direction(TextureCubeFace face, unsigned u, unsig return fv+s*sv+t*tv; } -UInt64 TextureCube::get_data_size() const +uint64_t TextureCube::get_data_size() const { return id ? size*size*6*get_pixel_size(storage_fmt) : 0; }