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 public: 00046 INLINE CullableObject(); 00047 INLINE CullableObject(const Geom *geom, const RenderState *state, 00048 const TransformState *net_transform, 00049 const TransformState *modelview_transform, 00050 const GraphicsStateGuardianBase *gsg); 00051 INLINE CullableObject(const Geom *geom, const RenderState *state, 00052 const TransformState *net_transform, 00053 const TransformState *modelview_transform, 00054 const TransformState *internal_transform); 00055 00056 INLINE CullableObject(const CullableObject ©); 00057 INLINE void operator = (const CullableObject ©); 00058 00059 INLINE bool is_fancy() const; 00060 INLINE bool has_decals() const; 00061 00062 bool munge_geom(GraphicsStateGuardianBase *gsg, 00063 GeomMunger *munger, const CullTraverser *traverser, 00064 bool force); 00065 INLINE void draw(GraphicsStateGuardianBase *gsg, 00066 bool force, Thread *current_thread); 00067 00068 INLINE bool request_resident() const; 00069 INLINE static void flush_level(); 00070 00071 INLINE void set_draw_callback(CallbackObject *draw_callback); 00072 INLINE void set_next(CullableObject *next); 00073 INLINE CullableObject *get_next() const; 00074 00075 public: 00076 ~CullableObject(); 00077 ALLOC_DELETED_CHAIN(CullableObject); 00078 00079 void output(ostream &out) const; 00080 00081 public: 00082 CPT(Geom) _geom; 00083 PT(GeomMunger) _munger; 00084 CPT(GeomVertexData) _munged_data; 00085 CPT(RenderState) _state; 00086 CPT(TransformState) _net_transform; 00087 CPT(TransformState) _modelview_transform; 00088 CPT(TransformState) _internal_transform; 00089 00090 private: 00091 bool _fancy; 00092 00093 // Fancy things below. These pointers are only meaningful if 00094 // _fancy, above, is true. 00095 CallbackObject *_draw_callback; 00096 CullableObject *_next; // for decals 00097 00098 private: 00099 INLINE void make_fancy(); 00100 bool munge_points_to_quads(const CullTraverser *traverser, bool force); 00101 bool munge_texcoord_light_vector(const CullTraverser *traverser, bool force); 00102 00103 static CPT(RenderState) get_flash_cpu_state(); 00104 static CPT(RenderState) get_flash_hardware_state(); 00105 00106 INLINE void draw_inline(GraphicsStateGuardianBase *gsg, 00107 bool force, Thread *current_thread); 00108 void draw_fancy(GraphicsStateGuardianBase *gsg, bool force, 00109 Thread *current_thread); 00110 void draw_with_decals(GraphicsStateGuardianBase *gsg, bool force, 00111 Thread *current_thread); 00112 00113 private: 00114 // This class is used internally by munge_points_to_quads(). 00115 class PointData { 00116 public: 00117 LPoint3f _eye; 00118 float _dist; 00119 }; 00120 class SortPoints { 00121 public: 00122 INLINE SortPoints(const PointData *array); 00123 INLINE bool operator ()(unsigned short a, unsigned short b) const; 00124 00125 const PointData *_array; 00126 }; 00127 00128 // This is a cache of converted vertex formats. 00129 class SourceFormat { 00130 public: 00131 SourceFormat(const GeomVertexFormat *format, bool sprite_texcoord); 00132 INLINE bool operator < (const SourceFormat &other) const; 00133 00134 CPT(GeomVertexFormat) _format; 00135 bool _sprite_texcoord; 00136 bool _retransform_sprites; 00137 }; 00138 typedef pmap<SourceFormat, CPT(GeomVertexFormat) > FormatMap; 00139 static FormatMap _format_map; 00140 static LightMutex _format_lock; 00141 00142 static PStatCollector _munge_geom_pcollector; 00143 static PStatCollector _munge_sprites_pcollector; 00144 static PStatCollector _munge_sprites_verts_pcollector; 00145 static PStatCollector _munge_sprites_prims_pcollector; 00146 static PStatCollector _munge_light_vector_pcollector; 00147 static PStatCollector _sw_sprites_pcollector; 00148 00149 public: 00150 static TypeHandle get_class_type() { 00151 return _type_handle; 00152 } 00153 static void init_type() { 00154 register_type(_type_handle, "CullableObject"); 00155 } 00156 00157 private: 00158 static TypeHandle _type_handle; 00159 }; 00160 00161 INLINE ostream &operator << (ostream &out, const CullableObject &object) { 00162 object.output(out); 00163 return out; 00164 } 00165 00166 #include "cullableObject.I" 00167 00168 #endif