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");
26 require_pixelformat(fmt);
32 void Texture1D::allocate(unsigned level)
34 if(allocated&(1<<level))
37 PixelFormat base_fmt = get_base_pixelformat(ifmt);
38 image(level, base_fmt, get_alloc_type(base_fmt), 0);
41 void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
44 throw invalid_operation("Texture1D::image");
46 unsigned w = get_level_size(level);
48 BindRestore _bind(this);
49 glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
51 allocated |= 1<<level;
52 if(gen_mipmap && level==0)
54 auto_generate_mipmap();
55 for(; w; w>>=1, ++level) ;
56 allocated |= (1<<level)-1;
60 void Texture1D::image(const Graphics::Image &img, bool srgb)
62 if(img.get_height()!=1)
63 throw incompatible_data("Texture1D::image");
65 unsigned w = img.get_width();
66 PixelFormat fmt = pixelformat_from_graphics(img.get_format());
68 storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
70 throw incompatible_data("Texture1D::image");
72 image(0, fmt, UNSIGNED_BYTE, img.get_data());
75 unsigned Texture1D::get_level_size(unsigned level)
80 UInt64 Texture1D::get_data_size() const
82 return id ? width*get_pixel_size(ifmt) : 0;
86 Texture1D::Loader::Loader(Texture1D &t):
87 DataFile::DerivedObjectLoader<Texture1D, Texture::Loader>(t)
92 Texture1D::Loader::Loader(Texture1D &t, Collection &c):
93 DataFile::DerivedObjectLoader<Texture1D, Texture::Loader>(t, c)
98 void Texture1D::Loader::init()
100 add("raw_data", &Loader::raw_data);
101 add("storage", &Loader::storage);
104 void Texture1D::Loader::raw_data(const string &data)
106 obj.image(0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
109 void Texture1D::Loader::storage(PixelFormat fmt, unsigned w)
112 fmt = get_srgb_pixelformat(fmt);