]> git.tdb.fi Git - libs/gl.git/blob - source/texture2darray.cpp
Appease the compiler with some extra copy-ctor's and operator='s
[libs/gl.git] / source / texture2darray.cpp
1 #include <msp/datafile/collection.h>
2 #include <msp/gl/extensions/ext_texture_array.h>
3 #include "error.h"
4 #include "pixelstore.h"
5 #include "texture2darray.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11
12 Texture2DArray::Texture2DArray():
13         Texture3D(GL_TEXTURE_2D_ARRAY)
14 {
15         static Require _req(EXT_texture_array);
16 }
17
18 void Texture2DArray::layer_image(unsigned level, unsigned z, PixelFormat fmt, DataType type, const void *data)
19 {
20         unsigned w = get_width();
21         unsigned h = get_height();
22         unsigned d = get_depth();
23         get_level_size(level, w, h, d);
24
25         sub_image(level, 0, 0, z, w, h, 1, fmt, type, data);
26 }
27
28 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
29 {
30         if(!get_width())
31                 throw invalid_operation("Texture2DArray::layer_image");
32
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");
38
39         PixelStore pstore = PixelStore::from_image(img);
40         BindRestore _bind_ps(pstore);
41
42         layer_image(level, z, fmt, UNSIGNED_BYTE, img.get_data());
43 }
44
45
46 Texture2DArray::Loader::Loader(Texture2DArray &t):
47         DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
48 {
49         init();
50 }
51
52 Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
53         DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
54 {
55         init();
56 }
57
58 void Texture2DArray::Loader::init()
59 {
60         add("external_image", &Loader::external_image);
61 }
62
63 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
64 {
65         Graphics::Image img;
66         RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
67         if(!io)
68                 throw IO::file_not_found(fn);
69         img.load_io(*io);
70
71         obj.layer_image(0, z, img);
72 }
73
74 } // namespace GL
75 } // namespace Msp