Panda3D
 All Classes Functions Variables Enumerations
cullableObject.I
1 // Filename: cullableObject.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: CullableObject::Constructor
18 // Access: Public
19 // Description: Creates an empty CullableObject whose pointers can be
20 // filled in later.
21 ////////////////////////////////////////////////////////////////////
22 INLINE CullableObject::
24 #ifdef DO_MEMORY_USAGE
25  MemoryUsage::update_type(this, get_class_type());
26 #endif
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: CullableObject::Constructor
31 // Access: Public
32 // Description: Creates a CullableObject based the indicated geom,
33 // with the indicated render state and transform.
34 ////////////////////////////////////////////////////////////////////
35 INLINE CullableObject::
36 CullableObject(const Geom *geom, const RenderState *state,
37  const TransformState *internal_transform) :
38  _geom(geom),
39  _state(state),
40  _internal_transform(internal_transform)
41 {
42 #ifdef DO_MEMORY_USAGE
43  MemoryUsage::update_type(this, get_class_type());
44 #endif
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: CullableObject::Copy Constructor
49 // Access: Public
50 // Description: Copies the CullableObject.
51 ////////////////////////////////////////////////////////////////////
52 INLINE CullableObject::
54  _geom(copy._geom),
55  _munger(copy._munger),
56  _munged_data(copy._munged_data),
57  _state(copy._state),
58  _internal_transform(copy._internal_transform)
59 {
60 #ifdef DO_MEMORY_USAGE
61  MemoryUsage::update_type(this, get_class_type());
62 #endif
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: CullableObject::Copy Assignment Operator
67 // Access: Public
68 // Description: Copies the CullableObject.
69 ////////////////////////////////////////////////////////////////////
70 INLINE void CullableObject::
72  _geom = copy._geom;
73  _munger = copy._munger;
74  _munged_data = copy._munged_data;
75  _state = copy._state;
76  _internal_transform = copy._internal_transform;
77  _draw_callback = copy._draw_callback;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: CullableObject::draw
82 // Access: Public
83 // Description: Draws the cullable object on the GSG immediately, in
84 // the GSG's current state. This should only be called
85 // from the draw thread.
86 ////////////////////////////////////////////////////////////////////
87 INLINE void CullableObject::
88 draw(GraphicsStateGuardianBase *gsg, bool force, Thread *current_thread) {
89  if (_draw_callback != (CallbackObject *)NULL) {
90  // It has a callback associated.
91  gsg->clear_before_callback();
92  gsg->set_state_and_transform(_state, _internal_transform);
93  GeomDrawCallbackData cbdata(this, gsg, force);
94  _draw_callback->do_callback(&cbdata);
95  if (cbdata.get_lost_state()) {
96  // Tell the GSG to forget its state.
97  gsg->clear_state_and_transform();
98  }
99  // Now the callback has taken care of drawing.
100  } else {
101  nassertv(_geom != (Geom *)NULL);
102  gsg->set_state_and_transform(_state, _internal_transform);
103  draw_inline(gsg, force, current_thread);
104  }
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: CullableObject::request_resident
109 // Access: Public
110 // Description: Returns true if all the data necessary to render this
111 // object is currently resident in memory. If this
112 // returns false, the data will be brought back into
113 // memory shortly; try again later.
114 ////////////////////////////////////////////////////////////////////
115 INLINE bool CullableObject::
117  bool resident = true;
118  if (!_geom->request_resident()) {
119  resident = false;
120  }
121  if (!_munged_data->request_resident()) {
122  resident = false;
123  }
124  return resident;
125 }
126 
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: CullableObject::set_draw_callback
130 // Access: Public
131 // Description: Specifies a CallbackObject that will be responsible
132 // for drawing this object.
133 ////////////////////////////////////////////////////////////////////
134 INLINE void CullableObject::
136  _draw_callback = draw_callback;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: CullableObject::flush_level
141 // Access: Public, Static
142 // Description: Flushes the PStatCollectors used during traversal.
143 ////////////////////////////////////////////////////////////////////
144 INLINE void CullableObject::
146  _sw_sprites_pcollector.flush_level();
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: CullableObject::draw_inline
151 // Access: Private
152 // Description: Draws the cullable object on the GSG immediately, in
153 // the GSG's current state. This should only be called
154 // from the draw thread. Assumes the GSG has already
155 // been set to the appropriate state.
156 ////////////////////////////////////////////////////////////////////
157 INLINE void CullableObject::
158 draw_inline(GraphicsStateGuardianBase *gsg, bool force, Thread *current_thread) {
159  _geom->draw(gsg, _munger, _munged_data, force, current_thread);
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function: CullableObject::SortPoints::Constructor
164 // Access: Public
165 // Description:
166 ////////////////////////////////////////////////////////////////////
167 INLINE CullableObject::SortPoints::
168 SortPoints(const CullableObject::PointData *array) :
169  _array(array)
170 {
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: CullableObject::SortPoints::operator ()
175 // Access: Public
176 // Description: Orders the points from back-to-front for correct
177 // transparency sorting in munge_points_to_quads
178 ////////////////////////////////////////////////////////////////////
179 INLINE bool CullableObject::SortPoints::
180 operator () (unsigned short a, unsigned short b) const {
181  return _array[a]._dist > _array[b]._dist;
182 }
183 
184 ////////////////////////////////////////////////////////////////////
185 // Function: CullableObject::SourceFormat::operator <
186 // Access: Public
187 // Description:
188 ////////////////////////////////////////////////////////////////////
189 INLINE bool CullableObject::SourceFormat::
190 operator < (const CullableObject::SourceFormat &other) const {
191  if (_format != other._format) {
192  return _format < other._format;
193  }
194  if (_sprite_texcoord != other._sprite_texcoord) {
195  return (int)_sprite_texcoord < (int)other._sprite_texcoord;
196  }
197  if (_retransform_sprites != other._retransform_sprites) {
198  return (int)_retransform_sprites < (int)other._retransform_sprites;
199  }
200  return false;
201 }
This specialization on CallbackData is passed when the callback is initiated from deep within the dra...
static void flush_level()
Flushes the PStatCollectors used during traversal.
bool request_resident() const
Returns true if all the data necessary to render this object is currently resident in memory...
void operator=(const CullableObject &copy)
Copies the CullableObject.
void draw(GraphicsStateGuardianBase *gsg, bool force, Thread *current_thread)
Draws the cullable object on the GSG immediately, in the GSG&#39;s current state.
The smallest atom of cull.
CullableObject()
Creates an empty CullableObject whose pointers can be filled in later.
A container for geometry primitives.
Definition: geom.h:58
bool get_lost_state() const
Returns the lost_state flag.
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...
void set_draw_callback(CallbackObject *draw_callback)
Specifies a CallbackObject that will be responsible for drawing this object.
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