X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fopengl%2Ftexture2d_backend.cpp;h=54c82280e5b1a0e3e30b0e51bc7a1da6abf28ff6;hb=3b98e13c823d4cb7e4d2d4d14e8440b44bc71f91;hp=72962117bc9967d98228735063b5189e10368dfd;hpb=f73e671dcb36c097647cddbf5b1eaaad2ffc9299;p=libs%2Fgl.git diff --git a/source/backends/opengl/texture2d_backend.cpp b/source/backends/opengl/texture2d_backend.cpp index 72962117..54c82280 100644 --- a/source/backends/opengl/texture2d_backend.cpp +++ b/source/backends/opengl/texture2d_backend.cpp @@ -41,9 +41,7 @@ OpenGLTexture2D::OpenGLTexture2D(): void OpenGLTexture2D::allocate() { - unsigned width = static_cast(this)->width; - unsigned height = static_cast(this)->height; - unsigned levels = static_cast(this)->levels; + const Texture2D &self = *static_cast(this); if(!id) create(); @@ -52,22 +50,22 @@ void OpenGLTexture2D::allocate() if(ARB_texture_storage) { if(ARB_direct_state_access) - glTextureStorage2D(id, levels, gl_fmt, width, height); + glTextureStorage2D(id, self.levels, gl_fmt, self.width, self.height); else { bind_scratch(); - glTexStorage2D(target, levels, gl_fmt, width, height); + glTexStorage2D(target, self.levels, gl_fmt, self.width, self.height); } } else { bind_scratch(); - glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.levels-1); 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); + auto lv_size = self.get_level_size(i); glTexImage2D(target, i, gl_fmt, lv_size.x, lv_size.y, 0, comp, type, 0); } } @@ -102,9 +100,16 @@ Resource::AsyncLoader *OpenGLTexture2D::load(IO::Seekable &io, const Resources * uint64_t OpenGLTexture2D::get_data_size() const { - unsigned width = static_cast(this)->width; - unsigned height = static_cast(this)->height; - return id ? width*height*get_pixel_size(format) : 0; + if(!id) + return 0; + + const Texture2D &self = *static_cast(this); + + size_t level_size = self.width*self.height*get_pixel_size(format); + size_t total_size = level_size; + for(unsigned i=0; i>=2) + total_size += level_size; + return total_size; } void OpenGLTexture2D::unload() @@ -158,7 +163,7 @@ bool OpenGLTexture2D::AsyncLoader::process() } else if(phase==1) { - pixel_buffer.storage(n_bytes); + pixel_buffer.storage(n_bytes, STREAMING); mapped_address = reinterpret_cast(pixel_buffer.map()); } else if(phase==2)