mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-10 17:23:15 +02:00
First Item really rendering , for the WorldBox, desigining more of the RenderContext and task interface
This commit is contained in:
parent
b90e04e451
commit
a5c5cc9b70
7 changed files with 69 additions and 48 deletions
|
@ -3174,25 +3174,35 @@ const ViewFrustum* Application::getDisplayViewFrustum() const {
|
|||
return &_displayViewFrustum;
|
||||
}
|
||||
|
||||
class MyFirstStuff {
|
||||
public:
|
||||
typedef render::Payload<MyFirstStuff> Payload;
|
||||
typedef std::shared_ptr<render::Item::PayloadInterface> PayloadPointer;
|
||||
typedef Payload::DataPointer Pointer;
|
||||
|
||||
};
|
||||
|
||||
// For Ubuntu, the compiler want's the Payload's functions to be specialized in the "render" namespace explicitely...
|
||||
// WorldBox Render Data & rendering functions
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const MyFirstStuff::Pointer& stuff) { return ItemKey::Builder::opaqueShape(); }
|
||||
template <> const Item::Bound payloadGetBound(const MyFirstStuff::Pointer& stuff) { return Item::Bound(); }
|
||||
template <> void payloadRender(const MyFirstStuff::Pointer& stuff, RenderArgs* args) {
|
||||
if (args) {
|
||||
args->_elementsTouched ++;
|
||||
class WorldBoxRenderData {
|
||||
public:
|
||||
typedef Payload<WorldBoxRenderData> Payload;
|
||||
typedef Payload::DataPointer Pointer;
|
||||
|
||||
static ItemID _item; // unique WorldBoxRenderData
|
||||
};
|
||||
|
||||
ItemID WorldBoxRenderData::_item = 0;
|
||||
|
||||
template <> const ItemKey payloadGetKey(const WorldBoxRenderData::Pointer& stuff) { return ItemKey::Builder::opaqueShape(); }
|
||||
template <> const Item::Bound payloadGetBound(const WorldBoxRenderData::Pointer& stuff) { return Item::Bound(); }
|
||||
template <> void payloadRender(const WorldBoxRenderData::Pointer& stuff, RenderArgs* args) {
|
||||
if (args->_renderMode != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||
PerformanceTimer perfTimer("worldBox");
|
||||
renderWorldBox();
|
||||
}
|
||||
|
||||
// never the less
|
||||
float originSphereRadius = 0.05f;
|
||||
DependencyManager::get<GeometryCache>()->renderSphere(originSphereRadius, 15, 15, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool selfAvatarOnly) {
|
||||
activeRenderingThread = QThread::currentThread();
|
||||
PROFILE_RANGE(__FUNCTION__);
|
||||
|
@ -3355,11 +3365,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
|||
DependencyManager::get<DeferredLightingEffect>()->prepare();
|
||||
|
||||
if (!selfAvatarOnly) {
|
||||
// draw a red sphere
|
||||
float originSphereRadius = 0.05f;
|
||||
DependencyManager::get<GeometryCache>()->renderSphere(originSphereRadius, 15, 15, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
|
||||
|
||||
// render JS/scriptable overlays
|
||||
{
|
||||
PerformanceTimer perfTimer("3dOverlays");
|
||||
|
@ -3413,22 +3419,28 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
|||
renderArgs->_renderMode = RenderArgs::NORMAL_RENDER_MODE;
|
||||
}
|
||||
|
||||
static render::ItemID myFirstRenderItem = 0;
|
||||
render::Scene::PendingChanges pendingChanges;
|
||||
|
||||
if (myFirstRenderItem == 0) {
|
||||
auto myVeryFirstStuff = MyFirstStuff::Pointer(new MyFirstStuff());
|
||||
auto myVeryFirstPayload = new MyFirstStuff::Payload(myVeryFirstStuff);
|
||||
auto myFirstPayload = MyFirstStuff::PayloadPointer(myVeryFirstPayload);
|
||||
myFirstRenderItem = _main3DScene->allocateID();
|
||||
// Make sure the WorldBox is in the scene
|
||||
if (render::WorldBoxRenderData::_item == 0) {
|
||||
auto worldBoxRenderData = render::WorldBoxRenderData::Pointer(new render::WorldBoxRenderData());
|
||||
auto worldBoxRenderPayload = render::PayloadPointer(new render::WorldBoxRenderData::Payload(worldBoxRenderData));
|
||||
|
||||
render::Scene::PendingChanges pendingChanges;
|
||||
pendingChanges.resetItem(myFirstRenderItem, myFirstPayload);
|
||||
render::WorldBoxRenderData::_item = _main3DScene->allocateID();
|
||||
|
||||
_main3DScene->enqueuePendingChanges(pendingChanges);
|
||||
pendingChanges.resetItem(render::WorldBoxRenderData::_item, worldBoxRenderPayload);
|
||||
}
|
||||
|
||||
|
||||
|
||||
_main3DScene->enqueuePendingChanges(pendingChanges);
|
||||
|
||||
_main3DScene->processPendingChangesQueue();
|
||||
|
||||
// FOr now every frame pass the renderCOntext
|
||||
render::RenderContext renderContext;
|
||||
renderContext.args = renderArgs;
|
||||
_renderEngine->setRenderContext(renderContext);
|
||||
|
||||
// Before the deferred pass, let's try to use the render engine
|
||||
_renderEngine->run();
|
||||
|
||||
|
@ -3458,12 +3470,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
|||
|
||||
if (!selfAvatarOnly) {
|
||||
_nodeBoundsDisplay.draw();
|
||||
|
||||
// Render the world box
|
||||
if (theCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||
PerformanceTimer perfTimer("worldBox");
|
||||
renderWorldBox();
|
||||
}
|
||||
|
||||
// render octree fades if they exist
|
||||
if (_octreeFades.size() > 0) {
|
||||
|
|
|
@ -17,7 +17,7 @@ using namespace render;
|
|||
DrawSceneTask::~DrawSceneTask() {
|
||||
}
|
||||
|
||||
void DrawSceneTask::run(const SceneContextPointer& sceneContext) {
|
||||
void DrawSceneTask::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
// sanity checks
|
||||
assert(sceneContext);
|
||||
if (!sceneContext->_scene) {
|
||||
|
@ -27,14 +27,14 @@ void DrawSceneTask::run(const SceneContextPointer& sceneContext) {
|
|||
|
||||
auto& itemBucketMap = scene->getMasterBucket();
|
||||
|
||||
RenderArgs args;
|
||||
RenderArgs* args = renderContext->args;
|
||||
// render opaques
|
||||
auto filter = ItemFilter::Builder::opaqueShape();
|
||||
auto& opaqueShapeItems = itemBucketMap.at(filter);
|
||||
|
||||
for (auto id : opaqueShapeItems) {
|
||||
auto item = scene->getItem(id);
|
||||
item.render(&args);
|
||||
item.render(args);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
DrawSceneTask() : Task() {}
|
||||
~DrawSceneTask();
|
||||
|
||||
virtual void run(const SceneContextPointer& sceneContext);
|
||||
virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ using namespace render;
|
|||
|
||||
|
||||
Engine::Engine() :
|
||||
_sceneContext(new SceneContext())
|
||||
_sceneContext(new SceneContext()),
|
||||
_renderContext(new RenderContext())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -23,6 +24,10 @@ void Engine::registerScene(const ScenePointer& scene) {
|
|||
_sceneContext->_scene = scene;
|
||||
}
|
||||
|
||||
void Engine::setRenderContext(const RenderContext& renderContext) {
|
||||
(*_renderContext) = renderContext;
|
||||
}
|
||||
|
||||
void Engine::addTask(const TaskPointer& task) {
|
||||
if (task) {
|
||||
_tasks.push_back(task);
|
||||
|
@ -31,7 +36,7 @@ void Engine::addTask(const TaskPointer& task) {
|
|||
|
||||
void Engine::run() {
|
||||
for (auto task : _tasks) {
|
||||
task->run(_sceneContext);
|
||||
task->run(_sceneContext, _renderContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,18 +25,25 @@ public:
|
|||
};
|
||||
typedef std::shared_ptr<SceneContext> SceneContextPointer;
|
||||
|
||||
|
||||
class RenderContext {
|
||||
public:
|
||||
RenderArgs* args;
|
||||
|
||||
RenderContext() {}
|
||||
};
|
||||
typedef std::shared_ptr<RenderContext> RenderContextPointer;
|
||||
|
||||
// THe base class for a task that runs on the SceneContext
|
||||
class Task {
|
||||
public:
|
||||
Task() {}
|
||||
~Task() {}
|
||||
|
||||
virtual void run(const SceneContextPointer& sceneContext) {}
|
||||
virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
typedef std::shared_ptr<Task> TaskPointer;
|
||||
typedef std::vector<TaskPointer> Tasks;
|
||||
|
||||
|
@ -51,6 +58,9 @@ public:
|
|||
// Register the scene should be [art of the init phase before running the engine
|
||||
void registerScene(const ScenePointer& scene);
|
||||
|
||||
// Push a RenderContext
|
||||
void setRenderContext(const RenderContext& renderContext);
|
||||
|
||||
void addTask(const TaskPointer& task);
|
||||
const Tasks& getTasks() const { return _tasks; }
|
||||
|
||||
|
@ -65,6 +75,7 @@ protected:
|
|||
Tasks _tasks;
|
||||
|
||||
SceneContextPointer _sceneContext;
|
||||
RenderContextPointer _renderContext;
|
||||
};
|
||||
typedef std::shared_ptr<Engine> EnginePointer;
|
||||
|
||||
|
|
|
@ -89,9 +89,8 @@ void Scene::PendingChanges::merge(PendingChanges& changes) {
|
|||
_movedItems.insert(_movedItems.end(), changes._movedItems.begin(), changes._movedItems.end());
|
||||
}
|
||||
|
||||
Scene::Scene() :
|
||||
_IDAllocator(0)
|
||||
{
|
||||
Scene::Scene() {
|
||||
_items.push_back(Item()); // add the itemID #0 to nothing
|
||||
_masterBucketMap.allocateStandardOpaqueTranparentBuckets();
|
||||
}
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ public:
|
|||
|
||||
protected:
|
||||
// Thread safe elements that can be accessed from anywhere
|
||||
std::atomic<unsigned int> _IDAllocator;
|
||||
std::atomic<unsigned int> _IDAllocator{ 1 }; // first valid itemID will be One
|
||||
std::mutex _changeQueueMutex;
|
||||
PendingChangesQueue _changeQueue;
|
||||
|
||||
|
|
Loading…
Reference in a new issue