Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -29,7 +29,6 @@ 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>(); | |
| 33 | 32 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); |
| 34 | 33 | |
| 35 | 34 | void MetavoxelSystem::init() { |
| @@ -113,9 +112,9 @@ void MetavoxelSystem::render() { · 77 unmodified lines | ||
| 113 | 112 | guideToAugmented(renderVisitor); |
| 114 | 113 | } |
| 115 | 114 | |
| 116 | −void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) { | |
| 117 | − delete height; | |
| 118 | − delete color; | |
| 115 | +void MetavoxelSystem::deleteTextures(int heightID, int colorID) { | |
| 116 | + glDeleteTextures(1, (GLuint*)&heightID); | |
| 117 | + glDeleteTextures(1, (GLuint*)&colorID); | |
| 119 | 118 | } |
| 120 | 119 | |
| 121 | 120 | MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { |
| @@ -267,18 +266,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, · 145 unmodified lines | ||
| 267 | 266 | _height(height), |
| 268 | 267 | _color(color), |
| 269 | 268 | _clearAfterLoading(clearAfterLoading), |
| 270 | − _heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)), | |
| 271 | − _colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) { | |
| 269 | + _heightTextureID(0), | |
| 270 | + _colorTextureID(0), | |
| 271 | + _heightSize(glm::sqrt(height.size())) { | |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | HeightfieldBuffer::~HeightfieldBuffer() { |
| 275 | 275 | // the textures have to be deleted on the main thread (for its opengl context) |
| 276 | 276 | if (QThread::currentThread() != Application::getInstance()->thread()) { |
| 277 | 277 | QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures", |
| 278 | − Q_ARG(const TexturePointer&, _heightTexture), Q_ARG(const TexturePointer&, _colorTexture)); | |
| 278 | + Q_ARG(int, _heightTextureID), Q_ARG(int, _colorTextureID)); | |
| 279 | 279 | } else { |
| 280 | − delete _heightTexture; | |
| 281 | − delete _colorTexture; | |
| 280 | + glDeleteTextures(1, &_heightTextureID); | |
| 281 | + glDeleteTextures(1, &_colorTextureID); | |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
| @@ -290,49 +290,46 @@ public: · 5 unmodified lines | ||
| 290 | 290 | |
| 291 | 291 | void HeightfieldBuffer::render() { |
| 292 | 292 | // initialize textures, etc. on first render |
| 293 | − if (!_heightTexture->isCreated()) { | |
| 294 | − int heightSize = glm::sqrt(_height.size()); | |
| 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()); | |
| 293 | + if (_heightTextureID == 0) { | |
| 294 | + glGenTextures(1, &_heightTextureID); | |
| 295 | + glBindTexture(GL_TEXTURE_2D, _heightTextureID); | |
| 296 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 297 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 298 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 299 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0, | |
| 300 | + GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData()); | |
| 302 | 301 | if (_clearAfterLoading) { |
| 303 | 302 | _height.clear(); |
| 304 | 303 | } |
| 305 | − if (!_color.isEmpty()) { | |
| 304 | + | |
| 305 | + glGenTextures(1, &_colorTextureID); | |
| 306 | + glBindTexture(GL_TEXTURE_2D, _colorTextureID); | |
| 307 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 308 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 309 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 310 | + if (_color.isEmpty()) { | |
| 311 | + const quint8 WHITE_COLOR[] = { 255, 255, 255 }; | |
| 312 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR); | |
| 313 | + | |
| 314 | + } else { | |
| 306 | 315 | int colorSize = glm::sqrt(_color.size() / 3); |
| 307 | − _colorTexture->setSize(colorSize, colorSize); | |
| 308 | − } | |
| 309 | − _colorTexture->setAutoMipMapGenerationEnabled(false); | |
| 310 | − _colorTexture->setMinificationFilter(QOpenGLTexture::Linear); | |
| 311 | − _colorTexture->setWrapMode(QOpenGLTexture::ClampToEdge); | |
| 312 | − _colorTexture->setFormat(QOpenGLTexture::RGBFormat); | |
| 313 | − _colorTexture->allocateStorage(); | |
| 314 | − if (!_color.isEmpty()) { | |
| 315 | − _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data()); | |
| 316 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData()); | |
| 316 | 317 | if (_clearAfterLoading) { |
| 317 | 318 | _color.clear(); |
| 318 | 319 | } |
| 319 | − } else { | |
| 320 | − const quint8 WHITE_COLOR[] = { 255, 255, 255 }; | |
| 321 | − _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR)); | |
| 322 | 320 | } |
| 323 | 321 | } |
| 324 | 322 | // create the buffer objects lazily |
| 325 | − int size = _heightTexture->width(); | |
| 326 | − int sizeWithSkirt = size + 2; | |
| 323 | + int sizeWithSkirt = _heightSize + 2; | |
| 327 | 324 | int vertexCount = sizeWithSkirt * sizeWithSkirt; |
| 328 | 325 | int rows = sizeWithSkirt - 1; |
| 329 | 326 | int indexCount = rows * rows * 4; |
| 330 | − BufferPair& bufferPair = _bufferPairs[size]; | |
| 327 | + BufferPair& bufferPair = _bufferPairs[_heightSize]; | |
| 331 | 328 | if (!bufferPair.first.isCreated()) { |
| 332 | 329 | QVector<HeightfieldPoint> vertices(vertexCount); |
| 333 | 330 | HeightfieldPoint* point = vertices.data(); |
| 334 | 331 | |
| 335 | − float step = 1.0f / (size - 1); | |
| 332 | + float step = 1.0f / (_heightSize - 1); | |
| 336 | 333 | float z = -step; |
| 337 | 334 | for (int i = 0; i < sizeWithSkirt; i++, z += step) { |
| 338 | 335 | float x = -step; |
| @@ -380,13 +377,17 @@ void HeightfieldBuffer::render() { · 41 unmodified lines | ||
| 380 | 377 | glTranslatef(_translation.x, _translation.y, _translation.z); |
| 381 | 378 | glScalef(_scale, _scale, _scale); |
| 382 | 379 | |
| 383 | − _heightTexture->bind(0); | |
| 384 | − _colorTexture->bind(1); | |
| 380 | + glBindTexture(GL_TEXTURE_2D, _heightTextureID); | |
| 381 | + | |
| 382 | + glActiveTexture(GL_TEXTURE1); | |
| 383 | + glBindTexture(GL_TEXTURE_2D, _colorTextureID); | |
| 385 | 384 | |
| 386 | 385 | glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); |
| 387 | 386 | |
| 388 | − _colorTexture->release(1); | |
| 389 | − _heightTexture->release(0); | |
| 387 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 388 | + | |
| 389 | + glActiveTexture(GL_TEXTURE0); | |
| 390 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 390 | 391 | |
| 391 | 392 | glPopMatrix(); |
| 392 | 393 | |