I found that the there is serious z-fighting on my Android phone. So I did a little investigation.
It turned out that the format of the depth buffer created on my Android phone for Urho3D programs is “D16” while for OpenGL desktop / D3D11/D3D9, the default format of depth/stencil buffer is “D24S8”, which means on a physical mobile device, we are using 16bit depth vs 24bit normally on desktop! This surely causes a lot of issues.
I don’t know the design and history of Urho3D’s depth-buffer or detailed spec about EGL2.0, however, as a dirty quick test, by adding SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
into Graphics::SetScreenMode
of OGLGraphics.cpp
makes the demo run normal:
#ifndef GL_ES_VERSION_2_0
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
if (externalWindow_)
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
else
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
if (!forceGL2_)
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
}
else
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
}
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); //<========= !!! Quick Test!!!
#endif
I think this will ask SDL to use eglChooseConfig to query a 24 bit depth size display for us.
Additionally, on my phone, the following check passed, which means D24S8 is supported.
if (CheckExtension("GL_OES_packed_depth_stencil"))
glesDepthStencilFormat = GL_DEPTH24_STENCIL8_OES;
Shall we check this failed before we decide not to call SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
?