Overte C++ Documentation
DrawTask.h
1 //
2 // DrawTask.h
3 // render/src/render
4 //
5 // Created by Sam Gateau on 5/21/15.
6 // Copyright 2015 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 
13 #ifndef hifi_render_DrawTask_h
14 #define hifi_render_DrawTask_h
15 
16 #include "Engine.h"
17 
18 namespace render {
19 
20 void renderItems(const RenderContextPointer& renderContext, const ItemBounds& inItems, int maxDrawnItems = -1);
21 void renderShapes(const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1, const ShapeKey& globalKey = ShapeKey());
22 void renderStateSortShapes(const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1, const ShapeKey& globalKey = ShapeKey());
23 
24 class DrawLightConfig : public Job::Config {
25  Q_OBJECT
26  Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY numDrawnChanged)
27  Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
28 public:
29  int getNumDrawn() { return numDrawn; }
30  void setNumDrawn(int num) { numDrawn = num; emit numDrawnChanged(); }
31 
32  int maxDrawn{ -1 };
33 signals:
34  void numDrawnChanged();
35  void dirty();
36 
37 protected:
38  int numDrawn{ 0 };
39 };
40 
41 class DrawLight {
42 public:
43  using Config = DrawLightConfig;
44  using JobModel = Job::ModelI<DrawLight, ItemBounds, Config>;
45 
46  void configure(const Config& config) { _maxDrawn = config.maxDrawn; }
47  void run(const RenderContextPointer& renderContext, const ItemBounds& inLights);
48 protected:
49  int _maxDrawn; // initialized by Config
50 };
51 
52 class DrawBounds {
53 public:
54  class Config : public render::JobConfig {
55  public:
56  Config(bool enabled = false) : JobConfig(enabled) {}
57  };
58 
59  using Inputs = render::ItemBounds;
60  using JobModel = render::Job::ModelI<DrawBounds, Inputs, Config>;
61 
62  DrawBounds(uint transformSlot) : _transformSlot(transformSlot) {}
63 
64  void configure(const Config& configuration) {}
65  void run(const render::RenderContextPointer& renderContext,
66  const Inputs& items);
67 
68 private:
69  static const gpu::PipelinePointer getPipeline();
70  static gpu::PipelinePointer _boundsPipeline;
71  gpu::BufferPointer _drawBuffer;
72  gpu::BufferPointer _paramsBuffer;
73  uint _transformSlot;
74 };
75 
76 class DrawQuadVolumeConfig : public render::JobConfig {
77  Q_OBJECT
78  Q_PROPERTY(bool isFrozen MEMBER isFrozen NOTIFY dirty)
79 public:
80 
81  DrawQuadVolumeConfig(bool enabled = false) : JobConfig(enabled) {}
82 
83  bool isFrozen{ false };
84 signals:
85  void dirty();
86 
87 };
88 
89 class DrawQuadVolume {
90 public:
91 
92  using Config = DrawQuadVolumeConfig;
93 
94  void configure(const Config& configuration);
95 
96 protected:
97  DrawQuadVolume(const glm::vec3& color);
98 
99  void run(const render::RenderContextPointer& renderContext, const glm::vec3 vertices[8],
100  const gpu::BufferView& indices, int indexCount);
101 
102  gpu::BufferView _meshVertices;
103  gpu::BufferPointer _params;
104  bool _isUpdateEnabled{ true };
105 
106  static gpu::Stream::FormatPointer _format;
107 
108  static gpu::PipelinePointer getPipeline();
109 };
110 
111 class DrawAABox : public DrawQuadVolume {
112 public:
113  using Inputs = AABox;
114  using JobModel = render::Job::ModelI<DrawAABox, Inputs, Config>;
115 
116  DrawAABox(const glm::vec3& color = glm::vec3(1.0f, 1.0f, 1.0f));
117 
118  void run(const render::RenderContextPointer& renderContext, const Inputs& box);
119 
120 protected:
121 
122  static gpu::BufferView _cubeMeshIndices;
123 
124  static void getVertices(const AABox& box, glm::vec3 vertices[8]);
125 };
126 
127 class DrawFrustum : public DrawQuadVolume {
128 public:
129  using Input = ViewFrustumPointer;
130  using JobModel = render::Job::ModelI<DrawFrustum, Input, Config>;
131 
132  DrawFrustum(const glm::vec3& color = glm::vec3(1.0f, 1.0f, 1.0f));
133 
134  void run(const render::RenderContextPointer& renderContext, const Input& input);
135 
136 private:
137 
138  static gpu::BufferView _frustumMeshIndices;
139 
140  static void getVertices(const ViewFrustum& frustum, glm::vec3 vertices[8]);
141 };
142 }
143 
144 #endif // hifi_render_DrawTask_h