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 unsigned w = get_width();
21 unsigned h = get_height();
22 unsigned d = get_depth();
23 get_level_size(level, w, h, d);
25 sub_image(level, 0, 0, z, w, h, 1, data);
28 void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
30 if(comp!=get_components(format) || type!=get_component_type(format))
31 throw incompatible_data("Texture2DArray::layer_image");
32 layer_image(level, z, data);
35 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
38 throw invalid_operation("Texture2DArray::layer_image");
40 unsigned w = img.get_width();
41 unsigned h = img.get_height();
42 if(w!=get_width() || h!=get_height())
43 throw incompatible_data("Texture2DArray::layer_image");
44 PixelFormat fmt = pixelformat_from_image(img);
45 if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
46 throw incompatible_data("Texture2DArray::layer_image");
48 PixelStore pstore = PixelStore::from_image(img);
49 BindRestore _bind_ps(pstore);
51 layer_image(level, z, img.get_pixels());
55 Texture2DArray::Loader::Loader(Texture2DArray &t):
56 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
61 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
62 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
67 void Texture2DArray::Loader::init()
69 add("external_image", &Loader::external_image);
72 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
75 load_external_image(img, fn);
76 obj.layer_image(0, z, img);