Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text example doesn't render any text on iOS Safari #65

Closed
fgoujeon opened this issue Sep 22, 2019 · 5 comments
Closed

Text example doesn't render any text on iOS Safari #65

fgoujeon opened this issue Sep 22, 2019 · 5 comments

Comments

@fgoujeon
Copy link

@fgoujeon fgoujeon commented Sep 22, 2019

Only the background color is rendered. The app doesn't seem to crash.

The device I'm using (iPhone 5) seems to be SDF-capable since it's able to run this demo: https://evanw.github.io/font-texture-generator/example-webgl/

I haven't been able to make my game render any SDF text or image on iOS either. The game runs, but just won't render SDF. I've tried to fiddle with mipmaps (following the answer of this Stack Overflow question: https://stackoverflow.com/questions/27892283/libgdx-distance-field-font-support-on-ios/49968657 ), without success.

@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented Sep 22, 2019

Hi!

This got revised quite heavily a year ago, though for native GLES, not WebGL. I got a hunch (24-bit texture formats are usually not renderable on iOS and the Text library is using RGB as a fallback), but the example is using a pre-baked 8-bit SDF so this codepath isn't executed in the web demo at all.

I originally missed the "Safari" part in the title, so I thought you mean native builds -- for those I'm pretty sure it works.

Unfortunately I don't have an iOS device nearby to test and experiment on, but ... depending on how far you went with magnum setup, would you be able to run its WebGL tests on the device? Those get enabled by BUILD_TESTS and BUILD_GL_TESTS CMake options (for the magnum repository). What I'm interested is the output of TextureToolsDistanceFieldGLTest and/or ShadersDistanceFieldVectorGLTest -- if you spin up a HTTP server in the emscripten build directory, you should be able to navigate to either the TextureTools or Shaders directories and then click on the corresponding *.html file to let it run

If for any reason you can't do the above, no worries ;)

@fgoujeon

This comment has been minimized.

Copy link
Author

@fgoujeon fgoujeon commented Sep 22, 2019

Hi mosra, thank you for your quick and kind response :).

Sorry, I'm so deep in my WebGL use case that I forgot to make it explicit. I also forgot to mention that I'm using Magnum 2019.01.

the example is using a pre-baked 8-bit SDF

Yes, I noticed that. I had to use the same technique to make SDF work on Android. magnum-fontconverter and magnum-distancefieldconverter are very useful :).

Anyway, here is the output of ShadersDistanceFieldVectorGLTest 2019.01:

Renderer: WebKit WebGL by WebKit
OpenGL version: OpenGL ES 2.0 (WebGL 1.0)
Using optional features:
    GL_ANGLE_instanced_arrays
    GL_EXT_texture_filter_anisotropic
    GL_OES_vertex_array_object
Starting Magnum::Shaders::Test::DistanceFieldVectorGLTest with 4 test cases...
Shader::compile(): compilation of fragment shader 2 succeeded with the following message:
WARNING: 0:13: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
WARNING: 0:14: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
    OK [1] construct2D()
Shader::compile(): compilation of fragment shader 2 succeeded with the following message:
WARNING: 0:13: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
WARNING: 0:14: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
    OK [2] construct3D()
Shader::compile(): compilation of fragment shader 2 succeeded with the following message:
WARNING: 0:13: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
WARNING: 0:14: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
  FAIL [3] constructMove2D() at /home/florian/Development/magnum/git/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp on line 76
        Values Magnum::GL::Renderer::error() and Magnum::GL::Renderer::Error::NoError are not the same, actual is
        GL::Renderer::Error::InvalidValue
        but expected
        GL::Renderer::Error::NoError
Shader::compile(): compilation of fragment shader 2 succeeded with the following message:
WARNING: 0:13: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
WARNING: 0:14: Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)
  FAIL [4] constructMove3D() at /home/florian/Development/magnum/git/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp on line 93
        Values Magnum::GL::Renderer::error() and Magnum::GL::Renderer::Error::NoError are not the same, actual is
        GL::Renderer::Error::InvalidValue
        but expected
        GL::Renderer::Error::NoError
Finished Magnum::Shaders::Test::DistanceFieldVectorGLTest with 2 errors out of 8 checks.

Output of TextureToolsDistanceFieldGLTest 2019.01 is:

Renderer: WebKit WebGL by WebKit
OpenGL version: OpenGL ES 2.0 (WebGL 1.0)
Using optional features:
    GL_ANGLE_instanced_arrays
    GL_EXT_texture_filter_anisotropic
    GL_OES_vertex_array_object
Starting Magnum::TextureTools::Test::DistanceFieldGLTest with 1 test cases...
  FAIL [1] test() at /home/florian/Development/magnum/git/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp on line 205
        Images *actualOutputImage and Utility::Directory::join(_testDir, "output.tga") have mean delta above threshold, actual 0.177978 but at most 0.0125 expected. Max delta 1 is below threshold 1. Delta image:
          |                                                                |
          |          M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM          |
          |        M  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMM      |
          |      MMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM  MMMM    |
          |    MM M M  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM    MM    |
          |    M M M                                             MMMMM M   |
          |    M M M                                             M M M M   |
          |    M M M                MM    M    M                 M M M M   |
          |    M M M        M                                    M M M M   |
          |    M M M                                     M       M M M M   |
          |    M M M                   M         M               M M M M   |
          |    M M M        M                  M   M     M       M M M M   |
          |    M M M       M       M MM M     M   M              M M M M   |
          |    M M M               M   MM               MMM      M M M M   |
          |    M M M          MMM              M MM M            M M M M   |
          |    M M M        M                  M   M             M M M M   |
          |    M M M                              M       MM     M M M M   |
          |    M M M       M M       M    MMM     MM M   M M     M M M M   |
          |    M M M        M     M               M M      M     M M M M   |
          |    M M M        M     MM      M  M   M MM            M M M M   |
          |    M M M       MM      M                M        M   M M M M   |
          |    M M M                 M                 M         M M M M   |
          |    M M M        M        M                    M      M M M M   |
          |    M M M         M                     M MM    M     M M M M   |
          |    M M M                    M  M                     M M M M   |
          |    M M M                                             M M M M   |
          |    MMM M                                               MM MM   |
          |     M MMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MM  M    |
          |      MM MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM  MMM      |
          |         MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM         |
          |                                                                |
          |                                                                |
        Top 10 out of 729 pixels above max/mean threshold:
          [53,60] Vector(2), expected Vector(3) (Δ = 1)
          [52,60] Vector(3), expected Vector(4) (Δ = 1)
          [51,60] Vector(3), expected Vector(4) (Δ = 1)
          [50,60] Vector(3), expected Vector(4) (Δ = 1)
          [49,60] Vector(3), expected Vector(4) (Δ = 1)
          [48,60] Vector(3), expected Vector(4) (Δ = 1)
          [47,60] Vector(3), expected Vector(4) (Δ = 1)
          [46,60] Vector(3), expected Vector(4) (Δ = 1)
          [45,60] Vector(3), expected Vector(4) (Δ = 1)
          [44,60] Vector(3), expected Vector(4) (Δ = 1)
Finished Magnum::TextureTools::Test::DistanceFieldGLTest with 1 errors out of 9 checks.

You also might be interested by the command line I've used to build Magnum (and its tests):

cd $builddir
cmake $gitdir \
    -DCMAKE_TOOLCHAIN_FILE=$gitdir/toolchains/generic/Emscripten-wasm.cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_PREFIX_PATH=/usr/lib/emscripten/system \
    -DCMAKE_INSTALL_PREFIX=/usr/lib/emscripten/system \
    -DWITH_SDL2APPLICATION=ON \
    -DWITH_MAGNUMFONT=ON \
    -DWITH_TGAIMPORTER=ON \
    -DWITH_TRADE=ON \
    -DWITH_ANYIMAGEIMPORTER=ON \
    -DBUILD_TESTS=ON \
    -DBUILD_GL_TESTS=ON
@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented Sep 24, 2019

Thanks for the test output, there doesn't seem to be much suspicious actually (just some minor rounding errors, but that's nothing unexpected), the invalid value error is something I'll look into but that's probably more due to silly things happening in the test than in the shader itself.

I'm using Magnum 2019.01

Oh! Could you try with latest master? There's a lot that happened since.

Overflow in implicit constant conversion, minimum range for lowp float is (-2,2)

This actually might point to something -- can you try applying this?

diff --git a/src/Magnum/Shaders/DistanceFieldVector.frag b/src/Magnum/Shaders/DistanceFieldVector.frag
index c00bc6fa3..f30532179 100644
--- a/src/Magnum/Shaders/DistanceFieldVector.frag
+++ b/src/Magnum/Shaders/DistanceFieldVector.frag
@@ -46,7 +46,7 @@ uniform lowp vec4 outlineColor; /* defaults to zero */
 #ifdef EXPLICIT_UNIFORM_LOCATION
 layout(location = 3)
 #endif
-uniform lowp vec2 outlineRange
+uniform mediump vec2 outlineRange
     #ifndef GL_ES
     = vec2(0.5, 1.0)
     #endif
@@ -55,7 +55,7 @@ uniform lowp vec2 outlineRange
 #ifdef EXPLICIT_UNIFORM_LOCATION
 layout(location = 4)
 #endif
-uniform lowp float smoothness
+uniform mediump float smoothness
     #ifndef GL_ES
     = 0.04
     #endif
@@ -83,8 +83,8 @@ void main() {
 
     /* Outline */
     if(outlineRange.x > outlineRange.y) {
-        lowp float mid = (outlineRange.x + outlineRange.y)/2.0;
-        lowp float halfRange = (outlineRange.x - outlineRange.y)/2.0;
+        mediump float mid = (outlineRange.x + outlineRange.y)/2.0;
+        mediump float halfRange = (outlineRange.x - outlineRange.y)/2.0;
         fragmentColor += smoothstep(halfRange+smoothness, halfRange-smoothness, distance(mid, intensity))*outlineColor;
     }
 }
@fgoujeon

This comment has been minimized.

Copy link
Author

@fgoujeon fgoujeon commented Sep 24, 2019

Could you please tell me which revision of Corrade I must use to build latest master (90c727c0258acca09bdf9c17f9df69177579897c) of Magnum? I get build errors with latest Corrade master (de69dbc62a8e62d0494c50a32633b8d0e806d667):

[…]
[ 39%] Building CXX object src/MagnumPlugins/TgaImporter/CMakeFiles/TgaImporter.dir/resource_TgaImporter.cpp.o
/home/florian/Development/magnum/build/wasm/src/MagnumPlugins/TgaImporter/resource_TgaImporter.cpp:24:81: error: 
      too many arguments to function call, expected single argument 'resource',
      have 5 arguments
    Corrade::Utility::Resource::registerData("CorradeStaticPlugin_TgaImporter", 1, resourcePositions, resourceFilenames, nullptr);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/emscripten/system/include/Corrade/Utility/Resource.h:192:9: note: 
      'registerData' declared here
        static void registerData(Implementation::ResourceGroup& resource);
        ^
/home/florian/Development/magnum/build/wasm/src/MagnumPlugins/TgaImporter/resource_TgaImporter.cpp:30:48: error: 
      non-const lvalue reference to type 'Implementation::ResourceGroup' cannot
      bind to a value of unrelated type 'const char [32]'
  ..."CorradeStaticPlugin_TgaImporter");
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/emscripten/system/include/Corrade/Utility/Resource.h:193:67: note: 
      passing argument to parameter 'resource' here
        static void unregisterData(Implementation::ResourceGroup& resource);
                                                                  ^
2 errors generated.

I've tried with Corrade 85be31a3366d2eed5d497b286fe82821853aa285, with no more success:

[…]
[ 37%] Building CXX object src/Magnum/Shaders/CMakeFiles/MagnumShadersObjects.dir/resource_MagnumShaders_RCS.cpp.o
/home/florian/Development/magnum/build/wasm/src/Magnum/Shaders/resource_MagnumShaders_RCS.cpp:3238:67: error: 
      cannot initialize a parameter of type 'const unsigned int *' with an
      lvalue of type 'const unsigned char [144]'
  ...18, resourcePositions, resourceFilenames, resourceData);
         ^~~~~~~~~~~~~~~~~
/usr/lib/emscripten/system/include/Corrade/Utility/Resource.h:159:93: note: 
      passing argument to parameter 'positions' here
  ...char* group, unsigned int count, const unsigned int* positions, const un...
                                                          ^
1 error generated.

I've also tried to rerun ShadersDistanceFieldVectorGLTest 2019.01 with your patch. This got rid of the shader compilation warnings, but not the test failures:

Renderer: WebKit WebGL by WebKit
OpenGL version: OpenGL ES 2.0 (WebGL 1.0)
Using optional features:
    GL_ANGLE_instanced_arrays
    GL_EXT_texture_filter_anisotropic
    GL_OES_vertex_array_object
Starting Magnum::Shaders::Test::DistanceFieldVectorGLTest with 4 test cases...
    OK [1] construct2D()
    OK [2] construct3D()
  FAIL [3] constructMove2D() at /home/florian/Development/magnum/git/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp on line 76
        Values Magnum::GL::Renderer::error() and Magnum::GL::Renderer::Error::NoError are not the same, actual is
        GL::Renderer::Error::InvalidValue
        but expected
        GL::Renderer::Error::NoError
  FAIL [4] constructMove3D() at /home/florian/Development/magnum/git/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp on line 93
        Values Magnum::GL::Renderer::error() and Magnum::GL::Renderer::Error::NoError are not the same, actual is
        GL::Renderer::Error::InvalidValue
        but expected
        GL::Renderer::Error::NoError
Finished Magnum::Shaders::Test::DistanceFieldVectorGLTest with 2 errors out of 8 checks.
@mosra mosra closed this Sep 28, 2019
@mosra mosra added this to the 2019.0b milestone Sep 28, 2019
@mosra mosra added this to TODO in Platforms via automation Sep 28, 2019
@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented Sep 28, 2019

Closing since you fixed this in mosra/magnum#374 👍 Also, sorry for the delayed replies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Platforms
  
TODO
2 participants
You can’t perform that action at this time.