Panda3D
 All Classes Functions Variables Enumerations
displayRegionDrawCallbackData.cxx
00001 // Filename: displayRegionDrawCallbackData.cxx
00002 // Created by:  drose (13Mar09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "displayRegionDrawCallbackData.h"
00016 #include "cullResult.h"
00017 #include "sceneSetup.h"
00018 
00019 TypeHandle DisplayRegionDrawCallbackData::_type_handle;
00020 
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: DisplayRegionDrawCallbackData::Constructor
00024 //       Access: Public
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 DisplayRegionDrawCallbackData::
00028 DisplayRegionDrawCallbackData(CullResult *cull_result, SceneSetup *scene_setup) :
00029   _cull_result(cull_result),
00030   _scene_setup(scene_setup)
00031 {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: DisplayRegionDrawCallbackData::output
00036 //       Access: Published, Virtual
00037 //  Description:
00038 ////////////////////////////////////////////////////////////////////
00039 void DisplayRegionDrawCallbackData::
00040 output(ostream &out) const {
00041   out << get_type() << "(" << (void *)_cull_result << ", " 
00042       << (void *)_scene_setup << ")";
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: DisplayRegionDrawCallbackData::upcall
00047 //       Access: Published, Virtual
00048 //  Description: You should make this call during the callback if you
00049 //               want to continue the normal rendering function that
00050 //               would have been done in the absence of a callback.
00051 //
00052 //               Specifically, this method will draw all of the
00053 //               objects in the CullResult list that have been built
00054 //               up for the DisplayRegion during the cull traversal.
00055 ////////////////////////////////////////////////////////////////////
00056 void DisplayRegionDrawCallbackData::
00057 upcall() {
00058   Thread *current_thread = Thread::get_current_thread();
00059   DisplayRegion *dr = _scene_setup->get_display_region();
00060   GraphicsStateGuardian *gsg = dr->get_window()->get_gsg();
00061 
00062   if (_cull_result == NULL || _scene_setup == NULL) {
00063     // Nothing to see here.
00064 
00065   } else if (dr->is_stereo()) {
00066     // We don't actually draw the stereo DisplayRegions.  These are
00067     // just placeholders; we draw the individual left and right eyes
00068     // instead.  (We might still clear the stereo DisplayRegions,
00069     // though, since it's probably faster to clear right and left
00070     // channels in one pass, than to clear them in two separate
00071     // passes.)
00072 
00073   } else if (!gsg->set_scene(_scene_setup)) {
00074     // The scene or lens is inappropriate somehow.
00075     display_cat.error()
00076       << gsg->get_type() << " cannot render scene with specified lens.\n";
00077 
00078   } else {
00079     // Tell the GSG to forget its state.
00080     gsg->clear_state_and_transform();
00081 
00082     if (gsg->begin_scene()) {
00083       _cull_result->draw(current_thread);
00084       gsg->end_scene();
00085     }
00086   }
00087 }
00088 
 All Classes Functions Variables Enumerations