Skip to content

Commit 5831a31

Browse files
tobsprrdb
authored andcommitted
Add RenderPipeline C++ lighting modules to Panda3D codebase
1 parent b5e9f23 commit 5831a31

39 files changed

+5382
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
*
3+
* RenderPipeline
4+
*
5+
* Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
#include "config_rplight.h"
28+
29+
#include "rpLight.h"
30+
#include "rpPointLight.h"
31+
32+
#include "dconfig.h"
33+
34+
Configure(config_rplight);
35+
NotifyCategoryDef(rplight, "");
36+
37+
ConfigureFn(config_rplight) {
38+
init_librplight();
39+
}
40+
41+
void
42+
init_librplight() {
43+
static bool initialized = false;
44+
if (initialized) {
45+
return;
46+
}
47+
initialized = true;
48+
49+
// RPLight::init_type();
50+
// RPPointLight::init_type();
51+
}

contrib/src/rplight/config_rplight.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
*
3+
* RenderPipeline
4+
*
5+
* Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
#ifndef CONFIG_RPLIGHT_H
28+
#define CONFIG_RPLIGHT_H
29+
30+
#include "pandabase.h"
31+
#include "notifyCategoryProxy.h"
32+
#include "configVariableDouble.h"
33+
#include "configVariableString.h"
34+
#include "configVariableInt.h"
35+
36+
NotifyCategoryDecl(rplight, EXPORT_CLASS, EXPORT_TEMPL);
37+
38+
extern void init_librplight();
39+
40+
#endif // CONFIG_RPLIGHT_H

contrib/src/rplight/gpuCommand.I

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

contrib/src/rplight/gpuCommand.cxx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
*
3+
* RenderPipeline
4+
*
5+
* Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
#include "gpuCommand.h"
28+
29+
#include <iostream>
30+
#include <iomanip>
31+
#include <stdlib.h>
32+
33+
34+
NotifyCategoryDef(gpucommand, "");
35+
36+
/**
37+
* @brief Constructs a new GPUCommand with the given command type.
38+
* @details This will construct a new GPUCommand of the given command type.
39+
* The command type should be of GPUCommand::CommandType, and determines
40+
* what data the GPUCommand contains, and how it will be handled.
41+
*
42+
* @param command_type The type of the GPUCommand
43+
*/
44+
GPUCommand::GPUCommand(CommandType command_type) {
45+
_command_type = command_type;
46+
_current_index = 0;
47+
memset(_data, 0x0, sizeof(float) * GPU_COMMAND_ENTRIES);
48+
49+
// Store the command type as the first entry
50+
push_int(command_type);
51+
}
52+
53+
/**
54+
* @brief Prints out the GPUCommand to the console
55+
* @details This method prints the type, size, and data of the GPUCommand to the
56+
* console. This helps for debugging the contents of the GPUCommand. Keep
57+
* in mind that integers might be shown in their binary float representation,
58+
* depending on the setting in the GPUCommand::convert_int_to_float method.
59+
*/
60+
void GPUCommand::write(ostream &out) const {
61+
out << "GPUCommand(type=" << _command_type << ", size=" << _current_index << ", data = {" << endl;
62+
for (size_t k = 0; k < GPU_COMMAND_ENTRIES; ++k) {
63+
out << std::setw(12) << std::fixed << std::setprecision(5) << _data[k] << " ";
64+
if (k % 6 == 5 || k == GPU_COMMAND_ENTRIES - 1) out << endl;
65+
}
66+
out << "})" << endl;
67+
}
68+
69+
/**
70+
* @brief Writes the GPU command to a given target.
71+
* @details This method writes all the data of the GPU command to a given target.
72+
* The target should be a pointer to memory being big enough to hold the
73+
* data. Presumably #dest will be a handle to texture memory.
74+
* The command_index controls the offset where the data will be written
75+
* to.
76+
*
77+
* @param dest Handle to the memory to write the command to
78+
* @param command_index Offset to write the command to. The command will write
79+
* its data to command_index * GPU_COMMAND_ENTRIES. When writing
80+
* the GPUCommand in a GPUCommandList, the command_index will
81+
* most likely be the index of the command in the list.
82+
*/
83+
void GPUCommand::write_to(const PTA_uchar &dest, size_t command_index) {
84+
size_t command_size = GPU_COMMAND_ENTRIES * sizeof(float);
85+
size_t offset = command_index * command_size;
86+
memcpy(dest.p() + offset, &_data, command_size);
87+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy