]> git.tdb.fi Git - libs/gl.git/commitdiff
Remove the PixelStore class
authorMikko Rasa <tdb@tdb.fi>
Sat, 28 Aug 2021 08:26:02 +0000 (11:26 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 28 Aug 2021 08:26:02 +0000 (11:26 +0300)
Instead just permanently set unpack alignment to 1.  This seems to
match Vulkan.

source/core/pixelstore.cpp [deleted file]
source/core/pixelstore.h [deleted file]
source/core/texture.cpp
source/core/texture2d.cpp
source/core/texture2darray.cpp
source/core/texture3d.cpp
source/core/texturecube.cpp

diff --git a/source/core/pixelstore.cpp b/source/core/pixelstore.cpp
deleted file mode 100644 (file)
index 409f0f9..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#include <algorithm>
-#include <msp/gl/extensions/ext_texture3d.h>
-#include <msp/gl/extensions/ext_unpack_subimage.h>
-#include "gl.h"
-#include "pixelformat.h"
-#include "pixelstore.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-PixelStore::PixelStore():
-       row_length(0),
-       image_height(0),
-       skip_pixels(0),
-       skip_rows(0),
-       skip_images(0),
-       alignment(4)
-{ }
-
-PixelStore PixelStore::from_image(const Graphics::Image &img)
-{
-       PixelStore pstore;
-       unsigned stride = img.get_stride();
-       unsigned ncomp = get_component_count(pixelformat_from_image(img));
-       pstore.set_canvas_size(img.get_stride()/ncomp, 0);
-       pstore.set_alignment(min(stride&~(stride-1), 8U));
-       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))
-               update_parameter(-1);
-}
-
-} // namespace GL
-} // namespace Msp
diff --git a/source/core/pixelstore.h b/source/core/pixelstore.h
deleted file mode 100644 (file)
index 80032c3..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef MSP_GL_PIXELSTORE_H_
-#define MSP_GL_PIXELSTORE_H_
-
-#include <msp/graphics/image.h>
-#include "bindable.h"
-
-namespace Msp {
-namespace GL {
-
-class PixelStore: public BindableWithDefault<PixelStore>
-{
-private:
-       enum ParameterMask
-       {
-               SIZE = 1,
-               ORIGIN = 2,
-               ALIGNMENT = 4
-       };
-
-       unsigned row_length;
-       unsigned image_height;
-       unsigned skip_pixels;
-       unsigned skip_rows;
-       unsigned skip_images;
-       unsigned alignment;
-
-public:
-       PixelStore();
-
-       static PixelStore from_image(const Graphics::Image &);
-
-private:
-       void update_parameter(int) const;
-
-public:
-       void set_canvas_size(unsigned, unsigned);
-       void set_origin(unsigned, unsigned, unsigned);
-       void set_alignment(unsigned);
-
-       void bind() const;
-};
-
-} // namespace GL
-} // namespace Msp
-
-#endif
index 5197b3da4bd7461564305e8d9f7ffa7e8312a794..3adc511e23ca2640d0ed7e5a4fc6644b50a65c40 100644 (file)
@@ -35,6 +35,13 @@ Texture::Texture(GLenum t, ResourceManager *m):
                set_manager(m);
        else
                generate_id();
+
+       static bool alignment_init = false;
+       if(!alignment_init)
+       {
+               glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+               alignment_init = true;
+       }
 }
 
 Texture::~Texture()
index 09831cb3385abcc5eeaf5f9e5404e33a6a427f3f..528c4a58d216416ad2ca9816852bd0a7001d2a9e 100644 (file)
@@ -5,7 +5,6 @@
 #include "bindable.h"
 #include "buffer.h"
 #include "error.h"
-#include "pixelstore.h"
 #include "resources.h"
 #include "texture2d.h"
 
@@ -203,9 +202,6 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
        PixelFormat fmt = pixelformat_from_image(img);
        storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv);
 
-       PixelStore pstore = PixelStore::from_image(img);
-       BindRestore _bind_ps(pstore);
-
        image(0, from_buffer ? 0 : img.get_pixels());
 }
 
index 1928d4e3503c6f68f2446125ffe4b423c96ac5fc..19066c726bdb16fda9bb6af27cd0904324901199 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/datafile/collection.h>
 #include <msp/gl/extensions/ext_texture_array.h>
 #include "error.h"
-#include "pixelstore.h"
 #include "texture2darray.h"
 
 using namespace std;
@@ -44,9 +43,6 @@ void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Ima
        if(get_components(fmt)!=get_components(format) || get_component_type(fmt)!=get_component_type(format))
                throw incompatible_data("Texture2DArray::layer_image");
 
-       PixelStore pstore = PixelStore::from_image(img);
-       BindRestore _bind_ps(pstore);
-
        layer_image(level, z, img.get_pixels());
 }
 
index 3c675dbb705847527586b452f414bdc4b49c1fb1..ab8bca7cba1c8cfd4f5598b73c8dfa759d96488c 100644 (file)
@@ -7,7 +7,6 @@
 #include <msp/graphics/image.h>
 #include "bindable.h"
 #include "error.h"
-#include "pixelstore.h"
 #include "texture3d.h"
 
 using namespace std;
@@ -190,9 +189,6 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv)
        PixelFormat fmt = pixelformat_from_image(img);
        storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, d, lv);
 
-       PixelStore pstore = PixelStore::from_image(img);
-       BindRestore _bind_ps(pstore);
-
        image(0, img.get_pixels());
 }
 
index 4984985c807489b28d6f5737c2f2ba03286488d3..5c7f61029c3c736eb3245e99b559b29c7e79f2aa 100644 (file)
@@ -7,7 +7,6 @@
 #include <msp/strings/format.h>
 #include "bindable.h"
 #include "error.h"
-#include "pixelstore.h"
 #include "texturecube.h"
 
 using namespace std;
@@ -223,9 +222,6 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img)
        PixelFormat fmt = pixelformat_from_image(img);
        storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w);
 
-       PixelStore pstore = PixelStore::from_image(img);
-       BindRestore _bind_ps(pstore);
-
        image(face, 0, img.get_pixels());
 }
 
@@ -249,9 +245,6 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv)
        else if(w!=size || h!=size)
                throw incompatible_data("TextureCube::image");
 
-       PixelStore pstore = PixelStore::from_image(img);
-       BindRestore _bind_ps(pstore);
-
        const char *pixels = reinterpret_cast<const char *>(img.get_pixels());
        unsigned face_size = img.get_stride()*size;
        for(unsigned i=0; i<6; ++i)