From: Mikko Rasa Date: Mon, 8 Nov 2021 19:19:15 +0000 (+0200) Subject: Make the SL::Features factory functions more flexible X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aa389f9840d961f7edbcf64eadced812134d8481;p=libs%2Fgl.git Make the SL::Features factory functions more flexible Passing the backend API as an argument is much better than having separate functions for each backend. --- diff --git a/source/glsl/features.cpp b/source/glsl/features.cpp index eff7dd8d..a174f644 100644 --- a/source/glsl/features.cpp +++ b/source/glsl/features.cpp @@ -1,32 +1,63 @@ +#include #include "features.h" +using namespace std; + namespace Msp { namespace GL { namespace SL { -Features Features::from_opengl_version(const Version &ver) +Features Features::from_api_version(GraphicsApi api, const Version &ver) { Features features; - features.target_api = OPENGL; + features.target_api = api; features.glsl_version = ver; - features.arb_enhanced_layouts = (ver>=Version(4, 40)); - features.arb_explicit_attrib_location = (ver>=Version(1, 30)); - features.arb_explicit_uniform_location = (ver>=Version(4, 30)); - features.arb_gpu_shader5 = (ver>=Version(4, 0)); - features.arb_separate_shader_objects = (ver>=Version(4, 10)); - features.arb_uniform_buffer_object = (ver>=Version(1, 50)); - features.ext_gpu_shader4 = (ver>=Version(1, 20)); - features.ext_texture_array = (ver>=Version(1, 30)); - features.uniform_binding_range = (ver>=Version(4, 30) ? 84 : ver>=Version(4, 0) ? 60 : - ver>=Version(3, 30) ? 36 : 24); - features.texture_binding_range = (ver>=Version(4, 30) ? 96 : ver>=Version(4, 0) ? 80 : - ver>=Version(1, 50) ? 48 : ver>=Version(1, 40) ? 32 : 16); + switch(api) + { + case OPENGL: + features.arb_enhanced_layouts = (ver>=Version(4, 40)); + features.arb_explicit_attrib_location = (ver>=Version(1, 30)); + features.arb_explicit_uniform_location = (ver>=Version(4, 30)); + features.arb_gpu_shader5 = (ver>=Version(4, 0)); + features.arb_separate_shader_objects = (ver>=Version(4, 10)); + features.arb_uniform_buffer_object = (ver>=Version(1, 50)); + features.ext_gpu_shader4 = (ver>=Version(1, 20)); + features.ext_texture_array = (ver>=Version(1, 30)); + features.uniform_binding_range = (ver>=Version(4, 30) ? 84 : ver>=Version(4, 0) ? 60 : + ver>=Version(3, 30) ? 36 : 24); + features.texture_binding_range = (ver>=Version(4, 30) ? 96 : ver>=Version(4, 0) ? 80 : + ver>=Version(1, 50) ? 48 : ver>=Version(1, 40) ? 32 : 16); + break; + case OPENGL_ES: + features.arb_enhanced_layouts = (ver>=Version(3, 20)); + features.arb_explicit_attrib_location = (ver>=Version(3, 0)); + features.arb_explicit_uniform_location = (ver>=Version(3, 10)); + features.arb_gpu_shader5 = (ver>=Version(3, 20)); + features.arb_separate_shader_objects = (ver>=Version(3, 10)); + features.arb_uniform_buffer_object = (ver>=Version(3, 0)); + features.ext_gpu_shader4 = (ver>=Version(3, 0)); + features.ext_texture_array = (ver>=Version(3, 0)); + features.uniform_binding_range = (ver>=Version(3, 20) ? 72 : ver>=Version(3, 10) ? 36 : 24); + features.texture_binding_range = (ver>=Version(3, 20) ? 96 : ver>=Version(3, 10) ? 48 : + ver>=Version(3, 0) ? 32 : 8); + break; + default: + throw invalid_argument("Features::from_api_version"); + } return features; } -Features Features::opengl_latest() +Features Features::latest(GraphicsApi api) { - return from_opengl_version(Version(4, 60)); + switch(api) + { + case OPENGL: + return from_api_version(api, Version(4, 60)); + case OPENGL_ES: + return from_api_version(api, Version(3, 20)); + default: + throw invalid_argument("Features::latest"); + } } } // namespace SL diff --git a/source/glsl/features.h b/source/glsl/features.h index 58777465..e0d7dd77 100644 --- a/source/glsl/features.h +++ b/source/glsl/features.h @@ -23,8 +23,8 @@ struct Features unsigned uniform_binding_range = 24; unsigned texture_binding_range = 16; - static Features from_opengl_version(const Version &); - static Features opengl_latest(); + static Features from_api_version(GraphicsApi, const Version &); + static Features latest(GraphicsApi); }; } // namespace SL diff --git a/tests/glsl/glslcompiler.cpp b/tests/glsl/glslcompiler.cpp index 3debd721..51664272 100644 --- a/tests/glsl/glslcompiler.cpp +++ b/tests/glsl/glslcompiler.cpp @@ -251,7 +251,7 @@ GlslCompilerTest::GlslCompilerTest() void GlslCompilerTest::run_test_case(const TestCase *test_case) { - GL::SL::Compiler compiler(GL::SL::Features::opengl_latest()); + GL::SL::Compiler compiler(GL::SL::Features::latest(GL::OPENGL)); try { compiler.set_source(test_case->source, ""); @@ -308,13 +308,13 @@ GlslCompilerIdempotence::GlslCompilerIdempotence() void GlslCompilerIdempotence::run_test_case(const TestCase *test_case) { - GL::SL::Compiler compiler(GL::SL::Features::opengl_latest()); + GL::SL::Compiler compiler(GL::SL::Features::latest(GL::OPENGL)); compiler.set_source(test_case->source, ""); if(test_case->compile_mode==GL::SL::Compiler::PROGRAM) compiler.specialize(test_case->spec_values); compiler.compile(test_case->compile_mode); - GL::SL::Compiler compiler2(GL::SL::Features::opengl_latest()); + GL::SL::Compiler compiler2(GL::SL::Features::latest(GL::OPENGL)); compiler2.set_source(compiler.get_combined_glsl(), ""); compiler2.compile(test_case->compile_mode); @@ -351,7 +351,7 @@ GlslCompilerSpirV::GlslCompilerSpirV(): void GlslCompilerSpirV::run_test_case(const TestCase *test_case) { - GL::SL::Compiler compiler(GL::SL::Features::opengl_latest()); + GL::SL::Compiler compiler(GL::SL::Features::latest(GL::OPENGL)); compiler.set_source(test_case->source, ""); compiler.compile(GL::SL::Compiler::SPIRV); diff --git a/tools/glslcompiler.cpp b/tools/glslcompiler.cpp index d11fd611..bcc787eb 100644 --- a/tools/glslcompiler.cpp +++ b/tools/glslcompiler.cpp @@ -44,7 +44,7 @@ using namespace std; using namespace Msp; GlslCompiler::GlslCompiler(int argc, char **argv): - features(GL::SL::Features::opengl_latest()), + features(GL::SL::Features::latest(GL::OPENGL)), compile_mode(GL::SL::Compiler::PROGRAM), parse_only(false), combined(false), @@ -71,7 +71,7 @@ GlslCompiler::GlslCompiler(int argc, char **argv): getopt(argc, argv); if(target_version) - features = GL::SL::Features::from_opengl_version(GL::Version(target_version/100, target_version%100)); + features = GL::SL::Features::from_api_version(GL::OPENGL, GL::Version(target_version/100, target_version%100)); if(as_module) {