Panda3D
pipelineCycler.I
1 // Filename: pipelineCycler.I
2 // Created by: drose (21Feb02)
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 #ifdef DO_PIPELINING
17 // The following implementations are to support the
18 // PipelineCyclerDummyImpl or the PipelineCyclerTrueImpl.
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: PipelineCycler::Constructor (dummy or true)
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 template<class CycleDataType>
27 PipelineCycler(Pipeline *pipeline) :
28  PipelineCyclerBase(new CycleDataType, pipeline)
29 {
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: PipelineCycler::Copy Constructor (dummy or true)
34 // Access: Public
35 // Description:
36 ////////////////////////////////////////////////////////////////////
37 template<class CycleDataType>
40  PipelineCyclerBase(copy)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: PipelineCycler::Copy Assignment (dummy or true)
46 // Access: Public
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 template<class CycleDataType>
52  PipelineCyclerBase::operator = (copy);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: PipelineCycler::read_unlocked (dummy or true)
57 // Access: Public
58 // Description: See PipelineCyclerBase::read_unlocked().
59 ////////////////////////////////////////////////////////////////////
60 template<class CycleDataType>
61 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
62 read_unlocked(Thread *current_thread) const {
63  return (const CycleDataType *)PipelineCyclerBase::read_unlocked(current_thread);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: PipelineCycler::read (dummy or true)
68 // Access: Public
69 // Description: See PipelineCyclerBase::read().
70 ////////////////////////////////////////////////////////////////////
71 template<class CycleDataType>
72 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
73 read(Thread *current_thread) const {
74  return (const CycleDataType *)PipelineCyclerBase::read(current_thread);
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: PipelineCycler::write (dummy or true)
79 // Access: Public
80 // Description: See PipelineCyclerBase::write().
81 ////////////////////////////////////////////////////////////////////
82 template<class CycleDataType>
83 INLINE CycleDataType *PipelineCycler<CycleDataType>::
84 write(Thread *current_thread) {
85  return (CycleDataType *)PipelineCyclerBase::write(current_thread);
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: PipelineCycler::write_upstream (dummy or true)
90 // Access: Public
91 // Description: See PipelineCyclerBase::write_upstream().
92 ////////////////////////////////////////////////////////////////////
93 template<class CycleDataType>
94 INLINE CycleDataType *PipelineCycler<CycleDataType>::
95 write_upstream(bool force_to_0, Thread *current_thread) {
96  return (CycleDataType *)PipelineCyclerBase::write_upstream(force_to_0, current_thread);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: PipelineCycler::elevate_read (dummy or true)
101 // Access: Public
102 // Description: See PipelineCyclerBase::elevate_read().
103 ////////////////////////////////////////////////////////////////////
104 template<class CycleDataType>
105 INLINE CycleDataType *PipelineCycler<CycleDataType>::
106 elevate_read(const CycleDataType *pointer, Thread *current_thread) {
107  return (CycleDataType *)PipelineCyclerBase::elevate_read(pointer, current_thread);
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: PipelineCycler::elevate_read_upstream (dummy or true)
112 // Access: Public
113 // Description: See PipelineCyclerBase::elevate_read_upstream().
114 ////////////////////////////////////////////////////////////////////
115 template<class CycleDataType>
116 INLINE CycleDataType *PipelineCycler<CycleDataType>::
117 elevate_read_upstream(const CycleDataType *pointer, bool force_to_0,
118  Thread *current_thread) {
119  return (CycleDataType *)PipelineCyclerBase::elevate_read_upstream(pointer, force_to_0, current_thread);
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: PipelineCycler::read_stage_unlocked (dummy or true)
124 // Access: Public
125 // Description: See PipelineCyclerBase::read_stage_unlocked().
126 ////////////////////////////////////////////////////////////////////
127 template<class CycleDataType>
128 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
129 read_stage_unlocked(int pipeline_stage) const {
130  return (const CycleDataType *)PipelineCyclerBase::read_stage_unlocked(pipeline_stage);
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: PipelineCycler::read_stage (dummy or true)
135 // Access: Public
136 // Description: See PipelineCyclerBase::read_stage().
137 ////////////////////////////////////////////////////////////////////
138 template<class CycleDataType>
139 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
140 read_stage(int pipeline_stage, Thread *current_thread) const {
141  return (const CycleDataType *)PipelineCyclerBase::read_stage(pipeline_stage, current_thread);
142 }
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: PipelineCycler::elevate_read_stage (dummy or true)
146 // Access: Public
147 // Description: See PipelineCyclerBase::elevate_read_stage().
148 ////////////////////////////////////////////////////////////////////
149 template<class CycleDataType>
150 INLINE CycleDataType *PipelineCycler<CycleDataType>::
151 elevate_read_stage(int pipeline_stage, const CycleDataType *pointer,
152  Thread *current_thread) {
153  return (CycleDataType *)PipelineCyclerBase::elevate_read_stage(pipeline_stage, pointer, current_thread);
154 }
155 
156 ////////////////////////////////////////////////////////////////////
157 // Function: PipelineCycler::elevate_read_stage_upstream (dummy or true)
158 // Access: Public
159 // Description: See PipelineCyclerBase::elevate_read_stage_upstream().
160 ////////////////////////////////////////////////////////////////////
161 template<class CycleDataType>
162 INLINE CycleDataType *PipelineCycler<CycleDataType>::
163 elevate_read_stage_upstream(int pipeline_stage, const CycleDataType *pointer,
164  bool force_to_0, Thread *current_thread) {
165  return (CycleDataType *)PipelineCyclerBase::elevate_read_stage_upstream(pipeline_stage, pointer, force_to_0, current_thread);
166 }
167 
168 ////////////////////////////////////////////////////////////////////
169 // Function: PipelineCycler::write_stage (dummy or true)
170 // Access: Public
171 // Description: See PipelineCyclerBase::write_stage().
172 ////////////////////////////////////////////////////////////////////
173 template<class CycleDataType>
174 INLINE CycleDataType *PipelineCycler<CycleDataType>::
175 write_stage(int pipeline_stage, Thread *current_thread) {
176  return (CycleDataType *)PipelineCyclerBase::write_stage(pipeline_stage, current_thread);
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: PipelineCycler::write_stage_upstream (dummy or true)
181 // Access: Public
182 // Description: See PipelineCyclerBase::write_stage_upstream().
183 ////////////////////////////////////////////////////////////////////
184 template<class CycleDataType>
185 INLINE CycleDataType *PipelineCycler<CycleDataType>::
186 write_stage_upstream(int pipeline_stage, bool force_to_0,
187  Thread *current_thread) {
188  return (CycleDataType *)PipelineCyclerBase::write_stage_upstream(pipeline_stage, force_to_0, current_thread);
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: PipelineCycler::cheat (dummy or true)
193 // Access: Public
194 // Description: Returns a pointer without counting it. This is only
195 // intended for use as the return value for certain
196 // nassertr() functions, so the application can recover
197 // after a failure to manage the read and write pointers
198 // correctly. You should never call this function
199 // directly.
200 ////////////////////////////////////////////////////////////////////
201 template<class CycleDataType>
202 INLINE CycleDataType *PipelineCycler<CycleDataType>::
203 cheat() const {
204  return (CycleDataType *)PipelineCyclerBase::cheat();
205 }
206 
207 #else // !DO_PIPELINING
208 // The following implementations are provided for when pipelining is
209 // not compiled in. They are trivial functions that do as little as
210 // possible.
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: PipelineCycler::Constructor (trivial)
214 // Access: Public
215 // Description:
216 ////////////////////////////////////////////////////////////////////
217 template<class CycleDataType>
219 PipelineCycler(Pipeline *pipeline) :
220  PipelineCyclerBase(&_typed_data, pipeline)
221 {
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: PipelineCycler::Copy Constructor (trivial)
226 // Access: Public
227 // Description:
228 ////////////////////////////////////////////////////////////////////
229 template<class CycleDataType>
232  PipelineCyclerBase(&_typed_data),
233  _typed_data(copy._typed_data)
234 {
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: PipelineCycler::Copy Assignment (trivial)
239 // Access: Public
240 // Description:
241 ////////////////////////////////////////////////////////////////////
242 template<class CycleDataType>
245  _typed_data = copy._typed_data;
246 }
247 
248 ////////////////////////////////////////////////////////////////////
249 // Function: PipelineCycler::read_unlocked (trivial)
250 // Access: Public
251 // Description: See PipelineCyclerBase::read_unlocked().
252 ////////////////////////////////////////////////////////////////////
253 template<class CycleDataType>
254 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
256  return &_typed_data;
257 }
258 
259 ////////////////////////////////////////////////////////////////////
260 // Function: PipelineCycler::read (trivial)
261 // Access: Public
262 // Description: See PipelineCyclerBase::read().
263 ////////////////////////////////////////////////////////////////////
264 template<class CycleDataType>
265 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
266 read(Thread *) const {
267  return &_typed_data;
268 }
269 
270 ////////////////////////////////////////////////////////////////////
271 // Function: PipelineCycler::write (trivial)
272 // Access: Public
273 // Description: See PipelineCyclerBase::write().
274 ////////////////////////////////////////////////////////////////////
275 template<class CycleDataType>
276 INLINE CycleDataType *PipelineCycler<CycleDataType>::
278  return &_typed_data;
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: PipelineCycler::write_upstream (trivial)
283 // Access: Public
284 // Description: See PipelineCyclerBase::write_upstream().
285 ////////////////////////////////////////////////////////////////////
286 template<class CycleDataType>
287 INLINE CycleDataType *PipelineCycler<CycleDataType>::
289  return &_typed_data;
290 }
291 
292 ////////////////////////////////////////////////////////////////////
293 // Function: PipelineCycler::elevate_read (trivial)
294 // Access: Public
295 // Description: See PipelineCyclerBase::elevate_read().
296 ////////////////////////////////////////////////////////////////////
297 template<class CycleDataType>
298 INLINE CycleDataType *PipelineCycler<CycleDataType>::
299 elevate_read(const CycleDataType *, Thread *) {
300  return &_typed_data;
301 }
302 
303 ////////////////////////////////////////////////////////////////////
304 // Function: PipelineCycler::elevate_read_upstream (trivial)
305 // Access: Public
306 // Description: See PipelineCyclerBase::elevate_read_upstream().
307 ////////////////////////////////////////////////////////////////////
308 template<class CycleDataType>
309 INLINE CycleDataType *PipelineCycler<CycleDataType>::
310 elevate_read_upstream(const CycleDataType *, bool, Thread *) {
311  return &_typed_data;
312 }
313 
314 ////////////////////////////////////////////////////////////////////
315 // Function: PipelineCycler::read_stage_unlocked (trivial)
316 // Access: Public
317 // Description: See PipelineCyclerBase::read_stage_unlocked().
318 ////////////////////////////////////////////////////////////////////
319 template<class CycleDataType>
320 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
322  return &_typed_data;
323 }
324 
325 ////////////////////////////////////////////////////////////////////
326 // Function: PipelineCycler::read_stage (trivial)
327 // Access: Public
328 // Description: See PipelineCyclerBase::read_stage().
329 ////////////////////////////////////////////////////////////////////
330 template<class CycleDataType>
331 INLINE const CycleDataType *PipelineCycler<CycleDataType>::
332 read_stage(int, Thread *) const {
333  return &_typed_data;
334 }
335 
336 ////////////////////////////////////////////////////////////////////
337 // Function: PipelineCycler::elevate_read_stage (trivial)
338 // Access: Public
339 // Description: See PipelineCyclerBase::elevate_read_stage().
340 ////////////////////////////////////////////////////////////////////
341 template<class CycleDataType>
342 INLINE CycleDataType *PipelineCycler<CycleDataType>::
343 elevate_read_stage(int, const CycleDataType *, Thread *) {
344  return &_typed_data;
345 }
346 
347 ////////////////////////////////////////////////////////////////////
348 // Function: PipelineCycler::elevate_read_stage_upstream (trivial)
349 // Access: Public
350 // Description: See PipelineCyclerBase::elevate_read_stage_upstream().
351 ////////////////////////////////////////////////////////////////////
352 template<class CycleDataType>
353 INLINE CycleDataType *PipelineCycler<CycleDataType>::
354 elevate_read_stage_upstream(int, const CycleDataType *, bool, Thread *) {
355  return &_typed_data;
356 }
357 
358 ////////////////////////////////////////////////////////////////////
359 // Function: PipelineCycler::write_stage (trivial)
360 // Access: Public
361 // Description: See PipelineCyclerBase::write_stage().
362 ////////////////////////////////////////////////////////////////////
363 template<class CycleDataType>
364 INLINE CycleDataType *PipelineCycler<CycleDataType>::
366  return &_typed_data;
367 }
368 
369 ////////////////////////////////////////////////////////////////////
370 // Function: PipelineCycler::write_stage_upstream (trivial)
371 // Access: Public
372 // Description: See PipelineCyclerBase::write_stage_upstream().
373 ////////////////////////////////////////////////////////////////////
374 template<class CycleDataType>
375 INLINE CycleDataType *PipelineCycler<CycleDataType>::
377  return &_typed_data;
378 }
379 
380 ////////////////////////////////////////////////////////////////////
381 // Function: PipelineCycler::cheat (trivial)
382 // Access: Public
383 // Description: Returns a pointer without counting it. This is only
384 // intended for use as the return value for certain
385 // nassertr() functions, so the application can recover
386 // after a failure to manage the read and write pointers
387 // correctly. You should never call this function
388 // directly.
389 ////////////////////////////////////////////////////////////////////
390 template<class CycleDataType>
391 INLINE CycleDataType *PipelineCycler<CycleDataType>::
392 cheat() const {
393  return (CycleDataType *)&_typed_data;
394 }
395 
396 
397 #endif // DO_PIPELINING
CycleData * write_stage(int pipeline_stage, Thread *current_thread)
Returns a pointer suitable for writing to the nth stage of the pipeline.
CycleData * write_upstream(bool force_to_0, Thread *current_thread)
This special variant on write() will automatically propagate changes back to upstream pipeline stages...
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
const CycleData * read_stage(int pipeline_stage, Thread *current_thread) const
Returns a const CycleData pointer, filled with the data for the indicated pipeline stage...
CycleDataType * elevate_read(const CycleDataType *pointer, Thread *current_thread)
See PipelineCyclerBase::elevate_read().
This is the trivial, non-threaded implementation of PipelineCyclerBase.
CycleDataType * cheat() const
Returns a pointer without counting it.
CycleDataType * elevate_read_stage_upstream(int pipeline_stage, const CycleDataType *pointer, bool force_to_0, Thread *current_thread)
See PipelineCyclerBase::elevate_read_stage_upstream().
const CycleDataType * read_stage(int pipeline_stage, Thread *current_thread) const
See PipelineCyclerBase::read_stage().
CycleDataType * elevate_read_stage(int pipeline_stage, const CycleDataType *pointer, Thread *current_thread)
See PipelineCyclerBase::elevate_read_stage().
CycleData * elevate_read_stage(int pipeline_stage, const CycleData *pointer, Thread *current_thread)
Elevates a currently-held read pointer into a write pointer.
CycleData * write(Thread *current_thread)
Returns a non-const CycleData pointer, filled with a unique copy of the data for the current stage of...
const CycleData * read_stage_unlocked(int pipeline_stage) const
Returns a const CycleData pointer, filled with the data for the indicated stage of the pipeline...
CycleData * write_stage_upstream(int pipeline_stage, bool force_to_0, Thread *current_thread)
Returns a pointer suitable for writing to the nth stage of the pipeline.
CycleDataType * write_stage_upstream(int pipeline_stage, bool force_to_0, Thread *current_thread)
See PipelineCyclerBase::write_stage_upstream().
CycleData * elevate_read(const CycleData *pointer, Thread *current_thread)
Elevates a currently-held read pointer into a write pointer.
CycleDataType * write_stage(int pipeline_stage, Thread *current_thread)
See PipelineCyclerBase::write_stage().
This class manages a staged pipeline of data, for instance the render pipeline, so that each stage of...
Definition: pipeline.h:41
CycleDataType * write(Thread *current_thread)
See PipelineCyclerBase::write().
CycleDataType * elevate_read_upstream(const CycleDataType *pointer, bool force_to_0, Thread *current_thread)
See PipelineCyclerBase::elevate_read_upstream().
const CycleDataType * read_unlocked(Thread *current_thread) const
See PipelineCyclerBase::read_unlocked().
CycleData * cheat() const
Returns a pointer without counting it.
A thread; that is, a lightweight process.
Definition: thread.h:51
const CycleData * read(Thread *current_thread) const
Returns a const CycleData pointer, filled with the data for the current stage of the pipeline as seen...
const CycleDataType * read_stage_unlocked(int pipeline_stage) const
See PipelineCyclerBase::read_stage_unlocked().
CycleDataType * write_upstream(bool force_to_0, Thread *current_thread)
See PipelineCyclerBase::write_upstream().
CycleData * elevate_read_stage_upstream(int pipeline_stage, const CycleData *pointer, bool force_to_0, Thread *current_thread)
Elevates a currently-held read pointer into a write pointer.
const CycleDataType * read(Thread *current_thread) const
See PipelineCyclerBase::read().
CycleData * elevate_read_upstream(const CycleData *pointer, bool force_to_0, Thread *current_thread)
Elevates a currently-held read pointer into a write pointer, like elevate_read(), but also propagates...
const CycleData * read_unlocked(Thread *current_thread) const
Returns a const CycleData pointer, filled with the data for the current stage of the pipeline as seen...