void OpenGLTextureCube::allocate()
{
- unsigned size = static_cast<const TextureCube *>(this)->size;
- unsigned levels = static_cast<const TextureCube *>(this)->levels;
+ const TextureCube &self = *static_cast<const TextureCube *>(this);
if(!id)
- generate_id();
+ create();
GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
if(ARB_texture_storage)
{
if(ARB_direct_state_access)
- glTextureStorage2D(id, levels, gl_fmt, size, size);
+ glTextureStorage2D(id, n_levels, gl_fmt, self.size, self.size);
else
{
bind_scratch();
- glTexStorage2D(target, levels, gl_fmt, size, size);
+ glTexStorage2D(target, n_levels, gl_fmt, self.size, self.size);
}
}
else
bind_scratch();
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<n_levels; ++i)
{
unsigned lv_size = static_cast<const TextureCube *>(this)->get_level_size(i);
for(unsigned j=0; j<6; ++j)
glTexImage2D(get_gl_cube_face(j), i, gl_fmt, lv_size, lv_size, 0, comp, type, 0);
}
- glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, n_levels-1);
}
apply_swizzle();
}
}
+size_t OpenGLTextureCube::get_data_size() const
+{
+ if(!id)
+ return 0;
+
+ const TextureCube &self = *static_cast<const TextureCube *>(this);
+
+ size_t level_size = self.size*self.size*get_pixel_size(storage_fmt);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<n_levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
+}
+
+
unsigned get_gl_cube_face(unsigned face)
{
switch(static_cast<TextureCubeFace>(face))