Panda3D
shaderBuffer.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 shaderBuffer.I
10  * @author rdb
11  * @date 2016-12-12
12  */
13 
14 /**
15  * Creates an uninitialized buffer object with the given size. For now, these
16  * parameters cannot be modified, but this may change in the future.
17  */
18 INLINE ShaderBuffer::
19 ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint) :
20  Namable(name),
21  _data_size_bytes(size),
22  _usage_hint(usage_hint) {
23 }
24 
25 /**
26  * Creates a buffer object initialized with the given data. For now, these
27  * parameters cannot be modified, but this may change in the future.
28  */
29 INLINE ShaderBuffer::
30 ShaderBuffer(const std::string &name, vector_uchar initial_data, UsageHint usage_hint) :
31  Namable(name),
32  _data_size_bytes(initial_data.size()),
33  _usage_hint(usage_hint),
34  _initial_data(std::move(initial_data)) {
35 
36  // Make sure it is padded to 16 bytes. Some drivers like that.
37  if ((_initial_data.size() & 15u) != 0) {
38  _initial_data.resize((_initial_data.size() + 15u) & ~15u, 0);
39  _data_size_bytes = _initial_data.size();
40  }
41 }
42 
43 /**
44  * Returns the buffer size in bytes.
45  */
46 INLINE uint64_t ShaderBuffer::
47 get_data_size_bytes() const {
48  return _data_size_bytes;
49 }
50 
51 /**
52  * Returns the buffer usage hint.
53  */
54 INLINE GeomEnums::UsageHint ShaderBuffer::
55 get_usage_hint() const {
56  return _usage_hint;
57 }
58 
59 /**
60  * Returns a pointer to the initial buffer data, or NULL if not specified.
61  */
62 INLINE const unsigned char *ShaderBuffer::
64  if (_initial_data.empty()) {
65  return nullptr;
66  } else {
67  return &_initial_data[0];
68  }
69 }
A base class for all things which can have a name.
Definition: namable.h:26
const unsigned char * get_initial_data() const
Returns a pointer to the initial buffer data, or NULL if not specified.
Definition: shaderBuffer.I:63