#include <msp/graphics/imageloader.h>
#include "buffer.h"
#include "error.h"
-#include "resources.h"
#include "texture2d.h"
using namespace std;
}
}
-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
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();
}