I'm going to append to this answer as new details reveal.
Attempt 1
Adding a Timer to a form and calling this procedure fills the screen with green, so that means GL context is already there:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
glClearColor(0, 1, 0, 0);
glClear(GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT);
eglSwapBuffers(TCustomAndroidContext.SharedDisplay, TCustomAndroidContext.SharedSurface);
end;
Of course rendering on Timer in controlled environment is definitely a bad idea. The app kept on flickering on minimize/maximize.
Attempt 2
I have overridden TContextAndroid
class (made a copy of Delphi unit and placed it into my app folder). I was able to inject custom code into DoEndScene
method and it has successfully executed it - for this test just a simple glClear(GL_COLOR_BUFFER_BIT);
. This has filled the entire application area with color. This time the application did not flickered and behaved just like normal.
Attempt 3
Here's the code that made it to work and that does not looks hacky:
types
TMyForm = class(TForm3D)
procedure Form3DRender(Sender: TObject; Context: TContext3D);
end;
implementation
//Event handler for TForm.OnRender
procedure TMyForm.Form3DRender(Sender: TObject; Context: TContext3D);
begin
glClearColor(1, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
end;