Page 1 of 2

Odd rendering errors on Android

Posted: Thu Sep 01, 2016 12:42 pm
by Imerion
I have pretty much finished a new game! But when running it on Android some weird things happen. It seems transparency isn't rendered correctly. (Or things are rendered in an incorrect order. Below is a screenshot of how it looks on my PC and one of how it looks on my Galaxy Tab 3. Any idea what might be causing this?

Re: Odd rendering errors on Android

Posted: Thu Sep 01, 2016 4:36 pm
by VilleK
Not sure what is going on. Can you tell me how that planet in the bottom right corner is rendered. Is it one mesh with transparent texture on top of another mesh?

Re: Odd rendering errors on Android

Posted: Thu Sep 01, 2016 8:31 pm
by Imerion
Exactly. There is also a transparent sprite on top of it (the aura-effect). This seems to hide the asteroids behind it. (Which are normal meshes.)

Re: Odd rendering errors on Android

Posted: Fri Sep 02, 2016 7:44 am
by VilleK
Can you please make a new small test project that shows this problem with as few components as possible and upload it here? I would greatly simplify for me when trying to debug this.

Re: Odd rendering errors on Android

Posted: Sun Sep 04, 2016 2:19 am
by Imerion
Here you go! This shows the same effect. Also, any other objects behind those auras seem to be hidden. Perhaps the problem is with the rendering order.

Thanks for helping me! :)

Re: Odd rendering errors on Android

Posted: Mon Sep 05, 2016 1:16 pm
by VilleK
I checked the ZGE sources and note that depthsorting is not implemented correctly for Android and I'm not sure when I have time to fix that.

If you still want this to work, I would try the following
1. Use the ANDROID define (it is defined when building for Android) to disable certain effects.
Example:

Code: Select all

if(!ANDROID)  //Only create halo when not on Android
  createModel(HaloModel);
2. Take advantage of the fact that the default render order in ZGE is based on categories. So if you keep your "background" models as category 0 then you can be certain they are rendered before any other categories. Then use larger Category values for foreground models.

There is possibly some other problems going on in that screenshot you posted. I'll see if I have time to test some more.

Re: Odd rendering errors on Android

Posted: Mon Sep 05, 2016 6:16 pm
by Imerion
I see. Thanks for having a look!

So if I re-sort things to use categories instead, transparent textures should work? In that case that shouldn't be a problem. :)

Re: Odd rendering errors on Android

Posted: Tue Sep 06, 2016 8:51 pm
by zondarg
I checked the ZGE sources and note that depthsorting is not implemented correctly for Android and I'm not sure when I have time to fix that.
..yes, this would be great... I noticed strange behaviour of transparent images when stacked, on Android only, on Windows it looks good.
Thanks for the workaround, I'll see if I can make use of it :)

Re: Odd rendering errors on Android

Posted: Mon Jun 08, 2020 11:32 am
by Ats
Where in the code can I investigate depthsorting for Android?
Because each time I release a PC and Android version, I remember why I had to make weird choices in order to make it kind of work on both versions... And it's not helping me advancing :roll:

Re: Odd rendering errors on Android

Posted: Mon Jun 08, 2020 1:10 pm
by VilleK
The depth sort is happening in ZApplication.pas, in procedure TZApplication.RenderModels.

The problem iirc is that these lines are not supported on GLES:

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
glGetFloatv(GL_MODELVIEW_MATRIX, @TmpM);

Maybe Kjell has some knowledge that could help solve this?

Re: Odd rendering errors on Android

Posted: Mon Jun 08, 2020 1:25 pm
by Kjell
Hej Ville,
VilleK wrote: Mon Jun 08, 2020 1:10 pmThe problem iirc is that these lines are not supported on GLES:

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
glGetFloatv(GL_MODELVIEW_MATRIX, @TmpM);
Those calls are supported in ES 1.1, so that shouldn't be the problem ( since i think Ats is using "Compatible" GLBase ). Regardless, you should "route" those calls through GLDrivers.pas .. so that ES 2.0 uses GLDriverProgrammable / MPtrs.

K

Re: Odd rendering errors on Android

Posted: Tue Jun 09, 2020 7:56 am
by VilleK
Thanks Kjell.

@Ats: What happens if you change the code from this (line 690 in ZApplication.pas):

Code: Select all

  {$ifndef android}
  glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
  glGetFloatv(GL_MODELVIEW_MATRIX, @TmpM);
  Matrix := MatrixMultiply(TmpM,Matrix);
  {$else}
  Matrix := IdentityHmgMatrix;
  {$endif}
To simply this:

Code: Select all

  glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
  glGetFloatv(GL_MODELVIEW_MATRIX, @TmpM);
  Matrix := MatrixMultiply(TmpM,Matrix);
edit: Or update from github, I just made a new commit.

Re: Odd rendering errors on Android

Posted: Tue Jun 09, 2020 10:39 am
by Ats
It works perfectly. Thanks :)
Here's the new Android lib

Re: Odd rendering errors on Android

Posted: Wed Mar 17, 2021 3:35 pm
by Ats
Hi VilleK,
I'm experiencing a new bug on a new Android phone that my father bought recently. ZGE applications don't even open on it.
It's a Huawei mate 20 pro (LYA-L29).
I compiled the latest libzgeandroid.so, and it's working perfectly on other phones.

So I launched the ADB to see what's going on. Here's the result:

Code: Select all

03-17 15:52:28.393 13643 13643 E ZgeAndroid: /storage/emulated/0
03-17 15:52:28.393 13643 13643 E ZgeAndroid: /data/user/0/com.txori.omeganaut/files/
03-17 15:52:28.393 13643 13643 E ZgeAndroid: /data/user/0/com.txori.omeganaut/lib/
03-17 15:52:28.416 13643 13643 E ZgeAndroid: Found JNI_OnLoad function, calling now...
03-17 15:52:28.416 13643 13643 E ZgeAndroid: glDepthRange
03-17 15:52:28.417 13643 13643 E ZgeAndroid: glGenLists
03-17 15:52:28.417 13643 13643 E ZgeAndroid: glMateriali
03-17 15:52:28.417 13643 13643 E ZgeAndroid: glIndexMask
03-17 15:52:28.417 13643 13643 E ZgeAndroid: glListBase
03-17 15:52:28.417 13643 13643 E ZgeAndroid: glBegin
03-17 15:52:28.417 13643 13643 E ZgeAndroid: glCallList
03-17 15:52:28.418 13643 13643 E ZgeAndroid: glColor3f
03-17 15:52:28.418 13643 13643 E ZgeAndroid: glColor3fv
03-17 15:52:28.418 13643 13643 E ZgeAndroid: glColor4fv
03-17 15:52:28.418 13643 13643 E ZgeAndroid: glEnd
03-17 15:52:28.418 13643 13643 E ZgeAndroid: glColorMaterial
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glDeleteLists
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glDrawBuffer
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glGetTexImage
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glPolygonMode
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glPopAttrib
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glPushAttrib
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glRasterPos2f
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glTexCoord2f
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glVertex2f
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glVertex3f
03-17 15:52:28.419 13643 13643 E ZgeAndroid: glTexGeni
03-17 15:52:28.421 13643 13643 E ZgeAndroid: glTexImage2DMultisample
03-17 15:52:28.421 13643 13643 E ZgeAndroid: File missing: /data/user/0/com.txori.omeganaut/files/config.dat
03-17 15:52:28.421 13643 13727 E ZgeAndroid: audiocallback started
03-17 15:52:28.423 13643 13643 E ZgeAndroid: JNI_OnLoad
03-17 15:52:28.426 13643 13643 E ZgeAndroid: Found JNI_OnLoad function, calling now...
03-17 15:52:28.440 13643 13643 E ZgeAndroid: CPUs: 8
03-17 15:52:28.445 13643 13643 E ZgeAndroid: JNI_OnLoad
03-17 15:52:28.598 13643 13643 E ZgeAndroid: GLBase: 1.1
03-17 15:52:28.634 13643 13751 E ZgeAndroid: Found JNI_OnLoad function, calling now...
03-17 15:52:28.635 13643 13751 E ZgeAndroid: glDepthRange
03-17 15:52:28.636 13643 13751 E ZgeAndroid: glGenLists
03-17 15:52:28.636 13643 13751 E ZgeAndroid: glMateriali
03-17 15:52:28.636 13643 13751 E ZgeAndroid: glIndexMask
03-17 15:52:28.636 13643 13751 E ZgeAndroid: glListBase
03-17 15:52:28.636 13643 13751 E ZgeAndroid: glBegin
03-17 15:52:28.636 13643 13751 E ZgeAndroid: glCallList
03-17 15:52:28.637 13643 13751 E ZgeAndroid: glColor3f
03-17 15:52:28.637 13643 13751 E ZgeAndroid: glColor3fv
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glColor4fv
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glEnd
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glColorMaterial
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glDeleteLists
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glDrawBuffer
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glGetTexImage
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glPolygonMode
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glPopAttrib
03-17 15:52:28.638 13643 13751 E ZgeAndroid: glPushAttrib
03-17 15:52:28.639 13643 13751 E ZgeAndroid: glRasterPos2f
03-17 15:52:28.639 13643 13751 E ZgeAndroid: glTexCoord2f
03-17 15:52:28.639 13643 13751 E ZgeAndroid: glVertex2f
03-17 15:52:28.639 13643 13751 E ZgeAndroid: glVertex3f
03-17 15:52:28.639 13643 13751 E ZgeAndroid: glTexGeni
03-17 15:52:28.651 13643 13751 E ZgeAndroid: glTexImage2DMultisample
--------- beginning of crash
Do you have an idea what might happen?

(It's even crashing with old ZGE android tests)



Edit:

The only occurence of glTexImage2DMultisample in ZGE is in ZOpenGL.pas line 1481
glTexImage2DMultisample : procedure(target: GLenum; samples: GLsizei; internalformat: GLint; width: GLsizei; height: GLsizei; fixedsamplelocations: GLboolean); {$IFDEF WIN32}stdcall; {$ELSE}cdecl; {$ENDIF}

While the glTexImage2DMultisample internet definition state:
void glTexImage2DMultisample( GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);

Could that be related?

Re: Odd rendering errors on Android

Posted: Thu Mar 18, 2021 8:50 am
by VilleK
If you try building an empty ZGE app, or with just a "trace("test");" in OnLoaded does it work?

What are the crash messages?