History

Merged with master

Olivier Prat committed 8 years ago

Commit f5a25572 parents 92e1fe8 0ef27941213 files · +53263 −55587Browse files

Showing the changes to libraries/render-utils/src/RenderCommonTask.cpp (1 of 1213 files). Show all

Unified · Split

libraries/render-utils/src/RenderCommonTask.cpp+210−0
@@ -0,0 +1,210 @@
1//
2// Created by Bradley Austin Davis on 2018/01/09
3// Copyright 2013-2018 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#include "RenderCommonTask.h"
10
11#include <gpu/Context.h>
12
13#include "DeferredLightingEffect.h"
14#include "RenderUtilsLogging.h"
15
16using namespace render;
17extern void initOverlay3DPipelines(render::ShapePlumber& plumber, bool depthTest = false);
18
19void BeginGPURangeTimer::run(const render::RenderContextPointer& renderContext, gpu::RangeTimerPointer& timer) {
20 timer = _gpuTimer;
21 gpu::doInBatch("BeginGPURangeTimer::run", renderContext->args->_context, [&](gpu::Batch& batch) {
22 _gpuTimer->begin(batch);
23 });
24}
25
26void EndGPURangeTimer::run(const render::RenderContextPointer& renderContext, const gpu::RangeTimerPointer& timer) {
27 gpu::doInBatch("EndGPURangeTimer::run", renderContext->args->_context, [&](gpu::Batch& batch) {
28 timer->end(batch);
29 });
30
31 auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
32 config->setGPUBatchRunTime(timer->getGPUAverage(), timer->getBatchAverage());
33}
34
35DrawOverlay3D::DrawOverlay3D(bool opaque) :
36 _shapePlumber(std::make_shared<ShapePlumber>()),
37 _opaquePass(opaque) {
38 initOverlay3DPipelines(*_shapePlumber);
39}
40
41void DrawOverlay3D::run(const RenderContextPointer& renderContext, const Inputs& inputs) {
42 assert(renderContext->args);
43 assert(renderContext->args->hasViewFrustum());
44
45 auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
46
47 const auto& inItems = inputs.get0();
48 const auto& lightingModel = inputs.get1();
49
50 config->setNumDrawn((int)inItems.size());
51 emit config->numDrawnChanged();
52
53 if (!inItems.empty()) {
54 RenderArgs* args = renderContext->args;
55
56 // Clear the framebuffer without stereo
57 // Needs to be distinct from the other batch because using the clear call
58 // while stereo is enabled triggers a warning
59 if (_opaquePass) {
60 gpu::doInBatch("DrawOverlay3D::run::clear", args->_context, [&](gpu::Batch& batch){
61 batch.enableStereo(false);
62 batch.clearFramebuffer(gpu::Framebuffer::BUFFER_DEPTH, glm::vec4(), 1.f, 0, false);
63 });
64 }
65
66 // Render the items
67 gpu::doInBatch("DrawOverlay3D::run", args->_context, [&](gpu::Batch& batch) {
68 args->_batch = &batch;
69 batch.setViewportTransform(args->_viewport);
70 batch.setStateScissorRect(args->_viewport);
71
72 glm::mat4 projMat;
73 Transform viewMat;
74 args->getViewFrustum().evalProjectionMatrix(projMat);
75 args->getViewFrustum().evalViewTransform(viewMat);
76
77 batch.setProjectionTransform(projMat);
78 batch.setViewTransform(viewMat);
79
80 // Setup lighting model for all items;
81 batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
82
83 renderShapes(renderContext, _shapePlumber, inItems, _maxDrawn);
84 args->_batch = nullptr;
85 });
86 }
87}
88
89void CompositeHUD::run(const RenderContextPointer& renderContext) {
90 assert(renderContext->args);
91 assert(renderContext->args->_context);
92
93 // We do not want to render HUD elements in secondary camera
94 if (renderContext->args->_renderMode == RenderArgs::RenderMode::SECONDARY_CAMERA_RENDER_MODE) {
95 return;
96 }
97
98 // Grab the HUD texture
99#if !defined(DISABLE_QML)
100 gpu::doInBatch("CompositeHUD::run", renderContext->args->_context, [&](gpu::Batch& batch) {
101 if (renderContext->args->_hudOperator) {
102 renderContext->args->_hudOperator(batch, renderContext->args->_hudTexture, renderContext->args->_renderMode == RenderArgs::RenderMode::MIRROR_RENDER_MODE);
103 }
104 });
105#endif
106}
107
108void Blit::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) {
109 assert(renderContext->args);
110 assert(renderContext->args->_context);
111
112 RenderArgs* renderArgs = renderContext->args;
113 auto blitFbo = renderArgs->_blitFramebuffer;
114
115 if (!blitFbo) {
116 qCWarning(renderutils) << "Blit::run - no blit frame buffer.";
117 return;
118 }
119
120 // Determine size from viewport
121 int width = renderArgs->_viewport.z;
122 int height = renderArgs->_viewport.w;
123
124 // Blit primary to blit FBO
125 auto primaryFbo = srcFramebuffer;
126
127 gpu::doInBatch("Blit::run", renderArgs->_context, [&](gpu::Batch& batch) {
128 batch.setFramebuffer(blitFbo);
129
130 if (renderArgs->_renderMode == RenderArgs::MIRROR_RENDER_MODE) {
131 if (renderArgs->isStereo()) {
132 gpu::Vec4i srcRectLeft;
133 srcRectLeft.z = width / 2;
134 srcRectLeft.w = height;
135
136 gpu::Vec4i srcRectRight;
137 srcRectRight.x = width / 2;
138 srcRectRight.z = width;
139 srcRectRight.w = height;
140
141 gpu::Vec4i destRectLeft;
142 destRectLeft.x = srcRectLeft.z;
143 destRectLeft.z = srcRectLeft.x;
144 destRectLeft.y = srcRectLeft.y;
145 destRectLeft.w = srcRectLeft.w;
146
147 gpu::Vec4i destRectRight;
148 destRectRight.x = srcRectRight.z;
149 destRectRight.z = srcRectRight.x;
150 destRectRight.y = srcRectRight.y;
151 destRectRight.w = srcRectRight.w;
152
153 // Blit left to right and right to left in stereo
154 batch.blit(primaryFbo, srcRectRight, blitFbo, destRectLeft);
155 batch.blit(primaryFbo, srcRectLeft, blitFbo, destRectRight);
156 } else {
157 gpu::Vec4i srcRect;
158 srcRect.z = width;
159 srcRect.w = height;
160
161 gpu::Vec4i destRect;
162 destRect.x = width;
163 destRect.y = 0;
164 destRect.z = 0;
165 destRect.w = height;
166
167 batch.blit(primaryFbo, srcRect, blitFbo, destRect);
168 }
169 } else {
170 gpu::Vec4i rect;
171 rect.z = width;
172 rect.w = height;
173
174 batch.blit(primaryFbo, rect, blitFbo, rect);
175 }
176 });
177}
178
179void ExtractFrustums::run(const render::RenderContextPointer& renderContext, Output& output) {
180 assert(renderContext->args);
181 assert(renderContext->args->_context);
182
183 RenderArgs* args = renderContext->args;
184
185 // Return view frustum
186 auto& viewFrustum = output[VIEW_FRUSTUM].edit<ViewFrustumPointer>();
187 if (!viewFrustum) {
188 viewFrustum = std::make_shared<ViewFrustum>(args->getViewFrustum());
189 } else {
190 *viewFrustum = args->getViewFrustum();
191 }
192
193 // Return shadow frustum
194 auto lightStage = args->_scene->getStage<LightStage>(LightStage::getName());
195 for (auto i = 0; i < SHADOW_CASCADE_FRUSTUM_COUNT; i++) {
196 auto& shadowFrustum = output[SHADOW_CASCADE0_FRUSTUM+i].edit<ViewFrustumPointer>();
197 if (lightStage) {
198 auto globalShadow = lightStage->getCurrentKeyShadow();
199
200 if (globalShadow && i<(int)globalShadow->getCascadeCount()) {
201 auto& cascade = globalShadow->getCascade(i);
202 shadowFrustum = cascade.getFrustum();
203 } else {
204 shadowFrustum.reset();
205 }
206 } else {
207 shadowFrustum.reset();
208 }
209 }
210}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t