void OpenGLTexture2D::allocate()
{
- unsigned width = static_cast<const Texture2D *>(this)->width;
- unsigned height = static_cast<const Texture2D *>(this)->height;
- unsigned levels = static_cast<const Texture2D *>(this)->levels;
+ const Texture2D &self = *static_cast<const Texture2D *>(this);
if(!id)
create();
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<levels; ++i)
+ for(unsigned i=0; i<self.levels; ++i)
{
- auto lv_size = static_cast<const Texture2D *>(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);
}
}
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<Texture2D &>(*this), io);
}
+uint64_t OpenGLTexture2D::get_data_size() const
+{
+ if(!id)
+ return 0;
+
+ const Texture2D &self = *static_cast<const Texture2D *>(this);
+
+ size_t level_size = self.width*self.height*get_pixel_size(format);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
+}
+
void OpenGLTexture2D::unload()
{
glDeleteTextures(1, &id);
}
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)