1 #include <msp/datafile/collection.h>
2 #include <msp/gl/extensions/ext_texture_array.h>
4 #include "pixelstore.h"
5 #include "texture2darray.h"
12 Texture2DArray::Texture2DArray():
13 Texture3D(GL_TEXTURE_2D_ARRAY)
15 static Require _req(EXT_texture_array);
18 void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
20 if(level>=levels || z>=depth)
21 throw out_of_range("Texture2DArray::layer_image");
23 LinAl::Vector<unsigned, 3> size = get_level_size(level);
24 sub_image(level, 0, 0, z, size.x, size.y, 1, data);
27 void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
29 if(comp!=get_components(format) || type!=get_component_type(format))
30 throw incompatible_data("Texture2DArray::layer_image");
31 layer_image(level, z, data);
34 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
37 throw invalid_operation("Texture2DArray::layer_image");
39 unsigned w = img.get_width();
40 unsigned h = img.get_height();
41 if(w!=get_width() || h!=get_height())
42 throw incompatible_data("Texture2DArray::layer_image");
43 PixelFormat fmt = pixelformat_from_image(img);
44 if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
45 throw incompatible_data("Texture2DArray::layer_image");
47 PixelStore pstore = PixelStore::from_image(img);
48 BindRestore _bind_ps(pstore);
50 layer_image(level, z, img.get_pixels());
54 Texture2DArray::Loader::Loader(Texture2DArray &t):
55 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
60 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
61 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
66 void Texture2DArray::Loader::init()
68 add("external_image", &Loader::external_image);
71 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
74 load_external_image(img, fn);
75 obj.layer_image(0, z, img);