Panda3D
|
00001 // Filename: cullableObject.h 00002 // Created by: drose (04Mar02) 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 #ifndef CULLABLEOBJECT_H 00016 #define CULLABLEOBJECT_H 00017 00018 #include "pandabase.h" 00019 00020 #include "geom.h" 00021 #include "geomVertexData.h" 00022 #include "geomMunger.h" 00023 #include "renderState.h" 00024 #include "transformState.h" 00025 #include "pointerTo.h" 00026 #include "referenceCount.h" 00027 #include "geomNode.h" 00028 #include "cullTraverserData.h" 00029 #include "pStatCollector.h" 00030 #include "deletedChain.h" 00031 #include "graphicsStateGuardianBase.h" 00032 #include "lightMutex.h" 00033 #include "callbackObject.h" 00034 00035 class CullTraverser; 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Class : CullableObject 00039 // Description : The smallest atom of cull. This is normally just a 00040 // Geom and its associated state, but it also represent 00041 // a number of Geoms to be drawn together, with a number 00042 // of Geoms decalled onto them. 00043 //////////////////////////////////////////////////////////////////// 00044 class EXPCL_PANDA_PGRAPH CullableObject 00045 #ifdef DO_MEMORY_USAGE 00046 : public ReferenceCount // We inherit from ReferenceCount just to get the memory type tracking that MemoryUsage provides. 00047 #endif // DO_MEMORY_USAGE 00048 { 00049 public: 00050 INLINE CullableObject(); 00051 INLINE CullableObject(const Geom *geom, const RenderState *state, 00052 const TransformState *net_transform, 00053 const TransformState *modelview_transform, 00054 const GraphicsStateGuardianBase *gsg); 00055 INLINE CullableObject(const Geom *geom, const RenderState *state, 00056 const TransformState *net_transform, 00057 const TransformState *modelview_transform, 00058 const TransformState *internal_transform); 00059 00060 INLINE CullableObject(const CullableObject ©); 00061 INLINE void operator = (const CullableObject ©); 00062 00063 INLINE bool is_fancy() const; 00064 INLINE bool has_decals() const; 00065 00066 bool munge_geom(GraphicsStateGuardianBase *gsg, 00067 GeomMunger *munger, const CullTraverser *traverser, 00068 bool force); 00069 INLINE void draw(GraphicsStateGuardianBase *gsg, 00070 bool force, Thread *current_thread); 00071 00072 INLINE bool request_resident() const; 00073 INLINE static void flush_level(); 00074 00075 INLINE void set_draw_callback(CallbackObject *draw_callback); 00076 INLINE void set_next(CullableObject *next); 00077 INLINE CullableObject *get_next() const; 00078 00079 public: 00080 ~CullableObject(); 00081 ALLOC_DELETED_CHAIN(CullableObject); 00082 00083 void output(ostream &out) const; 00084 00085 public: 00086 CPT(Geom) _geom; 00087 PT(GeomMunger) _munger; 00088 CPT(GeomVertexData) _munged_data; 00089 CPT(RenderState) _state; 00090 CPT(TransformState) _net_transform; 00091 CPT(TransformState) _modelview_transform; 00092 CPT(TransformState) _internal_transform; 00093 00094 private: 00095 bool _fancy; 00096 00097 // Fancy things below. These pointers are only meaningful if 00098 // _fancy, above, is true. 00099 CallbackObject *_draw_callback; 00100 CullableObject *_next; // for decals 00101 00102 private: 00103 INLINE void make_fancy(); 00104 bool munge_points_to_quads(const CullTraverser *traverser, bool force); 00105 bool munge_texcoord_light_vector(const CullTraverser *traverser, bool force); 00106 00107 static CPT(RenderState) get_flash_cpu_state(); 00108 static CPT(RenderState) get_flash_hardware_state(); 00109 00110 INLINE void draw_inline(GraphicsStateGuardianBase *gsg, 00111 bool force, Thread *current_thread); 00112 void draw_fancy(GraphicsStateGuardianBase *gsg, bool force, 00113 Thread *current_thread); 00114 void draw_with_decals(GraphicsStateGuardianBase *gsg, bool force, 00115 Thread *current_thread); 00116 00117 private: 00118 // This class is used internally by munge_points_to_quads(). 00119 class PointData { 00120 public: 00121 LPoint3 _eye; 00122 PN_stdfloat _dist; 00123 }; 00124 class SortPoints { 00125 public: 00126 INLINE SortPoints(const PointData *array); 00127 INLINE bool operator ()(unsigned short a, unsigned short b) const; 00128 00129 const PointData *_array; 00130 }; 00131 00132 // This is a cache of converted vertex formats. 00133 class SourceFormat { 00134 public: 00135 SourceFormat(const GeomVertexFormat *format, bool sprite_texcoord); 00136 INLINE bool operator < (const SourceFormat &other) const; 00137 00138 CPT(GeomVertexFormat) _format; 00139 bool _sprite_texcoord; 00140 bool _retransform_sprites; 00141 }; 00142 typedef pmap<SourceFormat, CPT(GeomVertexFormat) > FormatMap; 00143 static FormatMap _format_map; 00144 static LightMutex _format_lock; 00145 00146 static PStatCollector _munge_geom_pcollector; 00147 static PStatCollector _munge_sprites_pcollector; 00148 static PStatCollector _munge_sprites_verts_pcollector; 00149 static PStatCollector _munge_sprites_prims_pcollector; 00150 static PStatCollector _munge_light_vector_pcollector; 00151 static PStatCollector _sw_sprites_pcollector; 00152 00153 public: 00154 static TypeHandle get_class_type() { 00155 return _type_handle; 00156 } 00157 static void init_type() { 00158 #ifdef DO_MEMORY_USAGE 00159 ReferenceCount::init_type(); 00160 register_type(_type_handle, "CullableObject", 00161 ReferenceCount::get_class_type()); 00162 #else 00163 register_type(_type_handle, "CullableObject"); 00164 #endif // DO_MEMORY_USAGE 00165 } 00166 00167 private: 00168 static TypeHandle _type_handle; 00169 }; 00170 00171 INLINE ostream &operator << (ostream &out, const CullableObject &object) { 00172 object.output(out); 00173 return out; 00174 } 00175 00176 #include "cullableObject.I" 00177 00178 #endif