- if(setjmp(png_jmpbuf(pngs)))
- {
- png_destroy_read_struct(&pngs, &pngi, 0);
- fclose(file);
- throw Exception("PNG error");
- }
- png_init_io(pngs, file);
- png_set_sig_bytes(pngs, 8);
+void Texture2D::image(const Graphics::Image &img)
+{
+ unsigned w = img.get_width();
+ unsigned h = img.get_height();
+ PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+ if(width==0)
+ storage(fmt, w, h);
+ else if(w!=width || h!=height)
+ throw IncompatibleData("Image does not match texture storage");
+
+ image(0, fmt, UNSIGNED_BYTE, img.get_data());
+}