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