Gorilla.Viewport Unit Reference

Overview

The Gorilla.Viewport unit provides the core viewport component for Gorilla3D rendering. It contains the TGorillaViewport class, which is the primary container for 3D scenes and replaces FireMonkey's standard TViewport3D component.

Classes

TGorillaViewport

Main viewport class for rendering 3D scenes using Gorilla3D.

Inheritance: TControl → TGorillaViewport

Platforms: All Gorilla3D supported platforms (Windows, macOS, Linux, Android, iOS)

Public Properties

Property Type Description
Context TContext3D Get or set the current 3D context. Do not change unless you know what you are doing.
CurrentCamera TCamera Returns the currently applied camera component (user or design camera).
Gizmo TControl3D Returns the embedded gizmo component (TGorillaGizmo) for design-time Control3D editing.
FPS Double Returns the potential frames per second count. Measures performance in Delphi rendering mechanism.
ViewportScale Single Returns the viewport scaling value.
Smooth Boolean Activate or deactivate smooth rendering.
SceneBounds TBoundingBox Returns the lately computed scenery boundary.
CurrentFrustum TGorillaFrustum Returns the lately computed camera frustum.
Saturation TPoint3D Get or set saturation values applied while color merging. Contains 3 parts: X=Opaque, Y=Translucent, Z=Composite saturation.
LockRendering Boolean Lock or unlock the rendering process.
EditMode Boolean Activate/deactivate edit mode at design-time (also available at runtime).
FogMode TGorillaFogMode Get or set fog computation mode (linear, exp, exp2).
FragmentDepthRendering Boolean Enable/disable pre-render pass for fragment depth rendering. Improves translucent rendering but affects performance.
CurrentRenderer TRenderer Get or set the current active renderer.
MainPassRenderer TRenderer Returns the main pass renderer.
Diagnostics TRenderingDiagnostics Access rendering diagnostics information.
RenderingList TList<TControl3D> Access the list of objects to be rendered.

Published Properties

Viewport Settings
Property Type Default Description
RendererType TRendererType ForwardRenderer Define which renderer to use: ForwardRenderer (WBOIT, recommended) or LegacyRenderer (single framebuffer).
ManualRendering Boolean False Enable manual rendering mode where viewport only renders when RenderManual() is called.
UseFixedFrameRate Boolean True (Windows) Enable fixed framerate rendering.
FixedFrameRate Integer 60 Fixed frame rate value (only affects rendering if UseFixedFrameRate is enabled).
FrustumCulling Boolean True Enable or disable frustum culling for performance optimization.
HighRes Boolean False Use high resolution if available (primarily benefits Android).
VSync Boolean False Limit frame rate between FixedFrameRate and monitor refresh rate.
NearPlane Single 0.1 Near plane rendering clipping distance.
FarPlane Single 10000.0 Far plane rendering clipping distance.
Fog Settings
Property Type Default Description
Fog Boolean False Enable or disable fog computation.
FogKind TGorillaFogKind fkLinear Fog computation mode: fkLinear, fkExp, or fkExp2.
FogDensity Single - Density of computed fog.
FogStart Single - Lower limit of fog by distance.
FogEnd Single - Upper limit of fog by distance.
FogColor TAlphaColor - Fog color (TAlphaColor format).
FogColorF TAlphaColorF - Fog color (TAlphaColorF format).
Rendering Effects
Property Type Default Description
OpaqueSaturation Single 0.0 Saturation of opaque object rendering (ForwardRenderer/DeferredRenderer only).
TranslucentSaturation Single 1.5 Saturation of translucent object rendering (ForwardRenderer/DeferredRenderer only).
CompositeSaturation Single 0.0 Saturation of final composition (ForwardRenderer/DeferredRenderer only).
EmissiveBlur Integer 0 Emissive rendering blurring intensity. 0 deactivates. Higher values affect performance.
FXAA Integer 0 Number of FXAA anti-aliasing steps (0-8). Higher values = softer edges but lower performance.
Global Illumination (GAME_PACKAGE only)
Property Type Range Description
GlobalIllumDetail Integer 0-7 Detail level of global illumination. 0=off, 1-7=increasing voxel sizes (32-512).
GlobalIllumSoftness Single 0.0-5.0 Softness of global illumination including shadows and reflections.
ShadowStrength Single 0.0-10.0 Strength/darkness of shadows in global illumination.
ReflectionStrength Single 0.0-10.0 Strength/intensity of reflections in global illumination.
Design Settings
Property Type Description
DesignPosition TPosition3D Design camera target position (for design-time usage).
DesignRotationAngle TPosition3D Design camera target rotation angle (for design-time usage).
UsingDesignCamera Boolean Use the built-in design camera or custom camera.
Diagnostics
Property Type Description
DiagnosticsActive Boolean Enable or disable rendering diagnostics collection.
RendererOutputLayer TRendererOutputLayer Control which renderer output layers to display.
Standard Component Properties

Standard FireMonkey properties: Align, Anchors, Camera, ClipChildren, ClipParent, Color, Cursor, DragMode, EnableDragHighlight, Enabled, Height, HitTest, Locked, Padding, MSAA, Margins, Opacity, PopupMenu, Position, RotationAngle, RotationCenter, Scale, Size, Visible, Width.

Events

Standard FireMonkey events: OnDragDrop, OnDragEnd, OnDragEnter, OnDragLeave, OnDragOver, OnKeyDown, OnKeyUp, OnClick, OnDblClick, OnCanFocus, OnEnter, OnExit, OnMouseDown, OnMouseMove, OnMouseUp, OnMouseWheel, OnMouseEnter, OnMouseLeave, OnPainting, OnPaint, OnResize, OnResized.

Public Methods

Rendering Control
procedure BeginUpdate(); override;
procedure EndUpdate(); override;
procedure EndUpdateWithoutInvalidate(); virtual;

Batch property changes into single render instruction to optimize performance.

procedure Lock(); virtual;
procedure Unlock(); virtual;

Lock/unlock the viewport for thread-safe operations.

procedure Invalidate(); virtual;

Mark the viewport for redraw.

procedure RenderManual(); virtual;

Manually trigger rendering when ManualRendering is enabled.

procedure ForceUpdateEffects(); virtual;

Force update of all rendering effects.

Render List Management
procedure RebuildRenderingList(); virtual;
procedure RenderRenderList(const ARenderContext: PRenderContext);
procedure RenderRenderListByMode(AOpaque: Boolean);

Manage and render the list of 3D objects.

Render Pass Management
procedure AddRenderPass(const AController: TComponent); virtual;
procedure RemoveRenderPass(const AController: TComponent); virtual;
procedure UpdateRenderPasses(); virtual;
procedure UpdateRenderPassesOnResize(); virtual;
procedure CleanupRenderPasses(const AController: TComponent); virtual;

Manage custom render passes in the pipeline.

Coordinate Conversion
function ScreenToWorld(const APoint2D: TPointF): TPoint3D; virtual;
function WorldToScreen(const APoint3D: TPoint3D): TPointF; virtual;

Convert between screen and world coordinates.

Object Selection
function ObjectAtPoint(P: TPointF): IControl; override;
function RayCastIntersect(const P: TPointF): TControl3D; virtual;

Find objects at specific screen positions using raycasting.

Camera Access
function GetDesignCamera(): TCamera; virtual;
function GetDesignCameraController(): TGorillaSmoothCameraController; virtual;

Access the built-in design camera and controller.

Screenshot
function MakeScreenshot(): FMX.Graphics.TBitmap;

Capture the current viewport rendering as a bitmap.

Gizmo Management
procedure ShowGizmo(); overload;
procedure ShowGizmo(const ACtrl: TControl3D); overload;
procedure ChangeGizmoMode(const AMode: Byte);
procedure HideGizmo();
function IsGizmoActive(): Boolean;
function GetGizmoActivatedControl(): TControl3D;

Control the design-time gizmo for object manipulation.

Design Mode
procedure StartDesignMode();
procedure EndDesignMode();

Enter and exit design mode programmatically.

Display Settings
procedure UpdateDisplayRefreshRate(); virtual;

Update the cached display refresh rate.

Helper Classes

TGorillaRenderingHelper

Helper class for rendering operations.

Public Class Methods

class function Renderable(const ACtrl: TControl3D; const AFrustum: TGorillaFrustum;
  const AComponentState: TComponentState; var ASceneBounds: TBoundingBox;
  const AFrustumCulling: Boolean; const ACheckVisibility: Boolean): Boolean;

Determine if a control should be rendered based on frustum culling and visibility.

class procedure UpdateSceneBounds(const ACtrl: TControl3D;
  const AComponentState: TComponentState; var ASceneBounds: TBoundingBox);

Update scene bounds based on a control's bounding box.

Types

TGorillaFogKind

Enumeration for fog modes (wrapper for TGorillaFogMode).

Values:

  • fkLinear - Linear fog calculation
  • fkExp - Exponential fog calculation
  • fkExp2 - Exponential squared fog calculation

TRenderingDiagnostics

Record containing rendering performance diagnostics.

Fields:

  • Enabled - Boolean indicating if diagnostics are active
  • TotalFrames - Total number of frames rendered
  • AverageFrameTime - Average time per frame in milliseconds
  • AverageFramesPerSecond - Average FPS
  • DrawCalls - Number of draw calls
  • DrawInstances - Number of draw instances
  • TotalVertexCount - Total vertices processed
  • TotalIndexCount - Total indices processed
  • RenderPasses - Number of render passes
  • RenderListSize - Size of rendering list
  • RenderedObjects - Number of objects rendered
  • DisplayRefreshRate - Monitor refresh rate

Constants

Default Frame Rates

GORILLA_FRAMERATE_FIXED_DEFAULT = 60;  // All platforms

Usage Notes

  1. Compatibility: TGorillaViewport replaces FireMonkey's TViewport3D and TForm3D. They are not compatible.

  2. Fog Requirements: Fog effect requires TGorillaDefaultMaterialSource materials and is incompatible with standard FMX materials.

  3. Performance: Use BeginUpdate/EndUpdate to batch property changes. Enable ManualRendering for better control over rendering cycles.

  4. Frustum Culling: Improves performance but may affect render passes using different view matrices.

  5. Global Illumination: Only available in GAME_PACKAGE edition.

See Also