00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00039
00040
00041
00042
00043
00044 class EXPCL_PANDA_PGRAPH CullableObject
00045 #ifdef DO_MEMORY_USAGE
00046 : public ReferenceCount
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
00098
00099 CallbackObject *_draw_callback;
00100 CullableObject *_next;
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
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
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