Texture1D::Texture1D():
Texture(GL_TEXTURE_1D),
- width(0),
- allocated(0)
+ width(0)
{
static Require _req(MSP_texture1D);
}
levels = get_n_levels();
if(lv)
levels = min(levels, lv);
-}
-
-void Texture1D::allocate(unsigned level)
-{
- if(width==0)
- throw invalid_operation("Texture1D::allocate");
- if(level>=levels)
- throw invalid_argument("Texture1D::allocate");
- if(allocated&(1<<level))
- return;
+ GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
if(ARB_texture_storage)
{
- GLenum fmt = get_gl_pixelformat(storage_fmt);
if(ARB_direct_state_access)
- glTextureStorage1D(id, levels, fmt, width);
+ glTextureStorage1D(id, levels, gl_fmt, width);
else
{
bind_scratch();
- glTexStorage1D(target, levels, fmt, width);
+ glTexStorage1D(target, levels, gl_fmt, width);
}
- apply_swizzle();
- allocated |= (1<<levels)-1;
}
else
- image(level, 0);
-}
-
-void Texture1D::image(unsigned level, const void *data)
-{
- if(width==0)
- throw invalid_operation("Texture1D::image");
- if(level>=levels)
- throw out_of_range("Texture1D::image");
-
- if(ARB_texture_storage)
- return sub_image(level, 0, get_level_size(level), data);
-
- bind_scratch();
-
- if(!allocated)
{
+ bind_scratch();
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
- apply_swizzle();
+ 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)
+ glTexImage1D(target, i, gl_fmt, get_level_size(i), 0, comp, type, 0);
}
- 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));
- glTexImage1D(target, level, fmt, get_level_size(level), 0, comp, type, data);
+ apply_swizzle();
+}
- allocated |= 1<<level;
+void Texture1D::image(unsigned level, const void *data)
+{
+ return sub_image(level, 0, get_level_size(level), data);
}
void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
if(level>=levels)
throw out_of_range("Texture1D::sub_image");
- 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)
if(img.get_height()!=1)
throw incompatible_data("Texture1D::image");
- unsigned w = img.get_width();
- PixelFormat fmt = pixelformat_from_image(img);
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
-
+ storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), lv);
image(0, img.get_pixels());
}