Panda3D
Loading...
Searching...
No Matches
cycleDataStageWriter.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file cycleDataStageWriter.I
10 * @author drose
11 * @date 2006-02-06
12 */
13
14#ifndef CPPPARSER
15
16#ifdef DO_PIPELINING
17// This is the implementation for full support of pipelining (as well as the
18// sanity-check only implementation).
19
20/**
21 *
22 */
23template<class CycleDataType>
26 Thread *current_thread) :
27 _cycler(&cycler),
28 _current_thread(current_thread),
29 _stage(stage)
30{
31 _pointer = _cycler->write_stage(_stage, _current_thread);
32 nassertv(_pointer != nullptr);
33}
34
35/**
36 *
37 */
38template<class CycleDataType>
41 bool force_to_0, Thread *current_thread) :
42 _cycler(&cycler),
43 _current_thread(current_thread),
44 _stage(stage)
45{
46 _pointer = _cycler->write_stage_upstream(_stage, force_to_0, _current_thread);
47 nassertv(_pointer != nullptr);
48}
49
50/**
51 *
52 */
53template<class CycleDataType>
56 _cycler(copy._cycler),
57 _current_thread(copy._current_thread),
58 _pointer(copy._pointer),
59 _stage(copy._stage)
60{
61 nassertv(_pointer != nullptr);
62 _cycler->increment_write(_pointer);
63}
64
65/**
66 * This flavor of the constructor elevates the pointer from the
67 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
68 * the reader).
69 */
70template<class CycleDataType>
74 _cycler(&cycler),
75 _current_thread(take_from.get_current_thread()),
76 _stage(stage)
77{
78 _pointer = _cycler->elevate_read_stage(_stage, take_from.take_pointer(),
79 _current_thread);
80}
81
82/**
83 * This flavor of the constructor elevates the pointer from the
84 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
85 * the reader).
86 */
87template<class CycleDataType>
91 bool force_to_0) :
92 _cycler(&cycler),
93 _current_thread(take_from.get_current_thread()),
94 _stage(stage)
95{
96 _pointer = _cycler->elevate_read_stage_upstream(_stage, take_from.take_pointer(),
97 force_to_0, _current_thread);
98}
99
100/**
101 *
102 */
103template<class CycleDataType>
106 _cycler(from._cycler),
107 _current_thread(from._current_thread),
108 _pointer(from._pointer),
109 _stage(from._stage)
110{
111 from._pointer = nullptr;
112}
113
114/**
115 *
116 */
117template<class CycleDataType>
120 nassertv(_pointer == nullptr);
121 nassertv(_current_thread == copy._current_thread);
122
123 _cycler = copy._cycler;
124 _pointer = copy._pointer;
125 _stage = copy._stage;
126
127 nassertv(_pointer != nullptr);
128 _cycler->increment_write(_pointer);
129}
130
131/**
132 *
133 */
134template<class CycleDataType>
137 nassertv(_pointer == nullptr);
138 nassertv(_current_thread == from._current_thread);
139
140 _cycler = from._cycler;
141 _pointer = from._pointer;
142 _stage = from._stage;
143
144 from._pointer = nullptr;
145}
146
147/**
148 *
149 */
150template<class CycleDataType>
153 if (_pointer != nullptr) {
154 _cycler->release_write_stage(_stage, _pointer);
155 }
156}
157
158/**
159 * This provides an indirect member access to the actual CycleData data.
160 */
161template<class CycleDataType>
162INLINE CycleDataType *CycleDataStageWriter<CycleDataType>::
163operator -> () {
164 nassertr(_pointer != nullptr, _cycler->cheat());
165 return _pointer;
166}
167
168/**
169 * This provides an indirect member access to the actual CycleData data.
170 */
171template<class CycleDataType>
172INLINE const CycleDataType *CycleDataStageWriter<CycleDataType>::
173operator -> () const {
174 nassertr(_pointer != nullptr, _cycler->cheat());
175 return _pointer;
176}
177
178/**
179 * This allows the CycleDataStageWriter to be passed to any function that
180 * expects a CycleDataType pointer.
181 */
182template<class CycleDataType>
184operator CycleDataType * () {
185 nassertr(_pointer != nullptr, _cycler->cheat());
186 return _pointer;
187}
188
189/**
190 * Returns the Thread pointer of the currently-executing thread, as passed to
191 * the constructor of this object.
192 */
193template<class CycleDataType>
195get_current_thread() const {
196 return _current_thread;
197}
198
199#else // !DO_PIPELINING
200// This is the trivial, do-nothing implementation.
201
202/**
203 *
204 */
205template<class CycleDataType>
208 _pointer = cycler.cheat();
209}
210
211/**
212 *
213 */
214template<class CycleDataType>
217 _pointer = cycler.cheat();
218}
219
220/**
221 *
222 */
223template<class CycleDataType>
226 _pointer(copy._pointer)
227{
228}
229
230/**
231 *
232 */
233template<class CycleDataType>
236 _pointer(from._pointer)
237{
238 from._pointer = nullptr;
239}
240
241/**
242 *
243 */
244template<class CycleDataType>
247 _pointer = copy._pointer;
248}
249
250/**
251 *
252 */
253template<class CycleDataType>
256 nassertv(_pointer == nullptr);
257
258 _pointer = from._pointer;
259 from._pointer = nullptr;
260}
261
262/**
263 * This flavor of the constructor elevates the pointer from the
264 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
265 * the reader).
266 */
267template<class CycleDataType>
271 _pointer((CycleDataType *)take_from.take_pointer())
272{
273}
274
275/**
276 * This flavor of the constructor elevates the pointer from the
277 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
278 * the reader).
279 */
280template<class CycleDataType>
284 bool) :
285 _pointer((CycleDataType *)take_from.take_pointer())
286{
287}
288
289/**
290 *
291 */
292template<class CycleDataType>
295}
296
297/**
298 * This provides an indirect member access to the actual CycleData data.
299 */
300template<class CycleDataType>
302operator -> () {
303 return _pointer;
304}
305
306/**
307 * This provides an indirect member access to the actual CycleData data.
308 */
309template<class CycleDataType>
310INLINE const CycleDataType *CycleDataStageWriter<CycleDataType>::
311operator -> () const {
312 return _pointer;
313}
314
315/**
316 * This allows the CycleDataStageWriter to be passed to any function that
317 * expects a CycleDataType pointer.
318 */
319template<class CycleDataType>
321operator CycleDataType * () {
322 return _pointer;
323}
324
325/**
326 * Returns the Thread pointer of the currently-executing thread, as passed to
327 * the constructor of this object.
328 */
329template<class CycleDataType>
334
335#endif // DO_PIPELINING
336#endif // CPPPARSER
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataStageWriter when it elevates the pointer from read t...
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
CycleDataType * operator->()
This provides an indirect member access to the actual CycleData data.
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
CycleDataType * cheat() const
Returns a pointer without counting it.