]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor a common part in LocationAllocator into a function
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Nov 2021 22:59:22 +0000 (00:59 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Nov 2021 23:39:41 +0000 (01:39 +0200)
source/glsl/finalize.cpp
source/glsl/finalize.h

index e89aa4942ad768bb32318dad10cde682de7c78f8..864a128b9230543913a629ff25e4b031af4981aa 100644 (file)
@@ -169,6 +169,17 @@ void LocationAllocator::add_layout_value(RefPtr<Layout> &layout, const string &n
        layout->qualifiers.push_back(Layout::Qualifier(name, value));
 }
 
+bool LocationAllocator::visit_uniform(const string &name, RefPtr<Layout> &layout)
+{
+       int bind_point = (layout ? get_layout_value(*layout, "binding") : -1);
+       if(bind_point>=0)
+       {
+               used_bindings[0].insert(bind_point);
+               uniforms[name].bind_point = bind_point;
+       }
+       return bind_point>=0;
+}
+
 void LocationAllocator::visit(VariableDeclaration &var)
 {
        if(!var.name.compare(0, 3, "gl_"))
@@ -202,17 +213,8 @@ void LocationAllocator::visit(VariableDeclaration &var)
                const TypeDeclaration *type = var.type_declaration;
                while(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
                        type = basic->base_type;
-               if(dynamic_cast<const ImageTypeDeclaration *>(type))
-               {
-                       int bind_point = (var.layout ? get_layout_value(*var.layout, "binding") : -1);
-                       if(bind_point>=0)
-                       {
-                               used_bindings[0].insert(bind_point);
-                               uniforms[var.name].bind_point = bind_point;
-                       }
-                       else
-                               unbound_textures.push_back(&var);
-               }
+               if(dynamic_cast<const ImageTypeDeclaration *>(type) && !visit_uniform(var.name, var.layout))
+                       unbound_textures.push_back(&var);
        }
 }
 
@@ -230,18 +232,8 @@ void LocationAllocator::visit(InterfaceBlock &iface)
                        push_constant = (i!=iface.layout->qualifiers.end());
                }
 
-               if(!push_constant)
-               {
-                       int bind_point = (iface.layout ? get_layout_value(*iface.layout, "binding") : -1);
-
-                       if(bind_point>=0)
-                       {
-                               used_bindings[0].insert(bind_point);
-                               uniforms[iface.block_name].bind_point = bind_point;
-                       }
-                       else
-                               unbound_blocks.push_back(&iface);
-               }
+               if(!push_constant && !visit_uniform(iface.block_name, iface.layout))
+                       unbound_blocks.push_back(&iface);
        }
 }
 
index 263be454f252038cbee069abedcf854c9729ec97..1743074849831066a4ff038b093c67b75496395a 100644 (file)
@@ -52,6 +52,7 @@ private:
        void bind_uniform(RefPtr<Layout> &, const std::string &, unsigned);
        void add_layout_value(RefPtr<Layout> &, const std::string &, unsigned);
 
+       bool visit_uniform(const std::string &, RefPtr<Layout> &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(InterfaceBlock &);
        virtual void visit(FunctionDeclaration &) { }