From 296718e2aae5b20b54990bb81a1d9c54f5bfb612 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 21 Nov 2014 12:46:24 -0800 Subject: [PATCH] Removed redundant members, clarified class names, used better hash factors. --- interface/src/MetavoxelSystem.cpp | 8 ++++---- interface/src/MetavoxelSystem.h | 33 +++++++++++-------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index b0a5d3324c..b98fea8eca 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -215,7 +215,7 @@ void MetavoxelSystem::render() { _baseHeightfieldProgram.bind(); - foreach (const HeightfieldBaseBatch& batch, _heightfieldBaseBatches) { + foreach (const HeightfieldBaseLayerBatch& batch, _heightfieldBaseBatches) { glPushMatrix(); glTranslatef(batch.translation.x, batch.translation.y, batch.translation.z); glm::vec3 axis = glm::axis(batch.rotation); @@ -362,7 +362,7 @@ void MetavoxelSystem::render() { _baseVoxelProgram.bind(); - foreach (const VoxelBaseBatch& batch, _voxelBaseBatches) { + foreach (const VoxelBatch& batch, _voxelBaseBatches) { batch.vertexBuffer->bind(); batch.indexBuffer->bind(); @@ -1155,7 +1155,7 @@ void VoxelBuffer::render(bool cursor) { return; } - VoxelBaseBatch baseBatch; + VoxelBatch baseBatch; baseBatch.vertexBuffer = &_vertexBuffer; baseBatch.indexBuffer = &_indexBuffer; baseBatch.vertexCount = _vertexCount; @@ -2209,7 +2209,7 @@ void HeightfieldRenderer::render(bool cursor) { return; } - HeightfieldBaseBatch baseBatch; + HeightfieldBaseLayerBatch baseBatch; baseBatch.vertexBuffer = &bufferPair.first; baseBatch.indexBuffer = &bufferPair.second; baseBatch.translation = heightfield->getTranslation(); diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index dfbabbb2bf..c1cdfd3624 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -23,10 +23,10 @@ #include "renderer/ProgramObject.h" -class HeightfieldBaseBatch; +class HeightfieldBaseLayerBatch; class HeightfieldSplatBatch; class Model; -class VoxelBaseBatch; +class VoxelBatch; class VoxelSplatBatch; /// Renders a metavoxel tree. @@ -82,10 +82,10 @@ public: Q_INVOKABLE void setVoxelMaterial(const SharedObjectPointer& spanner, const SharedObjectPointer& material); - void addHeightfieldBaseBatch(const HeightfieldBaseBatch& batch) { _heightfieldBaseBatches.append(batch); } + void addHeightfieldBaseBatch(const HeightfieldBaseLayerBatch& batch) { _heightfieldBaseBatches.append(batch); } void addHeightfieldSplatBatch(const HeightfieldSplatBatch& batch) { _heightfieldSplatBatches.append(batch); } - void addVoxelBaseBatch(const VoxelBaseBatch& batch) { _voxelBaseBatches.append(batch); } + void addVoxelBaseBatch(const VoxelBatch& batch) { _voxelBaseBatches.append(batch); } void addVoxelSplatBatch(const VoxelSplatBatch& batch) { _voxelSplatBatches.append(batch); } signals: @@ -116,9 +116,9 @@ private: NetworkSimulation _networkSimulation; QReadWriteLock _networkSimulationLock; - QVector _heightfieldBaseBatches; + QVector _heightfieldBaseBatches; QVector _heightfieldSplatBatches; - QVector _voxelBaseBatches; + QVector _voxelBaseBatches; QVector _voxelSplatBatches; ProgramObject _baseHeightfieldProgram; @@ -174,19 +174,10 @@ public: glm::vec4 heightScale; }; -/// A batch containing a heightfield base. -class HeightfieldBaseBatch : public HeightfieldBatch { +/// A batch containing a heightfield base layer. +class HeightfieldBaseLayerBatch : public HeightfieldBatch { public: - QOpenGLBuffer* vertexBuffer; - QOpenGLBuffer* indexBuffer; - glm::vec3 translation; - glm::quat rotation; - glm::vec3 scale; - int vertexCount; - int indexCount; - GLuint heightTextureID; GLuint colorTextureID; - glm::vec4 heightScale; glm::vec2 colorScale; }; @@ -203,7 +194,7 @@ public: }; /// Base class for voxel batches. -class VoxelBaseBatch { +class VoxelBatch { public: QOpenGLBuffer* vertexBuffer; QOpenGLBuffer* indexBuffer; @@ -212,7 +203,7 @@ public: }; /// A batch containing a voxel splat. -class VoxelSplatBatch : public VoxelBaseBatch { +class VoxelSplatBatch : public VoxelBatch { public: int splatTextureIDs[4]; glm::vec4 splatTextureScalesS; @@ -319,8 +310,8 @@ public: }; inline uint qHash(const VoxelCoord& coord, uint seed) { - // 31 is just an arbitrary prime number - return qHash(qRed(coord.encoded) + 31 * (qGreen(coord.encoded) + 31 * qBlue(coord.encoded)), seed); + // multiply by prime numbers greater than the possible size + return qHash(qRed(coord.encoded) + 257 * (qGreen(coord.encoded) + 263 * qBlue(coord.encoded)), seed); } /// Contains the information necessary to render a voxel block.