Overriding OpenGL Rendering Parameters

From Appmethod Topics
Jump to: navigation, search

Go Up to FireMonkey Applications Guide


To increase the performance of graphical applications, you can override the OpenGL rendering parameters on iOS and Android platforms.

For example, if you do not use 3D models, you can disable depth buffer. Likewise, if you do not use filled paths or other vector canvas shapes, it is safe to disable stencil buffer. If you prefer high performance over visual quality, then you might want to use 16-bit color depth instead of 24-bit or 32-bit.

To override the OpenGL parameters:

  1. Add FMX.Platform.pas to the USES list in your unit.
  2. Write the rendering setup procedure:
    procedure RenderingSetupCallback(const Sender, Context: TObject; var ColorBits, DepthBits: Integer;
    var Stencil: Boolean; var Multisamples: Integer);
    begin
        // Override OpenGL rendering setup to use custom values.
        ColorBits := 16; // default is 24
        DepthBits := 0; // default is 24
        Stencil := False; // default is True
        Multisamples := 0; // default depends on TForm.Quality or TForm3D.Multisample
    end;
    
  3. Write the registration procedure:
    procedure RegisterRenderingSetup;
    var
        SetupService: IFMXRenderingSetupService;
    begin
        if TPlatformServices.Current.SupportsPlatformService(IFMXRenderingSetupService, IInterface(SetupService)) then
        SetupService.Subscribe(RenderingSetupCallback);
        // There is also SetupService.Unsubscribe, which removes the hook.
    end;
    
  4. Call the RegisterRenderingSetup in the initialization section of the unit.

See Also