]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture2d.cpp
Refactor uploading texture data from a buffer
[libs/gl.git] / source / core / texture2d.cpp
index 703b719a211f6390c78f35aacfe9f12a9c07701b..6edbba0d993a0f3795d264834c43054d5acd23b2 100644 (file)
@@ -113,15 +113,17 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
        }
 }
 
-void Texture2D::image(const Graphics::Image &img, unsigned lv)
+void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const Buffer &buffer, unsigned offset)
 {
-       image(img, lv, false);
+       glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer.id);
+       sub_image(level, x, y, wd, ht, reinterpret_cast<void *>(offset));
+       glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
 }
 
-void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
+void Texture2D::image(const Graphics::Image &img, unsigned lv)
 {
        storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv);
-       image(0, from_buffer ? 0 : img.get_pixels());
+       image(0, img.get_pixels());
 }
 
 unsigned Texture2D::get_n_levels() const
@@ -248,9 +250,12 @@ bool Texture2D::AsyncLoader::process()
 
                if(!texture.id)
                        texture.generate_id();
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixel_buffer.get_id());
-               texture.image(image, 0, true);
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+
+               unsigned w = image.get_width();
+               unsigned h = image.get_height();
+               texture.storage(pixelformat_from_image(image, texture.use_srgb_format), w, h);
+               texture.sub_image(0, 0, 0, w, h, pixel_buffer, 0);
+
                if(texture.auto_gen_mipmap)
                        texture.generate_mipmap();
        }