X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Ftexturecube.cpp;h=2f36f33624cee007b2667daeb993caaf212e9a04;hp=6239688cb304d66a381298d8057d4c9d3330a046;hb=7ef75a4c4dbfc437e466381dd67c23357e607b82;hpb=24b24e2203c776aacd9744bb947f5cf47b03d328 diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 6239688c..2f36f336 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -1,8 +1,4 @@ #include -#include -#include -#include -#include #include #include #include "error.h" @@ -33,22 +29,6 @@ const unsigned TextureCube::orientations[12] = 1, 3 }; -TextureCube::TextureCube(): - Texture(GL_TEXTURE_CUBE_MAP), - size(0) -{ - static Require _req(ARB_texture_cube_map); - if(ARB_seamless_cube_map) - { - static bool seamless_init = false; - if(!seamless_init) - { - glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); - seamless_init = true; - } - } -} - void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv) { if(size>0) @@ -66,32 +46,15 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv) if(lv>0) levels = min(levels, lv); - GLenum gl_fmt = get_gl_pixelformat(storage_fmt); - if(ARB_texture_storage) - { - if(ARB_direct_state_access) - glTextureStorage2D(id, levels, gl_fmt, size, size); - else - { - bind_scratch(); - glTexStorage2D(target, levels, gl_fmt, size, size); - } - } - else - { - bind_scratch(); - GLenum comp = get_gl_components(get_components(storage_fmt)); - GLenum type = get_gl_type(get_component_type(storage_fmt)); - for(unsigned i=0; i(j)), i, gl_fmt, lv_size, lv_size, 0, comp, type, 0); - } - glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); - } + allocate(); +} - apply_swizzle(); +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) @@ -100,23 +63,14 @@ void TextureCube::image(TextureCubeFace face, unsigned level, const void *data) return sub_image(face, level, 0, 0, lsz, lsz, data); } -void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data) +void TextureCube::sub_image(TextureCubeFace face, unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *data) { if(size==0) throw invalid_operation("TextureCube::sub_image"); - if(level>=levels) + if(level>=levels || x>size || x+wd>size || y>size || y+ht>size) throw out_of_range("TextureCube::sub_image"); - GLenum gl_face = get_gl_cube_face(face); - 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, face, wd, ht, 1, comp, type, data); - else - { - bind_scratch(); - glTexSubImage2D(gl_face, level, x, y, wd, ht, comp, type, data); - } + TextureCubeBackend::sub_image(face, level, x, y, wd, ht, data); } void TextureCube::image(TextureCubeFace face, const Graphics::Image &img) @@ -144,10 +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); + image(0, img.get_pixels()); } unsigned TextureCube::get_n_levels() const @@ -187,11 +138,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) @@ -248,20 +194,6 @@ void TextureCube::Loader::storage_levels(PixelFormat fmt, unsigned s, unsigned l } -unsigned get_gl_cube_face(TextureCubeFace face) -{ - switch(face) - { - case POSITIVE_X: return GL_TEXTURE_CUBE_MAP_POSITIVE_X; - case NEGATIVE_X: return GL_TEXTURE_CUBE_MAP_NEGATIVE_X; - case POSITIVE_Y: return GL_TEXTURE_CUBE_MAP_POSITIVE_Y; - case NEGATIVE_Y: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; - case POSITIVE_Z: return GL_TEXTURE_CUBE_MAP_POSITIVE_Z; - case NEGATIVE_Z: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; - default: throw invalid_argument("get_gl_cube_face"); - } -} - void operator>>(const LexicalConverter &conv, TextureCubeFace &face) { const string &str = conv.get();