Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -333,12 +333,11 @@ void PointBuffer::render(bool cursor) { · 332 unmodified lines | |||
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, | 335 | HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, |
| 336 | const QByteArray& height, const QByteArray& color, bool clearAfterLoading) : | 336 | const QByteArray& height, const QByteArray& color) : |
| 337 | _translation(translation), | 337 | _translation(translation), |
| 338 | _scale(scale), | 338 | _scale(scale), |
| 339 | _height(height), | 339 | _height(height), |
| 340 | _color(color), | 340 | _color(color), |
| 341 | _clearAfterLoading(clearAfterLoading), | ||
| 342 | _heightTextureID(0), | 341 | _heightTextureID(0), |
| 343 | _colorTextureID(0), | 342 | _colorTextureID(0), |
| 344 | _heightSize(glm::sqrt(height.size())) { | 343 | _heightSize(glm::sqrt(height.size())) { |
| @@ -355,6 +354,32 @@ HeightfieldBuffer::~HeightfieldBuffer() { · 10 unmodified lines | |||
| 355 | } | 354 | } |
| 356 | } | 355 | } |
| 357 | 356 | ||
| 357 | QByteArray HeightfieldBuffer::getUnextendedHeight() const { | ||
| 358 | int srcSize = glm::sqrt(_height.size()); | ||
| 359 | int destSize = srcSize - 3; | ||
| 360 | QByteArray unextended(destSize * destSize, 0); | ||
| 361 | const char* src = _height.constData() + srcSize + 1; | ||
| 362 | char* dest = unextended.data(); | ||
| 363 | for (int z = 0; z < destSize; z++, src += srcSize, dest += destSize) { | ||
| 364 | memcpy(dest, src, destSize); | ||
| 365 | } | ||
| 366 | return unextended; | ||
| 367 | } | ||
| 368 | |||
| 369 | QByteArray HeightfieldBuffer::getUnextendedColor() const { | ||
| 370 | int srcSize = glm::sqrt(_color.size() / HeightfieldData::COLOR_BYTES); | ||
| 371 | int destSize = srcSize - 1; | ||
| 372 | QByteArray unextended(destSize * destSize * HeightfieldData::COLOR_BYTES, 0); | ||
| 373 | const char* src = _color.constData(); | ||
| 374 | int srcStride = srcSize * HeightfieldData::COLOR_BYTES; | ||
| 375 | char* dest = unextended.data(); | ||
| 376 | int destStride = destSize * HeightfieldData::COLOR_BYTES; | ||
| 377 | for (int z = 0; z < destSize; z++, src += srcStride, dest += destStride) { | ||
| 378 | memcpy(dest, src, destStride); | ||
| 379 | } | ||
| 380 | return unextended; | ||
| 381 | } | ||
| 382 | |||
| 358 | class HeightfieldPoint { | 383 | class HeightfieldPoint { |
| 359 | public: | 384 | public: |
| 360 | glm::vec2 textureCoord; | 385 | glm::vec2 textureCoord; |
| @@ -372,9 +397,6 @@ void HeightfieldBuffer::render(bool cursor) { · 11 unmodified lines | |||
| 372 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 397 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 373 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0, | 398 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0, |
| 374 | GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData()); | 399 | GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData()); |
| 375 | if (_clearAfterLoading) { | ||
| 376 | _height.clear(); | ||
| 377 | } | ||
| 378 | 400 | ||
| 379 | glGenTextures(1, &_colorTextureID); | 401 | glGenTextures(1, &_colorTextureID); |
| 380 | glBindTexture(GL_TEXTURE_2D, _colorTextureID); | 402 | glBindTexture(GL_TEXTURE_2D, _colorTextureID); |
| @@ -386,15 +408,12 @@ void HeightfieldBuffer::render(bool cursor) { · 5 unmodified lines | |||
| 386 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR); | 408 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR); |
| 387 | 409 | ||
| 388 | } else { | 410 | } else { |
| 389 | int colorSize = glm::sqrt(_color.size() / 3); | 411 | int colorSize = glm::sqrt(_color.size() / HeightfieldData::COLOR_BYTES); |
| 390 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData()); | 412 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData()); |
| 391 | if (_clearAfterLoading) { | ||
| 392 | _color.clear(); | ||
| 393 | } | ||
| 394 | } | 413 | } |
| 395 | } | 414 | } |
| 396 | // create the buffer objects lazily | 415 | // create the buffer objects lazily |
| 397 | int innerSize = _heightSize - 2; | 416 | int innerSize = _heightSize - 2 * HeightfieldBuffer::HEIGHT_BORDER; |
| 398 | int vertexCount = _heightSize * _heightSize; | 417 | int vertexCount = _heightSize * _heightSize; |
| 399 | int rows = _heightSize - 1; | 418 | int rows = _heightSize - 1; |
| 400 | int indexCount = rows * rows * 4; | 419 | int indexCount = rows * rows * 4; |
| @@ -682,9 +701,9 @@ int HeightfieldAugmentVisitor::visit(MetavoxelInfo& info) { · 281 unmodified lines | |||
| 682 | if (height) { | 701 | if (height) { |
| 683 | const QByteArray& heightContents = height->getContents(); | 702 | const QByteArray& heightContents = height->getContents(); |
| 684 | int size = glm::sqrt(heightContents.size()); | 703 | int size = glm::sqrt(heightContents.size()); |
| 685 | int extendedSize = size + 3; | 704 | int extendedSize = size + HeightfieldBuffer::HEIGHT_EXTENSION; |
| 686 | QByteArray extendedHeightContents(extendedSize * extendedSize, 0); | 705 | QByteArray extendedHeightContents(extendedSize * extendedSize, 0); |
| 687 | char* dest = extendedHeightContents.data() + extendedSize + 1; | 706 | char* dest = extendedHeightContents.data() + (extendedSize + 1) * HeightfieldBuffer::HEIGHT_BORDER; |
| 688 | const char* src = heightContents.constData(); | 707 | const char* src = heightContents.constData(); |
| 689 | for (int z = 0; z < size; z++, src += size, dest += extendedSize) { | 708 | for (int z = 0; z < size; z++, src += size, dest += extendedSize) { |
| 690 | memcpy(dest, src, size); | 709 | memcpy(dest, src, size); |
| @@ -693,14 +712,13 @@ int HeightfieldAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines | |||
| 693 | HeightfieldDataPointer color = info.inputValues.at(1).getInlineValue<HeightfieldDataPointer>(); | 712 | HeightfieldDataPointer color = info.inputValues.at(1).getInlineValue<HeightfieldDataPointer>(); |
| 694 | if (color) { | 713 | if (color) { |
| 695 | const QByteArray& colorContents = color->getContents(); | 714 | const QByteArray& colorContents = color->getContents(); |
| 696 | const int BYTES_PER_PIXEL = 3; | 715 | int colorSize = glm::sqrt(colorContents.size() / HeightfieldData::COLOR_BYTES); |
| 697 | int colorSize = glm::sqrt(colorContents.size() / BYTES_PER_PIXEL); | 716 | int extendedColorSize = colorSize + HeightfieldBuffer::SHARED_EDGE; |
| 698 | int extendedColorSize = colorSize + 1; | 717 | extendedColorContents = QByteArray(extendedColorSize * extendedColorSize * HeightfieldData::COLOR_BYTES, 0); |
| 699 | extendedColorContents = QByteArray(extendedColorSize * extendedColorSize * BYTES_PER_PIXEL, 0); | ||
| 700 | char* dest = extendedColorContents.data(); | 718 | char* dest = extendedColorContents.data(); |
| 701 | const char* src = colorContents.constData(); | 719 | const char* src = colorContents.constData(); |
| 702 | int srcStride = colorSize * BYTES_PER_PIXEL; | 720 | int srcStride = colorSize * HeightfieldData::COLOR_BYTES; |
| 703 | int destStride = extendedColorSize * BYTES_PER_PIXEL; | 721 | int destStride = extendedColorSize * HeightfieldData::COLOR_BYTES; |
| 704 | for (int z = 0; z < colorSize; z++, src += srcStride, dest += destStride) { | 722 | for (int z = 0; z < colorSize; z++, src += srcStride, dest += destStride) { |
| 705 | memcpy(dest, src, srcStride); | 723 | memcpy(dest, src, srcStride); |
| 706 | } | 724 | } |