Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 8 files). Show all
Unified · Split
| @@ -26,6 +26,8 @@ · 25 unmodified lines | |||
| 26 | REGISTER_META_OBJECT(SphereRenderer) | 26 | REGISTER_META_OBJECT(SphereRenderer) |
| 27 | REGISTER_META_OBJECT(StaticModelRenderer) | 27 | REGISTER_META_OBJECT(StaticModelRenderer) |
| 28 | 28 | ||
| 29 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); | ||
| 30 | |||
| 29 | ProgramObject MetavoxelSystem::_program; | 31 | ProgramObject MetavoxelSystem::_program; |
| 30 | int MetavoxelSystem::_pointScaleLocation; | 32 | int MetavoxelSystem::_pointScaleLocation; |
| 31 | 33 | ||
| @@ -152,8 +154,22 @@ void MetavoxelSystem::render() { · 120 unmodified lines | |||
| 152 | 154 | ||
| 153 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | 155 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); |
| 154 | 156 | ||
| 155 | PointBufferRenderVisitor pointBufferRenderVisitor; | 157 | glDisable(GL_BLEND); |
| 156 | guide(pointBufferRenderVisitor); | 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); | ||
| 157 | 173 | ||
| 158 | glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | 174 | glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); |
| 159 | 175 | ||
| @@ -176,7 +192,35 @@ void MetavoxelSystem::updateClient(MetavoxelClient* client) { · 16 unmodified lines | |||
| 176 | } | 192 | } |
| 177 | 193 | ||
| 178 | MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelSystem* system) : | 194 | 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 | |||
| 180 | } | 224 | } |
| 181 | 225 | ||
| 182 | int MetavoxelSystemClient::parseData(const QByteArray& packet) { | 226 | int MetavoxelSystemClient::parseData(const QByteArray& packet) { |
| @@ -280,8 +324,73 @@ bool BufferBuilder::postVisit(MetavoxelInfo& info) { · 97 unmodified lines | |||
| 280 | return true; | 324 | return true; |
| 281 | } | 325 | } |
| 282 | 326 | ||
| 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 | |||
| 283 | void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { | 392 | void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { |
| 284 | BufferBuilder builder(_remoteDataLOD); | 393 | /* BufferBuilder builder(_remoteDataLOD); |
| 285 | const AttributePointer& pointBufferAttribute = Application::getInstance()->getMetavoxels()->getPointBufferAttribute(); | 394 | const AttributePointer& pointBufferAttribute = Application::getInstance()->getMetavoxels()->getPointBufferAttribute(); |
| 286 | MetavoxelNode* oldRoot = oldData.getRoot(pointBufferAttribute); | 395 | MetavoxelNode* oldRoot = oldData.getRoot(pointBufferAttribute); |
| 287 | if (oldRoot && oldData.getSize() == _data.getSize()) { | 396 | if (oldRoot && oldData.getSize() == _data.getSize()) { |
| @@ -292,7 +401,8 @@ void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { · 4 unmodified lines | |||
| 292 | } else { | 401 | } else { |
| 293 | _data.clear(pointBufferAttribute); | 402 | _data.clear(pointBufferAttribute); |
| 294 | _data.guide(builder); | 403 | _data.guide(builder); |
| 295 | } | 404 | } */ |
| 405 | QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD)); | ||
| 296 | } | 406 | } |
| 297 | 407 | ||
| 298 | void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { | 408 | void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { |