]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture2darray.cpp
Rearrange soucre files into subdirectories
[libs/gl.git] / source / core / texture2darray.cpp
diff --git a/source/core/texture2darray.cpp b/source/core/texture2darray.cpp
new file mode 100644 (file)
index 0000000..1ecb4cf
--- /dev/null
@@ -0,0 +1,80 @@
+#include <msp/datafile/collection.h>
+#include <msp/gl/extensions/ext_texture_array.h>
+#include "error.h"
+#include "pixelstore.h"
+#include "texture2darray.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+Texture2DArray::Texture2DArray():
+       Texture3D(GL_TEXTURE_2D_ARRAY)
+{
+       static Require _req(EXT_texture_array);
+}
+
+void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
+{
+       unsigned w = get_width();
+       unsigned h = get_height();
+       unsigned d = get_depth();
+       get_level_size(level, w, h, d);
+
+       sub_image(level, 0, 0, z, w, h, 1, data);
+}
+
+void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
+{
+       if(comp!=get_components(format) || type!=get_component_type(format))
+               throw incompatible_data("Texture2DArray::layer_image");
+       layer_image(level, z, data);
+}
+
+void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
+{
+       if(!get_width())
+               throw invalid_operation("Texture2DArray::layer_image");
+
+       unsigned w = img.get_width();
+       unsigned h = img.get_height();
+       if(w!=get_width() || h!=get_height())
+               throw incompatible_data("Texture2DArray::layer_image");
+       PixelFormat fmt = pixelformat_from_image(img);
+       if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
+               throw incompatible_data("Texture2DArray::layer_image");
+
+       PixelStore pstore = PixelStore::from_image(img);
+       BindRestore _bind_ps(pstore);
+
+       layer_image(level, z, img.get_pixels());
+}
+
+
+Texture2DArray::Loader::Loader(Texture2DArray &t):
+       DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t)
+{
+       init();
+}
+
+Texture2DArray::Loader::Loader(Texture2DArray &t, Collection &c):
+       DataFile::DerivedObjectLoader<Texture2DArray, Texture3D::Loader>(t, c)
+{
+       init();
+}
+
+void Texture2DArray::Loader::init()
+{
+       add("external_image", &Loader::external_image);
+}
+
+void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
+{
+       Graphics::Image img;
+       load_external_image(img, fn);
+       obj.layer_image(0, z, img);
+}
+
+} // namespace GL
+} // namespace Msp