]> git.tdb.fi Git - libs/gl.git/commitdiff
Throw an exception if there's too many uniforms in a ProgramData
authorMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 02:04:11 +0000 (04:04 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 02:04:11 +0000 (04:04 +0200)
I'd rather find out I need to make the mask wider than have a program
unexplainably slow down.

source/programdata.cpp
source/programdata.h

index 4a6c262a37a646bfd128f3cda4143ae5007e2a70..4d8ca4dd1adabc338967ab91bc2e817091d18a49 100644 (file)
@@ -109,15 +109,16 @@ void ProgramData::uniform(const string &name, Uniform *uni)
        if(i>=0)
        {
                uniforms[i].replace_value(uni);
-
-               if(static_cast<unsigned>(i)<MASK_BITS)
-                       dirty |= 1<<i;
-               else  // Force a full update if the mask isn't wide enough
-                       dirty = ALL_ONES;
-
+               dirty |= 1<<i;
                return;
        }
 
+       if(uniforms.size()>=MASK_BITS)
+       {
+               delete uni;
+               throw too_many_uniforms(name);
+       }
+
        vector<NamedUniform>::iterator j = lower_bound(uniforms.begin(), uniforms.end(), name, uniform_name_compare);
 
        NamedUniform nu;
index c367097bd886752fc94697ebfeb5c013acdffb64..d9eaf7469e337bf93f5ea64612b57e8f34d7fe54 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_GL_PROGRAMDATA_H_
 
 #include <map>
+#include <stdexcept>
 #include <msp/datafile/objectloader.h>
 #include "datatype.h"
 #include "matrix.h"
 namespace Msp {
 namespace GL {
 
+class too_many_uniforms: public std::runtime_error
+{
+public:
+       too_many_uniforms(const std::string &w): std::runtime_error(w) { }
+       virtual ~too_many_uniforms() throw() { }
+};
+
 class Buffer;
 class Uniform;
 class UniformBlock;