1 #include <msp/gl/extensions/arb_direct_state_access.h>
2 #include <msp/gl/extensions/arb_texture_storage.h>
3 #include <msp/gl/extensions/ext_texture3d.h>
4 #include <msp/gl/extensions/ext_texture_array.h>
7 #include "texture3d_backend.h"
12 OpenGLTexture3D::OpenGLTexture3D():
13 Texture(GL_TEXTURE_3D)
15 static Require _req(EXT_texture3D);
18 OpenGLTexture3D::OpenGLTexture3D(unsigned t):
22 void OpenGLTexture3D::allocate()
24 unsigned width = static_cast<const Texture3D *>(this)->width;
25 unsigned height = static_cast<const Texture3D *>(this)->height;
26 unsigned depth = static_cast<const Texture3D *>(this)->depth;
27 unsigned levels = static_cast<const Texture3D *>(this)->levels;
32 GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
33 if(ARB_texture_storage)
35 if(ARB_direct_state_access)
36 glTextureStorage3D(id, levels, gl_fmt, width, height, depth);
40 glTexStorage3D(target, levels, gl_fmt, width, height, depth);
46 GLenum comp = get_gl_components(get_components(storage_fmt));
47 GLenum type = get_gl_type(get_component_type(storage_fmt));
48 for(unsigned i=0; i<levels; ++i)
50 auto lv_size = static_cast<const Texture3D *>(this)->get_level_size(i);
51 glTexImage3D(target, i, gl_fmt, lv_size.x, lv_size.y, lv_size.z, 0, comp, type, 0);
53 glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
59 void OpenGLTexture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
61 GLenum comp = get_gl_components(get_components(storage_fmt));
62 GLenum type = get_gl_type(get_component_type(storage_fmt));
63 if(ARB_direct_state_access)
64 glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, comp, type, data);
68 glTexSubImage3D(target, level, x, y, z, wd, ht, dp, comp, type, data);
72 bool OpenGLTexture3D::is_array() const
74 return target==GL_TEXTURE_2D_ARRAY;