Various kinds of progress towards generic rendering.

This commit is contained in:
Andrzej Kapolka 2014-07-25 16:59:48 -07:00
parent 605b3282e7
commit 57ca606491
4 changed files with 165 additions and 10 deletions

View file

@ -158,13 +158,13 @@ int RenderVisitor::visit(MetavoxelInfo& info) {
return DEFAULT_ORDER;
}
static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
SharedObjectPointer>().data())->getImplementation()->render(info);
SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod);
return STOP_RECURSION;
}
void MetavoxelSystem::render() {
RenderVisitor renderVisitor(getLOD());
guide(renderVisitor);
guideToAugmented(renderVisitor);
int viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
@ -227,6 +227,18 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
return new MetavoxelSystemClient(node, _updater);
}
void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor) {
foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
if (node->getType() == NodeType::MetavoxelServer) {
QMutexLocker locker(&node->getMutex());
MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
if (client) {
client->getAugmentedData().guide(visitor);
}
}
}
}
MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :
MetavoxelClient(node, updater),
_pointCount(0) {
@ -259,6 +271,16 @@ void MetavoxelSystemClient::setPoints(const BufferPointVector& points) {
}
void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) {
QWriteLocker locker(&_augmentedDataLock);
_augmentedData = data;
}
MetavoxelData MetavoxelSystemClient::getAugmentedData() {
QReadLocker locker(&_augmentedDataLock);
return _augmentedData;
}
int MetavoxelSystemClient::parseData(const QByteArray& packet) {
// process through sequencer
QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));
@ -426,6 +448,67 @@ void PointBufferBuilder::run() {
qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now);
}
class AugmentVisitor : public MetavoxelVisitor {
public:
AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData);
virtual int visit(MetavoxelInfo& info);
private:
const MetavoxelData& _previousData;
};
AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) :
MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
QVector<AttributePointer>(), lod),
_previousData(previousData) {
}
int AugmentVisitor::visit(MetavoxelInfo& info) {
if (!info.isLeaf) {
return DEFAULT_ORDER;
}
static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod);
return STOP_RECURSION;
}
class Augmenter : public QRunnable {
public:
Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
const MetavoxelData& previousData, const MetavoxelLOD& lod);
virtual void run();
private:
QWeakPointer<Node> _node;
MetavoxelData _data;
MetavoxelData _previousData;
MetavoxelLOD _lod;
};
Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
const MetavoxelData& previousData, const MetavoxelLOD& lod) :
_node(node),
_data(data),
_previousData(previousData),
_lod(lod) {
}
void Augmenter::run() {
SharedNodePointer node = _node;
if (!node) {
return;
}
AugmentVisitor visitor(_lod, _previousData);
_data.guide(visitor);
QMetaObject::invokeMethod(node.data(), "setAugmentedData", Q_ARG(const MetavoxelData&, _data));
}
void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {
MetavoxelClient::dataChanged(oldData);
@ -442,6 +525,8 @@ void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {
_data.guide(builder);
} */
QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD));
QThreadPool::globalInstance()->start(new Augmenter(_node, _data, getAugmentedData(), _remoteDataLOD));
}
void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {
@ -505,7 +590,56 @@ AttributeValue PointBufferAttribute::inherit(const AttributeValue& parentValue)
PointMetavoxelRendererImplementation::PointMetavoxelRendererImplementation() {
}
void PointMetavoxelRendererImplementation::render(MetavoxelInfo& info) {
class PointAugmentVisitor : public MetavoxelVisitor {
public:
PointAugmentVisitor(const MetavoxelLOD& lod);
virtual int visit(MetavoxelInfo& info);
};
PointAugmentVisitor::PointAugmentVisitor(const MetavoxelLOD& lod) :
MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() <<
AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>() <<
Application::getInstance()->getMetavoxels()->getPointBufferAttribute(), lod) {
}
int PointAugmentVisitor::visit(MetavoxelInfo& info) {
if (!info.isLeaf) {
return DEFAULT_ORDER;
}
return STOP_RECURSION;
}
void PointMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
MetavoxelInfo& info, const MetavoxelLOD& lod) {
PointAugmentVisitor visitor(lod);
data.guideToDifferent(previous, visitor, &info);
}
class PointRenderVisitor : public MetavoxelVisitor {
public:
PointRenderVisitor(const MetavoxelLOD& lod);
virtual int visit(MetavoxelInfo& info);
};
PointRenderVisitor::PointRenderVisitor(const MetavoxelLOD& lod) :
MetavoxelVisitor(QVector<AttributePointer>() << Application::getInstance()->getMetavoxels()->getPointBufferAttribute(),
QVector<AttributePointer>(), lod) {
}
int PointRenderVisitor::visit(MetavoxelInfo& info) {
if (!info.isLeaf) {
return DEFAULT_ORDER;
}
return STOP_RECURSION;
}
void PointMetavoxelRendererImplementation::render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod) {
PointRenderVisitor visitor(lod);
data.guide(visitor, &info);
}
static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {

View file

@ -52,6 +52,8 @@ protected:
private:
void guideToAugmented(MetavoxelVisitor& visitor);
static ProgramObject _program;
static int _pointScaleLocation;
@ -82,6 +84,11 @@ public:
void render();
void setPoints(const BufferPointVector& points);
Q_INVOKABLE void setAugmentedData(const MetavoxelData& data);
/// Returns a copy of the augmented data. This function is thread-safe.
MetavoxelData getAugmentedData();
virtual int parseData(const QByteArray& packet);
@ -94,6 +101,9 @@ private:
QOpenGLBuffer _buffer;
int _pointCount;
MetavoxelData _augmentedData;
QReadWriteLock _augmentedDataLock;
};
/// Contains the information necessary to render a group of points at variable detail levels.
@ -134,7 +144,8 @@ public:
Q_INVOKABLE PointMetavoxelRendererImplementation();
virtual void render(MetavoxelInfo& info);
virtual void augment(MetavoxelData& data, const MetavoxelData& previous, MetavoxelInfo& info, const MetavoxelLOD& lod);
virtual void render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod);
};
/// Base class for spanner renderers; provides clipping.

View file

@ -81,7 +81,7 @@ Box MetavoxelData::getBounds() const {
return Box(glm::vec3(-halfSize, -halfSize, -halfSize), glm::vec3(halfSize, halfSize, halfSize));
}
void MetavoxelData::guide(MetavoxelVisitor& visitor) {
void MetavoxelData::guide(MetavoxelVisitor& visitor, const MetavoxelInfo* start) {
// let the visitor know we're about to begin a tour
visitor.prepare(this);
@ -128,7 +128,7 @@ void MetavoxelData::guide(MetavoxelVisitor& visitor) {
visitor.releaseVisitation();
}
void MetavoxelData::guideToDifferent(const MetavoxelData& other, MetavoxelVisitor& visitor) {
void MetavoxelData::guideToDifferent(const MetavoxelData& other, MetavoxelVisitor& visitor, const MetavoxelInfo* start) {
// if the other data is smaller, we need to expand it to compare
const MetavoxelData* expandedOther = &other;
if (_size > other._size) {
@ -1847,6 +1847,7 @@ MetavoxelRenderer::MetavoxelRenderer() :
}
MetavoxelRendererImplementation* MetavoxelRenderer::getImplementation() {
QMutexLocker locker(&_implementationMutex);
if (!_implementation) {
QByteArray className = getImplementationClassName();
const QMetaObject* metaObject = Bitstream::getMetaObject(className);
@ -1868,7 +1869,11 @@ void MetavoxelRendererImplementation::init(MetavoxelRenderer* renderer) {
_renderer = renderer;
}
void MetavoxelRendererImplementation::render(MetavoxelInfo& info) {
void MetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
MetavoxelInfo& info, const MetavoxelLOD& lod) {
}
void MetavoxelRendererImplementation::render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod) {
}
QByteArray MetavoxelRenderer::getImplementationClassName() const {

View file

@ -28,6 +28,7 @@
class QScriptContext;
class MetavoxelInfo;
class MetavoxelNode;
class MetavoxelRendererImplementation;
class MetavoxelVisitation;
@ -80,10 +81,12 @@ public:
Box getBounds() const;
/// Applies the specified visitor to the contained voxels.
void guide(MetavoxelVisitor& visitor);
/// \param start the location at which to start, or NULL for the root
void guide(MetavoxelVisitor& visitor, const MetavoxelInfo* start = NULL);
/// Guides the specified visitor to the voxels that differ from those of the specified other.
void guideToDifferent(const MetavoxelData& other, MetavoxelVisitor& visitor);
/// \param start the location at which to start, or NULL for the root
void guideToDifferent(const MetavoxelData& other, MetavoxelVisitor& visitor, const MetavoxelInfo* start = NULL);
/// Inserts a spanner into the specified attribute layer.
void insert(const AttributePointer& attribute, const SharedObjectPointer& object);
@ -533,6 +536,7 @@ public:
protected:
MetavoxelRendererImplementation* _implementation;
QMutex _implementationMutex;
/// Returns the name of the class to instantiate for the implementation.
virtual QByteArray getImplementationClassName() const;
@ -547,7 +551,8 @@ public:
Q_INVOKABLE MetavoxelRendererImplementation();
virtual void init(MetavoxelRenderer* renderer);
virtual void render(MetavoxelInfo& info);
virtual void augment(MetavoxelData& data, const MetavoxelData& previous, MetavoxelInfo& info, const MetavoxelLOD& lod);
virtual void render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod);
protected: