]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compatibility.cpp
Reduce coupling between the GLSL compiler and the graphics engine
[libs/gl.git] / source / glsl / compatibility.cpp
index 0308a391ab29b3c83ef63ea65c318f279797d06f..2e13a5f678eaa7592809fa292071b89cecf28beb 100644 (file)
@@ -1,10 +1,5 @@
 #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/gl/extensions/ext_texture_array.h>
 #include <msp/strings/lexicalcast.h>
 #include "compatibility.h"
 
@@ -85,14 +80,13 @@ void PrecisionRemover::visit(VariableDeclaration &var)
 
 
 LegacyConverter::LegacyConverter():
-       target_api(get_gl_api()),
-       target_version(get_glsl_version()),
        frag_out(0)
 { }
 
-void LegacyConverter::apply(Stage &s)
+void LegacyConverter::apply(Stage &s, const Features &feat)
 {
        stage = &s;
+       features = feat;
        visit(s.content);
 }
 
@@ -108,29 +102,27 @@ void LegacyConverter::visit(Block &block)
 
 bool LegacyConverter::check_version(const Version &feature_version) const
 {
-       if(target_version<feature_version)
+       if(features.glsl_version<feature_version)
                return false;
-       else if(stage->required_version<feature_version)
-               stage->required_version = feature_version;
+       else if(stage->required_features.glsl_version<feature_version)
+               stage->required_features.glsl_version = feature_version;
 
        return true;
 }
 
-bool LegacyConverter::check_extension(const Extension &extension) const
+bool LegacyConverter::check_extension(bool Features::*extension) const
 {
-       if(!extension)
+       if(!(features.*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);
+       stage->required_features.*extension = true;
 
        return true;
 }
 
 bool LegacyConverter::supports_unified_interface_syntax() const
 {
-       if(target_api==OPENGL_ES2)
+       if(features.gl_api==OPENGL_ES2)
                return check_version(Version(3, 0));
        else
                return check_version(Version(1, 30));
@@ -159,7 +151,7 @@ void LegacyConverter::visit(Assignment &assign)
 
 bool LegacyConverter::supports_unified_sampling_functions() const
 {
-       if(target_api==OPENGL_ES2)
+       if(features.gl_api==OPENGL_ES2)
                return check_version(Version(3, 0));
        else
                return check_version(Version(1, 30));
@@ -197,22 +189,22 @@ void LegacyConverter::visit(FunctionCall &call)
                                call.name = "shadow2D";
                        else if(sampler_type=="sampler1DArray")
                        {
-                               check_extension(EXT_texture_array);
+                               check_extension(&Features::ext_texture_array);
                                call.name = "texture1DArray";
                        }
                        else if(sampler_type=="sampler2DArray")
                        {
-                               check_extension(EXT_texture_array);
+                               check_extension(&Features::ext_texture_array);
                                call.name = "texture2DArray";
                        }
                        else if(sampler_type=="sampler1DArrayShadow")
                        {
-                               check_extension(EXT_texture_array);
+                               check_extension(&Features::ext_texture_array);
                                call.name = "shadow1DArray";
                        }
                        else if(sampler_type=="sampler2DArrayShadow")
                        {
-                               check_extension(EXT_texture_array);
+                               check_extension(&Features::ext_texture_array);
                                call.name = "shadow2DArray";
                        }
                }
@@ -223,32 +215,32 @@ void LegacyConverter::visit(FunctionCall &call)
 
 bool LegacyConverter::supports_interface_layouts() const
 {
-       if(target_api==OPENGL_ES2)
+       if(features.gl_api==OPENGL_ES2)
                return check_version(Version(3, 0));
        else if(check_version(Version(3, 30)))
                return true;
        else
-               return check_extension(ARB_explicit_attrib_location);
+               return check_extension(&Features::arb_explicit_attrib_location);
 }
 
 bool LegacyConverter::supports_centroid_sampling() const
 {
-       if(target_api==OPENGL_ES2)
+       if(features.gl_api==OPENGL_ES2)
                return check_version(Version(3, 0));
        else if(check_version(Version(1, 20)))
                return true;
        else
-               return check_extension(EXT_gpu_shader4);
+               return check_extension(&Features::ext_gpu_shader4);
 }
 
 bool LegacyConverter::supports_sample_sampling() const
 {
-       if(target_api==OPENGL_ES2)
+       if(features.gl_api==OPENGL_ES2)
                return check_version(Version(3, 20));
        else if(check_version(Version(4, 0)))
                return true;
        else
-               return check_extension(ARB_gpu_shader5);
+               return check_extension(&Features::arb_gpu_shader5);
 }
 
 void LegacyConverter::visit(VariableDeclaration &var)
@@ -268,7 +260,7 @@ void LegacyConverter::visit(VariableDeclaration &var)
                        else if(stage->type==Stage::FRAGMENT && var.interface=="out")
                        {
                                if(location!=0)
-                                       static Require _req(EXT_gpu_shader4);
+                                       check_extension(&Features::ext_gpu_shader4);
                                stage->locations[var.name] = location;
                                var.layout->qualifiers.erase(i);
                        }
@@ -303,7 +295,7 @@ void LegacyConverter::visit(VariableDeclaration &var)
 
 bool LegacyConverter::supports_interface_blocks(const string &iface) const
 {
-       if(target_api==OPENGL_ES2)
+       if(features.gl_api==OPENGL_ES2)
        {
                if(iface=="uniform")
                        return check_version(Version(3, 0));
@@ -313,7 +305,7 @@ bool LegacyConverter::supports_interface_blocks(const string &iface) const
        else if(check_version(Version(1, 50)))
                return true;
        else if(iface=="uniform")
-               return check_extension(ARB_uniform_buffer_object);
+               return check_extension(&Features::arb_uniform_buffer_object);
        else
                return false;
 }