throw invalid_operation("Texture1D::allocate");
if(level>=levels)
throw invalid_argument("Texture1D::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 Texture1D::allocate_(unsigned level)
+{
if(allocated&(1<<level))
return;
if(ARB_texture_storage)
{
- Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
glTextureStorage1D(id, levels, storage_fmt, width);
else
allocated |= (1<<levels)-1;
}
else
- image(level, 0);
+ image_(level, 0);
}
void Texture1D::image(unsigned level, const void *data)
if(level>=levels)
throw out_of_range("Texture1D::image");
- unsigned w = get_level_size(level);
-
if(ARB_texture_storage)
- return sub_image(level, 0, w, data);
+ return sub_image(level, 0, get_level_size(level), data);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(target, id);
+
+ image_(level, data);
+
+ if(auto_gen_mipmap && level==0)
+ {
+ generate_mipmap_();
+ allocated |= (1<<levels)-1;
+ }
- BindRestore _bind(this);
+ glBindTexture(target, 0);
+}
+void Texture1D::image_(unsigned level, const void *data)
+{
if(!allocated)
{
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
PixelComponents comp = get_components(storage_fmt);
GLenum type = get_gl_type(get_component_type(storage_fmt));
- glTexImage1D(target, level, storage_fmt, w, 0, comp, type, data);
+ glTexImage1D(target, level, storage_fmt, get_level_size(level), 0, comp, type, data);
allocated |= 1<<level;
- if(auto_gen_mipmap && level==0)
- {
- generate_mipmap();
- allocated |= (1<<levels)-1;
- }
}
void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
if(level>=levels)
throw out_of_range("Texture1D::sub_image");
- Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
- allocate(level);
+ bool direct = (ARB_direct_state_access && (ARB_texture_storage || (allocated&(1<<level))));
+ if(!direct)
+ {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(target, id);
+ }
+
+ allocate_(level);
PixelComponents comp = get_components(storage_fmt);
GLenum type = get_gl_type(get_component_type(storage_fmt));
glTexSubImage1D(target, level, x, wd, comp, type, data);
if(auto_gen_mipmap && level==0)
- generate_mipmap();
+ generate_mipmap_();
+
+ if(!direct)
+ glBindTexture(target, 0);
}
void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)