Panda3D
computeNode.h
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.h
10  * @author rdb
11  * @date 2014-06-19
12  */
13 
14 #ifndef COMPUTENODE_H
15 #define COMPUTENODE_H
16 
17 #include "pandabase.h"
18 #include "pandaNode.h"
19 #include "callbackObject.h"
20 #include "callbackNode.h"
21 #include "pointerTo.h"
22 
23 /**
24  * A special node, the sole purpose of which is to invoke a dispatch operation
25  * on the assigned compute shader.
26  */
27 class EXPCL_PANDA_PGRAPHNODES ComputeNode : public PandaNode {
28 PUBLISHED:
29  explicit ComputeNode(const std::string &name);
30 
31  INLINE void add_dispatch(const LVecBase3i &num_groups);
32  INLINE void add_dispatch(int num_groups_x, int num_groups_y, int num_groups_z);
33 
34  INLINE size_t get_num_dispatches() const;
35  INLINE const LVecBase3i &get_dispatch(size_t i) const;
36  INLINE void set_dispatch(size_t i, const LVecBase3i &num_groups);
37  INLINE void insert_dispatch(size_t i, const LVecBase3i &num_groups);
38  INLINE void remove_dispatch(size_t i);
39  INLINE void clear_dispatches();
40 
41  MAKE_SEQ(get_dispatches, get_num_dispatches, get_dispatch);
42  MAKE_SEQ_PROPERTY(dispatches, get_num_dispatches, get_dispatch, set_dispatch, remove_dispatch, insert_dispatch);
43 
44 public:
45  ComputeNode(const ComputeNode &copy);
46 
47  virtual PandaNode *make_copy() const;
48  virtual bool safe_to_combine() const;
49 
50  virtual bool is_renderable() const;
51  virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
52 
53  virtual void output(std::ostream &out) const;
54 
55 public:
56  class EXPCL_PANDA_PGRAPHNODES Dispatcher : public CallbackObject {
57  friend class ComputeNode;
58  public:
59  ALLOC_DELETED_CHAIN(Dispatcher);
60  Dispatcher();
61  Dispatcher(const Dispatcher &copy);
62 
63  virtual void do_callback(CallbackData *cbdata);
64 
66 
67  class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
68  public:
69  INLINE CData();
70  INLINE CData(const CData &copy);
71  virtual CycleData *make_copy() const;
72  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
73  virtual void fillin(DatagramIterator &scan, BamReader *manager);
74  virtual TypeHandle get_parent_type() const {
75  return CallbackNode::get_class_type();
76  }
77 
78  Dispatches _dispatches;
79  };
80 
81  PipelineCycler<CData> _cycler;
84 
85  };
86 
87 private:
88  // One per ComputeNode.
89  PT(Dispatcher) _dispatcher;
90 
91 public:
92  static void register_with_read_factory();
93  virtual void write_datagram(BamWriter *manager, Datagram &dg);
94 
95 protected:
96  static TypedWritable *make_from_bam(const FactoryParams &params);
97  void fillin(DatagramIterator &scan, BamReader *manager);
98 
99 public:
100  static TypeHandle get_class_type() {
101  return _type_handle;
102  }
103  static void init_type() {
104  PandaNode::init_type();
105  register_type(_type_handle, "ComputeNode",
106  PandaNode::get_class_type());
107  }
108  virtual TypeHandle get_type() const {
109  return get_class_type();
110  }
111  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
112 
113 private:
114  static TypeHandle _type_handle;
115 };
116 
117 #include "computeNode.I"
118 
119 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is a generic data block that is passed along to a CallbackObject when a callback is made.
Definition: callbackData.h:29
This is a generic object that can be assigned to a callback at various points in the rendering proces...
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: computeNode.h:74
A special node, the sole purpose of which is to invoke a dispatch operation on the assigned compute s...
Definition: computeNode.h:27
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,...
Definition: cullTraverser.h:45
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
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.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:228
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:462
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:3574
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:481
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,...
Definition: pandaNode.cxx:472
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:3583
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.
Definition: typedWritable.h:35
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.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22