]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compatibility.cpp
Remove the using declarations from visitors
[libs/gl.git] / source / glsl / compatibility.cpp
index 2e13a5f678eaa7592809fa292071b89cecf28beb..128902f3b9f473bb9df87559d40a231c139ac55e 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/core/raii.h>
 #include <msp/strings/lexicalcast.h>
 #include "compatibility.h"
+#include "glsl_error.h"
 
 using namespace std;
 
@@ -16,7 +17,7 @@ DefaultPrecisionGenerator::DefaultPrecisionGenerator():
 void DefaultPrecisionGenerator::apply(Stage &s)
 {
        stage = &s;
-       visit(s.content);
+       s.content.visit(*this);
 }
 
 void DefaultPrecisionGenerator::visit(Block &block)
@@ -64,7 +65,7 @@ void DefaultPrecisionGenerator::visit(VariableDeclaration &var)
 
 void PrecisionRemover::apply(Stage &stage)
 {
-       visit(stage.content);
+       stage.content.visit(*this);
        NodeRemover().apply(stage, nodes_to_remove);
 }
 
@@ -87,7 +88,9 @@ void LegacyConverter::apply(Stage &s, const Features &feat)
 {
        stage = &s;
        features = feat;
-       visit(s.content);
+       if(!supports_stage(s.type))
+               throw unsupported_shader(format("Stage %s is not supported", Stage::get_stage_name(s.type)));
+       s.content.visit(*this);
 }
 
 void LegacyConverter::visit(Block &block)
@@ -120,6 +123,19 @@ bool LegacyConverter::check_extension(bool Features::*extension) const
        return true;
 }
 
+bool LegacyConverter::supports_stage(Stage::Type st) const
+{
+       if(st==Stage::GEOMETRY)
+       {
+               if(features.gl_api==OPENGL_ES2)
+                       return check_version(Version(3, 20));
+               else
+                       return check_version(Version(1, 50));
+       }
+       else
+               return true;
+}
+
 bool LegacyConverter::supports_unified_interface_syntax() const
 {
        if(features.gl_api==OPENGL_ES2)
@@ -248,20 +264,19 @@ void LegacyConverter::visit(VariableDeclaration &var)
        if(var.layout && !supports_interface_layouts())
        {
                vector<Layout::Qualifier>::iterator i;
-               for(i=var.layout->qualifiers.begin(); (i!=var.layout->qualifiers.end() && i->identifier!="location"); ++i) ;
+               for(i=var.layout->qualifiers.begin(); (i!=var.layout->qualifiers.end() && i->name!="location"); ++i) ;
                if(i!=var.layout->qualifiers.end())
                {
-                       unsigned location = lexical_cast<unsigned>(i->value);
                        if(stage->type==Stage::VERTEX && var.interface=="in")
                        {
-                               stage->locations[var.name] = location;
+                               stage->locations[var.name] = i->value;
                                var.layout->qualifiers.erase(i);
                        }
                        else if(stage->type==Stage::FRAGMENT && var.interface=="out")
                        {
-                               if(location!=0)
-                                       check_extension(&Features::ext_gpu_shader4);
-                               stage->locations[var.name] = location;
+                               if(i->value!=0 && !check_extension(&Features::ext_gpu_shader4))
+                                       throw unsupported_shader("EXT_gpu_shader4 is required");
+                               stage->locations[var.name] = i->value;
                                var.layout->qualifiers.erase(i);
                        }