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