9 Texture2D::~Texture2D()
14 void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
18 if(fmt!=format || wd!=width || ht!=height || (lv && lv!=n_levels))
19 throw incompatible_data("Texture2D::storage");
23 throw invalid_argument("Texture2D::storage");
28 n_levels = count_levels(max(width, height));
30 n_levels = min(n_levels, lv);
35 void Texture2D::image(unsigned level, const void *data)
37 LinAl::Vector<unsigned, 2> size = get_level_size(level);
38 return sub_image(level, 0, 0, size.x, size.y, data);
41 void Texture2D::sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *data)
43 if(width==0 || height==0)
44 throw invalid_operation("Texture2D::sub_image");
45 if(level>=n_levels || x>width || x+wd>width || y>height || y+ht>height)
46 throw out_of_range("Texture2D::sub_image");
48 Texture2DBackend::sub_image(level, x, y, wd, ht, data);
51 Texture2D::AsyncTransfer Texture2D::sub_image_async(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht)
53 return AsyncTransfer(*this, level, x, y, wd, ht);
56 void Texture2D::image(const Graphics::Image &img, unsigned lv)
58 storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv);
59 image(0, img.get_pixels());
62 LinAl::Vector<unsigned, 2> Texture2D::get_level_size(unsigned level) const
64 unsigned w = width>>level;
65 unsigned h = height>>level;
72 return LinAl::Vector<unsigned, 2>(w, h);
76 Texture2D::Loader::Loader(Texture2D &t):
77 DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>(t)
82 Texture2D::Loader::Loader(Texture2D &t, Collection &c):
83 DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>(t, c)
88 void Texture2D::Loader::init()
90 add("storage", &Loader::storage);
91 add("storage", &Loader::storage_levels);
94 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
96 obj.storage(fmt, w, h);
99 void Texture2D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned l)
101 obj.storage(fmt, w, h, l);
105 Texture2D::AsyncTransfer::AsyncTransfer(Texture2D &t, unsigned l, unsigned x_, unsigned y_, unsigned wd, unsigned ht):
112 data_size(width*height*get_pixel_size(texture->storage_fmt)),
115 dest_addr = allocate();
118 Texture2D::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other):
119 Texture2DBackend::AsyncTransfer(move(other)),
120 texture(other.texture),
125 height(other.height),
126 data_size(other.data_size),
127 dest_addr(other.dest_addr)
132 Texture2D::AsyncTransfer &Texture2D::AsyncTransfer::operator=(AsyncTransfer &&other)
137 Texture2DBackend::AsyncTransfer::operator=(move(other));
139 texture = other.texture;
144 height = other.height;
145 data_size = other.data_size;
146 dest_addr = other.dest_addr;
153 Texture2D::AsyncTransfer::~AsyncTransfer()