class Buffer
{
friend class PipelineState;
+ friend class Texture2D;
friend class VertexSetup;
private:
Buffer();
~Buffer();
- /** Returns the OpenGL ID of the buffer. For internal use only. */
- unsigned get_id() const { return id; }
-
/** Defines the storage size of the buffer. Must be called before data can
be uploaded. Storage cannot be changed once set. */
void storage(unsigned);
}
}
-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();
}
namespace Msp {
namespace GL {
+class Buffer;
+
/**
Two-dimensional texture. Consists of an array of texels in the shape of a
rectangle. Texture coordinate have a range of [0, 1]. Coordinates outside of
and the update region must be fully inside the texture. */
void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data);
+private:
+ void sub_image(unsigned, int, int, unsigned, unsigned, const Buffer &, unsigned);
+
+public:
/** Updates the contents of the entire texture from an image. If storage
has not been defined, it will be set to match the image. Otherwise the
image must match the defined storage. */
using Texture::image;
-private:
- void image(const Graphics::Image &, unsigned, bool);
-
-public:
unsigned get_width() const { return width; }
unsigned get_height() const { return height; }