Browse Source

Fix DistanceFieldVector on WebGL iOS

findsdl-include-root
Florian Goujeon 7 years ago committed by Vladimír Vondruš
parent
commit
837defa182
  1. 6
      src/Magnum/Shaders/AbstractVector.h
  2. 10
      src/Magnum/Shaders/DistanceFieldVector.frag
  3. 3
      src/Magnum/Shaders/Vector.frag
  4. 4
      src/Magnum/TextureTools/DistanceField.cpp

6
src/Magnum/Shaders/AbstractVector.h

@ -100,7 +100,11 @@ template<UnsignedInt dimensions> class AbstractVector: public GL::AbstractShader
#else #else
private: private:
#endif #endif
enum: Int { VectorTextureLayer = 15 }; /* Those textures are quite specific (and likely reused multiple times
per frame for e.g. text rendering, so put them in a specific slot.
Older iOS (and iOS WebGL) has only 8 texture binding slots, so can't
go above that. Binding 7 is used by TextureTools::DistanceField. */
enum: Int { VectorTextureLayer = 6 };
explicit AbstractVector(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {} explicit AbstractVector(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
explicit AbstractVector() = default; explicit AbstractVector() = default;

10
src/Magnum/Shaders/DistanceFieldVector.frag

@ -62,7 +62,8 @@ uniform lowp float smoothness
; ;
#ifdef EXPLICIT_TEXTURE_LAYER #ifdef EXPLICIT_TEXTURE_LAYER
layout(binding = 15) /* See AbstractVector.h for details about the ID */
layout(binding = 6)
#endif #endif
uniform lowp sampler2D vectorTexture; uniform lowp sampler2D vectorTexture;
@ -83,8 +84,11 @@ void main() {
/* Outline */ /* Outline */
if(outlineRange.x > outlineRange.y) { if(outlineRange.x > outlineRange.y) {
lowp float mid = (outlineRange.x + outlineRange.y)/2.0; /* Doing *0.5 instead of /2.0 because the latter causes iOS / WebGL to
lowp float halfRange = (outlineRange.x - outlineRange.y)/2.0; complain that "Overflow in implicit constant conversion, minimum
range for lowp float is (-2,2)" */
lowp float mid = (outlineRange.x + outlineRange.y)*0.5;
lowp float halfRange = (outlineRange.x - outlineRange.y)*0.5;
fragmentColor += smoothstep(halfRange+smoothness, halfRange-smoothness, distance(mid, intensity))*outlineColor; fragmentColor += smoothstep(halfRange+smoothness, halfRange-smoothness, distance(mid, intensity))*outlineColor;
} }
} }

3
src/Magnum/Shaders/Vector.frag

@ -44,7 +44,8 @@ uniform lowp vec4 color
; ;
#ifdef EXPLICIT_TEXTURE_LAYER #ifdef EXPLICIT_TEXTURE_LAYER
layout(binding = 15) /* See AbstractVector.h for details about the ID */
layout(binding = 6)
#endif #endif
uniform lowp sampler2D vectorTexture; uniform lowp sampler2D vectorTexture;

4
src/Magnum/TextureTools/DistanceField.cpp

@ -73,7 +73,9 @@ class DistanceFieldShader: public GL::AbstractShaderProgram {
private: private:
/* ES2 on iOS (apparently independent on the device) has only 8 texture /* ES2 on iOS (apparently independent on the device) has only 8 texture
units, so be careful to not step over that. ES3 on the same has 16. */ units, so be careful to not step over that. ES3 on the same has 16.
Not using the default (0) because this shader is quite specific.
Unit 6 is used by Shaders::Vector and Shaders::DistanceFieldVector. */
enum: Int { TextureUnit = 7 }; enum: Int { TextureUnit = 7 };
Int scalingUniform{0}, Int scalingUniform{0},

Loading…
Cancel
Save