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
158 return DEFAULT_ORDER;158 return DEFAULT_ORDER;
159 }159 }
160 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<160 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
161 SharedObjectPointer>().data())->getImplementation()->render(info);161 SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod);
162 return STOP_RECURSION;162 return STOP_RECURSION;
163}163}
164 164
165void MetavoxelSystem::render() {165void MetavoxelSystem::render() {
166 RenderVisitor renderVisitor(getLOD());166 RenderVisitor renderVisitor(getLOD());
167 guide(renderVisitor);167 guideToAugmented(renderVisitor);
168 168
169 int viewport[4];169 int viewport[4];
170 glGetIntegerv(GL_VIEWPORT, viewport);170 glGetIntegerv(GL_VIEWPORT, viewport);
@@ -227,6 +227,18 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { · 56 unmodified lines
227 return new MetavoxelSystemClient(node, _updater);227 return new MetavoxelSystemClient(node, _updater);
228}228}
229 229
230void 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
230MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :242MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :
231 MetavoxelClient(node, updater),243 MetavoxelClient(node, updater),
232 _pointCount(0) {244 _pointCount(0) {
@@ -259,6 +271,16 @@ void MetavoxelSystemClient::setPoints(const BufferPointVector& points) { · 26 unmodified lines
259 271
260}272}
261 273
274void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) {
275 QWriteLocker locker(&_augmentedDataLock);
276 _augmentedData = data;
277}
278
279MetavoxelData MetavoxelSystemClient::getAugmentedData() {
280 QReadLocker locker(&_augmentedDataLock);
281 return _augmentedData;
282}
283
262int MetavoxelSystemClient::parseData(const QByteArray& packet) {284int MetavoxelSystemClient::parseData(const QByteArray& packet) {
263 // process through sequencer285 // process through sequencer
264 QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));286 QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));
@@ -426,6 +448,67 @@ void PointBufferBuilder::run() { · 161 unmodified lines
426 qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now);448 qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now);
427}449}
428 450
451class AugmentVisitor : public MetavoxelVisitor {
452public:
453
454 AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData);
455
456 virtual int visit(MetavoxelInfo& info);
457
458private:
459
460 const MetavoxelData& _previousData;
461};
462
463AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) :
464 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
465 QVector<AttributePointer>(), lod),
466 _previousData(previousData) {
467}
468
469int 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
478class Augmenter : public QRunnable {
479public:
480
481 Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
482 const MetavoxelData& previousData, const MetavoxelLOD& lod);
483
484 virtual void run();
485
486private:
487
488 QWeakPointer<Node> _node;
489 MetavoxelData _data;
490 MetavoxelData _previousData;
491 MetavoxelLOD _lod;
492};
493
494Augmenter::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
502void 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
429void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {512void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {
430 MetavoxelClient::dataChanged(oldData);513 MetavoxelClient::dataChanged(oldData);
431 514
@@ -442,6 +525,8 @@ void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { · 10 unmodified lines
442 _data.guide(builder);525 _data.guide(builder);
443 } */526 } */
444 QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD));527 QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD));
528
529 QThreadPool::globalInstance()->start(new Augmenter(_node, _data, getAugmentedData(), _remoteDataLOD));
445}530}
446 531
447void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {532void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {
@@ -505,7 +590,56 @@ AttributeValue PointBufferAttribute::inherit(const AttributeValue& parentValue) · 57 unmodified lines
505PointMetavoxelRendererImplementation::PointMetavoxelRendererImplementation() {590PointMetavoxelRendererImplementation::PointMetavoxelRendererImplementation() {
506}591}
507 592
508void PointMetavoxelRendererImplementation::render(MetavoxelInfo& info) {593class PointAugmentVisitor : public MetavoxelVisitor {
594public:
595
596 PointAugmentVisitor(const MetavoxelLOD& lod);
597
598 virtual int visit(MetavoxelInfo& info);
599};
600
601PointAugmentVisitor::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
607int PointAugmentVisitor::visit(MetavoxelInfo& info) {
608 if (!info.isLeaf) {
609 return DEFAULT_ORDER;
610 }
611 return STOP_RECURSION;
612}
613
614void 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
620class PointRenderVisitor : public MetavoxelVisitor {
621public:
622
623 PointRenderVisitor(const MetavoxelLOD& lod);
624
625 virtual int visit(MetavoxelInfo& info);
626};
627
628PointRenderVisitor::PointRenderVisitor(const MetavoxelLOD& lod) :
629 MetavoxelVisitor(QVector<AttributePointer>() << Application::getInstance()->getMetavoxels()->getPointBufferAttribute(),
630 QVector<AttributePointer>(), lod) {
631}
632
633int PointRenderVisitor::visit(MetavoxelInfo& info) {
634 if (!info.isLeaf) {
635 return DEFAULT_ORDER;
636 }
637 return STOP_RECURSION;
638}
639
640void PointMetavoxelRendererImplementation::render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod) {
641 PointRenderVisitor visitor(lod);
642 data.guide(visitor, &info);
509}643}
510 644
511static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {645static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {