#include <msp/gl/extensions/arb_direct_state_access.h>
#include <msp/gl/extensions/arb_texture_storage.h>
#include <msp/gl/extensions/msp_texture1d.h>
-#include "bindable.h"
#include "error.h"
#include "texture1d.h"
void Texture1D::storage(PixelFormat fmt, unsigned wd, unsigned lv)
{
if(width>0)
- throw invalid_operation("Texture1D::storage");
+ {
+ if(fmt!=format || wd!=width || (lv && lv!=levels))
+ throw incompatible_data("Texture1D::storage");
+ return;
+ }
if(wd==0)
throw invalid_argument("Texture1D::storage");
if(ARB_texture_storage)
{
- Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
+ GLenum fmt = get_gl_pixelformat(storage_fmt);
if(ARB_direct_state_access)
- glTextureStorage1D(id, levels, storage_fmt, width);
+ glTextureStorage1D(id, levels, fmt, width);
else
- glTexStorage1D(target, levels, storage_fmt, width);
+ {
+ bind_scratch();
+ glTexStorage1D(target, levels, fmt, width);
+ }
apply_swizzle();
allocated |= (1<<levels)-1;
}
{
if(width==0)
throw invalid_operation("Texture1D::image");
-
- unsigned w = get_level_size(level);
+ if(level>=levels)
+ throw out_of_range("Texture1D::image");
if(ARB_texture_storage)
- return sub_image(level, 0, w, data);
+ return sub_image(level, 0, get_level_size(level), data);
- BindRestore _bind(this);
+ bind_scratch();
if(!allocated)
{
apply_swizzle();
}
- PixelComponents comp = get_components(storage_fmt);
+ 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, storage_fmt, w, 0, comp, type, data);
+ glTexImage1D(target, level, 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)
void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
{
if(width==0)
- throw invalid_operation("Texture3D::image");
+ throw invalid_operation("Texture1D::sub_image");
+ if(level>=levels)
+ throw out_of_range("Texture1D::sub_image");
- Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
- PixelComponents comp = get_components(storage_fmt);
+ GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
if(ARB_direct_state_access)
glTextureSubImage1D(id, level, x, wd, comp, type, data);
else
+ {
+ bind_scratch();
glTexSubImage1D(target, level, x, wd, comp, type, data);
-
- if(auto_gen_mipmap && level==0)
- generate_mipmap();
+ }
}
void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
unsigned w = img.get_width();
PixelFormat fmt = pixelformat_from_image(img);
- if(width==0)
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
- else if(w!=width)
- throw incompatible_data("Texture1D::image");
+ storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
image(0, img.get_pixels());
}