]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/texture2d_backend.cpp
Add a usage parameter to Buffer
[libs/gl.git] / source / backends / opengl / texture2d_backend.cpp
index 72962117bc9967d98228735063b5189e10368dfd..45ba78cc8f6f10c1e4e8d3b7d372b82b148843f0 100644 (file)
@@ -102,9 +102,18 @@ Resource::AsyncLoader *OpenGLTexture2D::load(IO::Seekable &io, const Resources *
 
 uint64_t OpenGLTexture2D::get_data_size() const
 {
+       if(!id)
+               return 0;
+
        unsigned width = static_cast<const Texture2D *>(this)->width;
        unsigned height = static_cast<const Texture2D *>(this)->height;
-       return id ? width*height*get_pixel_size(format) : 0;
+       unsigned levels = static_cast<const Texture2D *>(this)->levels;
+
+       size_t level_size = width*height*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;
 }
 
 void OpenGLTexture2D::unload()
@@ -158,7 +167,7 @@ bool OpenGLTexture2D::AsyncLoader::process()
        }
        else if(phase==1)
        {
-               pixel_buffer.storage(n_bytes);
+               pixel_buffer.storage(n_bytes, STREAMING);
                mapped_address = reinterpret_cast<char *>(pixel_buffer.map());
        }
        else if(phase==2)