templatize graphics engine tasks' run method

This commit is contained in:
Zach Pomerantz 2016-12-22 22:21:51 -05:00
parent dbf4f2d23b
commit 8d63067fa5
9 changed files with 18 additions and 80 deletions

View file

@ -228,26 +228,6 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
}
void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
// sanity checks
assert(sceneContext);
if (!sceneContext->_scene) {
return;
}
// Is it possible that we render without a viewFrustum ?
if (!(renderContext->args && renderContext->args->hasViewFrustum())) {
return;
}
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
for (auto job : _jobs) {
job.run(sceneContext, renderContext);
}
}
void BeginGPURangeTimer::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, gpu::RangeTimerPointer& timer) {
timer = _gpuTimer;
gpu::doInBatch(renderContext->args->_context, [&](gpu::Batch& batch) {

View file

@ -200,7 +200,6 @@ public:
RenderDeferredTask(render::CullFunctor cullFunctor);
void configure(const Config& config) {}
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
using JobModel = Model<RenderDeferredTask, Config>;

View file

@ -86,26 +86,6 @@ RenderForwardTask::RenderForwardTask(CullFunctor cullFunctor) {
addJob<Blit>("Blit", framebuffer);
}
void RenderForwardTask::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
// sanity checks
assert(sceneContext);
if (!sceneContext->_scene) {
return;
}
// Is it possible that we render without a viewFrustum ?
if (!(renderContext->args && renderContext->args->hasViewFrustum())) {
return;
}
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
for (auto job : _jobs) {
job.run(sceneContext, renderContext);
}
}
void PrepareFramebuffer::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer) {
auto framebufferCache = DependencyManager::get<FramebufferCache>();
auto framebufferSize = framebufferCache->getFrameBufferSize();

View file

@ -24,7 +24,6 @@ public:
RenderForwardTask(render::CullFunctor cullFunctor);
void configure(const Config& config) {}
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
using JobModel = Model<RenderForwardTask, Config>;
};

View file

@ -139,20 +139,6 @@ void RenderShadowTask::configure(const Config& configuration) {
Task::configure(configuration);
}
void RenderShadowTask::run(const SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) {
assert(sceneContext);
RenderArgs* args = renderContext->args;
// sanity checks
if (!sceneContext->_scene || !args) {
return;
}
for (auto job : _jobs) {
job.run(sceneContext, renderContext);
}
}
void RenderShadowSetup::run(const SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, Output& output) {
auto lightStage = DependencyManager::get<DeferredLightingEffect>()->getLightStage();
const auto globalShadow = lightStage->getShadow(0);

View file

@ -49,7 +49,6 @@ public:
RenderShadowTask(render::CullFunctor shouldRender);
void configure(const Config& configuration);
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
};
class RenderShadowSetup {

View file

@ -52,11 +52,3 @@ void Engine::load() {
}
}
}
void Engine::run() {
for (auto job : _jobs) {
job.run(_sceneContext, _renderContext);
}
}

View file

@ -39,8 +39,8 @@ namespace render {
RenderContextPointer getRenderContext() const { return _renderContext; }
// Render a frame
// A frame must have a scene registered and a context set to render
void run();
// Must have a scene registered and a context set
void run() { assert(_sceneContext && _renderContext); Task::run(_sceneContext, _renderContext); }
protected:
SceneContextPointer _sceneContext;

View file

@ -593,22 +593,20 @@ public:
using QConfigPointer = Job::QConfigPointer;
using None = Job::None;
template <class T, class C = Config, class I = None, class O = None> class Model : public Job::Concept {
template <class T, class C = Config, class O = None> class Model : public Job::Concept {
public:
using Data = T;
using Input = I;
using Input = None;
using Output = O;
Data _data;
Varying _input;
Varying _output;
const Varying getInput() const override { return _input; }
const Varying getOutput() const override { return _output; }
template <class... A>
Model(const Varying& input, A&&... args) :
Concept(nullptr), _data(Data(std::forward<A>(args)...)), _input(input), _output(Output()) {
Concept(nullptr), _data(Data(std::forward<A>(args)...)), _output(Output()) {
// Recreate the Config to use the templated type
_data.template createConfiguration<C>();
_config = _data.getConfiguration();
@ -620,16 +618,15 @@ public:
}
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) override {
renderContext->jobConfig = std::static_pointer_cast<Config>(_config);
if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) {
jobRun(_data, sceneContext, renderContext, _input.get<I>(), _output.edit<O>());
auto config = std::static_pointer_cast<Config>(_config);
if (config->alwaysEnabled || config->enabled) {
for (auto job : _data._jobs) {
job.run(sceneContext, renderContext);
}
}
renderContext->jobConfig.reset();
}
};
template <class T, class I, class C = Config> using ModelI = Model<T, C, I, None>;
template <class T, class O, class C = Config> using ModelO = Model<T, C, None, O>;
template <class T, class I, class O, class C = Config> using ModelIO = Model<T, C, I, O>;
template <class T, class O, class C = Config> using ModelO = Model<T, C, O>;
using Jobs = std::vector<Job>;
@ -688,8 +685,14 @@ public:
}
}
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
for (auto job : _jobs) {
job.run(sceneContext, renderContext);
}
}
protected:
template <class T, class C, class I, class O> friend class Model;
template <class T, class C, class O> friend class Model;
QConfigPointer _config;
Jobs _jobs;