Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -90,8 +90,8 @@ public: · 89 unmodified lines | ||
| 90 | 90 | |
| 91 | 91 | SpannerRenderVisitor::SpannerRenderVisitor() : |
| 92 | 92 | SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), |
| 93 | − QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannerMaskAttribute(), | |
| 94 | − QVector<AttributePointer>(), QVector<AttributePointer>(), Application::getInstance()->getMetavoxels()->getLOD(), | |
| 93 | + QVector<AttributePointer>(), QVector<AttributePointer>(), QVector<AttributePointer>(), | |
| 94 | + Application::getInstance()->getMetavoxels()->getLOD(), | |
| 95 | 95 | encodeOrder(Application::getInstance()->getViewFrustum()->getDirection())) { |
| 96 | 96 | } |
| 97 | 97 | |
| @@ -239,53 +239,22 @@ void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { · 141 unmodified lines | ||
| 239 | 239 | Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size()); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | −PointBuffer::PointBuffer(const QVector<BufferPointVectorPair>& levelPoints) : | |
| 243 | − _levelPoints(levelPoints) { | |
| 242 | +PointBuffer::PointBuffer(const BufferPointVector& points) : | |
| 243 | + _points(points) { | |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | −void PointBuffer::render(int level) { | |
| 246 | +void PointBuffer::render() { | |
| 247 | 247 | // initalize buffer, etc. on first render |
| 248 | 248 | if (!_buffer.isCreated()) { |
| 249 | − _offsets.append(0); | |
| 250 | − _lastLeafCount = 0; | |
| 251 | − int totalPoints = 0; | |
| 252 | − foreach (const BufferPointVectorPair& pair, _levelPoints) { | |
| 253 | − _offsets.append(totalPoints += ((_lastLeafCount += pair.first.size()) + pair.second.size())); | |
| 254 | − } | |
| 255 | 249 | _buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 256 | 250 | _buffer.create(); |
| 257 | 251 | _buffer.bind(); |
| 258 | − _buffer.allocate(totalPoints * sizeof(BufferPoint)); | |
| 259 | − int offset = 0; | |
| 260 | − for (int i = 0; i < _levelPoints.size(); i++) { | |
| 261 | − // write the internal nodes from the current level | |
| 262 | − const BufferPointVector& internal = _levelPoints.at(i).second; | |
| 263 | − int length = internal.size() * sizeof(BufferPoint); | |
| 264 | − _buffer.write(offset, internal.constData(), length); | |
| 265 | − offset += length; | |
| 266 | − | |
| 267 | − // and the leaves from the top down | |
| 268 | − for (int j = 0; j <= i; j++) { | |
| 269 | − const BufferPointVector& leaves = _levelPoints.at(j).first; | |
| 270 | − length = leaves.size() * sizeof(BufferPoint); | |
| 271 | − _buffer.write(offset, leaves.constData(), length); | |
| 272 | − offset += length; | |
| 273 | − } | |
| 274 | − } | |
| 275 | − _levelPoints.clear(); | |
| 252 | + _pointCount = _points.size(); | |
| 253 | + _buffer.allocate(_points.constData(), _pointCount * sizeof(BufferPoint)); | |
| 254 | + _points.clear(); | |
| 276 | 255 | _buffer.release(); |
| 277 | 256 | } |
| 278 | − int first, count; | |
| 279 | − int nextLevel = level + 1; | |
| 280 | − if (nextLevel >= _offsets.size()) { | |
| 281 | − first = _offsets.last() - _lastLeafCount; | |
| 282 | − count = _lastLeafCount; | |
| 283 | − | |
| 284 | − } else { | |
| 285 | − first = _offsets.at(level); | |
| 286 | − count = _offsets.at(nextLevel) - first; | |
| 287 | − } | |
| 288 | − if (count == 0) { | |
| 257 | + if (_pointCount == 0) { | |
| 289 | 258 | return; |
| 290 | 259 | } |
| 291 | 260 | _buffer.bind(); |
| @@ -295,7 +264,7 @@ void PointBuffer::render(int level) { · 3 unmodified lines | ||
| 295 | 264 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(BufferPoint), &point->color); |
| 296 | 265 | glNormalPointer(GL_BYTE, sizeof(BufferPoint), &point->normal); |
| 297 | 266 | |
| 298 | − glDrawArrays(GL_POINTS, first, count); | |
| 267 | + glDrawArrays(GL_POINTS, 0, _pointCount); | |
| 299 | 268 | |
| 300 | 269 | _buffer.release(); |
| 301 | 270 | } |
| @@ -304,23 +273,18 @@ PointBufferAttribute::PointBufferAttribute() : · 2 unmodified lines | ||
| 304 | 273 | InlineAttribute<PointBufferPointer>("pointBuffer") { |
| 305 | 274 | } |
| 306 | 275 | |
| 307 | −MetavoxelNode* PointBufferAttribute::createMetavoxelNode(const AttributeValue& value, const MetavoxelNode* original) const { | |
| 308 | − return new MetavoxelNode(value, original); | |
| 309 | −} | |
| 310 | − | |
| 311 | 276 | bool PointBufferAttribute::merge(void*& parent, void* children[], bool postRead) const { |
| 312 | − for (int i = 0; i < MERGE_COUNT; i++) { | |
| 313 | − if (decodeInline<PointBufferPointer>(children[i])) { | |
| 277 | + PointBufferPointer firstChild = decodeInline<PointBufferPointer>(children[0]); | |
| 278 | + for (int i = 1; i < MERGE_COUNT; i++) { | |
| 279 | + if (firstChild != decodeInline<PointBufferPointer>(children[i])) { | |
| 280 | + *(PointBufferPointer*)&parent = _defaultValue; | |
| 314 | 281 | return false; |
| 315 | 282 | } |
| 316 | 283 | } |
| 284 | + *(PointBufferPointer*)&parent = firstChild; | |
| 317 | 285 | return true; |
| 318 | 286 | } |
| 319 | 287 | |
| 320 | −AttributeValue PointBufferAttribute::inherit(const AttributeValue& parentValue) const { | |
| 321 | − return AttributeValue(parentValue.getAttribute()); | |
| 322 | −} | |
| 323 | − | |
| 324 | 288 | void PointMetavoxelRendererImplementation::init() { |
| 325 | 289 | if (!_program.isLinked()) { |
| 326 | 290 | _program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/metavoxel_point.vert"); |
| @@ -340,12 +304,14 @@ public: · 13 unmodified lines | ||
| 340 | 304 | |
| 341 | 305 | PointAugmentVisitor(const MetavoxelLOD& lod); |
| 342 | 306 | |
| 307 | + virtual void prepare(MetavoxelData* data); | |
| 343 | 308 | virtual int visit(MetavoxelInfo& info); |
| 344 | 309 | virtual bool postVisit(MetavoxelInfo& info); |
| 345 | 310 | |
| 346 | 311 | private: |
| 347 | 312 | |
| 348 | − QVector<BufferPointVectorPair> _depthPoints; | |
| 313 | + BufferPointVector _points; | |
| 314 | + float _pointLeafSize; | |
| 349 | 315 | }; |
| 350 | 316 | |
| 351 | 317 | PointAugmentVisitor::PointAugmentVisitor(const MetavoxelLOD& lod) : |
| @@ -356,48 +322,61 @@ PointAugmentVisitor::PointAugmentVisitor(const MetavoxelLOD& lod) : · 4 unmodified lines | ||
| 356 | 322 | |
| 357 | 323 | const int ALPHA_RENDER_THRESHOLD = 0; |
| 358 | 324 | |
| 325 | +void PointAugmentVisitor::prepare(MetavoxelData* data) { | |
| 326 | + MetavoxelVisitor::prepare(data); | |
| 327 | + const float MAX_POINT_LEAF_SIZE = 64.0f; | |
| 328 | + _pointLeafSize = qMin(data->getSize(), MAX_POINT_LEAF_SIZE); | |
| 329 | +} | |
| 330 | + | |
| 359 | 331 | int PointAugmentVisitor::visit(MetavoxelInfo& info) { |
| 360 | − if (_depth >= _depthPoints.size()) { | |
| 361 | − _depthPoints.resize(_depth + 1); | |
| 332 | + if (!info.isLeaf) { | |
| 333 | + return (info.size > _pointLeafSize) ? DEFAULT_ORDER : (DEFAULT_ORDER | ALL_NODES_REST); | |
| 362 | 334 | } |
| 363 | 335 | QRgb color = info.inputValues.at(0).getInlineValue<QRgb>(); |
| 364 | 336 | quint8 alpha = qAlpha(color); |
| 365 | − if (alpha <= ALPHA_RENDER_THRESHOLD) { | |
| 366 | − return info.isLeaf ? STOP_RECURSION : (DEFAULT_ORDER | ALL_NODES); | |
| 337 | + if (alpha > ALPHA_RENDER_THRESHOLD) { | |
| 338 | + QRgb normal = info.inputValues.at(1).getInlineValue<QRgb>(); | |
| 339 | + BufferPoint point = { glm::vec4(info.minimum + glm::vec3(info.size, info.size, info.size) * 0.5f, info.size), | |
| 340 | + { quint8(qRed(color)), quint8(qGreen(color)), quint8(qBlue(color)) }, | |
| 341 | + { quint8(qRed(normal)), quint8(qGreen(normal)), quint8(qBlue(normal)) } }; | |
| 342 | + _points.append(point); | |
| 367 | 343 | } |
| 368 | − QRgb normal = info.inputValues.at(1).getInlineValue<QRgb>(); | |
| 369 | − BufferPoint point = { glm::vec4(info.minimum + glm::vec3(info.size, info.size, info.size) * 0.5f, info.size), | |
| 370 | − { quint8(qRed(color)), quint8(qGreen(color)), quint8(qBlue(color)) }, | |
| 371 | − { quint8(qRed(normal)), quint8(qGreen(normal)), quint8(qBlue(normal)) } }; | |
| 372 | − if (info.isLeaf) { | |
| 373 | − _depthPoints[_depth].first.append(point); | |
| 374 | − return STOP_RECURSION; | |
| 344 | + if (info.size >= _pointLeafSize) { | |
| 345 | + BufferPointVector swapPoints; | |
| 346 | + _points.swap(swapPoints); | |
| 347 | + info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(PointBufferPointer( | |
| 348 | + new PointBuffer(swapPoints)))); | |
| 375 | 349 | } |
| 376 | − _depthPoints[_depth].second.append(point); | |
| 377 | − return DEFAULT_ORDER | ALL_NODES; | |
| 350 | + return STOP_RECURSION; | |
| 378 | 351 | } |
| 379 | 352 | |
| 380 | 353 | bool PointAugmentVisitor::postVisit(MetavoxelInfo& info) { |
| 381 | − if (_depth != 0) { | |
| 354 | + if (info.size != _pointLeafSize) { | |
| 382 | 355 | return false; |
| 383 | 356 | } |
| 384 | − int lastDepth = _depthPoints.size(); | |
| 385 | − QVector<BufferPointVectorPair> levelPoints(lastDepth - _depth); | |
| 386 | − for (int i = 0; i < levelPoints.size(); i++) { | |
| 387 | − BufferPointVectorPair& levelPair = levelPoints[i]; | |
| 388 | − BufferPointVectorPair& depthPair = _depthPoints[_depth + i]; | |
| 389 | − levelPair.first.swap(depthPair.first); | |
| 390 | − levelPair.second.swap(depthPair.second); | |
| 391 | − } | |
| 357 | + BufferPointVector swapPoints; | |
| 358 | + _points.swap(swapPoints); | |
| 392 | 359 | info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(PointBufferPointer( |
| 393 | − new PointBuffer(levelPoints)))); | |
| 360 | + new PointBuffer(swapPoints)))); | |
| 394 | 361 | return true; |
| 395 | 362 | } |
| 396 | 363 | |
| 397 | 364 | void PointMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous, |
| 398 | 365 | MetavoxelInfo& info, const MetavoxelLOD& lod) { |
| 366 | + // copy the previous buffers | |
| 367 | + MetavoxelData expandedPrevious = previous; | |
| 368 | + while (expandedPrevious.getSize() < data.getSize()) { | |
| 369 | + expandedPrevious.expand(); | |
| 370 | + } | |
| 371 | + const AttributePointer& pointBufferAttribute = Application::getInstance()->getMetavoxels()->getPointBufferAttribute(); | |
| 372 | + MetavoxelNode* root = expandedPrevious.getRoot(pointBufferAttribute); | |
| 373 | + if (root) { | |
| 374 | + data.setRoot(pointBufferAttribute, root); | |
| 375 | + root->incrementReferenceCount(); | |
| 376 | + } | |
| 377 | + | |
| 399 | 378 | PointAugmentVisitor visitor(lod); |
| 400 | − data.guideToDifferent(previous, visitor, &info); | |
| 379 | + data.guideToDifferent(expandedPrevious, visitor); | |
| 401 | 380 | } |
| 402 | 381 | |
| 403 | 382 | class PointRenderVisitor : public MetavoxelVisitor { |
| @@ -421,7 +400,7 @@ PointRenderVisitor::PointRenderVisitor(const MetavoxelLOD& lod) : · 17 unmodified lines | ||
| 421 | 400 | int PointRenderVisitor::visit(MetavoxelInfo& info) { |
| 422 | 401 | PointBufferPointer buffer = info.inputValues.at(0).getInlineValue<PointBufferPointer>(); |
| 423 | 402 | if (buffer) { |
| 424 | − buffer->render(1000); | |
| 403 | + buffer->render(); | |
| 425 | 404 | } |
| 426 | 405 | return info.isLeaf ? STOP_RECURSION : _order; |
| 427 | 406 | } |
| @@ -450,7 +429,7 @@ void PointMetavoxelRendererImplementation::render(MetavoxelData& data, Metavoxel · 22 unmodified lines | ||
| 450 | 429 | glDisable(GL_BLEND); |
| 451 | 430 | |
| 452 | 431 | PointRenderVisitor visitor(lod); |
| 453 | − data.guide(visitor, &info); | |
| 432 | + data.guide(visitor); | |
| 454 | 433 | |
| 455 | 434 | glEnable(GL_BLEND); |
| 456 | 435 | |