From 0b4e6391a0e798b915153da04857024787b9cc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 19 Sep 2013 13:31:31 +0200 Subject: [PATCH] Shaders: extension support queries depend on selected GLSL version. Also added GLSL 1.30 (GL 3.0) into version list. Should fix issues where extension is supported but is not available in selected GLSL version. --- src/Shaders/DistanceFieldVector.cpp | 15 +++++++-------- src/Shaders/Flat.cpp | 13 ++++++------- src/Shaders/Phong.cpp | 15 +++++++-------- src/Shaders/Vector.cpp | 15 +++++++-------- src/Shaders/VertexColor.cpp | 13 ++++++------- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/Shaders/DistanceFieldVector.cpp b/src/Shaders/DistanceFieldVector.cpp index 506505f77..0916f30d5 100644 --- a/src/Shaders/DistanceFieldVector.cpp +++ b/src/Shaders/DistanceFieldVector.cpp @@ -42,26 +42,25 @@ template DistanceFieldVector::DistanceFieldV Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES - Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + const Version version = Context::current()->supportedVersion({Version::GL310, Version::GL300, Version::GL210}); #else - Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + const Version version = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif - Shader frag(v, Shader::Type::Vertex); + Shader frag(version, Shader::Type::Vertex); frag.addSource(rs.get("compatibility.glsl")) .addSource(rs.get(vertexShaderName())); CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); AbstractShaderProgram::attachShader(frag); - Shader vert(v, Shader::Type::Fragment); + Shader vert(version, Shader::Type::Fragment); vert.addSource(rs.get("compatibility.glsl")) .addSource(rs.get("DistanceFieldVector.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); AbstractShaderProgram::attachShader(vert); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported() || - Context::current()->version() == Version::GL210) + if(!Context::current()->isExtensionSupported(version)) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif @@ -73,7 +72,7 @@ template DistanceFieldVector::DistanceFieldV CORRADE_INTERNAL_ASSERT_OUTPUT(AbstractShaderProgram::link()); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); @@ -84,7 +83,7 @@ template DistanceFieldVector::DistanceFieldV } #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { AbstractShaderProgram::setUniform(AbstractShaderProgram::uniformLocation("vectorTexture"), diff --git a/src/Shaders/Flat.cpp b/src/Shaders/Flat.cpp index 5eea01e5c..e554ce9ed 100644 --- a/src/Shaders/Flat.cpp +++ b/src/Shaders/Flat.cpp @@ -41,26 +41,25 @@ template Flat::Flat(): transformationProject Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES - Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + const Version version = Context::current()->supportedVersion({Version::GL310, Version::GL300, Version::GL210}); #else - Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + const Version version = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif - Shader frag(v, Shader::Type::Vertex); + Shader frag(version, Shader::Type::Vertex); frag.addSource(rs.get("compatibility.glsl")) .addSource(rs.get(vertexShaderName())); CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); attachShader(frag); - Shader vert(v, Shader::Type::Fragment); + Shader vert(version, Shader::Type::Fragment); vert.addSource(rs.get("compatibility.glsl")) .addSource(rs.get("Flat.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); attachShader(vert); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported() || - Context::current()->version() == Version::GL210) + if(!Context::current()->isExtensionSupported(version)) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif @@ -71,7 +70,7 @@ template Flat::Flat(): transformationProject CORRADE_INTERNAL_ASSERT_OUTPUT(link()); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); diff --git a/src/Shaders/Phong.cpp b/src/Shaders/Phong.cpp index e4a93f068..62366837a 100644 --- a/src/Shaders/Phong.cpp +++ b/src/Shaders/Phong.cpp @@ -35,19 +35,19 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES - Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + const Version version = Context::current()->supportedVersion({Version::GL310, Version::GL300, Version::GL210}); #else - Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + const Version version = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif - Shader vert(v, Shader::Type::Vertex); + Shader vert(version, Shader::Type::Vertex); vert.addSource(flags ? "#define TEXTURED\n" : "") .addSource(rs.get("compatibility.glsl")) .addSource(rs.get("Phong.vert")); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); attachShader(vert); - Shader frag(v, Shader::Type::Fragment); + Shader frag(version, Shader::Type::Fragment); frag.addSource(flags & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n" : "") .addSource(flags & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n" : "") .addSource(flags & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n" : "") @@ -57,8 +57,7 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri attachShader(frag); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported() || - Context::current()->version() == Version::GL210) + if(!Context::current()->isExtensionSupported(version)) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif @@ -71,7 +70,7 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri CORRADE_INTERNAL_ASSERT_OUTPUT(link()); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { transformationMatrixUniform = uniformLocation("transformationMatrix"); @@ -86,7 +85,7 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri } #ifndef MAGNUM_TARGET_GLES - if(flags && !Context::current()->isExtensionSupported()) + if(flags && !Context::current()->isExtensionSupported(version)) #endif { if(flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureLayer); diff --git a/src/Shaders/Vector.cpp b/src/Shaders/Vector.cpp index 86181baa0..e89db7f86 100644 --- a/src/Shaders/Vector.cpp +++ b/src/Shaders/Vector.cpp @@ -42,26 +42,25 @@ template Vector::Vector(): transformationPro Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES - Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + const Version version = Context::current()->supportedVersion({Version::GL310, Version::GL300, Version::GL210}); #else - Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + const Version version = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif - Shader vert(v, Shader::Type::Vertex); + Shader vert(version, Shader::Type::Vertex); vert.addSource(rs.get("compatibility.glsl")) .addSource(rs.get(vertexShaderName())); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); AbstractShaderProgram::attachShader(vert); - Shader frag(v, Shader::Type::Fragment); + Shader frag(version, Shader::Type::Fragment); frag.addSource(rs.get("compatibility.glsl")) .addSource(rs.get("Vector.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); AbstractShaderProgram::attachShader(frag); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported() || - Context::current()->version() == Version::GL210) + if(!Context::current()->isExtensionSupported(version)) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif @@ -73,7 +72,7 @@ template Vector::Vector(): transformationPro CORRADE_INTERNAL_ASSERT_OUTPUT(AbstractShaderProgram::link()); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); @@ -81,7 +80,7 @@ template Vector::Vector(): transformationPro } #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { AbstractShaderProgram::setUniform(AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVector::VectorTextureLayer); diff --git a/src/Shaders/VertexColor.cpp b/src/Shaders/VertexColor.cpp index 9f9268006..d059949e2 100644 --- a/src/Shaders/VertexColor.cpp +++ b/src/Shaders/VertexColor.cpp @@ -41,26 +41,25 @@ template VertexColor::VertexColor(): transfo Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES - Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + const Version version = Context::current()->supportedVersion({Version::GL310, Version::GL300, Version::GL210}); #else - Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + const Version version = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif - Shader vert(v, Shader::Type::Vertex); + Shader vert(version, Shader::Type::Vertex); vert.addSource(rs.get("compatibility.glsl")) .addSource(rs.get(vertexShaderName())); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); attachShader(vert); - Shader frag(v, Shader::Type::Fragment); + Shader frag(version, Shader::Type::Fragment); frag.addSource(rs.get("compatibility.glsl")) .addSource(rs.get("VertexColor.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); attachShader(frag); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported() || - Context::current()->version() == Version::GL210) + if(!Context::current()->isExtensionSupported(version)) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif @@ -72,7 +71,7 @@ template VertexColor::VertexColor(): transfo CORRADE_INTERNAL_ASSERT_OUTPUT(link()); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) + if(!Context::current()->isExtensionSupported(version)) #endif { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");