]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture2darray.cpp
Remove remaining deprecated things from the core classes
[libs/gl.git] / source / core / texture2darray.cpp
1 #include <msp/datafile/collection.h>
2 #include <msp/gl/extensions/ext_texture_array.h>
3 #include "error.h"
4 #include "texture2darray.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 Texture2DArray::Texture2DArray():
12         Texture3D(GL_TEXTURE_2D_ARRAY)
13 {
14         static Require _req(EXT_texture_array);
15 }
16
17 void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
18 {
19         if(level>=levels || z>=depth)
20                 throw out_of_range("Texture2DArray::layer_image");
21
22         LinAl::Vector<unsigned, 3> size = get_level_size(level);
23         sub_image(level, 0, 0, z, size.x, size.y, 1, data);
24 }
25
26 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
27 {
28         if(!get_width())
29                 throw invalid_operation("Texture2DArray::layer_image");
30
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");
38
39         layer_image(level, z, img.get_pixels());
40 }
41
42
43 Texture2DArray::Loader::Loader(Texture2DArray &t):
44         DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
45 {
46         init();
47 }
48
49 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
50         DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
51 {
52         init();
53 }
54
55 void Texture2DArray::Loader::init()
56 {
57         add("external_image", &Loader::external_image);
58 }
59
60 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
61 {
62         Graphics::Image img;
63         load_external_image(img, fn);
64         obj.layer_image(0, z, img);
65 }
66
67 } // namespace GL
68 } // namespace Msp