Moving the stage objects under the scene umbrella and creating a cear task to update the scene elements

This commit is contained in:
samcake 2017-06-21 18:29:38 -07:00
parent 2919607f86
commit 9ae2861ee6
10 changed files with 140 additions and 14 deletions

View file

@ -111,10 +111,7 @@
#include <plugins/SteamClientPlugin.h>
#include <RecordingScriptingInterface.h>
#include <RenderableWebEntityItem.h>
#include <RenderShadowTask.h>
#include <render/RenderFetchCullSortTask.h>
#include <RenderDeferredTask.h>
#include <RenderForwardTask.h>
#include <UpdateSceneTask.h>
#include <RenderViewTask.h>
#include <SecondaryCamera.h>
#include <ResourceCache.h>
@ -1902,6 +1899,7 @@ void Application::initializeGL() {
render::CullFunctor cullFunctor = LODManager::shouldRender;
static const QString RENDER_FORWARD = "HIFI_RENDER_FORWARD";
bool isDeferred = !QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD);
_renderEngine->addJob<UpdateSceneTask>("UpdateScene");
_renderEngine->addJob<SecondaryCameraRenderTask>("SecondaryCameraFrame", cullFunctor);
_renderEngine->addJob<RenderViewTask>("RenderMainView", cullFunctor, isDeferred);
_renderEngine->load();

View file

@ -137,4 +137,15 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext,
}
*/
}
}
BackgroundStageSetup::BackgroundStageSetup() {
}
void BackgroundStageSetup::run(const render::RenderContextPointer& renderContext) {
auto stage = renderContext->_scene->getStage("BACKGROUND_STAGE");
if (!stage) {
renderContext->_scene->resetStage("BACKGROUND_STAGE", std::make_shared<BackgroundStage>());
}
}

View file

@ -15,12 +15,13 @@
#include <set>
#include <unordered_map>
#include <render/IndexedContainer.h>
#include <render/Stage.h>
#include "LightingModel.h"
// Background stage to set up background-related rendering tasks
class BackgroundStage {
class BackgroundStage : public render::Stage {
public:
using Index = render::indexed_container::Index;
static const Index INVALID_INDEX { render::indexed_container::INVALID_INDEX };
@ -66,6 +67,15 @@ public:
};
using BackgroundStagePointer = std::shared_ptr<BackgroundStage>;
class BackgroundStageSetup {
public:
using JobModel = render::Job::Model<BackgroundStageSetup>;
BackgroundStageSetup();
void run(const render::RenderContextPointer& renderContext);
protected:
};
class DrawBackgroundStage {
public:

View file

@ -165,3 +165,13 @@ void LightStage::updateLightArrayBuffer(Index lightId) {
}
}
LightStageSetup::LightStageSetup() {
}
void LightStageSetup::run(const render::RenderContextPointer& renderContext) {
auto stage = renderContext->_scene->getStage("LIGHT_STAGE");
if (!stage) {
renderContext->_scene->resetStage("LIGHT_STAGE", std::make_shared<LightStage>());
}
}

View file

@ -14,16 +14,19 @@
#include <set>
#include <unordered_map>
#include <gpu/Framebuffer.h>
#include <model/Light.h>
#include <render/IndexedContainer.h>
#include "gpu/Framebuffer.h"
#include "model/Light.h"
#include <render/Stage.h>
#include <render/Engine.h>
class ViewFrustum;
// Light stage to set up light-related rendering tasks
class LightStage {
class LightStage : public render::Stage {
public:
using Index = render::indexed_container::Index;
static const Index INVALID_INDEX { render::indexed_container::INVALID_INDEX };
@ -149,5 +152,15 @@ using LightStagePointer = std::shared_ptr<LightStage>;
class LightStageSetup {
public:
using JobModel = render::Job::Model<LightStageSetup>;
LightStageSetup();
void run(const render::RenderContextPointer& renderContext);
protected:
};
#endif

View file

@ -0,0 +1,24 @@
//
// UpdateSceneTask.cpp
// render-utils/src/
//
// Created by Sam Gateau on 6/21/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "UpdateSceneTask.h"
#include <render/SceneTask.h>
#include "LightStage.h"
#include "BackgroundStage.h"
void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render::Varying& output) {
task.addJob<render::PerformSceneTransaction>("PerformSceneTransaction");
task.addJob<LightStageSetup>("LightStageSetup");
}

View file

@ -0,0 +1,30 @@
//
// UpdateSceneTask.h
// render-utils/src/
//
// Created by Sam Gateau on 6/21/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#ifndef hifi_UpdateSceneTask_h
#define hifi_UpdateSceneTask_h
#include <render/Engine.h>
#include <render/RenderFetchCullSortTask.h>
class UpdateSceneTask {
public:
using JobModel = render::Task::Model<UpdateSceneTask>;
UpdateSceneTask() {}
void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs);
};
#endif // hifi_UpdateSceneTask_h

View file

@ -33,7 +33,6 @@ public:
void build(JobModel& task, const Varying& in, Varying& out) {
task.addJob<EngineStats>("Stats");
task.addJob<PerformSceneTransaction>("PerformSceneTransaction");
}
};

View file

@ -237,3 +237,26 @@ void Scene::resetSelections(const Selections& selections) {
}
}
}
// Access a particular Stage (empty if doesn't exist)
// Thread safe
StagePointer Scene::getStage(const Stage::Name& name) const {
std::unique_lock<std::mutex> lock(_stagesMutex);
auto found = _stages.find(name);
if (found == _stages.end()) {
return StagePointer();
} else {
return (*found).second;
}
}
void Scene::resetStage(const Stage::Name& name, const StagePointer& stage) {
std::unique_lock<std::mutex> lock(_stagesMutex);
auto found = _stages.find(name);
if (found == _stages.end()) {
_stages.insert(StageMap::value_type(name, stage));
} else {
(*found).second = stage;
}
}

View file

@ -111,6 +111,14 @@ public:
// Access non-spatialized items (overlays, backgrounds)
const ItemIDSet& getNonspatialSet() const { return _masterNonspatialSet; }
// Access a particular Stage (empty if doesn't exist)
// Thread safe
StagePointer getStage(const Stage::Name& name) const;
void resetStage(const Stage::Name& name, const StagePointer& stage);
protected:
// Thread safe elements that can be accessed from anywhere
std::atomic<unsigned int> _IDAllocator{ 1 }; // first valid itemID will be One
@ -139,11 +147,11 @@ protected:
// void appendToSelection(const Selection& selection);
// void mergeWithSelection(const Selection& selection);
// The Stages
// The Stage map
mutable std::mutex _stagesMutex; // mutable so it can be used in the thread safe getStage const method
StageMap _stages;
friend class Engine;
};