Panda3D
 All Classes Functions Variables Enumerations
cullableObject.h
1 // Filename: cullableObject.h
2 // Created by: drose (04Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CULLABLEOBJECT_H
16 #define CULLABLEOBJECT_H
17 
18 #include "pandabase.h"
19 
20 #include "geom.h"
21 #include "geomVertexData.h"
22 #include "geomMunger.h"
23 #include "renderState.h"
24 #include "transformState.h"
25 #include "pointerTo.h"
26 #include "referenceCount.h"
27 #include "geomNode.h"
28 #include "cullTraverserData.h"
29 #include "pStatCollector.h"
30 #include "deletedChain.h"
31 #include "graphicsStateGuardianBase.h"
32 #include "sceneSetup.h"
33 #include "lightMutex.h"
34 #include "callbackObject.h"
35 #include "geomDrawCallbackData.h"
36 
37 class CullTraverser;
38 
39 ////////////////////////////////////////////////////////////////////
40 // Class : CullableObject
41 // Description : The smallest atom of cull. This is normally just a
42 // Geom and its associated state, but it also contain
43 // a draw callback.
44 ////////////////////////////////////////////////////////////////////
45 class EXPCL_PANDA_PGRAPH CullableObject
46 #ifdef DO_MEMORY_USAGE
47  : public ReferenceCount // We inherit from ReferenceCount just to get the memory type tracking that MemoryUsage provides.
48 #endif // DO_MEMORY_USAGE
49 {
50 public:
51  INLINE CullableObject();
52  INLINE CullableObject(const Geom *geom, const RenderState *state,
53  const TransformState *internal_transform);
54 
55  INLINE CullableObject(const CullableObject &copy);
56  INLINE void operator = (const CullableObject &copy);
57 
58  bool munge_geom(GraphicsStateGuardianBase *gsg,
59  GeomMunger *munger, const CullTraverser *traverser,
60  bool force);
61  INLINE void draw(GraphicsStateGuardianBase *gsg,
62  bool force, Thread *current_thread);
63 
64  INLINE bool request_resident() const;
65  INLINE static void flush_level();
66 
67  INLINE void set_draw_callback(CallbackObject *draw_callback);
68 
69 public:
70  ALLOC_DELETED_CHAIN(CullableObject);
71 
72  void output(ostream &out) const;
73 
74 public:
75  CPT(Geom) _geom;
76  PT(GeomMunger) _munger;
77  CPT(GeomVertexData) _munged_data;
78  CPT(RenderState) _state;
79  CPT(TransformState) _internal_transform;
80  PT(CallbackObject) _draw_callback;
81 
82 private:
83  bool munge_points_to_quads(const CullTraverser *traverser, bool force);
84 
85  static CPT(RenderState) get_flash_cpu_state();
86  static CPT(RenderState) get_flash_hardware_state();
87 
88  INLINE void draw_inline(GraphicsStateGuardianBase *gsg,
89  bool force, Thread *current_thread);
90 
91 private:
92  // This class is used internally by munge_points_to_quads().
93  class PointData {
94  public:
95  PN_stdfloat _dist;
96  };
97  class SortPoints {
98  public:
99  INLINE SortPoints(const PointData *array);
100  INLINE bool operator ()(unsigned short a, unsigned short b) const;
101 
102  const PointData *_array;
103  };
104 
105  // This is a cache of converted vertex formats.
106  class SourceFormat {
107  public:
108  SourceFormat(const GeomVertexFormat *format, bool sprite_texcoord);
109  INLINE bool operator < (const SourceFormat &other) const;
110 
111  CPT(GeomVertexFormat) _format;
112  bool _sprite_texcoord;
113  bool _retransform_sprites;
114  };
116  static FormatMap _format_map;
117  static LightMutex _format_lock;
118 
119  static PStatCollector _munge_geom_pcollector;
120  static PStatCollector _munge_sprites_pcollector;
121  static PStatCollector _munge_sprites_verts_pcollector;
122  static PStatCollector _munge_sprites_prims_pcollector;
123  static PStatCollector _sw_sprites_pcollector;
124 
125 public:
126  static TypeHandle get_class_type() {
127  return _type_handle;
128  }
129  static void init_type() {
130 #ifdef DO_MEMORY_USAGE
131  ReferenceCount::init_type();
132  register_type(_type_handle, "CullableObject",
133  ReferenceCount::get_class_type());
134 #else
135  register_type(_type_handle, "CullableObject");
136 #endif // DO_MEMORY_USAGE
137  }
138 
139 private:
140  static TypeHandle _type_handle;
141 };
142 
143 INLINE ostream &operator << (ostream &out, const CullableObject &object) {
144  object.output(out);
145  return out;
146 }
147 
148 #include "cullableObject.I"
149 
150 #endif
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
Definition: geomMunger.h:57
A lightweight class that represents a single element that may be timed and/or counted via stats...
The smallest atom of cull.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition: geom.h:58
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
This is a generic object that can be assigned to a callback at various points in the rendering proces...
A base class for all things that want to be reference-counted.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
Definition: thread.h:51
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48