Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

GraphicsEngine Class Reference

This class is the main interface to controlling the render process. More...

#include <graphicsEngine.h>

List of all members.

Public Member Functions

 GraphicsEngine (Pipeline *pipeline=NULL)
 Creates a new GraphicsEngine object.

 ~GraphicsEngine ()
 Gracefully cleans up the graphics engine and its related threads and windows.

void set_frame_buffer_properties (const FrameBufferProperties &properties)
 Specifies the default frame buffer properties for future gsg's created using the one-parameter make_gsg() method.

FrameBufferProperties get_frame_buffer_properties () const
 Returns the current default threading model.

void set_threading_model (const GraphicsThreadingModel &threading_model)
 Specifies how windows created using future calls to the one-parameter version of make_gsg() will be threaded.

GraphicsThreadingModel get_threading_model () const
 Returns the current default threading model.

void set_auto_flip (bool auto_flip)
 Set this flag true to indicate the GraphicsEngine should automatically cause windows to sync and flip at the end of render_frame().

bool get_auto_flip () const
 Returns the current setting for the auto-flip flag.

PointerTo< GraphicsStateGuardianmake_gsg (GraphicsPipe *pipe)
PointerTo< GraphicsStateGuardianmake_gsg (GraphicsPipe *pipe, const FrameBufferProperties &properties, const GraphicsThreadingModel &threading_model)
 Creates a new gsg using the indicated GraphicsPipe and returns it.

GraphicsWindowmake_window (GraphicsPipe *pipe, GraphicsStateGuardian *gsg)
 Creates a new window using the indicated GraphicsStateGuardian and returns it.

GraphicsWindowmake_window (GraphicsPipe *pipe, GraphicsStateGuardian *gsg, const GraphicsThreadingModel &threading_model)
 Creates a new window using the indicated GraphicsStateGuardian and returns it.

bool remove_window (GraphicsWindow *window)
 Removes the indicated window from the set of windows that will be processed when render_frame() is called.

void remove_all_windows ()
 Removes and closes all windows from the engine.

bool is_empty () const
 Returns true if there are no windows managed by the engine, false if there is at least one.

void render_frame ()
 Renders the next frame in all the registered windows, and flips all of the frame buffers.

void sync_frame ()
 Waits for all the threads that started drawing their last frame to finish drawing.

void flip_frame ()
 Waits for all the threads that started drawing their last frame to finish drawing, and then flips all the windows.

void render_subframe (GraphicsStateGuardian *gsg, DisplayRegion *dr, bool cull_sorting)
 Performs a complete cull and draw pass for one particular display region.


Private Types

typedef pset< PointerTo< GraphicsWindow > > Windows
typedef pset< PointerTo< GraphicsStateGuardian > > GSGs
typedef pmap< string, PointerTo<
RenderThread > > 
Threads
enum  ThreadState {
  TS_wait, TS_do_frame, TS_do_flip, TS_do_release,
  TS_terminate
}
enum  FlipState { FS_draw, FS_sync, FS_flip }

Private Member Functions

void cull_and_draw_together (const Windows &wlist)
 This is called in the cull+draw thread by individual RenderThread objects during the frame rendering.

void cull_and_draw_together (GraphicsStateGuardian *gsg, DisplayRegion *dr)
 This variant of cull_and_draw_together() is called only by render_subframe().

void cull_bin_draw (const Windows &wlist)
 This is called in the cull thread by individual RenderThread objects during the frame rendering.

void cull_bin_draw (GraphicsStateGuardian *gsg, DisplayRegion *dr)
 This variant of cull_bin_draw() is called by render_subframe(), as well as within the implementation of cull_bin_draw(), above.

void process_events (const GraphicsEngine::Windows &wlist)
 This is called by the RenderThread object to process all the windows events (resize, etc.) for the given list of windows.

void flip_windows (const GraphicsEngine::Windows &wlist)
 This is called by the RenderThread object to flip the buffers (resize, etc.) for the given list of windows.

void do_sync_frame ()
 The implementation of sync_frame().

void do_flip_frame ()
 The implementation of flip_frame().

void close_gsg (GraphicsPipe *pipe, GraphicsStateGuardian *gsg)
 Calls GraphicsPipe::close_gsg() on the indicated pipe and GSG.

PointerTo< SceneSetupsetup_scene (const NodePath &camera, GraphicsStateGuardian *gsg)
 Returns a new SceneSetup object appropriate for rendering the scene from the indicated camera, or NULL if the scene should not be rendered for some reason.

void do_cull (CullHandler *cull_handler, SceneSetup *scene_setup, GraphicsStateGuardian *gsg)
 Fires off a cull traversal using the indicated camera.

void do_draw (CullResult *cull_result, SceneSetup *scene_setup, GraphicsStateGuardian *gsg, DisplayRegion *dr)
 Draws the previously-culled scene.

bool setup_gsg (GraphicsStateGuardian *gsg, SceneSetup *scene_setup)
 Sets up the GSG to draw the indicated scene.

void do_remove_window (GraphicsWindow *window)
 An internal function called by remove_window() and remove_all_windows() to actually remove the indicated window from all relevant structures, except the _windows list itself.

void terminate_threads ()
 Signals our child threads to terminate and waits for them to clean up.

WindowRendererget_window_renderer (const string &name)
 Returns the WindowRenderer with the given name.


Private Attributes

Pipeline_pipeline
Windows _windows
WindowRenderer _app
Threads _threads
FrameBufferProperties _frame_buffer_properties
GraphicsThreadingModel _threading_model
bool _auto_flip
FlipState _flip_state
Mutex _lock

Static Private Attributes

PStatCollector _cull_pcollector
PStatCollector _draw_pcollector

Friends

class WindowRenderer


Detailed Description

This class is the main interface to controlling the render process.

There is typically only one GraphicsEngine in an application, and it synchronizes rendering to all all of the active windows; although it is possible to have multiple GraphicsEngine objects if multiple synchronicity groups are required.

The GraphicsEngine is responsible for managing the various cull and draw threads. The application simply calls engine->render_frame() and considers it done.

Definition at line 71 of file graphicsEngine.h.


Member Typedef Documentation

typedef pset< PointerTo< GraphicsStateGuardian > > GraphicsEngine::GSGs [private]
 

Definition at line 108 of file graphicsEngine.h.

typedef pmap<string, PointerTo< RenderThread > > GraphicsEngine::Threads [private]
 

Definition at line 184 of file graphicsEngine.h.

typedef pset< PointerTo< GraphicsWindow > > GraphicsEngine::Windows [private]
 

Definition at line 107 of file graphicsEngine.h.


Member Enumeration Documentation

enum GraphicsEngine::FlipState [private]
 

Enumeration values:
FS_draw 
FS_sync 
FS_flip 

Definition at line 190 of file graphicsEngine.h.

enum GraphicsEngine::ThreadState [private]
 

Enumeration values:
TS_wait 
TS_do_frame 
TS_do_flip 
TS_do_release 
TS_terminate 

Definition at line 159 of file graphicsEngine.h.


Constructor & Destructor Documentation

GraphicsEngine::GraphicsEngine Pipeline pipeline = NULL  ) 
 

Creates a new GraphicsEngine object.

The Pipeline is normally left to default to NULL, which indicates the global render pipeline, but it may be any Pipeline you choose.

Definition at line 56 of file graphicsEngine.cxx.

References FrameBufferProperties::FM_depth, FrameBufferProperties::FM_double_buffer, and FrameBufferProperties::FM_rgba.

GraphicsEngine::~GraphicsEngine  ) 
 

Gracefully cleans up the graphics engine and its related threads and windows.

Definition at line 91 of file graphicsEngine.cxx.

References _frame_buffer_properties.


Member Function Documentation

void GraphicsEngine::close_gsg GraphicsPipe pipe,
GraphicsStateGuardian gsg
[inline, private]
 

Calls GraphicsPipe::close_gsg() on the indicated pipe and GSG.

This function mainly exists to allow GraphicsEngine::WindowRenderer to call the protected method GraphicsPipe::close_gsg().

Definition at line 159 of file graphicsEngine.I.

Referenced by terminate_threads().

void GraphicsEngine::cull_and_draw_together GraphicsStateGuardian gsg,
DisplayRegion dr
[private]
 

This variant of cull_and_draw_together() is called only by render_subframe().

Definition at line 573 of file graphicsEngine.cxx.

References GraphicsEngine::RenderThread::_cv_mutex, _flip_state, _threads, FS_draw, FS_sync, Mutex::lock(), nassertv, and Mutex::release().

void GraphicsEngine::cull_and_draw_together const Windows wlist  )  [private]
 

This is called in the cull+draw thread by individual RenderThread objects during the frame rendering.

It culls the geometry and immediately draws it, without first collecting it into bins. This is used when the threading model begins with the "-" character.

Definition at line 543 of file graphicsEngine.cxx.

References win.

Referenced by render_frame().

void GraphicsEngine::cull_bin_draw GraphicsStateGuardian gsg,
DisplayRegion dr
[private]
 

This variant of cull_bin_draw() is called by render_subframe(), as well as within the implementation of cull_bin_draw(), above.

Definition at line 643 of file graphicsEngine.cxx.

References NULL.

void GraphicsEngine::cull_bin_draw const Windows wlist  )  [private]
 

This is called in the cull thread by individual RenderThread objects during the frame rendering.

It collects the geometry into bins in preparation for drawing.

Definition at line 609 of file graphicsEngine.cxx.

References _app, _threads, TS_do_flip, and TS_wait.

Referenced by render_frame().

void GraphicsEngine::do_cull CullHandler cull_handler,
SceneSetup scene_setup,
GraphicsStateGuardian gsg
[private]
 

Fires off a cull traversal using the indicated camera.

Definition at line 858 of file graphicsEngine.cxx.

Referenced by render_subframe().

void GraphicsEngine::do_draw CullResult cull_result,
SceneSetup scene_setup,
GraphicsStateGuardian gsg,
DisplayRegion dr
[private]
 

Draws the previously-culled scene.

Definition at line 900 of file graphicsEngine.cxx.

Referenced by render_subframe().

void GraphicsEngine::do_flip_frame  )  [private]
 

The implementation of flip_frame().

We assume _lock is already held before this method is called.

Definition at line 752 of file graphicsEngine.cxx.

Referenced by is_empty().

void GraphicsEngine::do_remove_window GraphicsWindow window  )  [private]
 

An internal function called by remove_window() and remove_all_windows() to actually remove the indicated window from all relevant structures, except the _windows list itself.

Definition at line 972 of file graphicsEngine.cxx.

Referenced by make_window().

void GraphicsEngine::do_sync_frame  )  [private]
 

The implementation of sync_frame().

We assume _lock is already held before this method is called.

Definition at line 726 of file graphicsEngine.cxx.

Referenced by remove_all_windows().

void GraphicsEngine::flip_frame  ) 
 

Waits for all the threads that started drawing their last frame to finish drawing, and then flips all the windows.

It is not usually necessary to call this explicitly, unless you need to see the previous frame right away.

Definition at line 481 of file graphicsEngine.cxx.

References win.

void GraphicsEngine::flip_windows const GraphicsEngine::Windows wlist  )  [private]
 

This is called by the RenderThread object to flip the buffers (resize, etc.) for the given list of windows.

This is run in the draw thread.

Definition at line 703 of file graphicsEngine.cxx.

References NULL.

bool GraphicsEngine::get_auto_flip  )  const [inline]
 

Returns the current setting for the auto-flip flag.

See set_auto_flip.

Definition at line 75 of file graphicsEngine.I.

References get_frame_buffer_properties(), get_threading_model(), INLINE, and make_gsg().

FrameBufferProperties GraphicsEngine::get_frame_buffer_properties  )  const
 

Returns the current default threading model.

See set_frame_buffer_properties().

Definition at line 124 of file graphicsEngine.cxx.

Referenced by get_auto_flip().

GraphicsThreadingModel GraphicsEngine::get_threading_model  )  const
 

Returns the current default threading model.

See set_threading_model().

Definition at line 169 of file graphicsEngine.cxx.

References threading_model.

Referenced by get_auto_flip().

GraphicsEngine::WindowRenderer * GraphicsEngine::get_window_renderer const string &  name  )  [private]
 

Returns the WindowRenderer with the given name.

Creates a new RenderThread if there is no such thread already.

Definition at line 1058 of file graphicsEngine.cxx.

bool GraphicsEngine::is_empty  )  const
 

Returns true if there are no windows managed by the engine, false if there is at least one.

Definition at line 379 of file graphicsEngine.cxx.

References _flip_state, _lock, do_flip_frame(), and FS_flip.

PointerTo< GraphicsStateGuardian > GraphicsEngine::make_gsg GraphicsPipe pipe,
const FrameBufferProperties properties,
const GraphicsThreadingModel threading_model
 

Creates a new gsg using the indicated GraphicsPipe and returns it.

The GraphicsEngine does not officially own the pointer to the gsg; but if any windows are created using this GSG, the GraphicsEngine will own the pointers to these windows, which in turn will own the pointer to the GSG.

There is no explicit way to release a GSG, but it will be destructed when all windows that reference it are destructed, and the draw thread that owns the GSG runs one more time.

Definition at line 209 of file graphicsEngine.cxx.

PointerTo< GraphicsStateGuardian > GraphicsEngine::make_gsg GraphicsPipe pipe  )  [inline]
 

Referenced by get_auto_flip(), and WindowFramework::~WindowFramework().

GraphicsWindow * GraphicsEngine::make_window GraphicsPipe pipe,
GraphicsStateGuardian gsg,
const GraphicsThreadingModel threading_model
 

Creates a new window using the indicated GraphicsStateGuardian and returns it.

The GraphicsEngine becomes the owner of the window; it will persist at least until remove_window() is called later.

Definition at line 238 of file graphicsEngine.cxx.

References _lock, _windows, do_remove_window(), PT, and size_t.

GraphicsWindow * GraphicsEngine::make_window GraphicsPipe pipe,
GraphicsStateGuardian gsg
[inline]
 

Creates a new window using the indicated GraphicsStateGuardian and returns it.

The GraphicsEngine becomes the owner of the window; it will persist at least until remove_window() is called later.

Definition at line 140 of file graphicsEngine.I.

Referenced by WindowFramework::~WindowFramework().

void GraphicsEngine::process_events const GraphicsEngine::Windows wlist  )  [private]
 

This is called by the RenderThread object to process all the windows events (resize, etc.) for the given list of windows.

This is run in the window thread.

Definition at line 682 of file graphicsEngine.cxx.

void GraphicsEngine::remove_all_windows  ) 
 

Removes and closes all windows from the engine.

This also cleans up and terminates any threads that have been started to service those windows.

Definition at line 354 of file graphicsEngine.cxx.

References _flip_state, _lock, do_sync_frame(), and FS_draw.

Referenced by PandaFramework::open_framework().

bool GraphicsEngine::remove_window GraphicsWindow window  ) 
 

Removes the indicated window from the set of windows that will be processed when render_frame() is called.

This also closes the window if it is open, and removes the window from its GraphicsPipe, allowing the window to be destructed if there are no other references to it. (However, the window may not be actually closed until next frame, if it is controlled by a sub-thread.)

The return value is true if the window was removed, false if it was not found.

Unlike remove_all_windows(), this function does not terminate any of the threads that may have been started to service this window; they are left running (since you might open a new window later on these threads). If your intention is to clean up before shutting down, it is better to call remove_all_windows() then to call remove_window() one at a time.

Definition at line 324 of file graphicsEngine.cxx.

References _app, _pipeline, _threads, TS_do_frame, and TS_wait.

Referenced by PandaFramework::find_window().

void GraphicsEngine::render_frame  ) 
 

Renders the next frame in all the registered windows, and flips all of the frame buffers.

Definition at line 394 of file graphicsEngine.cxx.

References cull_and_draw_together(), and cull_bin_draw().

void GraphicsEngine::render_subframe GraphicsStateGuardian gsg,
DisplayRegion dr,
bool  cull_sorting
 

Performs a complete cull and draw pass for one particular display region.

This is normally useful only for special effects, like shaders, that require a complete offscreen render pass before they can complete.

This always executes completely within the calling thread, regardless of the threading model in use. Thus, it must always be called from the draw thread, whichever thread that may be.

Definition at line 517 of file graphicsEngine.cxx.

References DisplayRegion::_cull_result, do_cull(), do_draw(), and NULL.

void GraphicsEngine::set_auto_flip bool  auto_flip  )  [inline]
 

Set this flag true to indicate the GraphicsEngine should automatically cause windows to sync and flip at the end of render_frame().

This only applies to a single-threaded rendering model. In the presence of threading, the windows are never auto-flipped, regardless of this flag.

This only affects the timing of when the flip occurs. If this is true (the default), the flip occurs before render_frame() returns. If this is false, the flip occurs whenever flip_frame() is called, or at the beginning of the next call to render_frame(), if flip_frame() is never called.

Definition at line 58 of file graphicsEngine.I.

void GraphicsEngine::set_frame_buffer_properties const FrameBufferProperties properties  ) 
 

Specifies the default frame buffer properties for future gsg's created using the one-parameter make_gsg() method.

Definition at line 108 of file graphicsEngine.cxx.

void GraphicsEngine::set_threading_model const GraphicsThreadingModel threading_model  ) 
 

Specifies how windows created using future calls to the one-parameter version of make_gsg() will be threaded.

Definition at line 146 of file graphicsEngine.cxx.

References GraphicsPipe::make_gsg(), NULL, and PT.

bool GraphicsEngine::setup_gsg GraphicsStateGuardian gsg,
SceneSetup scene_setup
[private]
 

Sets up the GSG to draw the indicated scene.

Returns true if the scene (and its lens) is acceptable, false otherwise.

Definition at line 932 of file graphicsEngine.cxx.

PointerTo< SceneSetup > GraphicsEngine::setup_scene const NodePath camera,
GraphicsStateGuardian gsg
[private]
 

Returns a new SceneSetup object appropriate for rendering the scene from the indicated camera, or NULL if the scene should not be rendered for some reason.

Definition at line 792 of file graphicsEngine.cxx.

References _app, GraphicsWindow::_pipe, _threads, GraphicsEngine::WindowRenderer::do_pending(), GraphicsWindow::get_pipe(), NULL, PT, and GraphicsEngine::WindowRenderer::remove_window().

void GraphicsEngine::sync_frame  ) 
 

Waits for all the threads that started drawing their last frame to finish drawing.

The windows are not yet flipped when this returns; see also flip_frame(). It is not usually necessary to call this explicitly, unless you need to see the previous frame right away.

Definition at line 456 of file graphicsEngine.cxx.

References GraphicsStateGuardian::clear().

void GraphicsEngine::terminate_threads  )  [private]
 

Signals our child threads to terminate and waits for them to clean up.

Definition at line 1000 of file graphicsEngine.cxx.

References close_gsg(), and GraphicsStateGuardian::get_pipe().


Friends And Related Function Documentation

friend class WindowRenderer [friend]
 

Definition at line 200 of file graphicsEngine.h.


Member Data Documentation

WindowRenderer GraphicsEngine::_app [private]
 

Definition at line 183 of file graphicsEngine.h.

Referenced by cull_bin_draw(), remove_window(), and setup_scene().

bool GraphicsEngine::_auto_flip [private]
 

Definition at line 188 of file graphicsEngine.h.

PStatCollector GraphicsEngine::_cull_pcollector [static, private]
 

PStatCollector GraphicsEngine::_draw_pcollector [static, private]
 

FlipState GraphicsEngine::_flip_state [private]
 

Definition at line 195 of file graphicsEngine.h.

Referenced by cull_and_draw_together(), is_empty(), and remove_all_windows().

FrameBufferProperties GraphicsEngine::_frame_buffer_properties [private]
 

Definition at line 186 of file graphicsEngine.h.

Referenced by ~GraphicsEngine().

Mutex GraphicsEngine::_lock [private]
 

Definition at line 196 of file graphicsEngine.h.

Referenced by is_empty(), make_window(), and remove_all_windows().

Pipeline* GraphicsEngine::_pipeline [private]
 

Definition at line 180 of file graphicsEngine.h.

Referenced by remove_window().

GraphicsThreadingModel GraphicsEngine::_threading_model [private]
 

Definition at line 187 of file graphicsEngine.h.

Threads GraphicsEngine::_threads [private]
 

Definition at line 185 of file graphicsEngine.h.

Referenced by cull_and_draw_together(), cull_bin_draw(), remove_window(), and setup_scene().

Windows GraphicsEngine::_windows [private]
 

Definition at line 181 of file graphicsEngine.h.

Referenced by make_window().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:51:19 2003 for Panda by doxygen1.3