|
| 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