X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fopengl%2Ftexture2d_backend.cpp;h=54c82280e5b1a0e3e30b0e51bc7a1da6abf28ff6;hb=3b98e13c823d4cb7e4d2d4d14e8440b44bc71f91;hp=578cefe390f0a2ec2bfa4bdb15e73426fef43822;hpb=b274dc87db4422498e72823649358114dfca0096;p=libs%2Fgl.git diff --git a/source/backends/opengl/texture2d_backend.cpp b/source/backends/opengl/texture2d_backend.cpp index 578cefe3..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); } } @@ -95,11 +93,25 @@ void OpenGLTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsig glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } -Resource::AsyncLoader *OpenGLTexture2D::create_async_loader(IO::Seekable &io) +Resource::AsyncLoader *OpenGLTexture2D::load(IO::Seekable &io, const Resources *) { return new AsyncLoader(static_cast(*this), io); } +uint64_t OpenGLTexture2D::get_data_size() const +{ + 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() { glDeleteTextures(1, &id); @@ -151,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)