]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/validate.cpp
Require initializers on constant variables
[libs/gl.git] / source / glsl / validate.cpp
index 889eee221b265ca98788fcd8dd73a8db22b76f64..d154388f98cd9eed44aa8d16c00e1e70d09f801c 100644 (file)
@@ -70,16 +70,26 @@ void DeclarationValidator::visit(Layout &layout)
                        allowed = (variable && scope==GLOBAL);
                else if(i->name=="binding" || i->name=="set")
                {
+                       if(i->name=="set")
+                       {
+                               error(layout, "Layout qualifier 'set' not allowed when targeting OpenGL");
+                               continue;
+                       }
+
                        if(variable)
                        {
                                TypeDeclaration *type = variable->type_declaration;
                                while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
                                        type = basic->base_type;
-                               allowed = (scope==GLOBAL && dynamic_cast<ImageTypeDeclaration *>(type));
-                               err_descr = "variable of non-opaque type";
+                               bool uniform = (variable->interface=="uniform");
+                               allowed = (scope==GLOBAL && uniform && dynamic_cast<ImageTypeDeclaration *>(type));
+                               err_descr = (uniform ? "variable of non-opaque type" : "non-uniform variable");
                        }
                        else if(iface_block)
-                               allowed = true;
+                       {
+                               allowed = (iface_block->interface=="uniform");
+                               err_descr = "non-uniform interface block";
+                       }
                }
                else if(i->name=="constant_id")
                {
@@ -104,7 +114,9 @@ void DeclarationValidator::visit(Layout &layout)
                        }
                }
                else if(i->name=="offset")
-                       allowed = (variable && scope==INTERFACE_BLOCK);
+                       allowed = (variable && scope==INTERFACE_BLOCK && iface_block->interface=="uniform");
+               else if(i->name=="align")
+                       allowed = (scope==INTERFACE_BLOCK && iface_block->interface=="uniform");
                else if(i->name=="points")
                {
                        allowed = (stage->type==Stage::GEOMETRY && iface_layout && (iface_layout->interface=="in" || iface_layout->interface=="out"));
@@ -204,6 +216,8 @@ void DeclarationValidator::visit(VariableDeclaration &var)
        {
                if(scope==STRUCT || scope==INTERFACE_BLOCK)
                        error(var, format("Constant qualifier not allowed on %s", descr));
+               if(!var.init_expression)
+                       error(var, "Constant variable must have an initializer");
        }
 
        if(!var.interpolation.empty() || !var.sampling.empty())