Panda3D
shaderBuffer.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 shaderBuffer.h
10  * @author rdb
11  * @date 2016-12-12
12  */
13 
14 #ifndef SHADERBUFFER_H
15 #define SHADERBUFFER_H
16 
17 #include "pandabase.h"
19 #include "namable.h"
20 #include "geomEnums.h"
22 #include "factoryParams.h"
23 #include "vector_uchar.h"
24 
25 class BufferContext;
27 
28 /**
29  * This is a generic buffer object that lives in graphics memory.
30  */
31 class EXPCL_PANDA_GOBJ ShaderBuffer : public TypedWritableReferenceCount, public Namable, public GeomEnums {
32 private:
33  INLINE ShaderBuffer() = default;
34 
35 PUBLISHED:
36  ~ShaderBuffer();
37 
38  INLINE explicit ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint);
39  INLINE explicit ShaderBuffer(const std::string &name, vector_uchar initial_data, UsageHint usage_hint);
40 
41 public:
42  INLINE uint64_t get_data_size_bytes() const;
43  INLINE UsageHint get_usage_hint() const;
44  INLINE const unsigned char *get_initial_data() const;
45 
46  virtual void output(std::ostream &out) const;
47 
48 PUBLISHED:
49  MAKE_PROPERTY(data_size_bytes, get_data_size_bytes);
50  MAKE_PROPERTY(usage_hint, get_usage_hint);
51 
52  void prepare(PreparedGraphicsObjects *prepared_objects);
53  bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
54 
55  BufferContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
57  bool release(PreparedGraphicsObjects *prepared_objects);
58  int release_all();
59 
60 private:
61  void clear_prepared(PreparedGraphicsObjects *prepared_objects);
62 
63 private:
64  uint64_t _data_size_bytes;
65  UsageHint _usage_hint;
66  vector_uchar _initial_data;
67 
69  Contexts *_contexts = nullptr;
70 
71 public:
72  static void register_with_read_factory();
73  virtual void write_datagram(BamWriter *manager, Datagram &dg);
74 
75 protected:
76  static TypedWritable *make_from_bam(const FactoryParams &params);
77  void fillin(DatagramIterator &scan, BamReader *manager);
78 
79 public:
80  virtual TypeHandle get_type() const {
81  return get_class_type();
82  }
83  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
84  static TypeHandle get_class_type() {
85  return _type_handle;
86  }
87  static void init_type() {
88  TypedWritableReferenceCount::init_type();
89  Namable::init_type();
90  register_type(_type_handle, "ShaderBuffer",
91  TypedWritableReferenceCount::get_class_type(),
92  Namable::get_class_type());
93  }
94 
95 private:
96  static TypeHandle _type_handle;
97 
98  friend class PreparedGraphicsObjects;
99 };
100 
101 INLINE std::ostream &operator << (std::ostream &out, const ShaderBuffer &m) {
102  m.output(out);
103  return out;
104 }
105 
106 #include "shaderBuffer.I"
107 
108 #endif
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
This is a generic buffer object that lives in graphics memory.
Definition: shaderBuffer.h:31
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This class exists just to provide scoping for the various enumerated types used by Geom...
Definition: geomEnums.h:24
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:38
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(), along with zero to four record_derivation()s.
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A table of objects that are saved within the graphics context for reference by handle later...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void output(std::ostream &out) const
Outputs the Namable.
Definition: namable.I:61
A base class for all things which can have a name.
Definition: namable.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.