Panda3D
 All Classes Functions Variables Enumerations
displayRegionDrawCallbackData.cxx
1 // Filename: displayRegionDrawCallbackData.cxx
2 // Created by: drose (13Mar09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "displayRegionDrawCallbackData.h"
16 
17 #include "config_display.h"
18 #include "cullResult.h"
19 #include "displayRegion.h"
20 #include "graphicsOutput.h"
21 #include "graphicsStateGuardian.h"
22 #include "sceneSetup.h"
23 
24 TypeHandle DisplayRegionDrawCallbackData::_type_handle;
25 
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: DisplayRegionDrawCallbackData::Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 DisplayRegionDrawCallbackData::
33 DisplayRegionDrawCallbackData(CullResult *cull_result, SceneSetup *scene_setup) :
34  _cull_result(cull_result),
35  _scene_setup(scene_setup)
36 {
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: DisplayRegionDrawCallbackData::output
41 // Access: Published, Virtual
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 void DisplayRegionDrawCallbackData::
45 output(ostream &out) const {
46  out << get_type() << "(" << (void *)_cull_result << ", "
47  << (void *)_scene_setup << ")";
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: DisplayRegionDrawCallbackData::upcall
52 // Access: Published, Virtual
53 // Description: You should make this call during the callback if you
54 // want to continue the normal rendering function that
55 // would have been done in the absence of a callback.
56 //
57 // Specifically, this method will draw all of the
58 // objects in the CullResult list that have been built
59 // up for the DisplayRegion during the cull traversal.
60 ////////////////////////////////////////////////////////////////////
62 upcall() {
63  Thread *current_thread = Thread::get_current_thread();
64  DisplayRegion *dr = _scene_setup->get_display_region();
66 
67  if (_cull_result == NULL || _scene_setup == NULL) {
68  // Nothing to see here.
69 
70  } else if (dr->is_stereo()) {
71  // We don't actually draw the stereo DisplayRegions. These are
72  // just placeholders; we draw the individual left and right eyes
73  // instead. (We might still clear the stereo DisplayRegions,
74  // though, since it's probably faster to clear right and left
75  // channels in one pass, than to clear them in two separate
76  // passes.)
77 
78  } else if (!gsg->set_scene(_scene_setup)) {
79  // The scene or lens is inappropriate somehow.
80  display_cat.error()
81  << gsg->get_type() << " cannot render scene with specified lens.\n";
82 
83  } else {
84  // Tell the GSG to forget its state.
86 
87  if (gsg->begin_scene()) {
88  _cull_result->draw(current_thread);
89  gsg->end_scene();
90  }
91  }
92 }
93 
virtual bool is_stereo() const
Returns true if this is a StereoDisplayRegion, false otherwise.
virtual void upcall()
You should make this call during the callback if you want to continue the normal rendering function t...
DisplayRegion * get_display_region() const
Returns the display region for the scene.
Definition: sceneSetup.I:50
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
virtual void clear_state_and_transform()
Forgets the current graphics state and current transform, so that the next call to set_state_and_tran...
GraphicsOutput * get_window() const
Returns the GraphicsOutput that this DisplayRegion is ultimately associated with, or NULL if no windo...
GraphicsStateGuardian * get_gsg() const
Returns the GSG that is associated with this window.
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins, each of which holds a number of Geoms and RenderStates to be rendered in some defined order.
Definition: cullResult.h:47
A thread; that is, a lightweight process.
Definition: thread.h:51
Encapsulates all the communication with a particular instance of a given rendering backend...
virtual void end_scene()
Called between begin_frame() and end_frame() to mark the end of drawing commands for a &quot;scene&quot; (usual...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
void draw(Thread *current_thread)
Asks all the bins to draw themselves in the correct order.
Definition: cullResult.cxx:299
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:35
bool set_scene(SceneSetup *scene_setup)
Sets the SceneSetup object that indicates the initial camera position, etc.
virtual bool begin_scene()
Called between begin_frame() and end_frame() to mark the beginning of drawing commands for a &quot;scene&quot; ...