Panda3D

Loading...
Searching...
No Matches
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"
18#include "typedWritableReferenceCount.h"
19#include "namable.h"
20#include "geomEnums.h"
21#include "graphicsStateGuardianBase.h"
22#include "factoryParams.h"
23#include "vector_uchar.h"
24
25 class BufferContext;
26 class PreparedGraphicsObjects;
27
28/**
29 * This is a generic buffer object that lives in graphics memory.
30 *
31 * @since 1.10.0
32 */
33 class EXPCL_PANDA_GOBJ ShaderBuffer : public TypedWritableReferenceCount, public Namable, public GeomEnums {
34 private:
35 INLINE ShaderBuffer() = default;
36
37PUBLISHED:
38 ~ShaderBuffer();
39
40 INLINE explicit ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint);
41 INLINE explicit ShaderBuffer(const std::string &name, vector_uchar initial_data, UsageHint usage_hint);
42
43 public:
44 INLINE uint64_t get_data_size_bytes() const;
45 INLINE UsageHint get_usage_hint() const;
46 INLINE const unsigned char *get_initial_data() const;
47
48 virtual void output(std::ostream &out) const;
49
50PUBLISHED:
51 MAKE_PROPERTY(data_size_bytes, get_data_size_bytes);
52 MAKE_PROPERTY(usage_hint, get_usage_hint);
53
54 void prepare(PreparedGraphicsObjects *prepared_objects);
55 bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
56
57 BufferContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
58 GraphicsStateGuardianBase *gsg);
59 bool release(PreparedGraphicsObjects *prepared_objects);
60 int release_all();
61
62 private:
63 void clear_prepared(PreparedGraphicsObjects *prepared_objects);
64
65 private:
66 uint64_t _data_size_bytes;
67 UsageHint _usage_hint;
68 vector_uchar _initial_data;
69
70 typedef pmap<PreparedGraphicsObjects *, BufferContext *> Contexts;
71 Contexts *_contexts = nullptr;
72
73 public:
74 static void register_with_read_factory();
75 virtual void write_datagram(BamWriter *manager, Datagram &dg);
76
77 protected:
78 static TypedWritable *make_from_bam(const FactoryParams &params);
79 void fillin(DatagramIterator &scan, BamReader *manager);
80
81 public:
82 virtual TypeHandle get_type() const {
83 return get_class_type();
84 }
85 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
86 static TypeHandle get_class_type() {
87 return _type_handle;
88 }
89 static void init_type() {
90 TypedWritableReferenceCount::init_type();
91 Namable::init_type();
92 register_type(_type_handle, "ShaderBuffer",
93 TypedWritableReferenceCount::get_class_type(),
94 Namable::get_class_type());
95 }
96
97 private:
98 static TypeHandle _type_handle;
99
100 friend class PreparedGraphicsObjects;
101};
102
103INLINE std::ostream &operator << (std::ostream &out, const ShaderBuffer &m) {
104 m.output(out);
105 return out;
106}
107
108#include "shaderBuffer.I"
109
110#endif
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BufferContext
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition bufferContext.h:38
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
GeomEnums
This class exists just to provide scoping for the various enumerated types used by Geom,...
Definition geomEnums.h:24
GraphicsStateGuardianBase
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Definition graphicsStateGuardianBase.h:110
Namable::output
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
PreparedGraphicsObjects
A table of objects that are saved within the graphics context for reference by handle later.
Definition preparedGraphicsObjects.h:58
ShaderBuffer
This is a generic buffer object that lives in graphics memory.
Definition shaderBuffer.h:33
ShaderBuffer::is_prepared
bool is_prepared(PreparedGraphicsObjects *prepared_objects) const
Returns true if the data has already been prepared or enqueued for preparation on the indicated GSG,...
Definition shaderBuffer.cxx:53
ShaderBuffer::release
bool release(PreparedGraphicsObjects *prepared_objects)
Frees the data context only on the indicated object, if it exists there.
Definition shaderBuffer.cxx:105
ShaderBuffer::prepare_now
BufferContext * prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the data on the particular GSG, if it does not already exist.
Definition shaderBuffer.cxx:77
ShaderBuffer::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Definition shaderBuffer.cxx:180
ShaderBuffer::get_initial_data
const unsigned char * get_initial_data() const
Returns a pointer to the initial buffer data, or NULL if not specified.
Definition shaderBuffer.I:63
ShaderBuffer::prepare
void prepare(PreparedGraphicsObjects *prepared_objects)
Indicates that the data should be enqueued to be prepared in the indicated prepared_objects at the be...
Definition shaderBuffer.cxx:44
ShaderBuffer::get_usage_hint
get_usage_hint
Returns the buffer usage hint.
Definition shaderBuffer.h:52
ShaderBuffer::get_data_size_bytes
get_data_size_bytes
Returns the buffer size in bytes.
Definition shaderBuffer.h:51
ShaderBuffer::release_all
int release_all()
Frees the context allocated on all objects for which the data has been declared.
Definition shaderBuffer.cxx:125
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable::fillin
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition typedWritable.cxx:103
TypedWritable::write_datagram
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 typedWritable.cxx:54
factoryParams.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geomEnums.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
graphicsStateGuardianBase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
shaderBuffer.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedWritableReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vector_uchar.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.