Support Forum G3D Web Page |
Optional base class for quickly creating 3D applications.
More...
Inherited by G3D::VRApp.
Classes | |
class | DebugLabel |
class | DebugShape |
class | DebugVRMirrorMode |
class | Settings |
class | SubmitToDisplayMode |
Public Types | |
enum | { REAL_TIME = -100, MATCH_REAL_TIME_TARGET = -200 } |
For use as the simulationStepDuration argument of setFrameDuration. More... | |
enum | Action { ACTION_NONE, ACTION_QUIT, ACTION_SHOW_CONSOLE } |
Public Member Functions | |
GApp (const Settings &options=Settings(), OSWindow *window=nullptr, RenderDevice *rd=nullptr, bool createWindowOnNull=true) | |
virtual | ~GApp () |
virtual const shared_ptr< Camera > & | activeCamera () const |
The currently active camera for the primary view. More... | |
const shared_ptr< Entity > & | activeListener () const |
May be nullptr. More... | |
virtual void | addWidget (const shared_ptr< Widget > &module, bool setFocus=true) |
Installs a module. More... | |
shared_ptr< Manipulator > | cameraManipulator () const |
virtual const shared_ptr< Camera > & | debugCamera () const |
Exposes the debugging camera. More... | |
virtual void | drawDebugShapes () |
Draw everything in debugShapeArray. More... | |
virtual void | drawMessage (const String &message) |
Draw a simple, short message in the center of the screen and swap the buffers. More... | |
void | drawTitle (const String &title, const String &subtitle, const Any &any, const Color3 &fontColor, const Color4 &backColor) |
Draws a title card. More... | |
RealTime | frameDuration () const |
1.0 / desired frame rate More... | |
const GazeTracker::Gaze & | gazeForEye (int eye) const |
const shared_ptr< GazeTracker > & | gazeTracker () const |
const Stopwatch & | graphicsWatch () const |
virtual CFrame | headFrame () const |
The reference fram of the "XR Head" entity if it exists, otherwise the activeCamera frame. More... | |
void | initializeOpenGL (RenderDevice *rd, OSWindow *window, bool createWindowIfNull, const Settings &settings) |
Called from GApp constructor to initialize OpenGL and openGL-dependent state. More... | |
virtual void | loadScene (const String &sceneName) |
Load a new scene. More... | |
const Stopwatch & | logicWatch () const |
bool | lowerFrameRateInBackground () const |
const Stopwatch & | networkWatch () const |
virtual void | onAfterLoadScene (const Any &any, const String &sceneName) |
Invoked by loadScene() after the scene has been loaded. More... | |
RealTime | previousRealTimeStep () const |
Actual wall-clock time elapsed between the previous two frames. More... | |
SimTime | previousSimTimeStep () const |
A non-negative number that is the amount that time is was advanced by in the previous frame. More... | |
RealTime | realTime () const |
Accumulated wall-clock time since init was called on this applet. More... | |
RealTime | realTimeTargetDuration () const |
1.0 / desired frame rate More... | |
void | removeAllDebugShapes () |
Clears all debug shapes, regardless of their pending display time. More... | |
void | removeDebugShape (DebugID id) |
Clears just this debug shape (if it exists), regardless of its pending display time. More... | |
virtual void | removeWidget (const shared_ptr< Widget > &module) |
The actual removal of the module may be delayed until the next frame. More... | |
const shared_ptr< Renderer > & | renderer () |
int | run () |
Call this to run the app. More... | |
virtual void | saveScene () |
Save the current scene over the one on disk. More... | |
const shared_ptr< Scene > & | scene () const |
virtual const SceneVisualizationSettings & | sceneVisualizationSettings () const |
ScreenCapture * | screenCapture () const |
virtual void | setActiveCamera (const shared_ptr< Camera > &camera) |
The default camera is specified by the scene. More... | |
virtual void | setActiveListener (const shared_ptr< Entity > &listener) |
The default listener is the activeCamera object. More... | |
void | setCameraManipulator (const shared_ptr< Manipulator > &man) |
The manipulator that positions the debugCamera() every frame. More... | |
virtual void | setExitCode (int code=0) |
Invoke to true to end the program at the end of the next event loop. More... | |
virtual void | setFrameDuration (RealTime realTimeTargetDuration, SimTime simulationStepDuration=MATCH_REAL_TIME_TARGET) |
virtual void | setLowerFrameRateInBackground (bool s) |
If true, the wallClockTargetDuration from setFrameDuration() is ignored when the OSWindow does not have focus and the program switches to running 4fps to avoid slowing down the foreground application. More... | |
virtual void | setRealTime (RealTime r) |
virtual void | setSimTime (SimTime s) |
virtual void | setSimulationTimeScale (float s) |
Set the rate at which simulation time actually advances compared to the rate specified by setFrameDuration. More... | |
const Settings & | settings () const |
shared_ptr< GuiWindow > | show (const shared_ptr< Texture > &t, const String &windowCaption="") |
Displays the texture in a new GuiWindow. More... | |
shared_ptr< GuiWindow > | show (const shared_ptr< PixelTransferBuffer > &t, const String &windowCaption="") |
shared_ptr< GuiWindow > | show (const shared_ptr< Image > &t, const String &windowCaption="") |
shared_ptr< TextureBrowserWindow > | showInTextureBrowser (const String &textureName, Rect2D rect=Rect2D::empty()) |
Shows a texture by name. More... | |
shared_ptr< TextureBrowserWindow > | showInTextureBrowser (const shared_ptr< Texture > &texture, Rect2D rect=Rect2D::empty()) |
SimTime | simStepDuration () const |
May also be REAL_TIME or MATCH_REAL_TIME_TARGET. More... | |
SimTime | simTime () const |
In-simulation time since init was called on this applet. More... | |
float | simulationTimeScale () const |
const Stopwatch & | simulationWatch () const |
virtual void | swapBuffers () |
shared_ptr< Texture > | textureByName (const String &name) const |
Returns a texture by its name, or nullptr if not found. More... | |
template<class SceneSubclass = Scene> | |
shared_ptr< SceneSubclass > | typedScene () const |
const Stopwatch & | userInputWatch () const |
void | vscreenPrintf (const char *fmt, va_list argPtr) |
const Stopwatch & | waitWatch () const |
OSWindow * | window () const |
Static Public Member Functions | |
static GApp * | current () |
Returns a pointer to the current GApp. More... | |
static void | setCurrent (GApp *gApp) |
Sets the current GApp; the current GApp is used for debug drawing. More... | |
Public Attributes | |
bool | catchCommonExceptions |
When true, there is an assertion failure if an exception is thrown. More... | |
GConsoleRef | console |
Command console. More... | |
String | dataDir |
Initialized to GApp::Settings::dataDir, or if that is "<AUTO>", to FilePath::parent(System::currentProgramFilename()). More... | |
std::vector< String > | dataDirs |
Initialized to empty. More... | |
bool | dataDirsAddedToScene = false |
shared_ptr< GFont > | debugFont |
nullptr if not loaded More... | |
Array< DebugLabel > | debugLabelArray |
Labels to be rendered each frame, updated at the same times as debugShapeArray. More... | |
GuiPane * | debugPane |
debugWindow->pane() More... | |
Array< DebugShape > | debugShapeArray |
Shapes to be rendered each frame. More... | |
shared_ptr< GuiWindow > | debugWindow |
Add your own debugging controls to this window. More... | |
shared_ptr< DeveloperWindow > | developerWindow |
The window that displays buttons for debugging. More... | |
Action | escapeKeyAction |
When true an GKey::ESCAPE keydown event quits the program. More... | |
GazeTracker::Gaze * | m_gaze |
Gaze vector for the current eye, relative to the activeCamera(). More... | |
GazeTracker::Gaze | m_gazeArray [2] |
Gaze for each eye for the current frame. More... | |
shared_ptr< GazeTracker > | m_gazeTracker |
Defaults to a cyclops EmulatedGazeTracker. More... | |
DebugID | m_lastDebugID |
Last DebugShape::id issued. More... | |
bool | manageUserInput |
When true, the G3D::UserInput->beginEvents/endEvents processing is handled for you by calling processGEventQueue() before G3D::GApp::onUserInput is called. More... | |
RenderDevice * | renderDevice |
bool | showDebugText |
When true, screenPrintf prints to the screen. More... | |
bool | showRenderingStats |
When true, debugTextWidget prints the frame rate and other data to the screen. More... | |
UserInput * | userInput |
Protected Member Functions | |
void | beginRun () |
Initializes state at the beginning of onRun, including calling onCleanup. More... | |
void | createDeveloperHUD () |
Call from onInit to create the developer HUD. More... | |
void | endRun () |
Cleans up at the end of onRun, including calling onCleanup. More... | |
virtual void | extendGBufferSpecification (GBuffer::Specification &spec) |
Ensures any GBuffer using. More... | |
virtual void | onAfterEvents () |
virtual void | onAfterSimulation (RealTime rdt, SimTime sdt, SimTime idt) |
Invoked after onSimulation is run on the installed GModules and GApp. More... | |
virtual void | onAI () |
Update any state you need to here. More... | |
virtual void | onBeforeSimulation (RealTime &rdt, SimTime &sdt, SimTime &idt) |
Invoked before onSimulation is run on the installed GModules and GApp. More... | |
virtual void | onCleanup () |
Unload/deallocate your data here. More... | |
virtual void | onConsoleCommand (const String &cmd) |
Invoked when a user presses enter in the in-game console. More... | |
virtual void | oneFrame () |
A single frame of rendering, simulation, AI, events, networking, etc. More... | |
virtual bool | onEvent (const GEvent &event) |
It is recommended to override onUserInput() instead of this method. More... | |
virtual void | onGraphics (RenderDevice *rd, Array< shared_ptr< Surface > > &surface, Array< shared_ptr< Surface2D > > &surface2D) |
Rendering callback used to paint the screen. More... | |
virtual void | onGraphics2D (RenderDevice *rd, Array< shared_ptr< Surface2D > > &surface2D) |
Called from the default onGraphics. More... | |
virtual void | onGraphics3D (RenderDevice *rd, Array< shared_ptr< Surface > > &surface) |
Called from the default onGraphics. More... | |
virtual void | onInit () |
Load your data here. More... | |
virtual void | onNetwork () |
For a networked app, override this to implement your network message polling. More... | |
virtual void | onPose (Array< shared_ptr< Surface > > &posed3D, Array< shared_ptr< Surface2D > > &posed2D) |
Called before onGraphics. More... | |
virtual void | onPostProcessHDR3DEffects (RenderDevice *rd) |
Invoked by the default onGraphics3D to perform depth of field and motion blur post-processgiing on the m_framebuffer at high dynamic range. More... | |
void | onRun () |
Helper for run() that actually starts the program loop. More... | |
virtual void | onSimulation (RealTime rdt, SimTime sdt, SimTime idt) |
Override this with your simulation code. More... | |
virtual void | onUserInput (class UserInput *userInput) |
Routine for processing user input from the previous frame. More... | |
virtual void | onWait (RealTime waitTime) |
Task to be used for frame rate limiting. More... | |
virtual void | processGEventQueue () |
Processes all pending events on the OSWindow queue into the userInput. More... | |
virtual void | renderCubeMap (RenderDevice *rd, Array< shared_ptr< Texture > > &output, const shared_ptr< Camera > &camera, const shared_ptr< Texture > &depthMap, int resolution=1024) |
Helper for generating cube maps. More... | |
virtual void | resize (int w, int h) |
Change the size of the underlying Film. More... | |
virtual void | sampleGazeTrackerData () |
virtual void | setScene (const shared_ptr< Scene > &s) |
void | setSubmitToDisplayMode (SubmitToDisplayMode m) |
Defaults to SubmitMode::MAXIMIZE_THROUGHPUT. More... | |
SubmitToDisplayMode | submitToDisplayMode () const |
Static Protected Member Functions | |
static void | staticConsoleCallback (const String &command, void *me) |
Protected Attributes | |
Array< String > | debugText |
Strings that have been printed with screenPrintf. More... | |
shared_ptr< Camera > | m_activeCamera |
The currently selected camera. More... | |
shared_ptr< MarkerEntity > | m_activeCameraMarker |
Follows the activeCamera. More... | |
shared_ptr< Entity > | m_activeListener |
shared_ptr< class AmbientOcclusion > | m_ambientOcclusion |
Default/current AO object for the primary view, allocated in GApp::GApp. More... | |
shared_ptr< Manipulator > | m_cameraManipulator |
Used to find the frame for defaultCamera. More... | |
int | m_currentEyeIndex |
Set by onGraphics for each onGraphics3D call in VRApp. More... | |
shared_ptr< Camera > | m_debugCamera |
A camera that is driven by the debugController. More... | |
shared_ptr< FirstPersonManipulator > | m_debugController |
Allows first person (Quake game-style) control using the arrow keys or W,A,S,D and the mouse. More... | |
Color4 | m_debugTextColor |
std::mutex | m_debugTextMutex |
Color4 | m_debugTextOutlineColor |
shared_ptr< DebugTextWidget > | m_debugTextWidget |
shared_ptr< DepthOfField > | m_depthOfField |
shared_ptr< Framebuffer > | m_depthPeelFramebuffer |
shared_ptr< Framebuffer > | m_deviceFramebuffer |
The current device [LDR] framebuffer. More... | |
bool | m_endProgram |
int | m_exitCode |
shared_ptr< Film > | m_film |
Allocated if GApp::Settings::FilmSettings::enabled was true when the constructor executed. More... | |
shared_ptr< Framebuffer > | m_framebuffer |
The framebuffer that will be used by the default onGraphics3D. More... | |
shared_ptr< GBuffer > | m_gbuffer |
Bound to the current GBuffer, which is m_osWindowGBuffer by default. More... | |
GBuffer::Specification | m_gbufferSpecification |
Stopwatch | m_graphicsWatch |
RealTime | m_lastFrameOverWait |
Used to track how much onWait overshot its desired target during the previous frame. More... | |
RealTime | m_lastTime |
RealTime | m_lastWaitTime |
Used by onWait for elapsed time. More... | |
Stopwatch | m_logicWatch |
bool | m_lowerFrameRateInBackground |
If true, the wallClockTargetDuration from setFrameDuration() is ignored when the OSWindow does not have focus and the program switches to running 4fps to avoid slowing down the foreground application. More... | |
shared_ptr< MotionBlur > | m_motionBlur |
Stopwatch | m_networkWatch |
RealTime | m_now |
Used by onSimulation for elapsed time. More... | |
shared_ptr< Framebuffer > | m_osWindowDeviceFramebuffer |
The (probably low dynamic range, one sample per pixel) OpenGL hardware framebuffer for the window(). More... | |
shared_ptr< GBuffer > | m_osWindowGBuffer |
GBuffer used for the OSWindow. More... | |
shared_ptr< Framebuffer > | m_osWindowHDRFramebuffer |
Framebuffer used for rendering the 3D portion of the scene. More... | |
Array< shared_ptr< Surface2D > > | m_posed2D |
Array< shared_ptr< Surface > > | m_posed3D |
Stopwatch | m_poseWatch |
float | m_previousRealTimeStep |
float | m_previousSimTimeStep |
RealTime | m_realTime |
shared_ptr< Renderer > | m_renderer |
Used by the default onGraphics3D to render Surfaces. More... | |
int | m_renderPeriod |
onPose(), onGraphics(), and onWait() execute once every m_renderPeriod simulation frames. More... | |
Settings | m_settings |
The original settings. More... | |
SimTime | m_simTime |
float | m_simTimeScale |
float | m_simTimeStep |
SimTime seconds per frame,. More... | |
Stopwatch | m_simulationWatch |
Stopwatch | m_userInputWatch |
Stopwatch | m_waitWatch |
float | m_wallClockTargetDuration |
Seconds per frame target for the entire system. More... | |
shared_ptr< WidgetManager > | m_widgetManager |
shared_ptr< XR > | m_xrSystem |
The low-level XR API. More... | |
shared_ptr< XRWidget > | m_xrWidget |
Static Protected Attributes | |
static GApp * | s_currentGApp |
Pointer to the current GApp. More... | |
Friends | |
class | DebugTextWidget |
class | DeveloperWindow |
class | OSWindow |
class | SceneEditorWindow |
class | Shader |
Optional base class for quickly creating 3D applications.
GApp has several event handlers implemented as virtual methods. It invokes these in a cooperative, round-robin fashion. This avoids the need for threads in most applications. The methods are, in order of invocation from GApp::oneFrame:
To customize the rendering algorithm without modifying the post-processing setup, you can use the default GApp::onGraphics3D and simply change the GApp::m_renderer by subclassing G3D::Renderer.
The GApp::run method starts the main loop. It invokes GApp::onInit, runs the main loop until completion, and then invokes GApp::onCleanup.
onWait runs before onGraphics because the beginning of onGraphics causes the CPU to block, waiting for the GPU to complete the previous frame.
When you override a method, invoke the GApp version of that method to ensure that Widgets still work properly. This allows you to control whether your per-app operations occur before or after the Widget ones.
There are a number of framebuffers:
anonymous enum |
For use as the simulationStepDuration argument of setFrameDuration.
enum G3D::GApp::Action |
G3D::GApp::GApp | ( | const Settings & | options = Settings() , |
OSWindow * | window = nullptr , |
||
RenderDevice * | rd = nullptr , |
||
bool | createWindowOnNull = true |
||
) |
window | If null, an OSWindow will be created for you. This argument is useful for substituting a different window system (e.g., GlutWindow) |
createWindowOnNull | Create the window or renderDevice if they are nullptr. Setting createWindowOnNull = false allows a subclass to explicitly decide when to invoke those calls. |
|
virtual |
|
inlinevirtual |
The currently active camera for the primary view.
The special G3D::MarkerEntity named "(Active Camera Marker)" follows whichever camera is currently active. It does not update when the camera is not in the scene.
|
inline |
May be nullptr.
|
virtual |
Installs a module.
Actual insertion may be delayed until the next frame.
Referenced by setCameraManipulator().
|
protected |
Initializes state at the beginning of onRun, including calling onCleanup.
|
inline |
|
protected |
Call from onInit to create the developer HUD.
|
static |
|
inlinevirtual |
Exposes the debugging camera.
|
virtual |
Draw everything in debugShapeArray.
Subclasses should call from onGraphics3D() or onGraphics(). This will sort the debugShapeArray from back to front according to the current camera.
|
virtual |
Draw a simple, short message in the center of the screen and swap the buffers.
Useful for loading screens and other slow operations.
void G3D::GApp::drawTitle | ( | const String & | title, |
const String & | subtitle, | ||
const Any & | any, | ||
const Color3 & | fontColor, | ||
const Color4 & | backColor | ||
) |
Draws a title card.
|
protected |
Cleans up at the end of onRun, including calling onCleanup.
|
protectedvirtual |
Ensures any GBuffer using.
spec | has all of the fields necessary to render the effects on this GApp. By default, extends the specification to handle the current AmbientOcclusionSettings, DepthOfFieldSettings, MotionBlurSettings, and FilmSettings. |
Called from GApp::onGraphics3D.
|
inline |
1.0 / desired frame rate
|
inline |
|
inline |
|
inline |
|
virtual |
The reference fram of the "XR Head" entity if it exists, otherwise the activeCamera frame.
This allows unifying code across desktop and VR rendering. The VR APIs do not move the activeCamera with the HMD because XRWidget leaves that unmodified to represent the default tracking volume.
void G3D::GApp::initializeOpenGL | ( | RenderDevice * | rd, |
OSWindow * | window, | ||
bool | createWindowIfNull, | ||
const Settings & | settings | ||
) |
Called from GApp constructor to initialize OpenGL and openGL-dependent state.
Can't be virtual because it is invoked from a constructor, but allows subclasses to perform their own pre-OpenGL steps.
|
virtual |
Load a new scene.
A GApp may invoke this on itself, and the SceneEditorWindow will invoke this automatically when the user presses Reload or chooses a new scene from the GUI.
|
inline |
|
inline |
|
inline |
|
protectedvirtual |
|
inlinevirtual |
Invoked by loadScene() after the scene has been loaded.
This allows the GApp to modify the scene or load custom properties from the any structure.
The scene can be accessed using the scene() method.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
Invoked after onSimulation is run on the installed GModules and GApp.
Not used by most programs.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
Update any state you need to here.
This is a good place for AI code, for example. Called after onNetwork and onUserInput, before onSimulation.
|
protectedvirtual |
Invoked before onSimulation is run on the installed GModules and GApp.
This is not used by most programs; it is primarily a hook for those performing extensive physical simulation on the GModules that need a setup and cleanup step.
If you mutate the timestep arguments then those mutated time steps are passed to the onSimulation method. However, the accumulated time will not be affected by the changed timestep.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
Unload/deallocate your data here.
Unlike the destructor, this catches common exceptions. It is called after the last frame is processed.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
Invoked when a user presses enter in the in-game console.
The default implementation ends the program if the command is "exit".
Sample implementation:
void App::onConsoleCommand(const String& str) { // Add console processing here TextInput t(TextInput::FROM_STRING, str); if (t.isValid() && (t.peek().type() == Token::SYMBOL)) { String cmd = toLower(t.readSymbol()); if (cmd == "exit") { setExitCode(0); return; } else if (cmd == "help") { printConsoleHelp(); return; } // Add commands here } console->printf("Unknown command\n"); printConsoleHelp(); } void App::printConsoleHelp() { console->printf("exit - Quit the program\n"); console->printf("help - Display this text\n\n"); console->printf("~/ESC - Open/Close console\n"); console->printf("F2 - Enable first-person camera control\n"); console->printf("F4 - Record video\n"); }
|
protectedvirtual |
A single frame of rendering, simulation, AI, events, networking, etc.
Invokes the onXXX methods and performs timing.
|
protectedvirtual |
It is recommended to override onUserInput() instead of this method.
Override if you need to explicitly handle events raw in the order they appear rather than once per frame by checking the current system state.
Note that the userInput contains a record of all keys pressed/held, mouse, and joystick state, so you do not have to override this method to handle basic input events.
Return true if the event has been consumed (i.e., no-one else including GApp should process it further).
The default implementation does nothing.
This runs after the m_widgetManager's onEvent, so a widget may consume events before the App sees them.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
Rendering callback used to paint the screen.
Called automatically. RenderDevice::beginFrame and endFrame are called for you before this is invoked.
The default implementation calls onGraphics2D and onGraphics3D.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
Called from the default onGraphics.
|
protectedvirtual |
Called from the default onGraphics.
Override and implement.
The default implementation is a full forward renderer with AO and post processing. See the starter sample project for equivalent code.
|
protectedvirtual |
Load your data here.
Unlike the constructor, this catches common exceptions. It is called before the first frame is processed.
Reimplemented in G3D::VRApp.
|
protectedvirtual |
For a networked app, override this to implement your network message polling.
|
protectedvirtual |
Called before onGraphics.
Append any models that you want rendered (you can also explicitly pose and render in your onGraphics method). The provided arrays will already contain posed models from any installed Widgets.
|
protectedvirtual |
Invoked by the default onGraphics3D to perform depth of field and motion blur post-processgiing on the m_framebuffer at high dynamic range.
Does not include the tone-mapping (Film::exposeAndRender) HDR to LDR pass.
|
protected |
Override this with your simulation code.
Called from GApp::run.
The default implementation invokes WidgetManager::onSimulation on m_widgetManager, Scene::onSimulation on scene(), and GCamera::onSimulation on GApp::m_debugCamera in that order.
simTime(), idealSimTime() and realTime() are incremented after onSimulation is called, so at the beginning of call the current time is the end of the previous frame.
rdt | Elapsed real-world time since the last call to onSimulation. |
sdt | Elapsed sim-world time since the last call to onSimulation, computed by multiplying the wall-clock time by the simulation time rate. |
idt | Elapsed ideal sim-world time. Use this for perfectly reproducible timing results. Ideal time always advances by the desiredFrameDuration * simTimeRate, no matter how much wall-clock time has elapsed. |
|
protectedvirtual |
Routine for processing user input from the previous frame.
Default implementation does nothing.
|
protectedvirtual |
Task to be used for frame rate limiting.
Overriding onWait is not recommended unless you have significant computation tasks that cannot be executed conveniently on a separate thread.
Frame rate limiting is useful to avoid overloading a maching that is running background tasks and for situations where fixed time steps are needed for simulation and there is no reason to render faster.
Default implementation System::sleep()s on waitTime (which is always non-negative)
|
inline |
Actual wall-clock time elapsed between the previous two frames.
|
inline |
A non-negative number that is the amount that time is was advanced by in the previous frame.
Never an enum value. For the first frame, this is the amount that time will be advanced by if rendering runs at speed.
|
protectedvirtual |
Processes all pending events on the OSWindow queue into the userInput.
This is automatically called once per frame. You can manually call it more frequently to get higher resolution mouse tracking or to prevent the OS from locking up (and potentially crashing) while in a lengthy onGraphics call.
|
inline |
Accumulated wall-clock time since init was called on this applet.
Since this time is accumulated, it may drift from the true wall-clock obtained by System::time().
|
inline |
void G3D::GApp::removeAllDebugShapes | ( | ) |
Clears all debug shapes, regardless of their pending display time.
void G3D::GApp::removeDebugShape | ( | DebugID | id | ) |
Clears just this debug shape (if it exists), regardless of its pending display time.
|
virtual |
The actual removal of the module may be delayed until the next frame.
Referenced by setCameraManipulator().
|
protectedvirtual |
Helper for generating cube maps.
Invokes GApp::onGraphics3D six times, once for each face of a cube map. This is convenient both for microrendering and for generating cube maps to later use offline.
certain post processing effects are applied to the final image. Motion blur and depth of field are not but AO is if enabled. However AO will causes artifacts on the final image when enabled.
output | If empty or the first element is nullptr, this is set to a series of new reslolution x resolution ImageFormat::RGB16F() textures. Otherwise, the provided elements are used. Textures are assumed to be square. The images are generated in G3D::CubeFace order. |
camera | the camera will have all of its parameters reset before the end of the call. |
depthMap | Optional pre-allocated depth texture to use as the depth map when rendering each face. Will be allocated to match the texture resolution if not provided. The default depth format is ImageFormat::DEPTH24(). |
Example:
|
inline |
|
protectedvirtual |
Change the size of the underlying Film.
Called by GApp::GApp() and GApp::onEvent(). This is not an event handler. If you want to be notified when your app is resized, override GApp::onEvent to handle the resize event (just don't forget to call GApp::onEvent as well).
The guard band sizes are added to the specified width and height
int G3D::GApp::run | ( | ) |
Call this to run the app.
|
protectedvirtual |
|
virtual |
Save the current scene over the one on disk.
|
inline |
|
virtual |
|
inline |
|
virtual |
The default camera is specified by the scene.
Use the F2 key under the developer HUD to quickly switch to the debug camera. During rendering (e.g., by VRApp) the active camera may be temporarily changed.
If the scene() is not null, also creates a G3D::MarkerEntity named "activeCamera" in the scene that is at the position of this camera.
Reimplemented in G3D::VRApp.
|
inlinevirtual |
The default listener is the activeCamera object.
Set to nullptr to disable actively setting the underlying AudioDevice::setListener3DAttributes every frame if you intend to change those explicitly in your app.
The default value is scene()->entity("(Active Camera Marker)")
.
|
inline |
The manipulator that positions the debugCamera() every frame.
By default, this is set to an instance of G3D::FirstPersonManipulator. This may be set to shared_ptr<Manipulator>()
to disable explicit camera positioning.
Setting a camera manipulator automatically also adds it as a Widget if it is not already present. Overriding the camera manipulator automatically removes the previous manipulator as a Widget.
Example:
|
static |
|
virtual |
Invoke to true to end the program at the end of the next event loop.
|
inlinevirtual |
realTimeTargetDuration | Target duration between successive frames. If simulating and rendering (and all other onX methods) consume less time than this, then GApp will invoke onWait() to throttle. If the frame takes more time than wallClockTargetDuration, then the system will proceed to the next frame as quickly as it can. |
simulationStepDuration | Amount to increment simulation time by each frame under normal circumstances (this is modified by setSimulationTimeScale) Special values are GApp::REAL_TIME, GApp::MATCH_REAL_TIME_TARGET. |
|
inlinevirtual |
If true, the wallClockTargetDuration from setFrameDuration() is ignored when the OSWindow does not have focus and the program switches to running 4fps to avoid slowing down the foreground application.
|
virtual |
|
inlineprotectedvirtual |
|
virtual |
|
inlinevirtual |
|
inlineprotected |
Defaults to SubmitMode::MAXIMIZE_THROUGHPUT.
SubmitToDisplayMode::EXPLICIT requires an explicit call to swapBuffers()–GApp does not perform swapping in this case.
SubmitToDisplayMode::MAXIMIZE_THROUGHPUT swaps in the middle of the next frame, as soon as it needs to write to the hardware framebuffer to maximize throughput (framerate). This allows CPU physics, network, audio, AI, scene traversal, etc. to overlap GPU rendering, and even allows GPU work submission for offscreen buffers for the next frame to overlap GPU execution of the current frame.
SubmitToDisplayMode::BALANCE swaps at the beginning of the next frame to balance throughput and latency. This allows CPU physics, network, audio, AI, scene traversal, etc. to overlap GPU rendering.
SubmitToDisplayMode::MINIMIZE_LATENCY swaps at the end of the current frame to minimize latency. This blocks the CPU on the GPU until the currently-submitted work is complete.
|
inline |
shared_ptr<GuiWindow> G3D::GApp::show | ( | const shared_ptr< Texture > & | t, |
const String & | windowCaption = "" |
||
) |
Displays the texture in a new GuiWindow.
shared_ptr<GuiWindow> G3D::GApp::show | ( | const shared_ptr< PixelTransferBuffer > & | t, |
const String & | windowCaption = "" |
||
) |
shared_ptr<GuiWindow> G3D::GApp::show | ( | const shared_ptr< Image > & | t, |
const String & | windowCaption = "" |
||
) |
shared_ptr<TextureBrowserWindow> G3D::GApp::showInTextureBrowser | ( | const String & | textureName, |
Rect2D | rect = Rect2D::empty() |
||
) |
Shows a texture by name.
Convenient for creating debugging views of textures that are not exposed by other objects. Returns nullptr if the texture is not currently in memory.
shared_ptr<TextureBrowserWindow> G3D::GApp::showInTextureBrowser | ( | const shared_ptr< Texture > & | texture, |
Rect2D | rect = Rect2D::empty() |
||
) |
|
inline |
May also be REAL_TIME or MATCH_REAL_TIME_TARGET.
|
inline |
In-simulation time since init was called on this applet.
Takes into account simTimeSpeed. Automatically incremented after ooSimulation.
|
inline |
|
inline |
|
staticprotected |
|
inlineprotected |
|
virtual |
Reimplemented in G3D::VRApp.
Returns a texture by its name, or nullptr if not found.
Useful for bypassing language protection mechanisms when creating debugging GUIs
|
inline |
|
inline |
void G3D::GApp::vscreenPrintf | ( | const char * | fmt, |
va_list | argPtr | ||
) |
|
inline |
|
inline |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
bool G3D::GApp::catchCommonExceptions |
When true, there is an assertion failure if an exception is thrown.
Default is true.
GConsoleRef G3D::GApp::console |
Command console.
String G3D::GApp::dataDir |
Initialized to GApp::Settings::dataDir, or if that is "<AUTO>", to FilePath::parent(System::currentProgramFilename()).
To make your program distributable, override the default and copy all data files you need to a local directory. Recommended setting is "data/" or "./", depending on where you put your data relative to the executable.
Your data directory must contain the default debugging font, "console-small.fnt", unless you change it.
std::vector<String> G3D::GApp::dataDirs |
Initialized to empty.
Used for additional data directories in projects that have data in multiple folders in the filesystem hierarchy. Use std::vector for convenience when calling System::setAppDataDirs(const std::vector<String>& dataDirs).
bool G3D::GApp::dataDirsAddedToScene = false |
shared_ptr<GFont> G3D::GApp::debugFont |
nullptr if not loaded
Array<DebugLabel> G3D::GApp::debugLabelArray |
Labels to be rendered each frame, updated at the same times as debugShapeArray.
GuiPane* G3D::GApp::debugPane |
debugWindow->pane()
Array<DebugShape> G3D::GApp::debugShapeArray |
Shapes to be rendered each frame.
Added to by G3D::debugDraw. Rendered by drawDebugShapes(); Automatically cleared once per frame.
Strings that have been printed with screenPrintf.
Protected by m_debugTextMutex.
shared_ptr<GuiWindow> G3D::GApp::debugWindow |
Add your own debugging controls to this window.
shared_ptr<DeveloperWindow> G3D::GApp::developerWindow |
The window that displays buttons for debugging.
If GApp::Settings::useDeveloperTools is true this will be created and added as a Widget on the GApp. Otherwise this will be nullptr.
Action G3D::GApp::escapeKeyAction |
When true an GKey::ESCAPE keydown event quits the program.
(default is true)
|
protected |
|
protected |
Follows the activeCamera.
In the Scene.
|
protected |
Referenced by activeListener(), and setActiveListener().
|
protected |
Default/current AO object for the primary view, allocated in GApp::GApp.
|
protected |
Used to find the frame for defaultCamera.
Referenced by cameraManipulator(), and setCameraManipulator().
|
protected |
|
protected |
A camera that is driven by the debugController.
This is a copy of the default camera from the scene, but is not itself in the scene.
Do not reassign this–the CameraControlWindow is hardcoded to the original one.
Referenced by debugCamera().
|
protected |
Allows first person (Quake game-style) control using the arrow keys or W,A,S,D and the mouse.
To disable, use:
setCameraManipulator(nullptr);
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Allocated if GApp::Settings::FilmSettings::enabled was true when the constructor executed.
Automatically resized by resize() when the screen size changes.
|
protected |
The framebuffer that will be used by the default onGraphics3D.
GApp binds this to m_osWindowHDRFramebuffer by default. VRApp binds it to VRApp::m_hmdHDRFramebuffer[VRApp::m_currentEye].
GazeTracker::Gaze* G3D::GApp::m_gaze |
Gaze vector for the current eye, relative to the activeCamera().
This is a pointer into m_gazeArray
GazeTracker::Gaze G3D::GApp::m_gazeArray[2] |
Gaze for each eye for the current frame.
Referenced by gazeForEye().
shared_ptr<GazeTracker> G3D::GApp::m_gazeTracker |
Defaults to a cyclops EmulatedGazeTracker.
Set to a binocular EmulatedGazeTracker for a slightly slower but much better binocular simulation (tip: turn on Modle::accelerated ray casts for that), or instantiate a real gaze tracker if you have one.
Referenced by gazeTracker().
|
protected |
Bound to the current GBuffer, which is m_osWindowGBuffer by default.
|
protected |
|
protected |
Referenced by graphicsWatch().
DebugID G3D::GApp::m_lastDebugID |
Last DebugShape::id issued.
|
protected |
Used to track how much onWait overshot its desired target during the previous frame.
|
protected |
|
protected |
Used by onWait for elapsed time.
|
protected |
Referenced by logicWatch().
|
protected |
If true, the wallClockTargetDuration from setFrameDuration() is ignored when the OSWindow does not have focus and the program switches to running 4fps to avoid slowing down the foreground application.
Referenced by lowerFrameRateInBackground(), and setLowerFrameRateInBackground().
|
protected |
|
protected |
Referenced by networkWatch().
|
protected |
Used by onSimulation for elapsed time.
|
protected |
The (probably low dynamic range, one sample per pixel) OpenGL hardware framebuffer for the window().
Initialized in initializeOpenGL().
|
protected |
|
protected |
Framebuffer used for rendering the 3D portion of the scene.
Includes a color guard band. This is then resolved to m_osWindowDeviceFramebuffer.
|
protected |
|
protected |
Referenced by previousRealTimeStep().
|
protected |
Referenced by previousSimTimeStep().
|
protected |
Referenced by realTime().
|
protected |
Used by the default onGraphics3D to render Surfaces.
Referenced by renderer().
|
protected |
onPose(), onGraphics(), and onWait() execute once every m_renderPeriod simulation frames.
This allows UI/network/simulation to be clocked much faster than rendering to increase responsiveness.
|
protected |
The original settings.
Referenced by settings().
|
protected |
Referenced by setSimulationTimeScale(), and simulationTimeScale().
|
protected |
SimTime seconds per frame,.
Referenced by setFrameDuration(), and simStepDuration().
|
protected |
Referenced by simulationWatch().
|
protected |
Referenced by userInputWatch().
|
protected |
Referenced by waitWatch().
|
protected |
Seconds per frame target for the entire system.
Referenced by frameDuration(), realTimeTargetDuration(), and setFrameDuration().
|
protected |
|
protected |
|
protected |
bool G3D::GApp::manageUserInput |
When true, the G3D::UserInput->beginEvents/endEvents processing is handled for you by calling processGEventQueue() before G3D::GApp::onUserInput is called.
If you turn this off, you must call processGEventQueue() or provide your own event to userInput processing in onUserInput. (default is true)
RenderDevice* G3D::GApp::renderDevice |
|
staticprotected |
bool G3D::GApp::showDebugText |
When true, screenPrintf prints to the screen.
(default is true)
bool G3D::GApp::showRenderingStats |
When true, debugTextWidget prints the frame rate and other data to the screen.
UserInput* G3D::GApp::userInput |