Overte C++ Documentation
StencilMaskPass.h
1 //
2 // StencilMaskPass.h
3 // render-utils/src/
4 //
5 // Created by Sam Gateau on 5/31/17.
6 // Copyright 20154 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 #pragma once
12 #ifndef hifi_StencilMaskPass_h
13 #define hifi_StencilMaskPass_h
14 
15 #include <render/Engine.h>
16 #include <gpu/Pipeline.h>
17 #include <graphics/Geometry.h>
18 #include <StencilMaskMode.h>
19 
20 class PrepareStencilConfig : public render::Job::Config {
21  Q_OBJECT
22  Q_PROPERTY(StencilMaskMode maskMode MEMBER maskMode NOTIFY dirty)
23 
24 public:
25  PrepareStencilConfig(bool enabled = true) : JobConfig(enabled) {}
26 
27  // -1 -> don't force drawing (fallback to render args mode)
28  // 0 -> force draw without mesh
29  // 1 -> force draw with mesh
30  StencilMaskMode maskMode { StencilMaskMode::NONE };
31 
32 signals:
33  void dirty();
34 };
35 
36 class PrepareStencil {
37 public:
38  using Config = PrepareStencilConfig;
39 
40  using JobModel = render::Job::ModelI<PrepareStencil, gpu::FramebufferPointer, Config>;
41 
42  void configure(const Config& config);
43 
44  void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer);
45 
46  // Always use 0 to clear the stencil buffer to set it to background
47  static const gpu::int8 STENCIL_BACKGROUND = 0; // must match values in Skybox.cpp and ProceduralSkybox.cpp
48  static const gpu::int8 STENCIL_MASK = 1 << 0;
49  static const gpu::int8 STENCIL_SHAPE = 1 << 1;
50  static const gpu::int8 STENCIL_NO_AA = 1 << 2;
51 
52  static void drawMask(gpu::State& state);
53  static void drawBackground(gpu::State& state);
54  static void testMask(gpu::State& state);
55  static void testNoAA(gpu::State& state);
56  static void testBackground(gpu::State& state);
57  static void testShape(gpu::State& state);
58  static void testMaskDrawShape(gpu::State& state);
59  static void testMaskDrawShapeNoAA(gpu::State& state);
60 
61 private:
62  gpu::PipelinePointer _meshStencilPipeline;
63  gpu::PipelinePointer getMeshStencilPipeline();
64 
65  gpu::PipelinePointer _paintStencilPipeline;
66  gpu::PipelinePointer getPaintStencilPipeline();
67 
68  graphics::MeshPointer _mesh;
69  graphics::MeshPointer getMesh();
70 
71  StencilMaskMode _maskMode { StencilMaskMode::NONE };
72 };
73 
74 
75 #endif // hifi_StencilMaskPass_h