void OpenGLTexture1D::allocate()
{
- unsigned width = static_cast<const Texture1D *>(this)->width;
- unsigned levels = static_cast<const Texture1D *>(this)->levels;
+ const Texture1D &self = *static_cast<const Texture1D *>(this);
if(!id)
create();
if(ARB_texture_storage)
{
if(ARB_direct_state_access)
- glTextureStorage1D(id, levels, gl_fmt, width);
+ glTextureStorage1D(id, self.levels, gl_fmt, self.width);
else
{
bind_scratch();
- glTexStorage1D(target, levels, gl_fmt, width);
+ glTexStorage1D(target, self.levels, gl_fmt, self.width);
}
}
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)
{
- unsigned lv_size = static_cast<const Texture1D *>(this)->get_level_size(i);
+ unsigned lv_size = self.get_level_size(i);
glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0);
}
}
size_t OpenGLTexture1D::get_data_size() const
{
- unsigned width = static_cast<const Texture1D *>(this)->width;
- return id ? width*get_pixel_size(storage_fmt) : 0;
+ if(!id)
+ return 0;
+
+ const Texture1D &self = *static_cast<const Texture1D *>(this);
+
+ size_t level_size = self.width*get_pixel_size(storage_fmt);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
}
} // namespace GL