From 1847c7201df44bbc78a4bbf2b41838f080890580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 13 Mar 2023 16:25:26 +0100 Subject: [PATCH] Shaders: use explicit texture location and binding on ES3.1+. No reason not to, reduces the amount of unnecessary driver calls quite significantly. --- src/Magnum/Shaders/DistanceFieldVectorGL.cpp | 8 ++++++-- src/Magnum/Shaders/DistanceFieldVectorGL.h | 6 +++--- src/Magnum/Shaders/FlatGL.cpp | 8 ++++++-- src/Magnum/Shaders/FlatGL.h | 6 +++--- src/Magnum/Shaders/LineGL.cpp | 10 +++++++--- src/Magnum/Shaders/LineGL.h | 6 +++--- src/Magnum/Shaders/MeshVisualizerGL.cpp | 12 ++++++++++-- src/Magnum/Shaders/MeshVisualizerGL.h | 12 ++++++------ src/Magnum/Shaders/PhongGL.cpp | 8 ++++++-- src/Magnum/Shaders/PhongGL.h | 6 +++--- src/Magnum/Shaders/VectorGL.cpp | 8 ++++++-- src/Magnum/Shaders/VectorGL.h | 6 +++--- src/Magnum/Shaders/VertexColorGL.cpp | 8 ++++++-- src/Magnum/Shaders/VertexColorGL.h | 6 +++--- src/Magnum/Shaders/compatibility.glsl | 13 +++++++++---- src/Magnum/TextureTools/DistanceField.cpp | 6 +++++- 16 files changed, 85 insertions(+), 44 deletions(-) diff --git a/src/Magnum/Shaders/DistanceFieldVectorGL.cpp b/src/Magnum/Shaders/DistanceFieldVectorGL.cpp index 1265b4640..a9c5e5219 100644 --- a/src/Magnum/Shaders/DistanceFieldVectorGL.cpp +++ b/src/Magnum/Shaders/DistanceFieldVectorGL.cpp @@ -103,7 +103,7 @@ template typename DistanceFieldVectorGL::Com #ifndef MAGNUM_TARGET_GLES const GL::Version version = context.supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); #else - const GL::Version version = context.supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); + const GL::Version version = context.supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); #endif GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); @@ -160,7 +160,7 @@ template typename DistanceFieldVectorGL::Com out.submitLink(); return CompileState{std::move(out), std::move(vert), std::move(frag) - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -194,6 +194,8 @@ template DistanceFieldVectorGL::DistanceFiel #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { #ifndef MAGNUM_TARGET_GLES2 @@ -214,6 +216,8 @@ template DistanceFieldVectorGL::DistanceFiel #ifndef MAGNUM_TARGET_GLES if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { setUniform(uniformLocation("vectorTexture"_s), TextureUnit); diff --git a/src/Magnum/Shaders/DistanceFieldVectorGL.h b/src/Magnum/Shaders/DistanceFieldVectorGL.h index 9d91fa55c..2a447e680 100644 --- a/src/Magnum/Shaders/DistanceFieldVectorGL.h +++ b/src/Magnum/Shaders/DistanceFieldVectorGL.h @@ -755,17 +755,17 @@ template class DistanceFieldVectorGL::Compil explicit CompileState(NoCreateT): DistanceFieldVectorGL{NoCreate}, _vert{NoCreate}, _frag{NoCreate} {} explicit CompileState(DistanceFieldVectorGL&& shader, GL::Shader&& vert, GL::Shader&& frag - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): DistanceFieldVectorGL{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif {} Implementation::GLShaderWrapper _vert, _frag; - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/FlatGL.cpp b/src/Magnum/Shaders/FlatGL.cpp index 2f144ca3e..841e3a721 100644 --- a/src/Magnum/Shaders/FlatGL.cpp +++ b/src/Magnum/Shaders/FlatGL.cpp @@ -144,7 +144,7 @@ template typename FlatGL::CompileState FlatG #ifndef MAGNUM_TARGET_GLES const GL::Version version = context.supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); #else - const GL::Version version = context.supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); + const GL::Version version = context.supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); #endif FlatGL out{NoInit}; @@ -306,7 +306,7 @@ template typename FlatGL::CompileState FlatG out.submitLink(); return CompileState{std::move(out), std::move(vert), std::move(frag) - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -340,6 +340,8 @@ template FlatGL::FlatGL(CompileState&& state #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { #ifndef MAGNUM_TARGET_GLES2 @@ -373,6 +375,8 @@ template FlatGL::FlatGL(CompileState&& state #ifndef MAGNUM_TARGET_GLES if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { if(_flags & Flag::Textured) setUniform(uniformLocation("textureData"_s), TextureUnit); diff --git a/src/Magnum/Shaders/FlatGL.h b/src/Magnum/Shaders/FlatGL.h index e33e183ed..9845ac82b 100644 --- a/src/Magnum/Shaders/FlatGL.h +++ b/src/Magnum/Shaders/FlatGL.h @@ -1536,17 +1536,17 @@ template class FlatGL::CompileState: public explicit CompileState(NoCreateT): FlatGL{NoCreate}, _vert{NoCreate}, _frag{NoCreate} {} explicit CompileState(FlatGL&& shader, GL::Shader&& vert, GL::Shader&& frag - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): FlatGL{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif {} Implementation::GLShaderWrapper _vert, _frag; - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/LineGL.cpp b/src/Magnum/Shaders/LineGL.cpp index 719d0ff59..ccf7b6dde 100644 --- a/src/Magnum/Shaders/LineGL.cpp +++ b/src/Magnum/Shaders/LineGL.cpp @@ -92,12 +92,12 @@ template typename LineGL::CompileState LineG #endif Utility::Resource rs{"MagnumShadersGL"_s}; + const GL::Context& context = GL::Context::current(); #ifndef MAGNUM_TARGET_GLES - const GL::Context& context = GL::Context::current(); const GL::Version version = context.supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); #else - constexpr GL::Version version = GL::Version::GLES300; + const GL::Version version = context.supportedVersion({GL::Version::GLES310, GL::Version::GLES300}); #endif /* Cap and join style is needed by both the vertex and fragment shader, @@ -200,7 +200,7 @@ template typename LineGL::CompileState LineG out.submitLink(); return CompileState{std::move(out), std::move(vert), std::move(frag) - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -218,6 +218,8 @@ template LineGL::LineGL(CompileState&& state #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { _viewportSizeUniform = uniformLocation("viewportSize"_s); @@ -239,6 +241,8 @@ template LineGL::LineGL(CompileState&& state #ifndef MAGNUM_TARGET_GLES if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { if(_flags >= Flag::UniformBuffers) { diff --git a/src/Magnum/Shaders/LineGL.h b/src/Magnum/Shaders/LineGL.h index db505b5ad..a010f1550 100644 --- a/src/Magnum/Shaders/LineGL.h +++ b/src/Magnum/Shaders/LineGL.h @@ -1104,17 +1104,17 @@ template class LineGL::CompileState: public explicit CompileState(NoCreateT): LineGL{NoCreate}, _vert{NoCreate}, _frag{NoCreate} {} explicit CompileState(LineGL&& shader, GL::Shader&& vert, GL::Shader&& frag - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): LineGL{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif {} Implementation::GLShaderWrapper _vert, _frag; - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/MeshVisualizerGL.cpp b/src/Magnum/Shaders/MeshVisualizerGL.cpp index 7f27bf5ac..a244d5c29 100644 --- a/src/Magnum/Shaders/MeshVisualizerGL.cpp +++ b/src/Magnum/Shaders/MeshVisualizerGL.cpp @@ -630,7 +630,7 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration #if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) , geom ? &*geom : nullptr #endif - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -671,6 +671,8 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(CompileState&& state): MeshVisualizerGL2D #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { /* This one is used also in the UBO case as it's usually a global @@ -723,6 +725,8 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(CompileState&& state): MeshVisualizerGL2D #ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES if(flags() && !context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { @@ -1124,7 +1128,7 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration #if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) , geom ? &*geom : nullptr #endif - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -1165,6 +1169,8 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(CompileState&& state): MeshVisualizerGL3D #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { /* This one is used also in the UBO case as it's usually a global @@ -1235,6 +1241,8 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(CompileState&& state): MeshVisualizerGL3D #ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES if(flags() && !context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { diff --git a/src/Magnum/Shaders/MeshVisualizerGL.h b/src/Magnum/Shaders/MeshVisualizerGL.h index 459d38134..ae177f6dd 100644 --- a/src/Magnum/Shaders/MeshVisualizerGL.h +++ b/src/Magnum/Shaders/MeshVisualizerGL.h @@ -1339,11 +1339,11 @@ class MeshVisualizerGL2D::CompileState: public MeshVisualizerGL2D { #if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) , GL::Shader* geom #endif - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): MeshVisualizerGL2D{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif { @@ -1356,7 +1356,7 @@ class MeshVisualizerGL2D::CompileState: public MeshVisualizerGL2D { #if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) Implementation::GLShaderWrapper _geom{NoCreate}; #endif - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; @@ -3331,11 +3331,11 @@ class MeshVisualizerGL3D::CompileState: public MeshVisualizerGL3D { #if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) , GL::Shader* geom #endif - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): MeshVisualizerGL3D{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif { @@ -3348,7 +3348,7 @@ class MeshVisualizerGL3D::CompileState: public MeshVisualizerGL3D { #if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) Implementation::GLShaderWrapper _geom{NoCreate}; #endif - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/PhongGL.cpp b/src/Magnum/Shaders/PhongGL.cpp index 58310ca4e..fd79a0a17 100644 --- a/src/Magnum/Shaders/PhongGL.cpp +++ b/src/Magnum/Shaders/PhongGL.cpp @@ -164,7 +164,7 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { #ifndef MAGNUM_TARGET_GLES const GL::Version version = context.supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); #else - const GL::Version version = context.supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); + const GL::Version version = context.supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); #endif PhongGL out{NoInit}; @@ -391,7 +391,7 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { out.submitLink(); return CompileState{std::move(out), std::move(vert), std::move(frag) - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -431,6 +431,8 @@ PhongGL::PhongGL(CompileState&& state): PhongGL{static_cast(std::move #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { #ifndef MAGNUM_TARGET_GLES2 @@ -480,6 +482,8 @@ PhongGL::PhongGL(CompileState&& state): PhongGL{static_cast(std::move #ifndef MAGNUM_TARGET_GLES if(_flags && !context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { if(_flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"_s), AmbientTextureUnit); diff --git a/src/Magnum/Shaders/PhongGL.h b/src/Magnum/Shaders/PhongGL.h index 9c17cb8c9..46ea56df8 100644 --- a/src/Magnum/Shaders/PhongGL.h +++ b/src/Magnum/Shaders/PhongGL.h @@ -2358,17 +2358,17 @@ class PhongGL::CompileState: public PhongGL { explicit CompileState(NoCreateT): PhongGL{NoCreate}, _vert{NoCreate}, _frag{NoCreate} {} explicit CompileState(PhongGL&& shader, GL::Shader&& vert, GL::Shader&& frag - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): PhongGL{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif {} Implementation::GLShaderWrapper _vert, _frag; - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/VectorGL.cpp b/src/Magnum/Shaders/VectorGL.cpp index edd8042b4..0b228254f 100644 --- a/src/Magnum/Shaders/VectorGL.cpp +++ b/src/Magnum/Shaders/VectorGL.cpp @@ -103,7 +103,7 @@ template typename VectorGL::CompileState Vec #ifndef MAGNUM_TARGET_GLES const GL::Version version = context.supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); #else - const GL::Version version = context.supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); + const GL::Version version = context.supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); #endif GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); @@ -161,7 +161,7 @@ template typename VectorGL::CompileState Vec out.submitLink(); return CompileState{std::move(out), std::move(vert), std::move(frag) - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -195,6 +195,8 @@ template VectorGL::VectorGL(CompileState&& s #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { #ifndef MAGNUM_TARGET_GLES2 @@ -213,6 +215,8 @@ template VectorGL::VectorGL(CompileState&& s #ifndef MAGNUM_TARGET_GLES if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { setUniform(uniformLocation("vectorTexture"_s), TextureUnit); diff --git a/src/Magnum/Shaders/VectorGL.h b/src/Magnum/Shaders/VectorGL.h index eb299c62a..d8028f62f 100644 --- a/src/Magnum/Shaders/VectorGL.h +++ b/src/Magnum/Shaders/VectorGL.h @@ -704,17 +704,17 @@ template class VectorGL::CompileState: publi explicit CompileState(NoCreateT): VectorGL{NoCreate}, _vert{NoCreate}, _frag{NoCreate} {} explicit CompileState(VectorGL&& shader, GL::Shader&& vert, GL::Shader&& frag - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): VectorGL{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif {} Implementation::GLShaderWrapper _vert, _frag; - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/VertexColorGL.cpp b/src/Magnum/Shaders/VertexColorGL.cpp index 5356409bf..234298a59 100644 --- a/src/Magnum/Shaders/VertexColorGL.cpp +++ b/src/Magnum/Shaders/VertexColorGL.cpp @@ -94,7 +94,7 @@ template typename VertexColorGL::CompileStat #ifndef MAGNUM_TARGET_GLES const GL::Version version = context.supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); #else - const GL::Version version = context.supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); + const GL::Version version = context.supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); #endif GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); @@ -139,7 +139,7 @@ template typename VertexColorGL::CompileStat out.submitLink(); return CompileState{std::move(out), std::move(vert), std::move(frag) - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , version #endif }; @@ -172,6 +172,8 @@ template VertexColorGL::VertexColorGL(Compil #ifndef MAGNUM_TARGET_GLES const GL::Context& context = GL::Context::current(); if(!context.isExtensionSupported(state._version)) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(state._version < GL::Version::GLES310) #endif { #ifndef MAGNUM_TARGET_GLES2 @@ -188,6 +190,8 @@ template VertexColorGL::VertexColorGL(Compil if(_flags >= Flag::UniformBuffers #ifndef MAGNUM_TARGET_GLES && !context.isExtensionSupported(state._version) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + && state._version < GL::Version::GLES310 #endif ) { setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding); diff --git a/src/Magnum/Shaders/VertexColorGL.h b/src/Magnum/Shaders/VertexColorGL.h index ae89000d7..4e810fde2 100644 --- a/src/Magnum/Shaders/VertexColorGL.h +++ b/src/Magnum/Shaders/VertexColorGL.h @@ -517,17 +517,17 @@ template class VertexColorGL::CompileState: explicit CompileState(NoCreateT): VertexColorGL{NoCreate}, _vert{NoCreate}, _frag{NoCreate} {} explicit CompileState(VertexColorGL&& shader, GL::Shader&& vert, GL::Shader&& frag - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , GL::Version version #endif ): VertexColorGL{Utility::move(shader)}, _vert{Utility::move(vert)}, _frag{Utility::move(frag)} - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) , _version{version} #endif {} Implementation::GLShaderWrapper _vert, _frag; - #ifndef MAGNUM_TARGET_GLES + #if !defined(MAGNUM_TARGET_GLES) || (!defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)) GL::Version _version; #endif }; diff --git a/src/Magnum/Shaders/compatibility.glsl b/src/Magnum/Shaders/compatibility.glsl index 7e9c5955c..6d5e5d65a 100644 --- a/src/Magnum/Shaders/compatibility.glsl +++ b/src/Magnum/Shaders/compatibility.glsl @@ -43,10 +43,15 @@ #define EXPLICIT_UNIFORM_LOCATION #endif -#if defined(GL_ES) && __VERSION__ >= 300 - #define EXPLICIT_ATTRIB_LOCATION - /* EXPLICIT_BINDING, EXPLICIT_UNIFORM_LOCATION and RUNTIME_CONST is not - available in OpenGL ES */ +#ifdef GL_ES + #if __VERSION__ >= 300 + #define EXPLICIT_ATTRIB_LOCATION + #endif + #if __VERSION__ >= 310 + #define EXPLICIT_BINDING + #define EXPLICIT_UNIFORM_LOCATION + #endif + /* RUNTIME_CONST is not available in OpenGL ES */ #endif /* Precision qualifiers are not supported in GLSL 1.20 */ diff --git a/src/Magnum/TextureTools/DistanceField.cpp b/src/Magnum/TextureTools/DistanceField.cpp index f1eca6c3c..6f768eacf 100644 --- a/src/Magnum/TextureTools/DistanceField.cpp +++ b/src/Magnum/TextureTools/DistanceField.cpp @@ -96,7 +96,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { #ifndef MAGNUM_TARGET_GLES const GL::Version v = GL::Context::current().supportedVersion({GL::Version::GL320, GL::Version::GL300, GL::Version::GL210}); #else - const GL::Version v = GL::Context::current().supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); + const GL::Version v = GL::Context::current().supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); #endif GL::Shader vert = Shaders::Implementation::createCompatibilityShader(rs, v, GL::Shader::Type::Vertex); @@ -122,6 +122,8 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { #ifndef MAGNUM_TARGET_GLES if(!GL::Context::current().isExtensionSupported()) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(v < GL::Version::GLES310) #endif { scalingUniform = uniformLocation("scaling"_s); @@ -138,6 +140,8 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { #ifndef MAGNUM_TARGET_GLES if(!GL::Context::current().isExtensionSupported()) + #elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + if(v < GL::Version::GLES310) #endif { setUniform(uniformLocation("textureData"_s), TextureUnit);