Panda3D
tagStateManager.h
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 TAGSTATEMANAGER_H
28 #define TAGSTATEMANAGER_H
29 
30 #include "pandabase.h"
31 #include "bitMask.h"
32 #include "camera.h"
33 #include "nodePath.h"
34 #include "shader.h"
35 #include "renderState.h"
36 #include "shaderAttrib.h"
37 #include "colorWriteAttrib.h"
38 
39 NotifyCategoryDecl(tagstatemgr, EXPORT_CLASS, EXPORT_TEMPL);
40 
41 /**
42  * @brief This class handles all different tag states
43  * @details The TagStateManager stores a list of RenderStates assigned to different
44  * steps in the pipeline. For example, there are a list of shadow states, which
45  * are applied whenever objects are rendered from a shadow camera.
46  *
47  * The Manager also stores a list of all cameras used in the different stages,
48  * to keep track of the states used and to be able to attach new states.
49  */
51 PUBLISHED:
52  TagStateManager(NodePath main_cam_node);
54 
55  inline void apply_state(const std::string& state, NodePath np, Shader* shader, const std::string &name, int sort);
56  void cleanup_states();
57 
58  inline void register_camera(const std::string& state, Camera* source);
59  inline void unregister_camera(const std::string& state, Camera* source);
60  inline BitMask32 get_mask(const std::string &container_name);
61 
62 private:
63  typedef std::vector<Camera*> CameraList;
64  typedef pmap<std::string, CPT(RenderState)> TagStateList;
65 
66  struct StateContainer {
67  CameraList cameras;
68  TagStateList tag_states;
69  std::string tag_name;
70  BitMask32 mask;
71  bool write_color;
72 
73  StateContainer() {};
74  StateContainer(const std::string &tag_name, size_t mask, bool write_color)
75  : tag_name(tag_name), mask(BitMask32::bit(mask)), write_color(write_color) {};
76  };
77 
78  void apply_state(StateContainer& container, NodePath np, Shader* shader,
79  const std::string& name, int sort);
80  void cleanup_container_states(StateContainer& container);
81  void register_camera(StateContainer &container, Camera* source);
82  void unregister_camera(StateContainer &container, Camera* source);
83 
85  ContainerList _containers;
86 
87  NodePath _main_cam_node;
88 };
89 
90 
91 #include "tagStateManager.I"
92 
93 #endif // TAGSTATEMANAGER_H
static BitMask< WType, nbits > bit(int index)
Returns a BitMask with only the indicated bit on.
Definition: bitMask.I:70
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
This class handles all different tag states.
TagStateManager(NodePath main_cam_node)
Constructs a new TagStateManager.
void unregister_camera(const std::string &state, Camera *source)
Unregisters a camera from the list of shadow cameras.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
~TagStateManager()
Destructs the TagStateManager.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Definition: shader.h:49
BitMask32 get_mask(const std::string &container_name)
Returns the render mask for the given state.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
void cleanup_states()
Cleans up all registered states.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:35
void register_camera(const std::string &state, Camera *source)
RenderPipeline.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161