1 #include <msp/datafile/collection.h>
2 #include <msp/gl/extensions/ext_texture_array.h>
4 #include "texture2darray.h"
11 Texture2DArray::Texture2DArray():
12 Texture3D(GL_TEXTURE_2D_ARRAY)
14 static Require _req(EXT_texture_array);
17 void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
19 if(level>=levels || z>=depth)
20 throw out_of_range("Texture2DArray::layer_image");
22 LinAl::Vector<unsigned, 3> size = get_level_size(level);
23 sub_image(level, 0, 0, z, size.x, size.y, 1, data);
26 void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
28 if(comp!=get_components(format) || type!=get_component_type(format))
29 throw incompatible_data("Texture2DArray::layer_image");
30 layer_image(level, z, data);
33 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
36 throw invalid_operation("Texture2DArray::layer_image");
38 unsigned w = img.get_width();
39 unsigned h = img.get_height();
40 if(w!=get_width() || h!=get_height())
41 throw incompatible_data("Texture2DArray::layer_image");
42 PixelFormat fmt = pixelformat_from_image(img);
43 if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
44 throw incompatible_data("Texture2DArray::layer_image");
46 layer_image(level, z, img.get_pixels());
50 Texture2DArray::Loader::Loader(Texture2DArray &t):
51 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
56 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
57 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
62 void Texture2DArray::Loader::init()
64 add("external_image", &Loader::external_image);
67 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
70 load_external_image(img, fn);
71 obj.layer_image(0, z, img);