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