X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Ftexturecube.cpp;h=9aec4b1d19640f699adbf8c2596a7e14555b6200;hp=2a15eb1bec3359a3f665e4d48c4f62392644b41f;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=4a639bc5e80fce2467855a9e8f4c6cdff2f0adc0 diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 2a15eb1b..9aec4b1d 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,7 @@ 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); - } - - apply_swizzle(); + allocate(); } void TextureCube::image(TextureCubeFace face, unsigned level, const void *data) @@ -107,16 +62,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, if(level>=levels) 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) @@ -126,9 +72,7 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img) if(w!=h) throw incompatible_data("TextureCube::image"); - PixelFormat fmt = pixelformat_from_image(img); - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w); - + storage(pixelformat_from_image(img, use_srgb_format), w); image(face, 0, img.get_pixels()); } @@ -141,9 +85,8 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv) throw incompatible_data("TextureCube::image"); h /= 6; - PixelFormat fmt = pixelformat_from_image(img); if(size==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); + storage(pixelformat_from_image(img, use_srgb_format), w, lv); else if(w!=size || h!=size) throw incompatible_data("TextureCube::image"); @@ -251,20 +194,6 @@ void TextureCube::Loader::storage_levels(PixelFormat fmt, unsigned s, unsigned l } -GLenum 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();