1 #include <msp/gl/extensions/msp_texture1d.h>
11 Texture1D::Texture1D():
12 Texture(GL_TEXTURE_1D),
17 static Require _req(MSP_texture1D);
20 void Texture1D::storage(PixelFormat fmt, unsigned wd)
23 throw invalid_operation("Texture1D::storage");
25 throw invalid_argument("Texture1D::storage");
27 if(MSP_sized_internal_formats)
28 fmt = get_sized_pixelformat(fmt);
29 require_pixelformat(fmt);
35 void Texture1D::allocate(unsigned level)
37 if(allocated&(1<<level))
40 PixelFormat base_fmt = get_base_pixelformat(ifmt);
41 image(level, base_fmt, get_alloc_type(base_fmt), 0);
44 void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
47 throw invalid_operation("Texture1D::image");
49 unsigned w = get_level_size(level);
51 BindRestore _bind(this);
52 glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
54 allocated |= 1<<level;
55 if(gen_mipmap && level==0)
57 auto_generate_mipmap();
58 for(; w; w>>=1, ++level) ;
59 allocated |= (1<<level)-1;
63 void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, DataType type, const void *data)
66 throw invalid_operation("Texture3D::image");
70 BindRestore _bind(this);
71 glTexSubImage1D(target, level, x, wd, fmt, type, data);
74 void Texture1D::image(const Graphics::Image &img, bool srgb)
76 if(img.get_height()!=1)
77 throw incompatible_data("Texture1D::image");
79 unsigned w = img.get_width();
80 PixelFormat fmt = pixelformat_from_graphics(img.get_format());
82 storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
84 throw incompatible_data("Texture1D::image");
86 image(0, fmt, UNSIGNED_BYTE, img.get_data());
89 unsigned Texture1D::get_level_size(unsigned level)
94 UInt64 Texture1D::get_data_size() const
96 return id ? width*get_pixel_size(ifmt) : 0;
100 Texture1D::Loader::Loader(Texture1D &t):
101 DataFile::DerivedObjectLoader<Texture1D, Texture::Loader>(t)
106 Texture1D::Loader::Loader(Texture1D &t, Collection &c):
107 DataFile::DerivedObjectLoader<Texture1D, Texture::Loader>(t, c)
112 void Texture1D::Loader::init()
114 add("raw_data", &Loader::raw_data);
115 add("storage", &Loader::storage);
118 void Texture1D::Loader::raw_data(const string &data)
120 obj.image(0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
123 void Texture1D::Loader::storage(PixelFormat fmt, unsigned w)
126 fmt = get_srgb_pixelformat(fmt);