throw invalid_operation("TextureCube::allocate");
if(level>=levels)
throw invalid_argument("TextureCube::allocate");
-
- bool direct = ARB_texture_storage && ARB_direct_state_access;
- if(!direct)
- {
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(target, id);
- }
-
- allocate_(level);
-
- if(!direct)
- glBindTexture(target, 0);
-}
-
-void TextureCube::allocate_(unsigned level)
-{
if(allocated&(64<<level))
return;
if(ARB_direct_state_access)
glTextureStorage2D(id, levels, fmt, size, size);
else
+ {
+ bind_scratch();
glTexStorage2D(target, levels, fmt, size, size);
+ }
apply_swizzle();
allocated |= (64<<levels)-1;
}
else
{
for(unsigned i=0; i<6; ++i)
- image_(enumerate_faces(i), level, 0);
+ image(enumerate_faces(i), level, 0);
}
}
if(level>=levels)
throw out_of_range("TextureCube::image");
+ unsigned lsz = get_level_size(level);
+
if(ARB_texture_storage)
- {
- unsigned lsz = get_level_size(level);
return sub_image(face, level, 0, 0, lsz, lsz, data);
- }
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(target, id);
-
- image_(face, level, data);
- if(auto_gen_mipmap && level==0 && (allocated&63)==63)
- {
- generate_mipmap_();
- allocated |= (64<<levels)-1;
- }
-
- glBindTexture(target, 0);
-}
-
-void TextureCube::image_(TextureCubeFace face, unsigned level, const void *data)
-{
if(!allocated)
{
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
apply_swizzle();
}
- unsigned lsz = get_level_size(level);
GLenum fmt = get_gl_pixelformat(storage_fmt);
GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
{
allocated |= 1<<get_face_index(face);
if((allocated&63)==63)
+ {
allocated |= 64;
+ if(auto_gen_mipmap && level==0 && (allocated&63)==63)
+ {
+ generate_mipmap();
+ allocated |= (64<<levels)-1;
+ }
+ }
}
else if(!(allocated&(64<<level)))
{
if(level>=levels)
throw out_of_range("TextureCube::sub_image");
- bool direct = (ARB_direct_state_access && (ARB_texture_storage || (allocated&(1<<level))));
- if(!direct)
- {
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(target, id);
- }
-
- allocate_(level);
+ allocate(level);
GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
if(ARB_direct_state_access)
glTextureSubImage3D(id, level, x, y, get_face_index(face), wd, ht, 1, comp, type, data);
else
+ {
+ bind_scratch();
glTexSubImage2D(face, level, x, y, wd, ht, comp, type, data);
+ }
if(auto_gen_mipmap && level==0)
- generate_mipmap_();
-
- if(!direct)
- glBindTexture(target, 0);
+ generate_mipmap();
}
void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)