History

More point bits (trying a different tack).

Andrzej Kapolka committed 12 years ago

Commit 0ddd3e61 parent dd7f3708 files · +173 −22Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+115−5
@@ -26,6 +26,8 @@ · 25 unmodified lines
2626 REGISTER_META_OBJECT(SphereRenderer)
2727 REGISTER_META_OBJECT(StaticModelRenderer)
2828
29+static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
30+
2931 ProgramObject MetavoxelSystem::_program;
3032 int MetavoxelSystem::_pointScaleLocation;
3133
@@ -152,8 +154,22 @@ void MetavoxelSystem::render() { · 120 unmodified lines
152154
153155 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
154156
155− PointBufferRenderVisitor pointBufferRenderVisitor;
156− guide(pointBufferRenderVisitor);
157+ glDisable(GL_BLEND);
158+
159+ //PointBufferRenderVisitor pointBufferRenderVisitor;
160+ //guide(pointBufferRenderVisitor);
161+
162+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
163+ if (node->getType() == NodeType::MetavoxelServer) {
164+ QMutexLocker locker(&node->getMutex());
165+ MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
166+ if (client) {
167+ client->render();
168+ }
169+ }
170+ }
171+
172+ glEnable(GL_BLEND);
157173
158174 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
159175
@@ -176,7 +192,35 @@ void MetavoxelSystem::updateClient(MetavoxelClient* client) { · 16 unmodified lines
176192 }
177193
178194 MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelSystem* system) :
179− MetavoxelClient(node, system) {
195+ MetavoxelClient(node, system),
196+ _pointCount(0) {
197+
198+ _buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
199+ _buffer.create();
200+}
201+
202+void MetavoxelSystemClient::render() {
203+ _buffer.bind();
204+
205+ BufferPoint* point = 0;
206+ glVertexPointer(4, GL_FLOAT, sizeof(BufferPoint), &point->vertex);
207+ glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(BufferPoint), &point->color);
208+ glNormalPointer(GL_BYTE, sizeof(BufferPoint), &point->normal);
209+
210+ glDrawArrays(GL_POINTS, 0, _pointCount);
211+
212+ _buffer.release();
213+}
214+
215+void MetavoxelSystemClient::setPoints(const BufferPointVector& points) {
216+ qint64 now = QDateTime::currentMSecsSinceEpoch();
217+ _buffer.bind();
218+ _buffer.allocate(points.constData(), points.size() * sizeof(BufferPoint));
219+ _buffer.release();
220+ _pointCount = points.size();
221+ qDebug() << "upload" << (QDateTime::currentMSecsSinceEpoch() - now);
222+ qDebug() << _pointCount;
223+
180224 }
181225
182226 int MetavoxelSystemClient::parseData(const QByteArray& packet) {
@@ -280,8 +324,73 @@ bool BufferBuilder::postVisit(MetavoxelInfo& info) { · 97 unmodified lines
280324 return true;
281325 }
282326
327+class PointCollector : public MetavoxelVisitor {
328+public:
329+
330+ QVector<BufferPoint> points;
331+
332+ PointCollector(const MetavoxelLOD& lod);
333+
334+ virtual int visit(MetavoxelInfo& info);
335+};
336+
337+PointCollector::PointCollector(const MetavoxelLOD& lod) :
338+ MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() <<
339+ AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>(), lod) {
340+}
341+
342+int PointCollector::visit(MetavoxelInfo& info) {
343+ if (!info.isLeaf) {
344+ return DEFAULT_ORDER;
345+ }
346+ QRgb color = info.inputValues.at(0).getInlineValue<QRgb>();
347+ quint8 alpha = qAlpha(color);
348+ if (alpha <= ALPHA_RENDER_THRESHOLD) {
349+ return STOP_RECURSION;
350+ }
351+ QRgb normal = info.inputValues.at(1).getInlineValue<QRgb>();
352+ BufferPoint point = { glm::vec4(info.minimum + glm::vec3(info.size, info.size, info.size) * 0.5f, info.size),
353+ { quint8(qRed(color)), quint8(qGreen(color)), quint8(qBlue(color)) },
354+ { quint8(qRed(normal)), quint8(qGreen(normal)), quint8(qBlue(normal)) } };
355+ points.append(point);
356+ return STOP_RECURSION;
357+}
358+
359+/// Builds a point buffer.
360+class PointBufferBuilder : public QRunnable {
361+public:
362+
363+ PointBufferBuilder(const SharedNodePointer& node, const MetavoxelData& data, const MetavoxelLOD& lod);
364+
365+ virtual void run();
366+
367+private:
368+
369+ QWeakPointer<Node> _node;
370+ MetavoxelData _data;
371+ MetavoxelLOD _lod;
372+};
373+
374+PointBufferBuilder::PointBufferBuilder(const SharedNodePointer& node, const MetavoxelData& data, const MetavoxelLOD& lod) :
375+ _node(node),
376+ _data(data),
377+ _lod(lod) {
378+}
379+
380+void PointBufferBuilder::run() {
381+ SharedNodePointer node = _node;
382+ if (!node) {
383+ return;
384+ }
385+ qint64 now = QDateTime::currentMSecsSinceEpoch();
386+ PointCollector collector(_lod);
387+ _data.guide(collector);
388+ QMetaObject::invokeMethod(node->getLinkedData(), "setPoints", Q_ARG(const BufferPointVector&, collector.points));
389+ qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now);
390+}
391+
283392 void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {
284− BufferBuilder builder(_remoteDataLOD);
393+ /* BufferBuilder builder(_remoteDataLOD);
285394 const AttributePointer& pointBufferAttribute = Application::getInstance()->getMetavoxels()->getPointBufferAttribute();
286395 MetavoxelNode* oldRoot = oldData.getRoot(pointBufferAttribute);
287396 if (oldRoot && oldData.getSize() == _data.getSize()) {
@@ -292,7 +401,8 @@ void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { · 4 unmodified lines
292401 } else {
293402 _data.clear(pointBufferAttribute);
294403 _data.guide(builder);
295− }
404+ } */
405+ QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD));
296406 }
297407
298408 void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {