Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 6 files). Show all
Unified · Split
| @@ -29,6 +29,7 @@ REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) · 28 unmodified lines | ||
| 29 | 29 | REGISTER_META_OBJECT(SphereRenderer) |
| 30 | 30 | REGISTER_META_OBJECT(StaticModelRenderer) |
| 31 | 31 | |
| 32 | +static int texturePointerMetaTypeId = qRegisterMetaType<TexturePointer>(); | |
| 32 | 33 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); |
| 33 | 34 | |
| 34 | 35 | void MetavoxelSystem::init() { |
| @@ -112,6 +113,11 @@ void MetavoxelSystem::render() { · 77 unmodified lines | ||
| 112 | 113 | guideToAugmented(renderVisitor); |
| 113 | 114 | } |
| 114 | 115 | |
| 116 | +void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) { | |
| 117 | + delete height; | |
| 118 | + delete color; | |
| 119 | +} | |
| 120 | + | |
| 115 | 121 | MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { |
| 116 | 122 | return new MetavoxelSystemClient(node, _updater); |
| 117 | 123 | } |
| @@ -261,8 +267,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, · 143 unmodified lines | ||
| 261 | 267 | _height(height), |
| 262 | 268 | _color(color), |
| 263 | 269 | _clearAfterLoading(clearAfterLoading), |
| 264 | − _heightTexture(QOpenGLTexture::Target2D), | |
| 265 | − _colorTexture(QOpenGLTexture::Target2D) { | |
| 270 | + _heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)), | |
| 271 | + _colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) { | |
| 272 | +} | |
| 273 | + | |
| 274 | +HeightfieldBuffer::~HeightfieldBuffer() { | |
| 275 | + // the textures have to be deleted on the main thread (for its opengl context) | |
| 276 | + if (QThread::currentThread() != Application::getInstance()->thread()) { | |
| 277 | + QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures", | |
| 278 | + Q_ARG(const TexturePointer&, _heightTexture), Q_ARG(const TexturePointer&, _colorTexture)); | |
| 279 | + } else { | |
| 280 | + delete _heightTexture; | |
| 281 | + delete _colorTexture; | |
| 282 | + } | |
| 266 | 283 | } |
| 267 | 284 | |
| 268 | 285 | class HeightfieldPoint { |
| @@ -273,39 +290,39 @@ public: · 4 unmodified lines | ||
| 273 | 290 | |
| 274 | 291 | void HeightfieldBuffer::render() { |
| 275 | 292 | // initialize textures, etc. on first render |
| 276 | − if (!_heightTexture.isCreated()) { | |
| 293 | + if (!_heightTexture->isCreated()) { | |
| 277 | 294 | int heightSize = glm::sqrt(_height.size()); |
| 278 | − _heightTexture.setSize(heightSize, heightSize); | |
| 279 | − _heightTexture.setAutoMipMapGenerationEnabled(false); | |
| 280 | − _heightTexture.setMinificationFilter(QOpenGLTexture::Linear); | |
| 281 | − _heightTexture.setWrapMode(QOpenGLTexture::ClampToEdge); | |
| 282 | − _heightTexture.setFormat(QOpenGLTexture::LuminanceFormat); | |
| 283 | − _heightTexture.allocateStorage(); | |
| 284 | − _heightTexture.setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data()); | |
| 295 | + _heightTexture->setSize(heightSize, heightSize); | |
| 296 | + _heightTexture->setAutoMipMapGenerationEnabled(false); | |
| 297 | + _heightTexture->setMinificationFilter(QOpenGLTexture::Linear); | |
| 298 | + _heightTexture->setWrapMode(QOpenGLTexture::ClampToEdge); | |
| 299 | + _heightTexture->setFormat(QOpenGLTexture::LuminanceFormat); | |
| 300 | + _heightTexture->allocateStorage(); | |
| 301 | + _heightTexture->setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data()); | |
| 285 | 302 | if (_clearAfterLoading) { |
| 286 | 303 | _height.clear(); |
| 287 | 304 | } |
| 288 | 305 | if (!_color.isEmpty()) { |
| 289 | 306 | int colorSize = glm::sqrt(_color.size() / 3); |
| 290 | − _colorTexture.setSize(colorSize, colorSize); | |
| 307 | + _colorTexture->setSize(colorSize, colorSize); | |
| 291 | 308 | } |
| 292 | − _colorTexture.setAutoMipMapGenerationEnabled(false); | |
| 293 | − _colorTexture.setMinificationFilter(QOpenGLTexture::Linear); | |
| 294 | − _colorTexture.setWrapMode(QOpenGLTexture::ClampToEdge); | |
| 295 | − _colorTexture.setFormat(QOpenGLTexture::RGBFormat); | |
| 296 | − _colorTexture.allocateStorage(); | |
| 309 | + _colorTexture->setAutoMipMapGenerationEnabled(false); | |
| 310 | + _colorTexture->setMinificationFilter(QOpenGLTexture::Linear); | |
| 311 | + _colorTexture->setWrapMode(QOpenGLTexture::ClampToEdge); | |
| 312 | + _colorTexture->setFormat(QOpenGLTexture::RGBFormat); | |
| 313 | + _colorTexture->allocateStorage(); | |
| 297 | 314 | if (!_color.isEmpty()) { |
| 298 | − _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data()); | |
| 315 | + _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data()); | |
| 299 | 316 | if (_clearAfterLoading) { |
| 300 | 317 | _color.clear(); |
| 301 | 318 | } |
| 302 | 319 | } else { |
| 303 | 320 | const quint8 WHITE_COLOR[] = { 255, 255, 255 }; |
| 304 | − _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR)); | |
| 321 | + _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR)); | |
| 305 | 322 | } |
| 306 | 323 | } |
| 307 | 324 | // create the buffer objects lazily |
| 308 | − int size = _heightTexture.width(); | |
| 325 | + int size = _heightTexture->width(); | |
| 309 | 326 | int sizeWithSkirt = size + 2; |
| 310 | 327 | int vertexCount = sizeWithSkirt * sizeWithSkirt; |
| 311 | 328 | int rows = sizeWithSkirt - 1; |
| @@ -363,13 +380,13 @@ void HeightfieldBuffer::render() { · 51 unmodified lines | ||
| 363 | 380 | glTranslatef(_translation.x, _translation.y, _translation.z); |
| 364 | 381 | glScalef(_scale, _scale, _scale); |
| 365 | 382 | |
| 366 | − _heightTexture.bind(0); | |
| 367 | − _colorTexture.bind(1); | |
| 383 | + _heightTexture->bind(0); | |
| 384 | + _colorTexture->bind(1); | |
| 368 | 385 | |
| 369 | 386 | glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); |
| 370 | 387 | |
| 371 | − _colorTexture.release(1); | |
| 372 | − _heightTexture.release(0); | |
| 388 | + _colorTexture->release(1); | |
| 389 | + _heightTexture->release(0); | |
| 373 | 390 | |
| 374 | 391 | glPopMatrix(); |
| 375 | 392 | |
| @@ -678,7 +695,7 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 302 unmodified lines | ||
| 678 | 695 | |
| 679 | 696 | _pointProgram.release(); |
| 680 | 697 | |
| 681 | − glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
| 698 | + glColor4f(1.0f, 1.0f, 1.0f, 0.0f); | |
| 682 | 699 | |
| 683 | 700 | _heightfieldProgram.bind(); |
| 684 | 701 | |