]> git.tdb.fi Git - libs/gl.git/commitdiff
Add some checks for invalid arguments
authorMikko Rasa <tdb@tdb.fi>
Sat, 30 Oct 2021 20:32:18 +0000 (23:32 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 30 Oct 2021 22:28:13 +0000 (01:28 +0300)
12 files changed:
source/backends/opengl/deviceinfo_backend.cpp
source/core/buffer.cpp
source/core/deviceinfo.h
source/core/sampler.cpp
source/core/texture1d.cpp
source/core/texture1d.h
source/core/texture2d.cpp
source/core/texture2d.h
source/core/texture3d.cpp
source/core/texture3d.h
source/core/texturecube.cpp
source/core/texturecube.h

index 30eeb0327e9cb1c8b61f210a742f9ac376886d42..df085dc76e91a00e62c3111c24fc2e4f2c9cc162 100644 (file)
@@ -9,6 +9,7 @@
 #include <msp/gl/extensions/ext_framebuffer_object.h>
 #include <msp/gl/extensions/ext_gpu_shader4.h>
 #include <msp/gl/extensions/ext_texture_array.h>
+#include <msp/gl/extensions/ext_texture_filter_anisotropic.h>
 #include <msp/gl/extensions/msp_clipping.h>
 #include <msp/gl/extensions/nv_fbo_color_attachments.h>
 #include "deviceinfo.h"
@@ -34,6 +35,8 @@ Limits::Limits()
                glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<int *>(&max_uniform_bindings));
                glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<int *>(&uniform_buffer_alignment));
        }
+       if(EXT_texture_filter_anisotropic)
+               glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &max_anisotropy);
 }
 
 
index 557e576d2ac929e256646c0a3cdc59bd3887a962..240fcd72754b67babe7a28b9ee2fe42a80f1fe4b 100644 (file)
@@ -33,6 +33,8 @@ void Buffer::sub_data(size_t off, size_t sz, const void *d)
 {
        if(size==0)
                throw invalid_operation("Buffer::sub_data");
+       if(off>size || off+sz>size)
+               throw out_of_range("Buffer::sub_data");
 
        BufferBackend::sub_data(off, sz, d);
 }
index 6ac75ca18c758caaa3b2038a8348f7ded74993e4..a95841197a9c604585ec82aed8b039cbff25438e 100644 (file)
@@ -18,6 +18,7 @@ struct Limits
        unsigned max_samples = 4;
        unsigned max_uniform_bindings = 24;
        unsigned uniform_buffer_alignment = 256;
+       float max_anisotropy = 1.0f;
 
        Limits();
 };
index 6658ef9ac75d05a8b1016a84afb6847404b196d7..7560029c64642cdef978b147c9d2be5e4263bafe 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/strings/format.h>
+#include "deviceinfo.h"
 #include "error.h"
 #include "sampler.h"
 
@@ -21,6 +22,8 @@ void Sampler::set_min_filter(TextureFilter f)
 
 void Sampler::set_mag_filter(TextureFilter f)
 {
+       if(is_mipmapped(f))
+               throw invalid_argument("Sampler::set_mag_filter");
        mag_filter = f;
        dirty_params |= MAG_FILTER;
 }
@@ -35,6 +38,8 @@ void Sampler::set_max_anisotropy(float a)
 {
        if(a<1.0f)
                throw invalid_argument("Sampler::set_max_anisotropy");
+       if(a>DeviceInfo::get_global().limits.max_anisotropy)
+               throw out_of_range("Sampler::set_max_anisotropy");
        bool supported = check_anisotropic(a>1.0f);
        max_anisotropy = a;
        if(supported)
index 1015a0af9c4aae7c2906c8363eca1100e1d267cb..ae4347e334d8d99ee2c07d503a264528c4eb463b 100644 (file)
@@ -31,11 +31,11 @@ void Texture1D::image(unsigned level, const void *data)
        return sub_image(level, 0, get_level_size(level), data);
 }
 
-void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
+void Texture1D::sub_image(unsigned level, unsigned x, unsigned wd, const void *data)
 {
        if(width==0)
                throw invalid_operation("Texture1D::sub_image");
-       if(level>=levels)
+       if(level>=levels || x>width || x+wd>width)
                throw out_of_range("Texture1D::sub_image");
 
        Texture1DBackend::sub_image(level, x, wd, data);
index 7ef55f80fdf17ec9c295efff74f2e914dd91e975..f99d3ef0713daa64be029a59b9d2d2a0a30a87e9 100644 (file)
@@ -46,7 +46,7 @@ public:
        /** Replaces a range of texels in the texture.  Allocated storage must
        exist.  The image data is interpreted according to the storage format and
        the range must be fully inside the selected mipmap level. */
-       void sub_image(unsigned level, int x, unsigned wd, const void *);
+       void sub_image(unsigned level, unsigned x, unsigned wd, const void *);
 
        virtual void image(const Graphics::Image &, unsigned = 0);
 
index 3c3579c1d131137f89ab49b57dd565f15a3ed544..41f4ab11280259f1fd68f621c8f82ee289f9dbed 100644 (file)
@@ -38,11 +38,11 @@ void Texture2D::image(unsigned level, const void *data)
        return sub_image(level, 0, 0, size.x, size.y, data);
 }
 
-void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
+void Texture2D::sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *data)
 {
        if(width==0 || height==0)
                throw invalid_operation("Texture2D::sub_image");
-       if(level>=levels)
+       if(level>=levels || x>width || x+wd>width || y>height || y+ht>height)
                throw out_of_range("Texture2D::sub_image");
 
        Texture2DBackend::sub_image(level, x, y, wd, ht, data);
index 427e179563943b312c7ea4f87b7ae3a5595e09db..1c750bd1e87d301aed2f79799688e410ef1793bd 100644 (file)
@@ -50,7 +50,7 @@ public:
        /** Replaces a rectangular region of the texture.  Allocated storage must
        exist.  The image data is interpreted according to the storage format and
        the region must be fully inside the selected mipmap level. */
-       void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *);
+       void sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *);
 
        virtual void image(const Graphics::Image &, unsigned = 0);
 
index e48b7662011deb9b1c81ce5c73014c939ace2c52..0125dd0930a16a8a5dbc6cb5fe3c025cfdaddab9 100644 (file)
@@ -39,11 +39,11 @@ void Texture3D::image(unsigned level, const void *data)
        return sub_image(level, 0, 0, 0, size.x, size.y, size.z, data);
 }
 
-void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
+void Texture3D::sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *data)
 {
        if(width==0 || height==0 || depth==0)
                throw invalid_operation("Texture3D::sub_image");
-       if(level>=levels)
+       if(level>=levels || x>width || x+wd>width || y>height || y+ht>height || z>depth || z+dp>depth)
                throw out_of_range("Texture3D::sub_image");
 
        Texture3DBackend::sub_image(level, x, y, z, wd, ht, dp, data);
index 9d5104c91e42892de2d9189b31291f4352c98e2f..1fbcf4ee43044436a38cfdef6a2786762edd1ed6 100644 (file)
@@ -52,7 +52,7 @@ public:
        /** Replaces a cuboid-shaped region of the texture.  Allocated storage must
        exist.  The image data is interpreted according to the storage format and
        the region must be fully inside the texture. */
-       void sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *);
+       void sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *);
 
        /** Sets the texture's contents from an image.  The image is treated as a
        stack of square layers and its height must be divisible by its width.  If
index 9aec4b1d19640f699adbf8c2596a7e14555b6200..ff2b28755bb3e8e37c3dbadf57f6695b24e13d83 100644 (file)
@@ -55,11 +55,11 @@ void TextureCube::image(TextureCubeFace face, unsigned level, const void *data)
        return sub_image(face, level, 0, 0, lsz, lsz, data);
 }
 
-void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
+void TextureCube::sub_image(TextureCubeFace face, unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *data)
 {
        if(size==0)
                throw invalid_operation("TextureCube::sub_image");
-       if(level>=levels)
+       if(level>=levels || x>size || x+wd>size || y>size || y+ht>size)
                throw out_of_range("TextureCube::sub_image");
 
        TextureCubeBackend::sub_image(face, level, x, y, wd, ht, data);
index aa43c9da0a97ca084bd2690fd1f1e7b2dae35b13..0f753c757c54b85c421aade5d6b199137bae9141 100644 (file)
@@ -68,7 +68,7 @@ public:
        /** Replaces a rectangular region of a face.  Allocated storage must exist.
        The image data is interpreted according to the storage format and the region
        must be fully inside the face. */
-       void sub_image(TextureCubeFace, unsigned level, int x, int y, unsigned w, unsigned h, const void *);
+       void sub_image(TextureCubeFace, unsigned level, unsigned x, unsigned y, unsigned w, unsigned h, const void *);
 
        void image(TextureCubeFace, const Graphics::Image &);