Panda3D
cycleDataStageWriter.I
1 // Filename: cycleDataStageWriter.I
2 // Created by: drose (06Feb06)
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 CPPPARSER
16 
17 #ifdef DO_PIPELINING
18 // This is the implementation for full support of pipelining (as well
19 // as the sanity-check only implementation).
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: CycleDataStageWriter::Constructor (full)
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 template<class CycleDataType>
29  Thread *current_thread) :
30  _cycler(&cycler),
31  _current_thread(current_thread),
32  _stage(stage)
33 {
34  _pointer = _cycler->write_stage(_stage, _current_thread);
35  nassertv(_pointer != (CycleDataType *)NULL);
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: CycleDataStageWriter::Constructor (full)
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 template<class CycleDataType>
46  bool force_to_0, Thread *current_thread) :
47  _cycler(&cycler),
48  _current_thread(current_thread),
49  _stage(stage)
50 {
51  _pointer = _cycler->write_stage_upstream(_stage, force_to_0, _current_thread);
52  nassertv(_pointer != (CycleDataType *)NULL);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: CycleDataStageWriter::Copy Constructor (full)
57 // Access: Public
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 template<class CycleDataType>
63  _cycler(copy._cycler),
64  _current_thread(copy._current_thread),
65  _pointer(copy._pointer),
66  _stage(copy._stage)
67 {
68  nassertv(_pointer != (CycleDataType *)NULL);
69  _cycler->increment_write(_pointer);
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: CycleDataStageWriter::Copy Assignment (full)
74 // Access: Public
75 // Description:
76 ////////////////////////////////////////////////////////////////////
77 template<class CycleDataType>
80  nassertv(_pointer == (CycleDataType *)NULL);
81  nassertv(_current_thread == copy._current_thread);
82 
83  _cycler = copy._cycler;
84  _pointer = copy._pointer;
85  _stage = copy._stage;
86 
87  nassertv(_pointer != (CycleDataType *)NULL);
88  _cycler->increment_write(_pointer);
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: CycleDataStageWriter::Constructor (full)
93 // Access: Public
94 // Description: This flavor of the constructor elevates the pointer
95 // from the CycleDataLockedStageReader from a read to a write
96 // pointer (and invalidates the reader).
97 ////////////////////////////////////////////////////////////////////
98 template<class CycleDataType>
102  _cycler(&cycler),
103  _current_thread(take_from.get_current_thread()),
104  _stage(stage)
105 {
106  _pointer = _cycler->elevate_read_stage(_stage, take_from.take_pointer(),
107  _current_thread);
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: CycleDataStageWriter::Constructor (full)
112 // Access: Public
113 // Description: This flavor of the constructor elevates the pointer
114 // from the CycleDataLockedStageReader from a read to a write
115 // pointer (and invalidates the reader).
116 ////////////////////////////////////////////////////////////////////
117 template<class CycleDataType>
121  bool force_to_0) :
122  _cycler(&cycler),
123  _current_thread(take_from.get_current_thread()),
124  _stage(stage)
125 {
126  _pointer = _cycler->elevate_read_stage_upstream(_stage, take_from.take_pointer(),
127  force_to_0, _current_thread);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: CycleDataStageWriter::Destructor (full)
132 // Access: Public
133 // Description:
134 ////////////////////////////////////////////////////////////////////
135 template<class CycleDataType>
138  if (_pointer != (CycleDataType *)NULL) {
139  _cycler->release_write_stage(_stage, _pointer);
140  }
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: CycleDataStageWriter::operator -> (full)
145 // Access: Public
146 // Description: This provides an indirect member access to the actual
147 // CycleData data.
148 ////////////////////////////////////////////////////////////////////
149 template<class CycleDataType>
150 INLINE CycleDataType *CycleDataStageWriter<CycleDataType>::
151 operator -> () {
152  nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat());
153  return _pointer;
154 }
155 
156 ////////////////////////////////////////////////////////////////////
157 // Function: CycleDataStageWriter::operator -> (full)
158 // Access: Public
159 // Description: This provides an indirect member access to the actual
160 // CycleData data.
161 ////////////////////////////////////////////////////////////////////
162 template<class CycleDataType>
163 INLINE const CycleDataType *CycleDataStageWriter<CycleDataType>::
164 operator -> () const {
165  nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat());
166  return _pointer;
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: CycleDataStageWriter::Typecast pointer (full)
171 // Access: Public
172 // Description: This allows the CycleDataStageWriter to be passed to any
173 // function that expects a CycleDataType pointer.
174 ////////////////////////////////////////////////////////////////////
175 template<class CycleDataType>
177 operator CycleDataType * () {
178  nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat());
179  return _pointer;
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: CycleDataStageWriter::get_current_thread (full)
184 // Access: Public
185 // Description: Returns the Thread pointer of the currently-executing
186 // thread, as passed to the constructor of this object.
187 ////////////////////////////////////////////////////////////////////
188 template<class CycleDataType>
190 get_current_thread() const {
191  return _current_thread;
192 }
193 
194 #else // !DO_PIPELINING
195 // This is the trivial, do-nothing implementation.
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: CycleDataStageWriter::Constructor (trivial)
199 // Access: Public
200 // Description:
201 ////////////////////////////////////////////////////////////////////
202 template<class CycleDataType>
205  _pointer = cycler.cheat();
206 }
207 
208 ////////////////////////////////////////////////////////////////////
209 // Function: CycleDataStageWriter::Constructor (trivial)
210 // Access: Public
211 // Description:
212 ////////////////////////////////////////////////////////////////////
213 template<class CycleDataType>
216  _pointer = cycler.cheat();
217 }
218 
219 ////////////////////////////////////////////////////////////////////
220 // Function: CycleDataStageWriter::Copy Constructor (trivial)
221 // Access: Public
222 // Description:
223 ////////////////////////////////////////////////////////////////////
224 template<class CycleDataType>
227  _pointer(copy._pointer)
228 {
229 }
230 
231 ////////////////////////////////////////////////////////////////////
232 // Function: CycleDataStageWriter::Copy Assignment (trivial)
233 // Access: Public
234 // Description:
235 ////////////////////////////////////////////////////////////////////
236 template<class CycleDataType>
239  _pointer = copy._pointer;
240 }
241 
242 ////////////////////////////////////////////////////////////////////
243 // Function: CycleDataStageWriter::Constructor (trivial)
244 // Access: Public
245 // Description: This flavor of the constructor elevates the pointer
246 // from the CycleDataLockedStageReader from a read to a write
247 // pointer (and invalidates the reader).
248 ////////////////////////////////////////////////////////////////////
249 template<class CycleDataType>
253  _pointer((CycleDataType *)take_from.take_pointer())
254 {
255 }
256 
257 ////////////////////////////////////////////////////////////////////
258 // Function: CycleDataStageWriter::Constructor (trivial)
259 // Access: Public
260 // Description: This flavor of the constructor elevates the pointer
261 // from the CycleDataLockedStageReader from a read to a write
262 // pointer (and invalidates the reader).
263 ////////////////////////////////////////////////////////////////////
264 template<class CycleDataType>
268  bool) :
269  _pointer((CycleDataType *)take_from.take_pointer())
270 {
271 }
272 
273 ////////////////////////////////////////////////////////////////////
274 // Function: CycleDataStageWriter::Destructor (trivial)
275 // Access: Public
276 // Description:
277 ////////////////////////////////////////////////////////////////////
278 template<class CycleDataType>
281 }
282 
283 ////////////////////////////////////////////////////////////////////
284 // Function: CycleDataStageWriter::operator -> (trivial)
285 // Access: Public
286 // Description: This provides an indirect member access to the actual
287 // CycleData data.
288 ////////////////////////////////////////////////////////////////////
289 template<class CycleDataType>
290 INLINE CycleDataType *CycleDataStageWriter<CycleDataType>::
292  return _pointer;
293 }
294 
295 ////////////////////////////////////////////////////////////////////
296 // Function: CycleDataStageWriter::operator -> (trivial)
297 // Access: Public
298 // Description: This provides an indirect member access to the actual
299 // CycleData data.
300 ////////////////////////////////////////////////////////////////////
301 template<class CycleDataType>
302 INLINE const CycleDataType *CycleDataStageWriter<CycleDataType>::
303 operator -> () const {
304  return _pointer;
305 }
306 
307 ////////////////////////////////////////////////////////////////////
308 // Function: CycleDataStageWriter::Typecast pointer (trivial)
309 // Access: Public
310 // Description: This allows the CycleDataStageWriter to be passed to any
311 // function that expects a CycleDataType pointer.
312 ////////////////////////////////////////////////////////////////////
313 template<class CycleDataType>
315 operator CycleDataType * () {
316  return _pointer;
317 }
318 
319 ////////////////////////////////////////////////////////////////////
320 // Function: CycleDataStageWriter::get_current_thread (trivial)
321 // Access: Public
322 // Description: Returns the Thread pointer of the currently-executing
323 // thread, as passed to the constructor of this object.
324 ////////////////////////////////////////////////////////////////////
325 template<class CycleDataType>
329 }
330 
331 #endif // DO_PIPELINING
332 #endif // CPPPARSER
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
CycleDataType * cheat() const
Returns a pointer without counting it.
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataStageWriter when it elevates the pointer from read t...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
CycleDataType * operator->()
This provides an indirect member access to the actual CycleData data.
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
A thread; that is, a lightweight process.
Definition: thread.h:51
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...