#include <msp/datafile/collection.h>
-#include <msp/gl/extensions/arb_direct_state_access.h>
-#include <msp/gl/extensions/arb_seamless_cube_map.h>
-#include <msp/gl/extensions/arb_texture_cube_map.h>
-#include <msp/gl/extensions/arb_texture_storage.h>
#include <msp/io/memory.h>
#include <msp/strings/format.h>
#include "error.h"
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)
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<levels; ++i)
- {
- unsigned lv_size = get_level_size(i);
- for(unsigned j=0; j<6; ++j)
- glTexImage2D(get_gl_cube_face(static_cast<TextureCubeFace>(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)
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)
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());
}
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");
}
-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();