Panda3D
Loading...
Searching...
No Matches
computeNode.cxx
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 computeNode.cxx
10 * @author rdb
11 * @date 2014-06-19
12 */
13
14#include "pandabase.h"
15#include "computeNode.h"
16#include "cullTraverser.h"
17#include "cullableObject.h"
18#include "cullHandler.h"
20#include "omniBoundingVolume.h"
21#include "config_pgraph.h"
22
23TypeHandle ComputeNode::_type_handle;
24
25/**
26 * Creates a ComputeNode with the given name. Use add_dispatch and also
27 * assign a shader using a ShaderAttrib.
28 */
30ComputeNode(const std::string &name) :
31 PandaNode(name),
32 _dispatcher(new ComputeNode::Dispatcher)
33{
34 set_internal_bounds(new OmniBoundingVolume);
35}
36
37/**
38 *
39 */
41ComputeNode(const ComputeNode &copy) :
42 PandaNode(copy),
43 _dispatcher(new ComputeNode::Dispatcher(*copy._dispatcher))
44{
45}
46
47/**
48 * Returns a newly-allocated Node that is a shallow copy of this one. It will
49 * be a different Node pointer, but its internal data may or may not be shared
50 * with that of the original Node.
51 */
53make_copy() const {
54 return new ComputeNode(*this);
55}
56
57/**
58 * Returns true if it is generally safe to combine this particular kind of
59 * PandaNode with other kinds of PandaNodes of compatible type, adding
60 * children or whatever. For instance, an LODNode should not be combined with
61 * any other PandaNode, because its set of children is meaningful.
62 */
64safe_to_combine() const {
65 return false;
66}
67
68/**
69 * Returns true if there is some value to visiting this particular node during
70 * the cull traversal for any camera, false otherwise. This will be used to
71 * optimize the result of get_net_draw_show_mask(), so that any subtrees that
72 * contain only nodes for which is_renderable() is false need not be visited.
73 */
75is_renderable() const {
76 return true;
77}
78
79/**
80 * Adds the node's contents to the CullResult we are building up during the
81 * cull traversal, so that it will be drawn at render time. For most nodes
82 * other than GeomNodes, this is a do-nothing operation.
83 */
86 if (pgraph_cat.is_spam()) {
87 pgraph_cat.spam()
88 << "Found " << *this << " in state " << *data._state
89 << " draw_mask = " << data._draw_mask << "\n";
90 }
91
92 // OK, render this node. Rendering this node means creating a
93 // CullableObject for the Dispatcher. We don't need to pass any Geoms,
94 // however.
95 CullableObject *object =
96 new CullableObject(nullptr, data._state,
97 data.get_internal_transform(trav));
98 object->set_draw_callback(_dispatcher);
99 trav->get_cull_handler()->record_object(object, trav);
100}
101
102/**
103 * Writes a brief description of the node to the indicated output stream.
104 * This is invoked by the << operator. It may be overridden in derived
105 * classes to include some information relevant to the class.
106 */
108output(std::ostream &out) const {
109 PandaNode::output(out);
110}
111
112/**
113 *
114 */
115ComputeNode::Dispatcher::
116Dispatcher() {
117}
118
119/**
120 *
121 */
122ComputeNode::Dispatcher::
123Dispatcher(const Dispatcher &copy) :
124 _cycler(copy._cycler)
125{
126}
127
128/**
129 * Asks the GSG to dispatch the compute shader.
130 */
132do_callback(CallbackData *cbdata) {
134 GraphicsStateGuardianBase *gsg = data->get_gsg();
135
136 CDReader cdata(_cycler);
137
138 Dispatches::const_iterator it;
139 for (it = cdata->_dispatches.begin(); it != cdata->_dispatches.end(); ++it) {
140 gsg->dispatch_compute(it->get_x(), it->get_y(), it->get_z());
141 }
142
143 // No need to upcall; we don't have any geometry, after all.
144}
145
146/**
147 * Tells the BamReader how to create objects of type ComputeNode.
148 */
151 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
152}
153
154/**
155 * Writes the contents of this object to the datagram for shipping out to a
156 * Bam file.
157 */
159write_datagram(BamWriter *manager, Datagram &dg) {
160 PandaNode::write_datagram(manager, dg);
161 manager->write_cdata(dg, _dispatcher->_cycler);
162}
163
164/**
165 * This function is called by the BamReader's factory when a new object of
166 * type ComputeNode is encountered in the Bam file. It should create the
167 * ComputeNode and extract its information from the file.
168 */
169TypedWritable *ComputeNode::
170make_from_bam(const FactoryParams &params) {
171 ComputeNode *node = new ComputeNode("");
172 DatagramIterator scan;
173 BamReader *manager;
174
175 parse_params(params, scan, manager);
176 node->fillin(scan, manager);
177
178 return node;
179}
180
181/**
182 * This internal function is called by make_from_bam to read in all of the
183 * relevant data from the BamFile for the new ComputeNode.
184 */
185void ComputeNode::
186fillin(DatagramIterator &scan, BamReader *manager) {
187 PandaNode::fillin(scan, manager);
188 manager->read_cdata(scan, _dispatcher->_cycler);
189}
190
191/**
192 *
193 */
194CycleData *ComputeNode::Dispatcher::CData::
195make_copy() const {
196 return new CData(*this);
197}
198
199/**
200 * Writes the contents of this object to the datagram for shipping out to a
201 * Bam file.
202 */
204write_datagram(BamWriter *manager, Datagram &dg) const {
205 dg.add_uint16(_dispatches.size());
206
207 Dispatches::const_iterator it;
208 for (it = _dispatches.begin(); it != _dispatches.end(); ++it) {
209 generic_write_datagram(dg, *it);
210 }
211}
212
213/**
214 * This internal function is called by make_from_bam to read in all of the
215 * relevant data from the BamFile for the new ComputeNode.
216 */
218fillin(DatagramIterator &scan, BamReader *manager) {
219 int num_dispatches = scan.get_uint16();
220 _dispatches.resize(num_dispatches);
221
222 for (int i = 0; i < num_dispatches; ++i) {
223 generic_read_datagram(_dispatches[i], scan);
224 }
225}
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler)
Reads in the indicated CycleData object.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
void write_cdata(Datagram &packet, const PipelineCyclerBase &cycler)
Writes out the indicated CycleData object.
This is a generic data block that is passed along to a CallbackObject when a callback is made.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is called by make_from_bam to read in all of the relevant data from the BamFil...
virtual void write_datagram(BamWriter *manager, Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void do_callback(CallbackData *cbdata)
Asks the GSG to dispatch the compute shader.
A special node, the sole purpose of which is to invoke a dispatch operation on the assigned compute s...
Definition computeNode.h:27
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node's contents to the CullResult we are building up during the cull traversal,...
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
static void register_with_read_factory()
Tells the BamReader how to create objects of type ComputeNode.
ComputeNode(const std::string &name)
Creates a ComputeNode with the given name.
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
virtual void output(std::ostream &out) const
Writes a brief description of the node to the indicated output stream.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void record_object(CullableObject *object, const CullTraverser *traverser)
This callback function is intended to be overridden by a derived class.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
CullHandler * get_cull_handler() const
Returns the object that will receive the culled Geoms.
The smallest atom of cull.
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
A class to retrieve the individual data elements previously stored in a Datagram.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition datagram.I:85
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition factory.I:73
This specialization on CallbackData is passed when the callback is initiated from deep within the dra...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This is a special kind of GeometricBoundingVolume that fills all of space.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.