]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture2darray.cpp
Remove the PixelStore class
[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, PixelComponents comp, DataType type, const void *data)
27 {
28         if(comp!=get_components(format) || type!=get_component_type(format))
29                 throw incompatible_data("Texture2DArray::layer_image");
30         layer_image(level, z, data);
31 }
32
33 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
34 {
35         if(!get_width())
36                 throw invalid_operation("Texture2DArray::layer_image");
37
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");
45
46         layer_image(level, z, img.get_pixels());
47 }
48
49
50 Texture2DArray::Loader::Loader(Texture2DArray &t):
51         DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
52 {
53         init();
54 }
55
56 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
57         DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
58 {
59         init();
60 }
61
62 void Texture2DArray::Loader::init()
63 {
64         add("external_image", &Loader::external_image);
65 }
66
67 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
68 {
69         Graphics::Image img;
70         load_external_image(img, fn);
71         obj.layer_image(0, z, img);
72 }
73
74 } // namespace GL
75 } // namespace Msp