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 | 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 | 337 | _translation(translation), |
| 338 | 338 | _scale(scale), |
| 339 | 339 | _height(height), |
| 340 | 340 | _color(color), |
| 341 | − _clearAfterLoading(clearAfterLoading), | |
| 342 | 341 | _heightTextureID(0), |
| 343 | 342 | _colorTextureID(0), |
| 344 | 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 | 383 | class HeightfieldPoint { |
| 359 | 384 | public: |
| 360 | 385 | glm::vec2 textureCoord; |
| @@ -372,9 +397,6 @@ void HeightfieldBuffer::render(bool cursor) { · 11 unmodified lines | ||
| 372 | 397 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 373 | 398 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0, |
| 374 | 399 | GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData()); |
| 375 | − if (_clearAfterLoading) { | |
| 376 | − _height.clear(); | |
| 377 | − } | |
| 378 | 400 | |
| 379 | 401 | glGenTextures(1, &_colorTextureID); |
| 380 | 402 | glBindTexture(GL_TEXTURE_2D, _colorTextureID); |
| @@ -386,15 +408,12 @@ void HeightfieldBuffer::render(bool cursor) { · 5 unmodified lines | ||
| 386 | 408 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR); |
| 387 | 409 | |
| 388 | 410 | } else { |
| 389 | − int colorSize = glm::sqrt(_color.size() / 3); | |
| 411 | + int colorSize = glm::sqrt(_color.size() / HeightfieldData::COLOR_BYTES); | |
| 390 | 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 | 415 | // create the buffer objects lazily |
| 397 | − int innerSize = _heightSize - 2; | |
| 416 | + int innerSize = _heightSize - 2 * HeightfieldBuffer::HEIGHT_BORDER; | |
| 398 | 417 | int vertexCount = _heightSize * _heightSize; |
| 399 | 418 | int rows = _heightSize - 1; |
| 400 | 419 | int indexCount = rows * rows * 4; |
| @@ -682,9 +701,9 @@ int HeightfieldAugmentVisitor::visit(MetavoxelInfo& info) { · 281 unmodified lines | ||
| 682 | 701 | if (height) { |
| 683 | 702 | const QByteArray& heightContents = height->getContents(); |
| 684 | 703 | int size = glm::sqrt(heightContents.size()); |
| 685 | − int extendedSize = size + 3; | |
| 704 | + int extendedSize = size + HeightfieldBuffer::HEIGHT_EXTENSION; | |
| 686 | 705 | QByteArray extendedHeightContents(extendedSize * extendedSize, 0); |
| 687 | − char* dest = extendedHeightContents.data() + extendedSize + 1; | |
| 706 | + char* dest = extendedHeightContents.data() + (extendedSize + 1) * HeightfieldBuffer::HEIGHT_BORDER; | |
| 688 | 707 | const char* src = heightContents.constData(); |
| 689 | 708 | for (int z = 0; z < size; z++, src += size, dest += extendedSize) { |
| 690 | 709 | memcpy(dest, src, size); |
| @@ -693,14 +712,13 @@ int HeightfieldAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines | ||
| 693 | 712 | HeightfieldDataPointer color = info.inputValues.at(1).getInlineValue<HeightfieldDataPointer>(); |
| 694 | 713 | if (color) { |
| 695 | 714 | const QByteArray& colorContents = color->getContents(); |
| 696 | − const int BYTES_PER_PIXEL = 3; | |
| 697 | − int colorSize = glm::sqrt(colorContents.size() / BYTES_PER_PIXEL); | |
| 698 | − int extendedColorSize = colorSize + 1; | |
| 699 | − extendedColorContents = QByteArray(extendedColorSize * extendedColorSize * BYTES_PER_PIXEL, 0); | |
| 715 | + int colorSize = glm::sqrt(colorContents.size() / HeightfieldData::COLOR_BYTES); | |
| 716 | + int extendedColorSize = colorSize + HeightfieldBuffer::SHARED_EDGE; | |
| 717 | + extendedColorContents = QByteArray(extendedColorSize * extendedColorSize * HeightfieldData::COLOR_BYTES, 0); | |
| 700 | 718 | char* dest = extendedColorContents.data(); |
| 701 | 719 | const char* src = colorContents.constData(); |
| 702 | − int srcStride = colorSize * BYTES_PER_PIXEL; | |
| 703 | − int destStride = extendedColorSize * BYTES_PER_PIXEL; | |
| 720 | + int srcStride = colorSize * HeightfieldData::COLOR_BYTES; | |
| 721 | + int destStride = extendedColorSize * HeightfieldData::COLOR_BYTES; | |
| 704 | 722 | for (int z = 0; z < colorSize; z++, src += srcStride, dest += destStride) { |
| 705 | 723 | memcpy(dest, src, srcStride); |
| 706 | 724 | } |