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 | #include <render/drawItemBounds_vert.h> | 27 | #include <render/drawItemBounds_vert.h> |
| 28 | #include <render/drawItemBounds_frag.h> | 28 | #include <render/drawItemBounds_frag.h> |
| 29 | #include "nop_frag.h" | ||
| 29 | 30 | ||
| 30 | using namespace render; | 31 | using namespace render; |
| 32 | extern void initForwardPipelines(ShapePlumber& plumber); | ||
| 31 | 33 | ||
| 32 | RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) { | 34 | RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) { |
| 33 | // Prepare the ShapePipelines | 35 | // Prepare the ShapePipelines |
| 34 | ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>(); | 36 | ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>(); |
| 37 | initForwardPipelines(*shapePlumber); | ||
| 35 | 38 | ||
| 36 | // Extract opaques / transparents / lights / overlays | 39 | // Extract opaques / transparents / lights / overlays |
| 37 | const auto opaques = items[0]; | 40 | const auto opaques = items[0]; |
| @@ -44,9 +47,10 @@ RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) { · 6 unmodified lines | |||
| 44 | const auto framebuffer = addJob<PrepareFramebuffer>("PrepareFramebuffer"); | 47 | const auto framebuffer = addJob<PrepareFramebuffer>("PrepareFramebuffer"); |
| 45 | 48 | ||
| 46 | addJob<Draw>("DrawOpaques", opaques, shapePlumber); | 49 | addJob<Draw>("DrawOpaques", opaques, shapePlumber); |
| 50 | addJob<Stencil>("Stencil"); | ||
| 47 | addJob<DrawBackground>("DrawBackground", background); | 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 | addJob<DrawBounds>("DrawBounds", opaques); | 54 | addJob<DrawBounds>("DrawBounds", opaques); |
| 51 | 55 | ||
| 52 | // Blit! | 56 | // Blit! |
| @@ -116,6 +120,42 @@ void Draw::run(const SceneContextPointer& sceneContext, const RenderContextPoint · 63 unmodified lines | |||
| 116 | args->_batch = nullptr; | 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 | void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, | 159 | void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, |
| 120 | const Inputs& background) { | 160 | const Inputs& background) { |
| 121 | RenderArgs* args = renderContext->args; | 161 | RenderArgs* args = renderContext->args; |