X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fpixelstore.cpp;h=e1a7cc0ef9ea378bce5db24f7035500b00829a36;hp=c32cf60964a30b43cf7946782fa2c5943231e710;hb=4598d28936d3a4772927d1e3a1534f872731b358;hpb=055f553b1a75f44e72f3c2b5a1c98c1e1e8f3f30 diff --git a/source/pixelstore.cpp b/source/pixelstore.cpp index c32cf609..e1a7cc0e 100644 --- a/source/pixelstore.cpp +++ b/source/pixelstore.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "gl.h" #include "pixelformat.h" #include "pixelstore.h" @@ -27,35 +29,57 @@ PixelStore PixelStore::from_image(const Graphics::Image &img) return pstore; } +void PixelStore::update_parameter(int mask) const +{ + if(cur_obj!=this) + return; + + if(mask&SIZE) + { + glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); + if(EXT_texture3D) + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image_height); + } + if(mask&ORIGIN) + { + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels); + glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows); + if(EXT_texture3D) + glPixelStorei(GL_UNPACK_SKIP_IMAGES, skip_images); + } + if(mask&ALIGNMENT) + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); +} + void PixelStore::set_canvas_size(unsigned w, unsigned h) { + static Require _req(EXT_unpack_subimage); row_length = w; image_height = h; + update_parameter(SIZE); } void PixelStore::set_origin(unsigned x, unsigned y, unsigned z) { + static Require _req(EXT_unpack_subimage); + if(z>0) + static Require _req3d(EXT_texture3D); skip_pixels = x; skip_rows = y; skip_images = z; + update_parameter(ORIGIN); } void PixelStore::set_alignment(unsigned a) { alignment = a; + update_parameter(ALIGNMENT); } void PixelStore::bind() const { if(set_current(this)) - { - glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image_height); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels); - glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows); - glPixelStorei(GL_UNPACK_SKIP_IMAGES, skip_images); - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); - } + update_parameter(-1); } } // namespace GL