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