Skip to content

Commit af871e9

Browse files
committed
Add RPRenderState adapter for RenderState
- Move some implementations on RPGeomNode to RPRenderState
1 parent 811884a commit af871e9

File tree

5 files changed

+473
-217
lines changed

5 files changed

+473
-217
lines changed

files.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ set(header_rpcore_util
133133
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/primitives.hpp"
134134
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/rpgeomnode.hpp"
135135
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/rpmaterial.hpp"
136+
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/rprender_state.hpp"
136137
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/shader_input_blocks.hpp"
137138
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/task_scheduler.hpp"
138139
"${PROJECT_SOURCE_DIR}/render_pipeline/rpcore/util/rptextnode.hpp"
@@ -336,6 +337,7 @@ set(source_rpcore_util
336337
"${PROJECT_SOURCE_DIR}/src/rpcore/util/post_process_region.cpp"
337338
"${PROJECT_SOURCE_DIR}/src/rpcore/util/primitives.cpp"
338339
"${PROJECT_SOURCE_DIR}/src/rpcore/util/rpgeomnode.cpp"
340+
"${PROJECT_SOURCE_DIR}/src/rpcore/util/rprender_state.cpp"
339341
"${PROJECT_SOURCE_DIR}/src/rpcore/util/shader_input_blocks.cpp"
340342
"${PROJECT_SOURCE_DIR}/src/rpcore/util/smooth_connected_curve.hpp"
341343
"${PROJECT_SOURCE_DIR}/src/rpcore/util/smooth_connected_curve.cpp"

render_pipeline/rpcore/util/rpgeomnode.hpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
#include <geomNode.h>
2525

26-
#include <render_pipeline/rpcore/config.hpp>
27-
#include <render_pipeline/rpcore/util/rpmaterial.hpp>
26+
#include <render_pipeline/rpcore/util/rprender_state.hpp>
2827

2928
class Texture;
3029
class NodePath;
@@ -36,15 +35,6 @@ namespace rpcore {
3635
*/
3736
class RENDER_PIPELINE_DECL RPGeomNode
3837
{
39-
public:
40-
enum class TextureStageIndex : int
41-
{
42-
basecolor = 0,
43-
normal,
44-
specular,
45-
roughness,
46-
};
47-
4838
public:
4939
RPGeomNode(const NodePath& nodepath);
5040
RPGeomNode(PT(GeomNode) geomnode);
@@ -58,6 +48,10 @@ class RENDER_PIPELINE_DECL RPGeomNode
5848

5949
int get_num_geoms() const;
6050

51+
RPRenderState get_state(int geom_index) const;
52+
void set_state(int geom_index, const RPRenderState& state);
53+
void set_state(int geom_index, const RenderState* state);
54+
6155
bool has_material(int geom_index) const;
6256
RPMaterial get_material(int geom_index) const;
6357
void set_material(int geom_index, const RPMaterial& material);
@@ -220,6 +214,21 @@ inline int RPGeomNode::get_num_geoms() const
220214
return node_->get_num_geoms();
221215
}
222216

217+
inline RPRenderState RPGeomNode::get_state(int geom_index) const
218+
{
219+
return RPRenderState(node_->get_geom_state(geom_index));
220+
}
221+
222+
inline void RPGeomNode::set_state(int geom_index, const RPRenderState& state)
223+
{
224+
node_->set_geom_state(geom_index, state.get_state());
225+
}
226+
227+
inline void RPGeomNode::set_state(int geom_index, const RenderState* state)
228+
{
229+
node_->set_geom_state(geom_index, state);
230+
}
231+
223232
// ************************************************************************************************
224233

225234
inline bool operator==(const RPGeomNode& a, const RPGeomNode& b)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* Render Pipeline C++
3+
*
4+
* Copyright (c) 2018 Center of Human-centered Interaction for Coexistence.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
8+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all copies or substantial
13+
* portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16+
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
#pragma once
23+
24+
#include <render_pipeline/rpcore/config.hpp>
25+
#include <render_pipeline/rpcore/util/rpmaterial.hpp>
26+
27+
class Texture;
28+
class NodePath;
29+
class RenderState;
30+
class TextureStage;
31+
32+
namespace rpcore {
33+
34+
/**
35+
* Adapater of RenderState.
36+
*/
37+
class RENDER_PIPELINE_DECL RPRenderState
38+
{
39+
public:
40+
enum class TextureStageIndex : int
41+
{
42+
basecolor = 0,
43+
normal,
44+
specular,
45+
roughness,
46+
};
47+
48+
public:
49+
RPRenderState(const NodePath& nodepath);
50+
RPRenderState(CPT(RenderState) state);
51+
52+
~RPRenderState();
53+
54+
explicit operator bool() const;
55+
bool operator!() const;
56+
57+
const RenderState* get_state() const;
58+
59+
bool has_material() const;
60+
RPMaterial get_material() const;
61+
RPRenderState& set_material(const RPMaterial& material);
62+
RPRenderState& set_material(Material* material);
63+
64+
bool has_texture() const;
65+
Texture* get_texture() const;
66+
Texture* get_texture(TextureStage* stage) const;
67+
68+
/**
69+
* Get the texture on specific type.
70+
* @return Texture pointer or nullptr if empty or failed.
71+
*/
72+
Texture* get_basecolor_texture() const;
73+
Texture* get_normal_texture() const;
74+
Texture* get_specular_texture() const;
75+
Texture* get_roughness_texture() const;
76+
77+
/** Set the texture on the first TextureStage or default stage if texture does not exist. */
78+
RPRenderState& set_texture(Texture* texture, int priority = 0);
79+
80+
/** Set the texture on the given TextureStage. */
81+
RPRenderState& set_texture(TextureStage* stage, Texture* texture, int priority = 0);
82+
83+
/** Set the texture on specific type. */
84+
RPRenderState& set_basecolor_texture(Texture* texture, int priority = 0);
85+
RPRenderState& set_normal_texture(Texture* texture, int priority = 0);
86+
RPRenderState& set_specular_texture(Texture* texture, int priority = 0);
87+
RPRenderState& set_roughness_texture(Texture* texture, int priority = 0);
88+
89+
protected:
90+
CPT(RenderState) state_;
91+
};
92+
93+
// ************************************************************************************************
94+
95+
inline RPRenderState::RPRenderState(CPT(RenderState) state) : state_(state)
96+
{
97+
}
98+
99+
inline RPRenderState::operator bool() const
100+
{
101+
return state_ != nullptr;
102+
}
103+
104+
inline bool RPRenderState::operator!() const
105+
{
106+
return state_ == nullptr;
107+
}
108+
109+
inline const RenderState* RPRenderState::get_state() const
110+
{
111+
return state_;
112+
}
113+
114+
inline RPRenderState& RPRenderState::set_material(const RPMaterial& material)
115+
{
116+
return set_material(material.get_material());
117+
}
118+
119+
// ************************************************************************************************
120+
121+
inline bool operator==(const RPRenderState& a, const RPRenderState& b)
122+
{
123+
return a.get_state() == b.get_state();
124+
}
125+
126+
inline bool operator!=(const RPRenderState& a, const RPRenderState& b)
127+
{
128+
return a.get_state() != b.get_state();
129+
}
130+
131+
inline bool operator==(const RPRenderState& m, std::nullptr_t)
132+
{
133+
return m.get_state() == nullptr;
134+
}
135+
136+
inline bool operator==(std::nullptr_t, const RPRenderState& m)
137+
{
138+
return m.get_state() == nullptr;
139+
}
140+
141+
inline bool operator!=(const RPRenderState& m, std::nullptr_t)
142+
{
143+
return m.get_state() != nullptr;
144+
}
145+
146+
inline bool operator!=(std::nullptr_t, const RPRenderState& m)
147+
{
148+
return m.get_state() != nullptr;
149+
}
150+
151+
}

0 commit comments

Comments
 (0)