Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 18 files). Show all
Unified · Split
| @@ -723,7 +723,7 @@ gpu::ShaderPointer GeometryCache::_forwardUnlitShader; · 722 unmodified lines | |||
| 723 | gpu::ShaderPointer GeometryCache::_forwardSimpleFadeShader; | 723 | gpu::ShaderPointer GeometryCache::_forwardSimpleFadeShader; |
| 724 | gpu::ShaderPointer GeometryCache::_forwardUnlitFadeShader; | 724 | gpu::ShaderPointer GeometryCache::_forwardUnlitFadeShader; |
| 725 | 725 | ||
| 726 | std::map<std::tuple<bool, bool, bool>, render::ShapePipelinePointer> GeometryCache::_shapePipelines; | 726 | std::map<std::tuple<bool, bool, bool, graphics::MaterialKey::CullFaceMode>, render::ShapePipelinePointer> GeometryCache::_shapePipelines; |
| 727 | 727 | ||
| 728 | GeometryCache::GeometryCache() : | 728 | GeometryCache::GeometryCache() : |
| 729 | _nextID(0) { | 729 | _nextID(0) { |
| @@ -776,15 +776,18 @@ void GeometryCache::initializeShapePipelines() { · 46 unmodified lines | |||
| 776 | bool transparent = i & 1; | 776 | bool transparent = i & 1; |
| 777 | bool unlit = i & 2; | 777 | bool unlit = i & 2; |
| 778 | bool forward = i & 4; | 778 | bool forward = i & 4; |
| 779 | _shapePipelines[std::make_tuple(transparent, unlit, forward)] = getShapePipeline(false, transparent, true, unlit, false, forward); | 779 | for (int cullFaceMode = graphics::MaterialKey::CullFaceMode::CULL_NONE; cullFaceMode < graphics::MaterialKey::CullFaceMode::NUM_CULL_FACE_MODES; cullFaceMode++) { |
| 780 | auto cullMode = (graphics::MaterialKey::CullFaceMode)cullFaceMode; | ||
| 781 | _shapePipelines[std::make_tuple(transparent, unlit, forward, cullMode)] = getShapePipeline(false, transparent, unlit, false, forward, cullMode); | ||
| 782 | } | ||
| 780 | } | 783 | } |
| 781 | } | 784 | } |
| 782 | } | 785 | } |
| 783 | 786 | ||
| 784 | render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool culled, | 787 | render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool unlit, bool depthBias, bool forward, |
| 785 | bool unlit, bool depthBias, bool forward) { | 788 | graphics::MaterialKey::CullFaceMode cullFaceMode) { |
| 786 | 789 | ||
| 787 | return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, false, true, forward), nullptr, | 790 | return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, unlit, depthBias, false, true, forward, cullFaceMode), nullptr, |
| 788 | [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) { | 791 | [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) { |
| 789 | batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture()); | 792 | batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture()); |
| 790 | DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch); | 793 | DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch); |
| @@ -792,12 +795,12 @@ render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool · 1 unmodified line | |||
| 792 | ); | 795 | ); |
| 793 | } | 796 | } |
| 794 | 797 | ||
| 795 | render::ShapePipelinePointer GeometryCache::getFadingShapePipeline(bool textured, bool transparent, bool culled, | 798 | render::ShapePipelinePointer GeometryCache::getFadingShapePipeline(bool textured, bool transparent, bool unlit, bool depthBias, bool forward, |
| 796 | bool unlit, bool depthBias, bool forward) { | 799 | graphics::MaterialKey::CullFaceMode cullFaceMode) { |
| 797 | auto fadeEffect = DependencyManager::get<FadeEffect>(); | 800 | auto fadeEffect = DependencyManager::get<FadeEffect>(); |
| 798 | auto fadeBatchSetter = fadeEffect->getBatchSetter(); | 801 | auto fadeBatchSetter = fadeEffect->getBatchSetter(); |
| 799 | auto fadeItemSetter = fadeEffect->getItemUniformSetter(); | 802 | auto fadeItemSetter = fadeEffect->getItemUniformSetter(); |
| 800 | return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, true, true, forward), nullptr, | 803 | return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, unlit, depthBias, true, true, forward, cullFaceMode), nullptr, |
| 801 | [fadeBatchSetter, fadeItemSetter](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args* args) { | 804 | [fadeBatchSetter, fadeItemSetter](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args* args) { |
| 802 | batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture()); | 805 | batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture()); |
| 803 | fadeBatchSetter(shapePipeline, batch, args); | 806 | fadeBatchSetter(shapePipeline, batch, args); |
| @@ -2049,54 +2052,60 @@ void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bo · 1245 unmodified lines | |||
| 2049 | class SimpleProgramKey { | 2052 | class SimpleProgramKey { |
| 2050 | public: | 2053 | public: |
| 2051 | enum FlagBit { | 2054 | enum FlagBit { |
| 2052 | IS_TEXTURED_FLAG = 0, | 2055 | IS_TEXTURED_BIT = 0, |
| 2053 | IS_TRANSPARENT_FLAG, | 2056 | IS_TRANSPARENT_BIT, |
| 2054 | IS_CULLED_FLAG, | 2057 | IS_UNLIT_BIT, |
| 2055 | IS_UNLIT_FLAG, | 2058 | IS_DEPTH_BIASED_BIT, |
| 2056 | HAS_DEPTH_BIAS_FLAG, | 2059 | IS_FADING_BIT, |
| 2057 | IS_FADING_FLAG, | 2060 | IS_ANTIALIASED_BIT, |
| 2058 | IS_ANTIALIASED_FLAG, | 2061 | IS_FORWARD_BIT, |
| 2059 | IS_FORWARD_FLAG, | 2062 | IS_CULL_FACE_NONE_BIT, // if neither of these are set, we're CULL_FACE_BACK |
| 2063 | IS_CULL_FACE_FRONT_BIT, | ||
| 2060 | 2064 | ||
| 2061 | NUM_FLAGS, | 2065 | NUM_FLAGS, |
| 2062 | }; | 2066 | }; |
| 2063 | 2067 | typedef std::bitset<NUM_FLAGS> Flags; | |
| 2064 | enum Flag { | 2068 | |
| 2065 | IS_TEXTURED = (1 << IS_TEXTURED_FLAG), | 2069 | bool isTextured() const { return _flags[IS_TEXTURED_BIT]; } |
| 2066 | IS_TRANSPARENT = (1 << IS_TRANSPARENT_FLAG), | 2070 | bool isTransparent() const { return _flags[IS_TRANSPARENT_BIT]; } |
| 2067 | IS_CULLED = (1 << IS_CULLED_FLAG), | 2071 | bool isUnlit() const { return _flags[IS_UNLIT_BIT]; } |
| 2068 | IS_UNLIT = (1 << IS_UNLIT_FLAG), | 2072 | bool hasDepthBias() const { return _flags[IS_DEPTH_BIASED_BIT]; } |
| 2069 | HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG), | 2073 | bool isFading() const { return _flags[IS_FADING_BIT]; } |
| 2070 | IS_FADING = (1 << IS_FADING_FLAG), | 2074 | bool isAntiAliased() const { return _flags[IS_ANTIALIASED_BIT]; } |
| 2071 | IS_ANTIALIASED = (1 << IS_ANTIALIASED_FLAG), | 2075 | bool isForward() const { return _flags[IS_FORWARD_BIT]; } |
| 2072 | IS_FORWARD = (1 << IS_FORWARD_FLAG), | 2076 | bool isCullFaceNone() const { return _flags[IS_CULL_FACE_NONE_BIT]; } |
| 2073 | }; | 2077 | bool isCullFaceFront() const { return _flags[IS_CULL_FACE_FRONT_BIT]; } |
| 2074 | typedef unsigned short Flags; | ||
| 2075 | |||
| 2076 | bool isFlag(short flagNum) const { return bool((_flags & flagNum) != 0); } | ||
| 2077 | |||
| 2078 | bool isTextured() const { return isFlag(IS_TEXTURED); } | ||
| 2079 | bool isTransparent() const { return isFlag(IS_TRANSPARENT); } | ||
| 2080 | bool isCulled() const { return isFlag(IS_CULLED); } | ||
| 2081 | bool isUnlit() const { return isFlag(IS_UNLIT); } | ||
| 2082 | bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); } | ||
| 2083 | bool isFading() const { return isFlag(IS_FADING); } | ||
| 2084 | bool isAntiAliased() const { return isFlag(IS_ANTIALIASED); } | ||
| 2085 | bool isForward() const { return isFlag(IS_FORWARD); } | ||
| 2086 | 2078 | ||
| 2087 | Flags _flags = 0; | 2079 | Flags _flags = 0; |
| 2088 | #if defined(__clang__) | ||
| 2089 | __attribute__((unused)) | ||
| 2090 | #endif | ||
| 2091 | short _spare = 0; // Padding | ||
| 2092 | |||
| 2093 | int getRaw() const { return *reinterpret_cast<const int*>(this); } | ||
| 2094 | 2080 | ||
| 2095 | 2081 | unsigned long getRaw() const { return _flags.to_ulong(); } | |
| 2096 | SimpleProgramKey(bool textured = false, bool transparent = false, bool culled = true, | 2082 | |
| 2097 | bool unlit = false, bool depthBias = false, bool fading = false, bool isAntiAliased = true, bool forward = false) { | 2083 | SimpleProgramKey(bool textured = false, bool transparent = false, bool unlit = false, bool depthBias = false, bool fading = false, |
| 2098 | _flags = (textured ? IS_TEXTURED : 0) | (transparent ? IS_TRANSPARENT : 0) | (culled ? IS_CULLED : 0) | | 2084 | bool isAntiAliased = true, bool forward = false, graphics::MaterialKey::CullFaceMode cullFaceMode = graphics::MaterialKey::CULL_BACK) { |
| 2099 | (unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0) | (fading ? IS_FADING : 0) | (isAntiAliased ? IS_ANTIALIASED : 0) | (forward ? IS_FORWARD : 0); | 2085 | _flags.set(IS_TEXTURED_BIT, textured); |
| 2086 | _flags.set(IS_TRANSPARENT_BIT, transparent); | ||
| 2087 | _flags.set(IS_UNLIT_BIT, unlit); | ||
| 2088 | _flags.set(IS_DEPTH_BIASED_BIT, depthBias); | ||
| 2089 | _flags.set(IS_FADING_BIT, fading); | ||
| 2090 | _flags.set(IS_ANTIALIASED_BIT, isAntiAliased); | ||
| 2091 | _flags.set(IS_FORWARD_BIT, forward); | ||
| 2092 | |||
| 2093 | switch (cullFaceMode) { | ||
| 2094 | case graphics::MaterialKey::CullFaceMode::CULL_NONE: | ||
| 2095 | _flags.set(IS_CULL_FACE_NONE_BIT); | ||
| 2096 | _flags.reset(IS_CULL_FACE_FRONT_BIT); | ||
| 2097 | break; | ||
| 2098 | case graphics::MaterialKey::CullFaceMode::CULL_FRONT: | ||
| 2099 | _flags.reset(IS_CULL_FACE_NONE_BIT); | ||
| 2100 | _flags.set(IS_CULL_FACE_FRONT_BIT); | ||
| 2101 | break; | ||
| 2102 | case graphics::MaterialKey::CullFaceMode::CULL_BACK: | ||
| 2103 | _flags.reset(IS_CULL_FACE_NONE_BIT); | ||
| 2104 | _flags.reset(IS_CULL_FACE_FRONT_BIT); | ||
| 2105 | break; | ||
| 2106 | default: | ||
| 2107 | break; | ||
| 2108 | } | ||
| 2100 | } | 2109 | } |
| 2101 | 2110 | ||
| 2102 | SimpleProgramKey(int bitmask) : _flags(bitmask) {} | 2111 | SimpleProgramKey(int bitmask) : _flags(bitmask) {} |
| @@ -2141,8 +2150,9 @@ gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool · 38 unmodified lines | |||
| 2141 | return _webPipelines[{ transparent, forward }]; | 2150 | return _webPipelines[{ transparent, forward }]; |
| 2142 | } | 2151 | } |
| 2143 | 2152 | ||
| 2144 | void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool isAntiAliased, bool forward) { | 2153 | void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool transparent, bool unlit, bool depthBiased, bool isAntiAliased, |
| 2145 | batch.setPipeline(getSimplePipeline(textured, transparent, culled, unlit, depthBiased, false, isAntiAliased, forward)); | 2154 | bool forward, graphics::MaterialKey::CullFaceMode cullFaceMode) { |
| 2155 | batch.setPipeline(getSimplePipeline(textured, transparent, unlit, depthBiased, false, isAntiAliased, forward, cullFaceMode)); | ||
| 2146 | 2156 | ||
| 2147 | // If not textured, set a default albedo map | 2157 | // If not textured, set a default albedo map |
| 2148 | if (!textured) { | 2158 | if (!textured) { |
| @@ -2151,8 +2161,9 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool tra · 2 unmodified lines | |||
| 2151 | } | 2161 | } |
| 2152 | } | 2162 | } |
| 2153 | 2163 | ||
| 2154 | gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool fading, bool isAntiAliased, bool forward) { | 2164 | gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool unlit, bool depthBiased, bool fading, bool isAntiAliased, |
| 2155 | SimpleProgramKey config { textured, transparent, culled, unlit, depthBiased, fading, isAntiAliased, forward }; | 2165 | bool forward, graphics::MaterialKey::CullFaceMode cullFaceMode) { |
| 2166 | SimpleProgramKey config { textured, transparent, unlit, depthBiased, fading, isAntiAliased, forward, cullFaceMode }; | ||
| 2156 | 2167 | ||
| 2157 | // If the pipeline already exists, return it | 2168 | // If the pipeline already exists, return it |
| 2158 | auto it = _simplePrograms.find(config); | 2169 | auto it = _simplePrograms.find(config); |
| @@ -2189,10 +2200,12 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 30 unmodified lines | |||
| 2189 | 2200 | ||
| 2190 | // If the pipeline did not exist, make it | 2201 | // If the pipeline did not exist, make it |
| 2191 | auto state = std::make_shared<gpu::State>(); | 2202 | auto state = std::make_shared<gpu::State>(); |
| 2192 | if (config.isCulled()) { | 2203 | if (config.isCullFaceNone()) { |
| 2193 | state->setCullMode(gpu::State::CULL_BACK); | ||
| 2194 | } else { | ||
| 2195 | state->setCullMode(gpu::State::CULL_NONE); | 2204 | state->setCullMode(gpu::State::CULL_NONE); |
| 2205 | } else if (config.isCullFaceFront()) { | ||
| 2206 | state->setCullMode(gpu::State::CULL_FRONT); | ||
| 2207 | } else { | ||
| 2208 | state->setCullMode(gpu::State::CULL_BACK); | ||
| 2196 | } | 2209 | } |
| 2197 | state->setDepthTest(true, true, gpu::LESS_EQUAL); | 2210 | state->setDepthTest(true, true, gpu::LESS_EQUAL); |
| 2198 | if (config.hasDepthBias()) { | 2211 | if (config.hasDepthBias()) { |