Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 174 files). Show all
Unified · Split
| @@ -113,6 +113,7 @@ static const uint SHAPE_NORMALS_OFFSET = offsetof(GeometryCache::ShapeVertex, no · 112 unmodified lines | ||
| 113 | 113 | static const uint SHAPE_TEXCOORD0_OFFSET = offsetof(GeometryCache::ShapeVertex, uv); |
| 114 | 114 | static const uint SHAPE_TANGENT_OFFSET = offsetof(GeometryCache::ShapeVertex, tangent); |
| 115 | 115 | |
| 116 | +std::map<std::pair<bool, bool>, gpu::PipelinePointer> GeometryCache::_webPipelines; | |
| 116 | 117 | std::map<std::pair<bool, bool>, gpu::PipelinePointer> GeometryCache::_gridPipelines; |
| 117 | 118 | |
| 118 | 119 | void GeometryCache::computeSimpleHullPointListForShape(const int entityShape, const glm::vec3 &entityExtents, QVector<glm::vec3> &outPointList) { |
| @@ -2045,7 +2046,7 @@ void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bo · 1926 unmodified lines | ||
| 2045 | 2046 | const float DEPTH_BIAS = 0.001f; |
| 2046 | 2047 | |
| 2047 | 2048 | static const std::vector<std::tuple<bool, bool, uint32_t>> keys = { |
| 2048 | − std::make_tuple(false, false, grid), std::make_tuple(false, true, forward_grid), std::make_tuple(true, false, grid_translucent), std::make_tuple(true, true, forward_grid_translucent) | |
| 2049 | + std::make_tuple(false, false, grid), std::make_tuple(false, true, grid_forward), std::make_tuple(true, false, grid_translucent), std::make_tuple(true, true, grid_translucent_forward) | |
| 2049 | 2050 | }; |
| 2050 | 2051 | |
| 2051 | 2052 | for (auto& key : keys) { |
| @@ -2136,34 +2137,36 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) { · 84 unmodified lines | ||
| 2136 | 2137 | return a.getRaw() == b.getRaw(); |
| 2137 | 2138 | } |
| 2138 | 2139 | |
| 2139 | −static void buildWebShader(int programId, bool blendEnable, | |
| 2140 | − gpu::ShaderPointer& shaderPointerOut, gpu::PipelinePointer& pipelinePointerOut) { | |
| 2141 | − shaderPointerOut = gpu::Shader::createProgram(programId); | |
| 2142 | − auto state = std::make_shared<gpu::State>(); | |
| 2143 | − state->setCullMode(gpu::State::CULL_NONE); | |
| 2144 | − state->setDepthTest(true, true, gpu::LESS_EQUAL); | |
| 2145 | − state->setBlendFunction(blendEnable, | |
| 2146 | − gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, | |
| 2147 | − gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); | |
| 2140 | +void GeometryCache::bindWebBrowserProgram(gpu::Batch& batch, bool transparent, bool forward) { | |
| 2141 | + batch.setPipeline(getWebBrowserProgram(transparent, forward)); | |
| 2142 | +} | |
| 2148 | 2143 | |
| 2149 | − PrepareStencil::testMaskDrawShapeNoAA(*state); | |
| 2144 | +gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool forward) { | |
| 2145 | + if (_webPipelines.empty()) { | |
| 2146 | + using namespace shader::render_utils::program; | |
| 2147 | + static const std::vector<std::tuple<bool, bool, uint32_t>> keys = { | |
| 2148 | + std::make_tuple(false, false, web_browser), std::make_tuple(false, true, web_browser_forward), | |
| 2149 | + std::make_tuple(true, false, web_browser_translucent) | |
| 2150 | + }; | |
| 2150 | 2151 | |
| 2151 | − pipelinePointerOut = gpu::Pipeline::create(shaderPointerOut, state); | |
| 2152 | −} | |
| 2152 | + for (auto& key : keys) { | |
| 2153 | + gpu::StatePointer state = gpu::StatePointer(new gpu::State()); | |
| 2154 | + state->setDepthTest(true, true, gpu::LESS_EQUAL); | |
| 2155 | + // FIXME: do we need a testMaskDrawNoAA? | |
| 2156 | + PrepareStencil::testMaskDrawShapeNoAA(*state); | |
| 2157 | + state->setBlendFunction(std::get<0>(key), | |
| 2158 | + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, | |
| 2159 | + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); | |
| 2160 | + state->setCullMode(gpu::State::CULL_NONE); | |
| 2153 | 2161 | |
| 2154 | −void GeometryCache::bindWebBrowserProgram(gpu::Batch& batch, bool transparent) { | |
| 2155 | − batch.setPipeline(getWebBrowserProgram(transparent)); | |
| 2156 | −} | |
| 2162 | + _webPipelines[{std::get<0>(key), std::get<1>(key)}] = gpu::Pipeline::create(gpu::Shader::createProgram(std::get<2>(key)), state); | |
| 2163 | + } | |
| 2157 | 2164 | |
| 2158 | −gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent) { | |
| 2159 | − static std::once_flag once; | |
| 2160 | − std::call_once(once, [&]() { | |
| 2161 | − // FIXME: need a forward pipeline for this | |
| 2162 | − buildWebShader(shader::render_utils::program::simple_opaque_web_browser, false, _simpleOpaqueWebBrowserShader, _simpleOpaqueWebBrowserPipeline); | |
| 2163 | − buildWebShader(shader::render_utils::program::simple_transparent_web_browser, true, _simpleTransparentWebBrowserShader, _simpleTransparentWebBrowserPipeline); | |
| 2164 | − }); | |
| 2165 | + // The forward opaque/translucent pipelines are the same for now | |
| 2166 | + _webPipelines[{ true, true }] = _webPipelines[{ false, true }]; | |
| 2167 | + } | |
| 2165 | 2168 | |
| 2166 | − return transparent ? _simpleTransparentWebBrowserPipeline : _simpleOpaqueWebBrowserPipeline; | |
| 2169 | + return _webPipelines[{ transparent, forward }]; | |
| 2167 | 2170 | } |
| 2168 | 2171 | |
| 2169 | 2172 | void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool isAntiAliased, bool forward) { |
| @@ -2191,24 +2194,24 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 21 unmodified lines | ||
| 2191 | 2194 | std::call_once(once, [&]() { |
| 2192 | 2195 | using namespace shader::render_utils::program; |
| 2193 | 2196 | |
| 2194 | − _forwardSimpleShader = gpu::Shader::createProgram(forward_simple_textured); | |
| 2195 | − _forwardTransparentShader = gpu::Shader::createProgram(forward_simple_textured_transparent); | |
| 2196 | − _forwardUnlitShader = gpu::Shader::createProgram(forward_simple_textured_unlit); | |
| 2197 | + _forwardSimpleShader = gpu::Shader::createProgram(simple_forward); | |
| 2198 | + _forwardTransparentShader = gpu::Shader::createProgram(simple_translucent_forward); | |
| 2199 | + _forwardUnlitShader = gpu::Shader::createProgram(simple_unlit_forward); | |
| 2197 | 2200 | |
| 2198 | − _simpleShader = gpu::Shader::createProgram(simple_textured); | |
| 2199 | − _transparentShader = gpu::Shader::createProgram(simple_transparent_textured); | |
| 2200 | − _unlitShader = gpu::Shader::createProgram(simple_textured_unlit); | |
| 2201 | + _simpleShader = gpu::Shader::createProgram(simple); | |
| 2202 | + _transparentShader = gpu::Shader::createProgram(simple_translucent); | |
| 2203 | + _unlitShader = gpu::Shader::createProgram(simple_unlit); | |
| 2201 | 2204 | }); |
| 2202 | 2205 | } else { |
| 2203 | 2206 | static std::once_flag once; |
| 2204 | 2207 | std::call_once(once, [&]() { |
| 2205 | 2208 | using namespace shader::render_utils::program; |
| 2206 | − // FIXME: these aren't right... | |
| 2207 | − _forwardSimpleFadeShader = gpu::Shader::createProgram(forward_simple_textured); | |
| 2208 | − _forwardUnlitFadeShader = gpu::Shader::createProgram(forward_simple_textured_unlit); | |
| 2209 | + // Fading is currently disabled during forward rendering | |
| 2210 | + _forwardSimpleFadeShader = gpu::Shader::createProgram(simple_forward); | |
| 2211 | + _forwardUnlitFadeShader = gpu::Shader::createProgram(simple_unlit_forward); | |
| 2209 | 2212 | |
| 2210 | − _simpleFadeShader = gpu::Shader::createProgram(simple_textured_fade); | |
| 2211 | − _unlitFadeShader = gpu::Shader::createProgram(simple_textured_unlit_fade); | |
| 2213 | + _simpleFadeShader = gpu::Shader::createProgram(simple_fade); | |
| 2214 | + _unlitFadeShader = gpu::Shader::createProgram(simple_unlit_fade); | |
| 2212 | 2215 | }); |
| 2213 | 2216 | } |
| 2214 | 2217 | |