--- /dev/null
+#include <msp/gl/extensions/arb_direct_state_access.h>
+#include <msp/gl/extensions/arb_texture_storage.h>
+#include <msp/gl/extensions/ext_texture3d.h>
+#include <msp/gl/extensions/ext_texture_array.h>
+#include "gl.h"
+#include "texture3d.h"
+#include "texture3d_backend.h"
+
+namespace Msp {
+namespace GL {
+
+OpenGLTexture3D::OpenGLTexture3D():
+ Texture(GL_TEXTURE_3D)
+{
+ static Require _req(EXT_texture3D);
+}
+
+OpenGLTexture3D::OpenGLTexture3D(unsigned t):
+ Texture(t)
+{ }
+
+void OpenGLTexture3D::allocate()
+{
+ unsigned width = static_cast<const Texture3D *>(this)->width;
+ unsigned height = static_cast<const Texture3D *>(this)->height;
+ unsigned depth = static_cast<const Texture3D *>(this)->depth;
+ unsigned levels = static_cast<const Texture3D *>(this)->levels;
+
+ GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
+ if(ARB_texture_storage)
+ {
+ if(ARB_direct_state_access)
+ glTextureStorage3D(id, levels, gl_fmt, width, height, depth);
+ else
+ {
+ bind_scratch();
+ glTexStorage3D(target, levels, gl_fmt, width, height, depth);
+ }
+ }
+ 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)
+ {
+ auto lv_size = static_cast<const Texture3D *>(this)->get_level_size(i);
+ glTexImage3D(target, i, gl_fmt, lv_size.x, lv_size.y, lv_size.z, 0, comp, type, 0);
+ }
+ glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ }
+
+ apply_swizzle();
+}
+
+void OpenGLTexture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
+{
+ 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, z, wd, ht, dp, comp, type, data);
+ else
+ {
+ bind_scratch();
+ glTexSubImage3D(target, level, x, y, z, wd, ht, dp, comp, type, data);
+ }
+}
+
+bool OpenGLTexture3D::is_array() const
+{
+ return target==GL_TEXTURE_2D_ARRAY;
+}
+
+} // namespace GL
+} // namespace Msp