]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programcompiler.cpp
Consider extensions when checking GLSL features
[libs/gl.git] / source / programcompiler.cpp
index 3dc07d80fa4dd2566c069d0cae5bdb4451f7ac5d..6b8d2eb8a6ae75bbd7d5ea74c7fe7bde4e4b39b6 100644 (file)
@@ -1,4 +1,8 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/raii.h>
+#include <msp/gl/extensions/arb_explicit_attrib_location.h>
+#include <msp/gl/extensions/arb_gpu_shader5.h>
+#include <msp/gl/extensions/arb_uniform_buffer_object.h>
 #include <msp/gl/extensions/ext_gpu_shader4.h>
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
@@ -321,6 +325,11 @@ void ProgramCompiler::Formatter::apply(ProgramSyntax::Stage &s)
                formatted += '\n';
        }
 
+       for(vector<const Extension *>::const_iterator i=s.required_extensions.begin(); i!=s.required_extensions.end(); ++i)
+               formatted += format("#extension %s: require\n", (*i)->get_name());
+       if(!s.required_extensions.empty())
+               formatted += '\n';
+
        Visitor::apply(s);
 }
 
@@ -1776,6 +1785,18 @@ bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_vers
        return true;
 }
 
+bool ProgramCompiler::LegacyConverter::check_extension(const Extension &extension) const
+{
+       if(!extension)
+               return false;
+
+       vector<const Extension *>::iterator i = find(stage->required_extensions, &extension);
+       if(i==stage->required_extensions.end())
+               stage->required_extensions.push_back(&extension);
+
+       return true;
+}
+
 bool ProgramCompiler::LegacyConverter::supports_unified_interface_syntax() const
 {
        if(target_api==OPENGL_ES2)
@@ -1844,24 +1865,30 @@ bool ProgramCompiler::LegacyConverter::supports_interface_layouts() const
 {
        if(target_api==OPENGL_ES2)
                return check_version(Version(3, 0));
+       else if(check_version(Version(3, 30)))
+               return true;
        else
-               return check_version(Version(3, 30));
+               return check_extension(ARB_explicit_attrib_location);
 }
 
 bool ProgramCompiler::LegacyConverter::supports_centroid_sampling() const
 {
        if(target_api==OPENGL_ES2)
                return check_version(Version(3, 0));
+       else if(check_version(Version(1, 20)))
+               return true;
        else
-               return check_version(Version(1, 20));
+               return check_extension(EXT_gpu_shader4);
 }
 
 bool ProgramCompiler::LegacyConverter::supports_sample_sampling() const
 {
        if(target_api==OPENGL_ES2)
                return check_version(Version(3, 20));
+       else if(check_version(Version(4, 0)))
+               return true;
        else
-               return check_version(Version(4, 0));
+               return check_extension(ARB_gpu_shader5);
 }
 
 void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var)
@@ -1923,8 +1950,12 @@ bool ProgramCompiler::LegacyConverter::supports_interface_blocks(const string &i
                else
                        return check_version(Version(3, 20));
        }
+       else if(check_version(Version(1, 50)))
+               return true;
+       else if(iface=="uniform")
+               return check_extension(ARB_uniform_buffer_object);
        else
-               return check_version(Version(1, 50));
+               return false;
 }
 
 void ProgramCompiler::LegacyConverter::visit(InterfaceBlock &iface)