Overte C++ Documentation
Args.h
1 //
2 // Created by Brad Hefta-Gaub on 10/29/14.
3 // Copyright 2013-2014 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_render_Args_h
11 #define hifi_render_Args_h
12 
13 #include <functional>
14 #include <memory>
15 #include <stack>
16 #include <unordered_set>
17 
18 #include <GLMHelpers.h>
19 #include <ViewFrustum.h>
20 #include <StencilMaskMode.h>
21 #include <UUIDHasher.h>
22 
23 #include <gpu/Forward.h>
24 #include "Forward.h"
25 
26 class AABox;
27 
28 namespace render {
30  class RenderDetails {
31  public:
33  enum Type {
36 
39 
41  OTHER
42  };
43 
45  struct Item {
47  int _considered = 0;
48 
50  int _outOfView = 0;
51 
53  int _tooSmall = 0;
54 
56  int _rendered = 0;
57  };
58 
61 
64 
67 
70 
73 
81  Item& edit(Type type) {
82  switch (type) {
83  case SHADOW:
84  return _shadow;
85  case ITEM:
86  return _item;
87  default:
88  return _other;
89  }
90  }
91  };
92 
93 
100  class Args {
101  public:
102  enum RenderMode {
105 
108 
111 
114  };
115 
116  enum DisplayMode { MONO, STEREO_MONITOR, STEREO_HMD };
117 
118  enum RenderMethod { DEFERRED, FORWARD };
119 
120  Args() {}
121 
136  Args(const gpu::ContextPointer& context,
137  float sizeScale = 1.0f,
138  int boundaryLevelAdjust = 0,
139  float lodFarAngleHalfTan = 0.1f,
140  float lodNearAngleHalfTan = 0.01f,
141  float lodFarDist = 200.0f,
142  float lodNearDist = 4.0f,
143  RenderMode renderMode = DEFAULT_RENDER_MODE,
144  DisplayMode displayMode = MONO,
145  RenderMethod renderMethod = DEFERRED, // TODO: Application_Grapics.cpp always passes DEFERRED here, even when forward renderer is used. Maybe it's better to not have a parameter in the constructor at all?
146  gpu::Batch* batch = nullptr) :
147  _context(context),
148  _sizeScale(sizeScale),
149  _boundaryLevelAdjust(boundaryLevelAdjust),
150  _lodFarAngleHalfTan(lodFarAngleHalfTan),
151  _lodFarAngleHalfTanSq(lodFarAngleHalfTan * lodFarAngleHalfTan),
152  _lodNearAngleHalfTan(lodNearAngleHalfTan),
153  _lodNearAngleHalfTanSq(lodNearAngleHalfTan * lodNearAngleHalfTan),
154  _lodFarDist(lodFarDist),
155  _lodNearDist(lodNearDist),
156  _lodFarDistSq(lodFarDist * lodFarDist),
157  _lodNearDistSq(lodNearDist * lodNearDist),
158  _renderMode(renderMode),
159  _displayMode(displayMode),
160  _renderMethod(renderMethod),
161  _batch(batch) {
162  }
163 
167  bool hasViewFrustum() const { return _viewFrustums.size() > 0; }
168 
174  void setViewFrustum(const ViewFrustum& viewFrustum) {
175  while (_viewFrustums.size() > 0) {
176  _viewFrustums.pop();
177  }
178  _viewFrustums.push(viewFrustum);
179  }
180 
187  const ViewFrustum& getViewFrustum() const { assert(_viewFrustums.size() > 0); return _viewFrustums.top(); }
188 
195  void pushViewFrustum(const ViewFrustum& viewFrustum) { _viewFrustums.push(viewFrustum); }
196 
202  void popViewFrustum() { _viewFrustums.pop(); }
203 
207  bool isStereo() const { return _displayMode != MONO; }
208 
209  std::shared_ptr<gpu::Context> _context;
210 
214  std::shared_ptr<gpu::Framebuffer> _blitFramebuffer;
215 
217  std::shared_ptr<render::ShapePipeline> _shapePipeline;
218 
222  std::stack<ViewFrustum> _viewFrustums;
223 
225  glm::ivec4 _viewport { 0.0f, 0.0f, 1.0f, 1.0f };
226 
230  float _sizeScale { 1.0f };
231 
235 
238  float _lodFarAngleHalfTan{ 0.1f };
239 
242 
245  float _lodNearAngleHalfTan{ 0.01f };
246 
249 
252  float _lodFarDist { 200.0f };
253 
255  float _lodNearDist { 4.0f };
256 
259 
262 
267 
269  DisplayMode _displayMode { MONO };
270 
274  RenderMethod _renderMethod { DEFERRED };
275 
277  gpu::Batch* _batch = nullptr;
278 
281  uint32_t _globalShapeKey { 0 };
282 
285  uint32_t _itemShapeKey { 0 };
286 
288  bool _enableTexturing { true };
289 
291  bool _enableBlendshape { true };
292 
294  bool _enableSkinning { true };
295 
298 
300  render::ScenePointer _scene;
301 
304  int8_t _cameraMode { -1 };
305 
307  std::function<void(gpu::Batch&, const gpu::TexturePointer&)> _hudOperator { nullptr };
308 
310  gpu::TexturePointer _hudTexture { nullptr };
311 
314  bool _takingSnapshot { false };
315 
318  StencilMaskMode _stencilMaskMode { StencilMaskMode::NONE };
319 
321  std::function<void(gpu::Batch&)> _stencilMaskOperator;
322 
325  ItemID _ignoreItem { 0 };
326 
328  size_t _mirrorDepth { 0 };
329 
331  size_t _numMirrorFlips { 0 };
332  };
333 
334 }
335 
336 using RenderArgs = render::Args;
337 
338 #endif // hifi_render_Args_h
Definition: Args.h:100
std::shared_ptr< gpu::Framebuffer > _blitFramebuffer
Definition: Args.h:214
float _lodFarDistSq
See _lodNearDist.
Definition: Args.h:258
float _lodNearDistSq
See _lodFarDist.
Definition: Args.h:261
void pushViewFrustum(const ViewFrustum &viewFrustum)
Adds a view frustum to the top of the stack.
Definition: Args.h:195
float _lodNearAngleHalfTanSq
See _lodFarAngleHalfTan.
Definition: Args.h:248
DisplayMode _displayMode
Current display mode. It can be temporarily overridden for secondary camera task and then restored wh...
Definition: Args.h:269
std::function< void(gpu::Batch &, const gpu::TexturePointer &)> _hudOperator
Used to generate commands for drawing HUD.
Definition: Args.h:307
bool _enableTexturing
Set to false in MakeLightingModel task if texturing is disabled.
Definition: Args.h:288
float _lodFarAngleHalfTan
Definition: Args.h:238
float _lodNearAngleHalfTan
Definition: Args.h:245
render::ScenePointer _scene
Pointer to the main 3D scene.
Definition: Args.h:300
bool _enableSkinning
Set to false in MakeLightingModel task if skinning is disabled.
Definition: Args.h:294
uint32_t _itemShapeKey
Definition: Args.h:285
float _sizeScale
Definition: Args.h:230
int _boundaryLevelAdjust
Definition: Args.h:234
std::function< void(gpu::Batch &)> _stencilMaskOperator
Function that adds batch commands to draw stencil mesh for VR views.
Definition: Args.h:321
bool hasViewFrustum() const
Definition: Args.h:167
size_t _numMirrorFlips
Incremented on each reflection. Not incremented for portals.
Definition: Args.h:331
std::shared_ptr< render::ShapePipeline > _shapePipeline
Temporarily set to a proper pipeline when generating batch commands to render shapes.
Definition: Args.h:217
const ViewFrustum & getViewFrustum() const
Returns reference to the top view frustum on the stack.
Definition: Args.h:187
RenderMode
Definition: Args.h:102
@ MIRROR_RENDER_MODE
This is for the mirror camera mode for the main camera and not for actual mirrors in-game.
Definition: Args.h:110
@ DEFAULT_RENDER_MODE
Used for regular view.
Definition: Args.h:104
@ SHADOW_RENDER_MODE
Used for shadows and maybe highlight effect(?).
Definition: Args.h:107
@ SECONDARY_CAMERA_RENDER_MODE
Secondary camera can render to texture for effects such as mirrors or to screen.
Definition: Args.h:113
bool _takingSnapshot
Definition: Args.h:314
std::stack< ViewFrustum > _viewFrustums
Definition: Args.h:222
gpu::Batch * _batch
Current batch to which the commands will be written.
Definition: Args.h:277
RenderDetails _details
Contains statistics about culling in current frame.
Definition: Args.h:297
RenderMode _renderMode
Definition: Args.h:266
bool isStereo() const
Definition: Args.h:207
int8_t _cameraMode
Definition: Args.h:304
glm::ivec4 _viewport
Viewport rectangle in pixels.
Definition: Args.h:225
float _lodNearDist
Distance in meters at which _lodNearAngleHalfTan applies for size-based culling.
Definition: Args.h:255
size_t _mirrorDepth
Current mirror depth. 0 for main view, 1 for a view reflected once so on.
Definition: Args.h:328
ItemID _ignoreItem
Definition: Args.h:325
float _lodFarDist
Definition: Args.h:252
void popViewFrustum()
Removes the top view frustum from the stack.
Definition: Args.h:202
bool _enableBlendshape
Set to false in MakeLightingModel task if blendshapes are disabled.
Definition: Args.h:291
uint32_t _globalShapeKey
Definition: Args.h:281
RenderMethod _renderMethod
Definition: Args.h:274
Args(const gpu::ContextPointer &context, float sizeScale=1.0f, int boundaryLevelAdjust=0, float lodFarAngleHalfTan=0.1f, float lodNearAngleHalfTan=0.01f, float lodFarDist=200.0f, float lodNearDist=4.0f, RenderMode renderMode=DEFAULT_RENDER_MODE, DisplayMode displayMode=MONO, RenderMethod renderMethod=DEFERRED, gpu::Batch *batch=nullptr)
Definition: Args.h:136
gpu::TexturePointer _hudTexture
Texture that will be drawn as HUD.
Definition: Args.h:310
StencilMaskMode _stencilMaskMode
Definition: Args.h:318
float _lodFarAngleHalfTanSq
See _lodFarAngleHalfTan.
Definition: Args.h:241
void setViewFrustum(const ViewFrustum &viewFrustum)
Removes currently stored view frustums and adds a given one.
Definition: Args.h:174
Used for gathering statistics about culling in current frame.
Definition: Args.h:30
int _materialSwitches
Number of material switches during this frame.
Definition: Args.h:60
Item _other
Not used currently.
Definition: Args.h:72
Item & edit(Type type)
Gets an editable reference to statistics for a requested render mode.
Definition: Args.h:81
int _trianglesRendered
Number of triangles rendered during this frame.
Definition: Args.h:63
Item _shadow
Used during culling items for shadow bounds.
Definition: Args.h:69
Type
Statistics are generated separately for culling in different render modes.
Definition: Args.h:33
@ ITEM
Used during regular culling.
Definition: Args.h:35
@ SHADOW
Used during culling items for shadow bounds.
Definition: Args.h:38
@ OTHER
Not used currently.
Definition: Args.h:41
Item _item
Used during regular culling.
Definition: Args.h:66
Object containing culling statistics.
Definition: Args.h:45
int _considered
Items considered for culling.
Definition: Args.h:47
int _tooSmall
Items that are too small based on current LOD settings.
Definition: Args.h:53
int _outOfView
Items outside of view frustum.
Definition: Args.h:50
int _rendered
Items that will be rendered.
Definition: Args.h:56