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, PixelFormat fmt, DataType type, 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, fmt, type, data);
28 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
31 throw invalid_operation("Texture2DArray::layer_image");
33 unsigned w = img.get_width();
34 unsigned h = img.get_height();
35 PixelFormat fmt = pixelformat_from_graphics(img.get_format());
36 if(w!=get_width() || h!=get_height())
37 throw incompatible_data("Texture2DArray::layer_image");
39 PixelStore pstore = PixelStore::from_image(img);
40 BindRestore _bind_ps(pstore);
42 layer_image(level, z, fmt, UNSIGNED_BYTE, img.get_data());
46 Texture2DArray::Loader::Loader(Texture2DArray &t):
47 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
52 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
53 DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
58 void Texture2DArray::Loader::init()
60 add("external_image", &Loader::external_image);
63 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
66 RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
68 throw IO::file_not_found(fn);
71 obj.layer_image(0, z, img);