History

Various kinds of progress towards generic rendering.

Andrzej Kapolka committed 12 years ago

Commit 57ca6061 parent 605b3284 files · +165 −10Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 4 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+137−3
@@ -158,13 +158,13 @@ int RenderVisitor::visit(MetavoxelInfo& info) { · 157 unmodified lines
158158 return DEFAULT_ORDER;
159159 }
160160 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
161− SharedObjectPointer>().data())->getImplementation()->render(info);
161+ SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod);
162162 return STOP_RECURSION;
163163 }
164164
165165 void MetavoxelSystem::render() {
166166 RenderVisitor renderVisitor(getLOD());
167− guide(renderVisitor);
167+ guideToAugmented(renderVisitor);
168168
169169 int viewport[4];
170170 glGetIntegerv(GL_VIEWPORT, viewport);
@@ -227,6 +227,18 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { · 56 unmodified lines
227227 return new MetavoxelSystemClient(node, _updater);
228228 }
229229
230+void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor) {
231+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
232+ if (node->getType() == NodeType::MetavoxelServer) {
233+ QMutexLocker locker(&node->getMutex());
234+ MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
235+ if (client) {
236+ client->getAugmentedData().guide(visitor);
237+ }
238+ }
239+ }
240+}
241+
230242 MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :
231243 MetavoxelClient(node, updater),
232244 _pointCount(0) {
@@ -259,6 +271,16 @@ void MetavoxelSystemClient::setPoints(const BufferPointVector& points) { · 26 unmodified lines
259271
260272 }
261273
274+void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) {
275+ QWriteLocker locker(&_augmentedDataLock);
276+ _augmentedData = data;
277+}
278+
279+MetavoxelData MetavoxelSystemClient::getAugmentedData() {
280+ QReadLocker locker(&_augmentedDataLock);
281+ return _augmentedData;
282+}
283+
262284 int MetavoxelSystemClient::parseData(const QByteArray& packet) {
263285 // process through sequencer
264286 QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));
@@ -426,6 +448,67 @@ void PointBufferBuilder::run() { · 161 unmodified lines
426448 qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now);
427449 }
428450
451+class AugmentVisitor : public MetavoxelVisitor {
452+public:
453+
454+ AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData);
455+
456+ virtual int visit(MetavoxelInfo& info);
457+
458+private:
459+
460+ const MetavoxelData& _previousData;
461+};
462+
463+AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) :
464+ MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
465+ QVector<AttributePointer>(), lod),
466+ _previousData(previousData) {
467+}
468+
469+int AugmentVisitor::visit(MetavoxelInfo& info) {
470+ if (!info.isLeaf) {
471+ return DEFAULT_ORDER;
472+ }
473+ static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
474+ SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod);
475+ return STOP_RECURSION;
476+}
477+
478+class Augmenter : public QRunnable {
479+public:
480+
481+ Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
482+ const MetavoxelData& previousData, const MetavoxelLOD& lod);
483+
484+ virtual void run();
485+
486+private:
487+
488+ QWeakPointer<Node> _node;
489+ MetavoxelData _data;
490+ MetavoxelData _previousData;
491+ MetavoxelLOD _lod;
492+};
493+
494+Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
495+ const MetavoxelData& previousData, const MetavoxelLOD& lod) :
496+ _node(node),
497+ _data(data),
498+ _previousData(previousData),
499+ _lod(lod) {
500+}
501+
502+void Augmenter::run() {
503+ SharedNodePointer node = _node;
504+ if (!node) {
505+ return;
506+ }
507+ AugmentVisitor visitor(_lod, _previousData);
508+ _data.guide(visitor);
509+ QMetaObject::invokeMethod(node.data(), "setAugmentedData", Q_ARG(const MetavoxelData&, _data));
510+}
511+
429512 void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {
430513 MetavoxelClient::dataChanged(oldData);
431514
@@ -442,6 +525,8 @@ void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { · 10 unmodified lines
442525 _data.guide(builder);
443526 } */
444527 QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD));
528+
529+ QThreadPool::globalInstance()->start(new Augmenter(_node, _data, getAugmentedData(), _remoteDataLOD));
445530 }
446531
447532 void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {
@@ -505,7 +590,56 @@ AttributeValue PointBufferAttribute::inherit(const AttributeValue& parentValue) · 57 unmodified lines
505590 PointMetavoxelRendererImplementation::PointMetavoxelRendererImplementation() {
506591 }
507592
508−void PointMetavoxelRendererImplementation::render(MetavoxelInfo& info) {
593+class PointAugmentVisitor : public MetavoxelVisitor {
594+public:
595+
596+ PointAugmentVisitor(const MetavoxelLOD& lod);
597+
598+ virtual int visit(MetavoxelInfo& info);
599+};
600+
601+PointAugmentVisitor::PointAugmentVisitor(const MetavoxelLOD& lod) :
602+ MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() <<
603+ AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>() <<
604+ Application::getInstance()->getMetavoxels()->getPointBufferAttribute(), lod) {
605+}
606+
607+int PointAugmentVisitor::visit(MetavoxelInfo& info) {
608+ if (!info.isLeaf) {
609+ return DEFAULT_ORDER;
610+ }
611+ return STOP_RECURSION;
612+}
613+
614+void PointMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
615+ MetavoxelInfo& info, const MetavoxelLOD& lod) {
616+ PointAugmentVisitor visitor(lod);
617+ data.guideToDifferent(previous, visitor, &info);
618+}
619+
620+class PointRenderVisitor : public MetavoxelVisitor {
621+public:
622+
623+ PointRenderVisitor(const MetavoxelLOD& lod);
624+
625+ virtual int visit(MetavoxelInfo& info);
626+};
627+
628+PointRenderVisitor::PointRenderVisitor(const MetavoxelLOD& lod) :
629+ MetavoxelVisitor(QVector<AttributePointer>() << Application::getInstance()->getMetavoxels()->getPointBufferAttribute(),
630+ QVector<AttributePointer>(), lod) {
631+}
632+
633+int PointRenderVisitor::visit(MetavoxelInfo& info) {
634+ if (!info.isLeaf) {
635+ return DEFAULT_ORDER;
636+ }
637+ return STOP_RECURSION;
638+}
639+
640+void PointMetavoxelRendererImplementation::render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod) {
641+ PointRenderVisitor visitor(lod);
642+ data.guide(visitor, &info);
509643 }
510644
511645 static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {