History

Attempting to remove some number magic.

Andrzej Kapolka committed 12 years ago

Commit ee01d851 parent 24cc90c5 files · +95 −73Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+36−18
@@ -333,12 +333,11 @@ void PointBuffer::render(bool cursor) { · 332 unmodified lines
333333 }
334334
335335 HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale,
336− const QByteArray& height, const QByteArray& color, bool clearAfterLoading) :
336+ const QByteArray& height, const QByteArray& color) :
337337 _translation(translation),
338338 _scale(scale),
339339 _height(height),
340340 _color(color),
341− _clearAfterLoading(clearAfterLoading),
342341 _heightTextureID(0),
343342 _colorTextureID(0),
344343 _heightSize(glm::sqrt(height.size())) {
@@ -355,6 +354,32 @@ HeightfieldBuffer::~HeightfieldBuffer() { · 10 unmodified lines
355354 }
356355 }
357356
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+
358383 class HeightfieldPoint {
359384 public:
360385 glm::vec2 textureCoord;
@@ -372,9 +397,6 @@ void HeightfieldBuffer::render(bool cursor) { · 11 unmodified lines
372397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
373398 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0,
374399 GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData());
375− if (_clearAfterLoading) {
376− _height.clear();
377− }
378400
379401 glGenTextures(1, &_colorTextureID);
380402 glBindTexture(GL_TEXTURE_2D, _colorTextureID);
@@ -386,15 +408,12 @@ void HeightfieldBuffer::render(bool cursor) { · 5 unmodified lines
386408 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
387409
388410 } else {
389− int colorSize = glm::sqrt(_color.size() / 3);
411+ int colorSize = glm::sqrt(_color.size() / HeightfieldData::COLOR_BYTES);
390412 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());
391− if (_clearAfterLoading) {
392− _color.clear();
393− }
394413 }
395414 }
396415 // create the buffer objects lazily
397− int innerSize = _heightSize - 2;
416+ int innerSize = _heightSize - 2 * HeightfieldBuffer::HEIGHT_BORDER;
398417 int vertexCount = _heightSize * _heightSize;
399418 int rows = _heightSize - 1;
400419 int indexCount = rows * rows * 4;
@@ -682,9 +701,9 @@ int HeightfieldAugmentVisitor::visit(MetavoxelInfo& info) { · 281 unmodified lines
682701 if (height) {
683702 const QByteArray& heightContents = height->getContents();
684703 int size = glm::sqrt(heightContents.size());
685− int extendedSize = size + 3;
704+ int extendedSize = size + HeightfieldBuffer::HEIGHT_EXTENSION;
686705 QByteArray extendedHeightContents(extendedSize * extendedSize, 0);
687− char* dest = extendedHeightContents.data() + extendedSize + 1;
706+ char* dest = extendedHeightContents.data() + (extendedSize + 1) * HeightfieldBuffer::HEIGHT_BORDER;
688707 const char* src = heightContents.constData();
689708 for (int z = 0; z < size; z++, src += size, dest += extendedSize) {
690709 memcpy(dest, src, size);
@@ -693,14 +712,13 @@ int HeightfieldAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines
693712 HeightfieldDataPointer color = info.inputValues.at(1).getInlineValue<HeightfieldDataPointer>();
694713 if (color) {
695714 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);
700718 char* dest = extendedColorContents.data();
701719 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;
704722 for (int z = 0; z < colorSize; z++, src += srcStride, dest += destStride) {
705723 memcpy(dest, src, srcStride);
706724 }