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, const Graphics::Image &img)
29 throw invalid_operation("Texture2DArray::layer_image");
31 unsigned w = img.get_width();
32 unsigned h = img.get_height();
33 if(w!=get_width() || h!=get_height())
34 throw incompatible_data("Texture2DArray::layer_image");
35 PixelFormat fmt = pixelformat_from_image(img);
36 if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
37 throw incompatible_data("Texture2DArray::layer_image");
39 layer_image(level, z, img.get_pixels());
43 Texture2DArray::Loader::Loader(Texture2DArray &t):
44 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
49 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
50 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
55 void Texture2DArray::Loader::init()
57 add("external_image", &Loader::external_image);
60 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
63 load_external_image(img, fn);
64 obj.layer_image(0, z, img);