Panda3D
Loading...
Searching...
No Matches
tagStateManager.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 * @brief Registers a new camera which renders a certain pass
29 * @details This registers a new camera which will be used to render the given
30 * pass. The TagStateManager will keep track of the camera and
31 * applies all registered states onto the camera with Camera::set_tag_state.
32 * It also applies the appropriate camera mask to the camera,
33 * and sets an initial state to disable color write depending on the pass.
34 *
35 * @param source Camera which will be used to render shadows
36 */
38register_camera(const std::string& name, Camera* source) {
39 ContainerList::iterator entry = _containers.find(name);
40 nassertv(entry != _containers.end());
41 register_camera(entry->second, source);
42}
43
44/**
45 * @brief Unregisters a camera from the list of shadow cameras
46 * @details This unregisters a camera from the list of shadows cameras. It also
47 * resets all tag states of the camera, and also its initial state.
48 *
49 * @param source Camera to unregister
50 */
52unregister_camera(const std::string& name, Camera* source) {
53 ContainerList::iterator entry = _containers.find(name);
54 nassertv(entry != _containers.end());
55 unregister_camera(entry->second, source);
56}
57
58/**
59 * @brief Applies a given state for a pass to a NodePath
60 * @details This applies a shader to the given NodePath which is used when the
61 * NodePath is rendered by any registered camera for that pass.
62 * It also disables color write depending on the pass.
63 *
64 * @param np The nodepath to apply the shader to
65 * @param shader A handle to the shader to apply
66 * @param name Name of the state, should be a unique identifier
67 * @param sort Determines the sort with which the shader will be applied.
68 */
70apply_state(const std::string& state, NodePath np, Shader* shader,
71 const std::string &name, int sort) {
72 ContainerList::iterator entry = _containers.find(state);
73 nassertv(entry != _containers.end());
74 apply_state(entry->second, np, shader, name, sort);
75}
76
77/**
78 * @brief Returns the render mask for the given state
79 * @details This returns the mask of a given render pass, which can be used
80 * to either show or hide objects from this pass.
81 *
82 * @param container_name Name of the render-pass
83 * @return Bit mask of the render pass
84 */
86get_mask(const std::string &container_name) {
87 if (container_name == "gbuffer") {
88 return BitMask32::bit(1);
89 }
90 ContainerList::iterator entry = _containers.find(container_name);
91 nassertr(entry != _containers.end(), BitMask32());
92 return entry->second.mask;
93}
static BitMask< uint32_t, nbits > bit(int index)
Returns a BitMask with only the indicated bit on.
Definition bitMask.I:70
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition camera.h:35
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
BitMask32 get_mask(const std::string &container_name)
Returns the render mask for the given state.
void register_camera(const std::string &state, Camera *source)
RenderPipeline.
void unregister_camera(const std::string &state, Camera *source)
Unregisters a camera from the list of shadow cameras.
void apply_state(const std::string &state, NodePath np, Shader *shader, const std::string &name, int sort)
Applies a given state for a pass to a NodePath.