Showing the changes to libraries/render-utils/src/RenderForwardTask.cpp (1 of 4 files). Show all
Unified · Split
| @@ -26,12 +26,15 @@ · 25 unmodified lines | ||
| 26 | 26 | |
| 27 | 27 | #include <render/drawItemBounds_vert.h> |
| 28 | 28 | #include <render/drawItemBounds_frag.h> |
| 29 | +#include "nop_frag.h" | |
| 29 | 30 | |
| 30 | 31 | using namespace render; |
| 32 | +extern void initForwardPipelines(ShapePlumber& plumber); | |
| 31 | 33 | |
| 32 | 34 | RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) { |
| 33 | 35 | // Prepare the ShapePipelines |
| 34 | 36 | ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>(); |
| 37 | + initForwardPipelines(*shapePlumber); | |
| 35 | 38 | |
| 36 | 39 | // Extract opaques / transparents / lights / overlays |
| 37 | 40 | const auto opaques = items[0]; |
| @@ -44,9 +47,10 @@ RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) { · 6 unmodified lines | ||
| 44 | 47 | const auto framebuffer = addJob<PrepareFramebuffer>("PrepareFramebuffer"); |
| 45 | 48 | |
| 46 | 49 | addJob<Draw>("DrawOpaques", opaques, shapePlumber); |
| 50 | + addJob<Stencil>("Stencil"); | |
| 47 | 51 | addJob<DrawBackground>("DrawBackground", background); |
| 48 | 52 | |
| 49 | − // bounds do not draw on stencil buffer, so they must come last | |
| 53 | + // Bounds do not draw on stencil buffer, so they must come last | |
| 50 | 54 | addJob<DrawBounds>("DrawBounds", opaques); |
| 51 | 55 | |
| 52 | 56 | // Blit! |
| @@ -116,6 +120,42 @@ void Draw::run(const SceneContextPointer& sceneContext, const RenderContextPoint · 63 unmodified lines | ||
| 116 | 120 | args->_batch = nullptr; |
| 117 | 121 | } |
| 118 | 122 | |
| 123 | +const gpu::PipelinePointer Stencil::getPipeline() { | |
| 124 | + if (!_stencilPipeline) { | |
| 125 | + auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); | |
| 126 | + auto ps = gpu::Shader::createPixel(std::string(nop_frag)); | |
| 127 | + gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); | |
| 128 | + gpu::Shader::makeProgram(*program); | |
| 129 | + | |
| 130 | + auto state = std::make_shared<gpu::State>(); | |
| 131 | + state->setDepthTest(true, false, gpu::LESS_EQUAL); | |
| 132 | + const gpu::int8 STENCIL_OPAQUE = 1; | |
| 133 | + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, | |
| 134 | + gpu::State::STENCIL_OP_REPLACE, | |
| 135 | + gpu::State::STENCIL_OP_REPLACE, | |
| 136 | + gpu::State::STENCIL_OP_KEEP)); | |
| 137 | + | |
| 138 | + _stencilPipeline = gpu::Pipeline::create(program, state); | |
| 139 | + } | |
| 140 | + return _stencilPipeline; | |
| 141 | +} | |
| 142 | + | |
| 143 | +void Stencil::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { | |
| 144 | + RenderArgs* args = renderContext->args; | |
| 145 | + | |
| 146 | + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { | |
| 147 | + args->_batch = &batch; | |
| 148 | + | |
| 149 | + batch.enableStereo(false); | |
| 150 | + batch.setViewportTransform(args->_viewport); | |
| 151 | + batch.setStateScissorRect(args->_viewport); | |
| 152 | + | |
| 153 | + batch.setPipeline(getPipeline()); | |
| 154 | + batch.draw(gpu::TRIANGLE_STRIP, 4); | |
| 155 | + }); | |
| 156 | + args->_batch = nullptr; | |
| 157 | +} | |
| 158 | + | |
| 119 | 159 | void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, |
| 120 | 160 | const Inputs& background) { |
| 121 | 161 | RenderArgs* args = renderContext->args; |