]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture2d.cpp
Add an abstraction for queries
[libs/gl.git] / source / core / texture2d.cpp
index 31d7016574b17ecdf3200d587f781d940914d21e..70a9528d9af9b030dec83c6c88f18dfedce47bd4 100644 (file)
@@ -4,7 +4,6 @@
 #include <msp/graphics/imageloader.h>
 #include "buffer.h"
 #include "error.h"
-#include "resources.h"
 #include "texture2d.h"
 
 using namespace std;
@@ -113,19 +112,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)
 {
-       unsigned w = img.get_width();
-       unsigned h = img.get_height();
-       PixelFormat fmt = pixelformat_from_image(img);
-       storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv);
-
-       image(0, from_buffer ? 0 : img.get_pixels());
+       storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv);
+       image(0, img.get_pixels());
 }
 
 unsigned Texture2D::get_n_levels() const
@@ -252,9 +249,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();
        }