forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpuCommand.I
More file actions
185 lines (171 loc) · 6.36 KB
/
gpuCommand.I
File metadata and controls
185 lines (171 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
*
* RenderPipeline
*
* Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include <stdint.h>
/**
* @brief Appends an integer to the GPUCommand.
* @details This adds an integer to the back of the GPUCommand. Depending on the
* setting in convert_int_to_float, this will either just convert the int to a
* float by casting it, or just do a bitwise copy.
*
* @param v The integer to append.
*/
inline void GPUCommand::push_int(int v) {
push_float(convert_int_to_float(v));
}
/**
* @brief Internal method to convert an integer to float
* @details This methods gets called by the GPUCommand::push_int, and manages
* storing an integer in a floating point variable. There are two options,
* which are documented inside of the method.
*
* @param v Integer to convert
* @return Float-representation of that integer, either casted or binary converted.s
*/
inline float GPUCommand::convert_int_to_float(int v) const {
#if !PACK_INT_AS_FLOAT
// Just round to float, can cause rounding issues tho
return (float)v;
#else
assert(sizeof(float) == 4); // We really need this for packing! Better
// throw an error if the compiler uses more
// than 4 bytes.
// Simple binary conversion, assuming sizeof(int) == sizeof(float)
union { int32_t _int; float _float; } converter = { (int32_t)v };
return converter._float;
#endif
}
/**
* @brief Appends a float to the GPUCommand.
* @details This adds an integer to the back of the GPUCommand. Its used by all
* other push_xxx methods, and simply stores the value, then increments the write
* pointer. When the amount of floats exceeds the capacity of the GPUCommand,
* an error will be printed, and the method returns without doing anything else.
*
* @param v The float to append.
*/
inline void GPUCommand::push_float(float v) {
if (_current_index >= GPU_COMMAND_ENTRIES) {
gpucommand_cat.error() << "Out of bounds! Exceeded command size of " << GPU_COMMAND_ENTRIES << std::endl;
return;
}
_data[_current_index++] = v;
}
/**
* @brief Appends a 3-component floating point vector to the GPUCommand.
* @details This appends a 3-component floating point vector to the command.
* It basically just calls push_float() for every component, in the order
* x, y, z, which causes the vector to occupy the space of 3 floats.
*
* @param v Int-Vector to append.
*/
inline void GPUCommand::push_vec3(const LVecBase3 &v) {
push_float(v.get_x());
push_float(v.get_y());
push_float(v.get_z());
}
/**
* @brief Appends a 3-component integer vector to the GPUCommand.
* @details This appends a 3-component integer vector to the command.
* It basically just calls push_int() for every component, in the order
* x, y, z, which causes the vector to occupy the space of 3 floats.
*
* @param v Int-Vector to append.
*/
inline void GPUCommand::push_vec3(const LVecBase3i &v) {
push_int(v.get_x());
push_int(v.get_y());
push_int(v.get_z());
}
/**
* @brief Appends a 4-component floating point vector to the GPUCommand.
* @details This appends a 4-component floating point vector to the command.
* It basically just calls push_float() for every component, in the order
* x, y, z, which causes the vector to occupy the space of 3 floats.
*
* @param v Int-Vector to append.
*/
inline void GPUCommand::push_vec4(const LVecBase4 &v) {
push_float(v.get_x());
push_float(v.get_y());
push_float(v.get_z());
push_float(v.get_w());
}
/**
* @brief Appends a 4-component integer vector to the GPUCommand.
* @details This appends a 4-component integer vector to the command.
* It basically just calls push_int() for every component, in the order
* x, y, z, w, which causes the vector to occupy the space of 4 floats.
*
* @param v Int-Vector to append.
*/
inline void GPUCommand::push_vec4(const LVecBase4i &v) {
push_int(v.get_x());
push_int(v.get_y());
push_int(v.get_z());
push_int(v.get_w());
}
/**
* @brief Appends a floating point 3x3 matrix to the GPUCommand.
* @details This appends a floating point 3x3 matrix to the GPUCommand, by
* pushing all components in row-order to the command. This occupies a space of
* 9 floats.
*
* @param v Matrix to append
*/
inline void GPUCommand::push_mat3(const LMatrix3 &v) {
for (size_t i = 0; i < 3; ++i) {
for (size_t j = 0; j < 3; ++j) {
push_float(v.get_cell(i, j));
}
}
}
/**
* @brief Appends a floating point 4x4 matrix to the GPUCommand.
* @details This appends a floating point 4x4 matrix to the GPUCommand, by
* pushing all components in row-order to the command. This occupies a space of
* 16 floats.
*
* @param v Matrix to append
*/
inline void GPUCommand::push_mat4(const LMatrix4 &v) {
for (size_t i = 0; i < 4; ++i) {
for (size_t j = 0; j < 4; ++j) {
push_float(v.get_cell(i, j));
}
}
}
/**
* @brief Returns whether integers are packed as floats.
* @details This returns how integer are packed into the data stream. If the
* returned value is true, then integers are packed using their binary
* representation converted to floating point format. If the returned value
* is false, then integers are packed by simply casting them to float,
* e.g. val = (float)i;
* @return The integer representation flag
*/
inline bool GPUCommand::get_uses_integer_packing() {
return PACK_INT_AS_FLOAT;
}