MonoGame currently does not support SurfaceFormat.Single for GL ES 3.0. I opened this issue in response to a topic on the forums: http://community.monogame.net/t/android-shadowmap-and-render-target-sufaceformat-lack-of-float-support/10459
In OpenGL ES 2.0 float textures are supported through the OES_texture_float extension, but only in the alpha channel. Since SurfaceFormat.Single is defined as a float in the red channel we can't support it in GL ES 2.0.
In OpenGL ES 3.0 things work just like in OpenGL, so things should just work if MG did exactly the same thing as in DesktopGL. Currently an UnsupportedOperationException is thrown. The user reporting this issue in the forum topic mentioned the following line causes the exception:
new RenderTarget2D(GraphicsDevice, 2048, 2048, false, SurfaceFormat.Single, DepthFormat.Depth24);
We should investigate where this exception is thrown so we can prevent throwing it under OpenGL ES 3.0. The docs should mention that SurfaceFormat.Single is not supported for OpenGL ES 2.0.
This does raise the question if we should actually support OpenGL ES 3.0+ only features on mobile, since it's not portable. In this case it's zero-effort though, so I'm all for it :)
but only in the alpha channel. Since SurfaceFormat.Single is defined as a float in the red channel we can't support it in GL ES 2.0.
Are we sure if you sample the texture and do color.r it doesn't return the same value as color.a?
Still supporting it in just GL 3.x would be fine as well. I think Single is only actually supported in HiDef in XNA... so it sort of makes sense.
This does raise the question if we should actually support OpenGL ES 3.0+ only features on mobile, since it's not portable.
If ES 3.0+ is more like XNA HiDef then we should support it and set the correct graphics profile to alert the user.
In OpenGL ES 2.0 float textures are supported through the OES_texture_float extension, but only in the alpha channel.
This isn't completely right. The OpenGL ES 2.0 extension also mentions the LUMINANCE format that, when sampled in GLSL, gives (L, L, L, 1). It would not be completely equivalent to r32f, but if we assume the user uses only the red channel it would appear the same. The difference should be clearly documented though, because I imagine this might stump some users that assume (R, 0, 0, 1).
The LUMINANCE-FLOAT combination is not supported in OpenGL ES 3.0, so it should just use the DesktopGL code path.
The difference should be clearly documented though, because I imagine this might stump some users that assume (R, 0, 0, 1).
Right if you did: color.rgb += sample.rgb you would clearly get different results in that case. But i would say assuming bg is zero on a Single texture is playing with fire.
PR related to this https://github.com/MonoGame/MonoGame/pull/6264
I would argue that we should support features if the platform does (in this case GLES 3.0+).
The good thing about android is developers can add attributes to their apps to ensure that google play will only install on devices which support those features.