mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-17 17:16:49 +02:00
adding the concept of job
This commit is contained in:
parent
75144b4489
commit
2cbd049e4e
5 changed files with 168 additions and 29 deletions
|
@ -14,6 +14,11 @@
|
|||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const RenderableEntityItem::Pointer& payload) {
|
||||
if (payload && payload->entity) {
|
||||
if (payload->entity->getType() == EntityTypes::Light) {
|
||||
return ItemKey::Builder::light();
|
||||
}
|
||||
}
|
||||
return ItemKey::Builder::opaqueShape();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,80 @@
|
|||
|
||||
using namespace render;
|
||||
|
||||
Job::~Job() {
|
||||
}
|
||||
|
||||
template <> void render::jobRun(const FilterItems& filterItems, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
auto& scene = sceneContext->_scene;
|
||||
|
||||
}
|
||||
|
||||
template <> void render::jobRun(const RenderItems& renderItems, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
auto& scene = sceneContext->_scene;
|
||||
RenderArgs* args = renderContext->args;
|
||||
// render
|
||||
for (auto id : renderItems._items) {
|
||||
auto item = scene->getItem(id);
|
||||
item.render(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <> void render::jobRun(const DrawOpaque& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
// render opaques
|
||||
auto& scene = sceneContext->_scene;
|
||||
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::opaqueShape());
|
||||
|
||||
RenderArgs* args = renderContext->args;
|
||||
gpu::Batch theBatch;
|
||||
args->_batch = &theBatch;
|
||||
for (auto id : items) {
|
||||
auto item = scene->getItem(id);
|
||||
item.render(args);
|
||||
}
|
||||
|
||||
args->_context->enqueueBatch((*args->_batch));
|
||||
args->_batch = nullptr;
|
||||
}
|
||||
|
||||
|
||||
template <> void render::jobRun(const DrawTransparent& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
// render transparents
|
||||
auto& scene = sceneContext->_scene;
|
||||
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::transparentShape());
|
||||
|
||||
RenderArgs* args = renderContext->args;
|
||||
gpu::Batch theBatch;
|
||||
args->_batch = &theBatch;
|
||||
for (auto id : items) {
|
||||
auto item = scene->getItem(id);
|
||||
item.render(args);
|
||||
}
|
||||
|
||||
args->_context->enqueueBatch((*args->_batch));
|
||||
args->_batch = nullptr;
|
||||
}
|
||||
|
||||
template <> void render::jobRun(const DrawLight& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
// render lights
|
||||
auto& scene = sceneContext->_scene;
|
||||
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::light());
|
||||
|
||||
RenderArgs* args = renderContext->args;
|
||||
for (auto id : items) {
|
||||
auto item = scene->getItem(id);
|
||||
item.render(args);
|
||||
}
|
||||
}
|
||||
|
||||
DrawSceneTask::DrawSceneTask() : Task() {
|
||||
|
||||
_jobs.push_back(Job(DrawOpaque()));
|
||||
_jobs.push_back(Job(DrawLight()));
|
||||
_jobs.push_back(Job(DrawTransparent()));
|
||||
}
|
||||
|
||||
DrawSceneTask::~DrawSceneTask() {
|
||||
}
|
||||
|
@ -29,25 +103,9 @@ void DrawSceneTask::run(const SceneContextPointer& sceneContext, const RenderCon
|
|||
if (!sceneContext->_scene) {
|
||||
return;
|
||||
}
|
||||
auto& scene = sceneContext->_scene;
|
||||
|
||||
auto& itemBucketMap = scene->getMasterBucket();
|
||||
|
||||
RenderArgs* args = renderContext->args;
|
||||
gpu::Batch theBatch;
|
||||
|
||||
args->_batch = &theBatch;
|
||||
|
||||
// render opaques
|
||||
auto filter = ItemFilter::Builder::opaqueShape();
|
||||
auto& opaqueShapeItems = itemBucketMap.at(filter);
|
||||
|
||||
for (auto id : opaqueShapeItems) {
|
||||
auto item = scene->getItem(id);
|
||||
item.render(args);
|
||||
for (auto job : _jobs) {
|
||||
job.run(sceneContext, renderContext);
|
||||
}
|
||||
|
||||
args->_context->enqueueBatch((*args->_batch));
|
||||
args->_batch = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,19 +16,91 @@
|
|||
|
||||
namespace render {
|
||||
|
||||
template <class T> void jobRun(const T& jobModel, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { }
|
||||
|
||||
class DrawSceneTask : public Task {
|
||||
class Job {
|
||||
public:
|
||||
|
||||
DrawSceneTask() : Task() {}
|
||||
~DrawSceneTask();
|
||||
template <class T>
|
||||
Job(T data) : _concept(new Model<T>(data)) {}
|
||||
Job(const Job& other) : _concept(other._concept) {}
|
||||
~Job();
|
||||
|
||||
virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||
if (_concept) {
|
||||
_concept->run(sceneContext, renderContext);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
class Concept {
|
||||
public:
|
||||
virtual ~Concept() = default;
|
||||
virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) = 0;
|
||||
};
|
||||
|
||||
template <class T> class Model : public Concept {
|
||||
public:
|
||||
typedef T Data;
|
||||
|
||||
Data _data;
|
||||
Model(Data data): _data(data) {}
|
||||
|
||||
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { jobRun(_data, sceneContext, renderContext); }
|
||||
};
|
||||
|
||||
std::shared_ptr<Concept> _concept;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
typedef std::vector<Job> Jobs;
|
||||
|
||||
|
||||
|
||||
class DrawOpaque {
|
||||
public:
|
||||
Jobs _jobs;
|
||||
};
|
||||
template <> void jobRun(const DrawOpaque& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
|
||||
|
||||
class DrawTransparent {
|
||||
public:
|
||||
};
|
||||
template <> void jobRun(const DrawTransparent& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
|
||||
class DrawLight {
|
||||
public:
|
||||
};
|
||||
template <> void jobRun(const DrawLight& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
|
||||
|
||||
class FilterItems {
|
||||
public:
|
||||
ItemIDs _items;
|
||||
};
|
||||
template <> void jobRun(const FilterItems& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
|
||||
class RenderItems {
|
||||
public:
|
||||
ItemIDs _items;
|
||||
};
|
||||
template <> void jobRun(const RenderItems& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
|
||||
|
||||
class DrawSceneTask : public Task {
|
||||
public:
|
||||
|
||||
DrawSceneTask();
|
||||
~DrawSceneTask();
|
||||
|
||||
Jobs _jobs;
|
||||
|
||||
virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // hifi_render_Task_h
|
||||
|
|
|
@ -47,6 +47,8 @@ void ItemBucketMap::reset(const ItemID& id, const ItemKey& oldKey, const ItemKey
|
|||
void ItemBucketMap::allocateStandardOpaqueTranparentBuckets() {
|
||||
(*this)[ItemFilter::Builder::opaqueShape()];
|
||||
(*this)[ItemFilter::Builder::transparentShape()];
|
||||
auto lightFilter = ItemFilter::Builder().withTypeLight().build();
|
||||
(*this)[lightFilter];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
ItemKey(const Flags& flags) : _flags(flags) {}
|
||||
|
||||
class Builder {
|
||||
Flags _flags;
|
||||
Flags _flags{ 0 };
|
||||
public:
|
||||
Builder() {}
|
||||
|
||||
|
@ -72,6 +72,7 @@ public:
|
|||
// Convenient standard keys that we will keep on using all over the place
|
||||
static ItemKey opaqueShape() { return Builder().withTypeShape().build(); }
|
||||
static ItemKey transparentShape() { return Builder().withTypeShape().withTransparent().build(); }
|
||||
static ItemKey light() { return Builder().withTypeLight().build(); }
|
||||
};
|
||||
|
||||
bool isOpaque() const { return !_flags[TRANSLUCENT]; }
|
||||
|
@ -111,8 +112,8 @@ public:
|
|||
ItemFilter(const ItemKey::Flags& value = ItemKey::Flags(0), const ItemKey::Flags& mask = ItemKey::Flags(0)) : _value(value), _mask(mask) {}
|
||||
|
||||
class Builder {
|
||||
ItemKey::Flags _value;
|
||||
ItemKey::Flags _mask;
|
||||
ItemKey::Flags _value{ 0 };
|
||||
ItemKey::Flags _mask{ 0 };
|
||||
public:
|
||||
Builder() {}
|
||||
|
||||
|
@ -142,8 +143,9 @@ public:
|
|||
Builder& withPickable() { _value.set(ItemKey::PICKABLE); _mask.set(ItemKey::PICKABLE); return (*this); }
|
||||
|
||||
// Convenient standard keys that we will keep on using all over the place
|
||||
static ItemFilter opaqueShape() { return Builder().withTypeShape().withOpaque().build(); }
|
||||
static ItemFilter transparentShape() { return Builder().withTypeShape().withTransparent().build(); }
|
||||
static ItemFilter opaqueShape() { return Builder().withTypeShape().withOpaque().withWorldSpace().build(); }
|
||||
static ItemFilter transparentShape() { return Builder().withTypeShape().withTransparent().withWorldSpace().build(); }
|
||||
static ItemFilter light() { return Builder().withTypeLight().build(); }
|
||||
};
|
||||
|
||||
// Item Filter operator testing if a key pass the filter
|
||||
|
@ -152,10 +154,10 @@ public:
|
|||
class Less {
|
||||
public:
|
||||
bool operator() (const ItemFilter& left, const ItemFilter& right) const {
|
||||
if (left._value.to_ulong() >= right._value.to_ulong()) {
|
||||
if (left._value.to_ulong() == right._value.to_ulong()) {
|
||||
return left._mask.to_ulong() < right._mask.to_ulong();
|
||||
} else {
|
||||
return true;
|
||||
return left._value.to_ulong() < right._value.to_ulong();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue