1 #include <msp/gl/extensions/arb_direct_state_access.h>
2 #include <msp/gl/extensions/arb_seamless_cube_map.h>
3 #include <msp/gl/extensions/arb_texture_cube_map.h>
4 #include <msp/gl/extensions/arb_texture_storage.h>
6 #include "texturecube.h"
7 #include "texturecube_backend.h"
14 OpenGLTextureCube::OpenGLTextureCube():
15 Texture(GL_TEXTURE_CUBE_MAP)
17 static Require _req(ARB_texture_cube_map);
18 if(ARB_seamless_cube_map)
20 static bool seamless_init = false;
23 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
29 void OpenGLTextureCube::allocate()
31 unsigned size = static_cast<const TextureCube *>(this)->size;
32 unsigned levels = static_cast<const TextureCube *>(this)->levels;
37 GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
38 if(ARB_texture_storage)
40 if(ARB_direct_state_access)
41 glTextureStorage2D(id, levels, gl_fmt, size, size);
45 glTexStorage2D(target, levels, gl_fmt, size, size);
51 GLenum comp = get_gl_components(get_components(storage_fmt));
52 GLenum type = get_gl_type(get_component_type(storage_fmt));
53 for(unsigned i=0; i<levels; ++i)
55 unsigned lv_size = static_cast<const TextureCube *>(this)->get_level_size(i);
56 for(unsigned j=0; j<6; ++j)
57 glTexImage2D(get_gl_cube_face(j), i, gl_fmt, lv_size, lv_size, 0, comp, type, 0);
59 glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
65 void OpenGLTextureCube::sub_image(unsigned face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
67 GLenum comp = get_gl_components(get_components(storage_fmt));
68 GLenum type = get_gl_type(get_component_type(storage_fmt));
69 if(ARB_direct_state_access)
70 glTextureSubImage3D(id, level, x, y, face, wd, ht, 1, comp, type, data);
74 glTexSubImage2D(get_gl_cube_face(face), level, x, y, wd, ht, comp, type, data);
78 unsigned get_gl_cube_face(unsigned face)
80 switch(static_cast<TextureCubeFace>(face))
82 case POSITIVE_X: return GL_TEXTURE_CUBE_MAP_POSITIVE_X;
83 case NEGATIVE_X: return GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
84 case POSITIVE_Y: return GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
85 case NEGATIVE_Y: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
86 case POSITIVE_Z: return GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
87 case NEGATIVE_Z: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
88 default: throw invalid_argument("get_gl_cube_face");