Panda3D
internalLightManager.I
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 
28 /**
29  * @brief Returns the maximum light index
30  * @details This returns the maximum light index (also called slot). Any lights
31  * after that slot are guaranteed to be zero-lights. This is useful when
32  * iterating over the list of lights, because iteration can be stopped when
33  * the maximum light index is reached.
34  *
35  * The maximum light index points to the last slot which is used. If no lights
36  * are attached, -1 is returned. If one light is attached at slot 0, the index
37  * is 0, if two are attached at the slots 0 and 1, the index is 1, and so on.
38  *
39  * If, for example, two lights are attached at the slots 2 and 5, then the
40  * index will be 5. Keep in mind that the max-index is not an indicator for
41  * how many lights are attached. Also, zero lights still may occur when iterating
42  * over the light lists
43  *
44  * @return Maximum light index
45  */
47  return _lights.get_max_index();
48 }
49 
50 /**
51  * @brief Returns the amount of stored lights.
52  * @details This returns the amount of stored lights. This behaves unlike
53  * InternalLightManager::get_max_light_index, and instead returns the true
54  * amount of lights, which is completely unrelated to the amount of used slots.
55  *
56  * @return Amount of stored lights
57  */
58 inline size_t InternalLightManager::get_num_lights() const {
59  return _lights.get_num_entries();
60 }
61 
62 /**
63  * @brief Returns the amount of shadow sources.
64  * @details This returns the total amount of stored shadow sources. This does
65  * not denote the amount of updated sources, but instead takes into account
66  * all sources, even those out of frustum.
67  * @return Amount of shadow sources.
68  */
70  return _shadow_sources.get_num_entries();
71 }
72 
73 /**
74  * @brief Sets the handle to the shadow manager
75  * @details This sets the handle to the global shadow manager. It is usually
76  * constructed on the python side, so we need to get a handle to it.
77  *
78  * The manager should be a handle to a ShadowManager instance, and will be
79  * stored somewhere on the python side most likely. The light manager does not
80  * keep a reference to it, so the python side should make sure to keep one.
81  *
82  * Be sure to call this before the InternalLightManager::update() method is
83  * called, otherwise an assertion will get triggered.
84  *
85  * @param mgr The ShadowManager instance
86  */
88  _shadow_manager = mgr;
89 }
90 
91 /**
92  * @brief Sets a handle to the command list
93  * @details This sets a handle to the global GPUCommandList. This is required to
94  * emit GPUCommands, which are used for attaching and detaching lights, as well
95  * as shadow source updates.
96  *
97  * The cmd_list should be a handle to a GPUCommandList handle, and will be
98  * stored somewhere on the python side most likely. The light manager does not
99  * keep a reference to it, so the python side should make sure to keep one.
100  *
101  * Be sure to call this before the InternalLightManager::update() method is
102  * called, otherwise an assertion will get triggered.
103  *
104  * @param cmd_list The GPUCommandList instance
105  */
107  _cmd_list = cmd_list;
108 }
109 
110 /**
111  * @brief Sets the camera position
112  * @details This sets the camera position, which will be used to determine which
113  * shadow sources have to get updated
114  *
115  * @param mat View projection mat
116  */
117 inline void InternalLightManager::set_camera_pos(const LPoint3 &pos) {
118  _camera_pos = pos;
119 }
120 
121 /**
122  * @brief Sets the maximum shadow update distance
123  * @details This controls the maximum distance until which shadows are updated.
124  * If a shadow source is past that distance, it is ignored and no longer recieves
125  * updates until it is in range again
126  *
127  * @param dist Distance in world space units
128  */
130  _shadow_update_distance = dist;
131 }
132 
133 /**
134  * @brief Returns the internal used ShadowManager
135  * @details This returns a handle to the internally used shadow manager
136  * @return Shadow manager
137  */
138 inline ShadowManager* InternalLightManager::get_shadow_manager() const {
139  return _shadow_manager;
140 }
size_t get_num_entries() const
Returns the amount of elements of the container.
set_shadow_manager
Sets the handle to the shadow manager.
void set_shadow_update_distance(PN_stdfloat dist)
Sets the maximum shadow update distance.
RenderPipeline.
get_num_shadow_sources
Returns the amount of shadow sources.
int get_max_index() const
Returns the maximum index of the container.
get_max_light_index
RenderPipeline.
void set_camera_pos(const LPoint3 &pos)
Sets the camera position.
void set_command_list(GPUCommandList *cmd_list)
Sets a handle to the command list.
get_num_lights
Returns the amount of stored lights.