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