]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/texture3d_backend.cpp
Add support for padding in vertex formats
[libs/gl.git] / source / backends / opengl / texture3d_backend.cpp
index 6826993ae6d9c37c414d5e6ff5aa50f1c9b7ff09..961dd7e721766596f439312c45d11348e4eaebc7 100644 (file)
@@ -26,6 +26,9 @@ void OpenGLTexture3D::allocate()
        unsigned depth = static_cast<const Texture3D *>(this)->depth;
        unsigned levels = static_cast<const Texture3D *>(this)->levels;
 
+       if(!id)
+               create();
+
        GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
        if(ARB_texture_storage)
        {
@@ -71,5 +74,22 @@ bool OpenGLTexture3D::is_array() const
        return target==GL_TEXTURE_2D_ARRAY;
 }
 
+size_t OpenGLTexture3D::get_data_size() const
+{
+       if(!id)
+               return 0;
+
+       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;
+
+       size_t level_size = width*height*depth*get_pixel_size(format);
+       size_t total_size = level_size;
+       for(unsigned i=0; i<levels; ++i, level_size>>=2)
+               total_size += level_size;
+       return total_size;
+}
+
 } // namespace GL
 } // namespace Msp