]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor VertexSetup format checking
authorMikko Rasa <tdb@tdb.fi>
Fri, 1 Oct 2021 16:35:32 +0000 (19:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 1 Oct 2021 16:38:36 +0000 (19:38 +0300)
source/core/vertexsetup.cpp
source/core/vertexsetup.h

index 55424d6caf41eb9979f2de294547cf7f13fd210a..892cec86f2d8df5c6825b4ca07f9a6266b8e5e5c 100644 (file)
@@ -43,7 +43,7 @@ void VertexSetup::set_format(const VertexFormat &vfmt)
        if(!vertex_format.empty())
                throw invalid_operation("VertexSetup::set_format");
 
-       require_format(vfmt);
+       require_format(vfmt, false);
 
        vertex_format = vfmt;
 }
@@ -55,8 +55,8 @@ void VertexSetup::set_format_instanced(const VertexFormat &vfmt, const VertexFor
        if(!vertex_format.empty())
                throw invalid_operation("VertexSetup::set_format");
 
-       require_format(vfmt);
-       require_format(ifmt);
+       require_format(vfmt, false);
+       require_format(ifmt, true);
 
        vertex_format = vfmt;
        inst_format = ifmt;
@@ -84,8 +84,6 @@ void VertexSetup::set_instance_array(const VertexArray &a)
        if(!a.get_buffer())
                throw invalid_argument("VertexSetup::set_instance_array");
 
-       static Require req(ARB_instanced_arrays);
-
        inst_array = &a;
        dirty |= INSTANCE_ARRAY;
 }
@@ -102,23 +100,16 @@ bool VertexSetup::verify_format(const VertexFormat &fmt)
        if(fmt.empty())
                return false;
 
-       unsigned max_attribs = DeviceInfo::get_global().limits.max_vertex_attributes;
-
-       for(VertexAttribute a: fmt)
-               if(get_attribute_semantic(a)>=max_attribs)
-                       return false;
-
-       return true;
+       static unsigned max_attribs = DeviceInfo::get_global().limits.max_vertex_attributes;
+       return all_of(fmt.begin(), fmt.end(), [](VertexAttribute a){ return get_attribute_semantic(a)<max_attribs; });
 }
 
-void VertexSetup::require_format(const VertexFormat &fmt)
+void VertexSetup::require_format(const VertexFormat &fmt, bool instanced)
 {
-       bool has_int = false;
-       for(VertexAttribute a: fmt)
-               has_int = has_int | is_integer_attribute(a);
-
-       if(has_int)
+       if(any_of(fmt.begin(), fmt.end(), is_integer_attribute))
                static Require _req(EXT_gpu_shader4);
+       if(instanced)
+               static Require req(ARB_instanced_arrays);
 }
 
 void VertexSetup::update() const
index 2e483fc81768e1fcb3b4c0b15a5c91b53fd346cb..beade58ed3daeb9b4421193a3b5d97524c8265c1 100644 (file)
@@ -52,7 +52,7 @@ public:
 
 private:
        static bool verify_format(const VertexFormat &);
-       static void require_format(const VertexFormat &);
+       static void require_format(const VertexFormat &, bool);
        void update() const;
        void update_vertex_array(const VertexArray &, unsigned, unsigned, bool) const;