00001 // Filename: cullHandler.cxx 00002 // Created by: drose (23Feb02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "cullHandler.h" 00020 #include "cullableObject.h" 00021 #include "geom.h" 00022 #include "transformState.h" 00023 #include "renderState.h" 00024 #include "notify.h" 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: CullHandler::Destructor 00028 // Access: Public, Virtual 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 CullHandler:: 00032 ~CullHandler() { 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: CullHandler::record_object 00037 // Access: Public, Virtual 00038 // Description: This callback function is intended to be overridden 00039 // by a derived class. This is called as each Geom is 00040 // discovered by the CullTraverser. 00041 // 00042 // The CullHandler becomes the owner of the 00043 // CullableObject pointer and is expected to delete it 00044 // later. 00045 //////////////////////////////////////////////////////////////////// 00046 void CullHandler:: 00047 record_object(CullableObject *object) { 00048 nout << *object->_geom << " " << *object->_transform << " " 00049 << *object->_state << "\n"; 00050 delete object; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: CullHandler::draw_with_decals 00055 // Access: Public, Static 00056 // Description: Draws the indicated CullableObject, assuming it has 00057 // attached decals. 00058 //////////////////////////////////////////////////////////////////// 00059 void CullHandler:: 00060 draw_with_decals(CullableObject *object, GraphicsStateGuardianBase *gsg) { 00061 // We draw with a three-step process. 00062 00063 // First, render all of the base geometry for the first pass. 00064 CPT(RenderState) state = gsg->begin_decal_base_first(); 00065 00066 CullableObject *base = object; 00067 while (base != (CullableObject *)NULL && base->_geom != (Geom *)NULL) { 00068 gsg->set_state_and_transform(base->_state->compose(state), base->_transform); 00069 base->_geom->draw(gsg); 00070 00071 base = base->_next; 00072 } 00073 00074 if (base != (CullableObject *)NULL) { 00075 // Now, draw all the decals. 00076 state = gsg->begin_decal_nested(); 00077 00078 CullableObject *decal = base->_next; 00079 while (decal != (CullableObject *)NULL) { 00080 gsg->set_state_and_transform(decal->_state->compose(state), decal->_transform); 00081 decal->_geom->draw(gsg); 00082 00083 decal = decal->_next; 00084 } 00085 } 00086 00087 // And now, re-draw the base geometry, if required. 00088 state = gsg->begin_decal_base_second(); 00089 if (state != (const RenderState *)NULL) { 00090 base = object; 00091 while (base != (CullableObject *)NULL && base->_geom != (Geom *)NULL) { 00092 gsg->set_state_and_transform(base->_state->compose(state), base->_transform); 00093 base->_geom->draw(gsg); 00094 00095 base = base->_next; 00096 } 00097 } 00098 } 00099