]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texturecube.cpp
Implement loading functionality for texture classes that were missing it
[libs/gl.git] / source / texturecube.cpp
index 576f1c718b3848aa043cb165b04a578f83500a70..743eb986247eb95318c98490179b3fdb95683980 100644 (file)
@@ -97,6 +97,30 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s
        image(face, 0, fmt, UNSIGNED_BYTE, img.get_data());
 }
 
+void TextureCube::image(const Graphics::Image &img, bool srgb)
+{
+       unsigned w = img.get_width();
+       unsigned h = img.get_height();
+
+       if(h!=w*6)
+               throw incompatible_data("TextureCube::image");
+       h /= 6;
+
+       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       if(size==0)
+               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
+       else if(w!=size || h!=size)
+               throw incompatible_data("TextureCube::image");
+
+       PixelStore pstore = PixelStore::from_image(img);
+       BindRestore _bind_ps(pstore);
+
+       const char *cdata = reinterpret_cast<const char *>(img.get_data());
+       unsigned face_size = img.get_stride()*size;
+       for(unsigned i=0; i<6; ++i)
+               image(enumerate_faces(i), 0, fmt, UNSIGNED_BYTE, cdata+i*face_size);
+}
+
 unsigned TextureCube::get_level_size(unsigned level)
 {
        return size>>level;