X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fopengl%2Ftexture3d_backend.cpp;fp=source%2Fbackends%2Fopengl%2Ftexture3d_backend.cpp;h=6826993ae6d9c37c414d5e6ff5aa50f1c9b7ff09;hb=160e9eea29bd10034733d59507fa1bcca36be401;hp=0000000000000000000000000000000000000000;hpb=93448d16e72e38afbaecbccf6fdedd46d6a82a73;p=libs%2Fgl.git diff --git a/source/backends/opengl/texture3d_backend.cpp b/source/backends/opengl/texture3d_backend.cpp new file mode 100644 index 00000000..6826993a --- /dev/null +++ b/source/backends/opengl/texture3d_backend.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#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(this)->width; + unsigned height = static_cast(this)->height; + unsigned depth = static_cast(this)->depth; + unsigned levels = static_cast(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(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