diff --git a/interface/src/PrimitiveRenderer.cpp b/interface/src/PrimitiveRenderer.cpp index a285058a7c..fd1f3fd2e7 100644 --- a/interface/src/PrimitiveRenderer.cpp +++ b/interface/src/PrimitiveRenderer.cpp @@ -9,31 +9,27 @@ #include "OctreeElement.h" #include "PrimitiveRenderer.h" -Primitive::Primitive() -{} +Primitive::Primitive() { +} -Primitive::~Primitive() -{} +Primitive::~Primitive() { +} // Simple dispatch between API and SPI -VertexElementList const & Primitive::vertexElements() const -{ +VertexElementList const & Primitive::vertexElements() const { return vVertexElements(); } -VertexElementIndexList & Primitive::vertexElementIndices() -{ +VertexElementIndexList& Primitive::vertexElementIndices() { return vVertexElementIndices(); } -TriElementList & Primitive::triElements() -{ +TriElementList& Primitive::triElements() { return vTriElements(); } -void Primitive::releaseVertexElements() -{ +void Primitive::releaseVertexElements() { vReleaseVertexElements(); } @@ -47,13 +43,11 @@ Cube::Cube( unsigned char g, unsigned char b, unsigned char faceExclusions - ) -{ + ) { initialize(x, y, z, s, r, g, b, faceExclusions); } -Cube::~Cube() -{ +Cube::~Cube() { terminate(); } @@ -66,14 +60,14 @@ void Cube::initialize( unsigned char g, unsigned char b, unsigned char faceExclusions - ) -{ + ) { + initializeVertices(x, y, z, s, r, g, b, faceExclusions); initializeTris(faceExclusions); } -void Cube::terminate() -{ +void Cube::terminate() { + terminateTris(); terminateVertices(); } @@ -87,27 +81,25 @@ void Cube::initializeVertices( unsigned char g, unsigned char b, unsigned char faceExclusions - ) -{ - for (int i = 0; i < 24; i++) - { + ) { + + for (int i = 0; i < _sNumVerticesPerCube; i++) { // Check whether the vertex is necessary for the faces indicated by faceExclusions bit mask. - if (~faceExclusions & s_faceIndexToHalfSpaceMask[i >> 2]) - //if (~0x00 & s_faceIndexToHalfSpaceMask[i >> 2]) - //if (faceExclusions & s_faceIndexToHalfSpaceMask[i >> 2]) - { - VertexElement *v = new VertexElement(); - if (v) - { + if (~faceExclusions & _sFaceIndexToHalfSpaceMask[i >> 2]) { + //if (~0x00 & _sFaceIndexToHalfSpaceMask[i >> 2]) { + //if (faceExclusions & _sFaceIndexToHalfSpaceMask[i >> 2]) { + + VertexElement* v = new VertexElement(); + if (v) { // Construct vertex position - v->position.x = x + s * s_vertexIndexToConstructionVector[i][0]; - v->position.y = y + s * s_vertexIndexToConstructionVector[i][1]; - v->position.z = z + s * s_vertexIndexToConstructionVector[i][2]; + v->position.x = x + s * _sVertexIndexToConstructionVector[i][0]; + v->position.y = y + s * _sVertexIndexToConstructionVector[i][1]; + v->position.z = z + s * _sVertexIndexToConstructionVector[i][2]; // Construct vertex normal - v->normal.x = s_vertexIndexToNormalVector[i >> 2][0]; - v->normal.y = s_vertexIndexToNormalVector[i >> 2][1]; - v->normal.z = s_vertexIndexToNormalVector[i >> 2][2]; + v->normal.x = _sVertexIndexToNormalVector[i >> 2][0]; + v->normal.y = _sVertexIndexToNormalVector[i >> 2][1]; + v->normal.z = _sVertexIndexToNormalVector[i >> 2][2]; // Construct vertex color //#define FALSE_COLOR @@ -138,13 +130,12 @@ void Cube::initializeVertices( } } -void Cube::terminateVertices() -{ +void Cube::terminateVertices() { + VertexElementList::iterator it = _vertices.begin(); VertexElementList::iterator end = _vertices.end(); - for ( ; it != end; ++it) - { + for ( ; it != end; ++it) { delete *it; } _vertices.clear(); @@ -152,17 +143,16 @@ void Cube::terminateVertices() void Cube::initializeTris( unsigned char faceExclusions - ) -{ + ) { + int index = 0; - for (int i = 0; i < 6; i++) - { + for (int i = 0; i < _sNumFacesPerCube; i++) { // Check whether the vertex is necessary for the faces indicated by faceExclusions bit mask. // uncomment this line to exclude shared faces: - if (~faceExclusions & s_faceIndexToHalfSpaceMask[i]) - // uncomment this line to load all faces: if (~0x00 & s_faceIndexToHalfSpaceMask[i]) - // uncomment this line to include shared faces: if (faceExclusions & s_faceIndexToHalfSpaceMask[i]) - { + if (~faceExclusions & _sFaceIndexToHalfSpaceMask[i]) { + // uncomment this line to load all faces: if (~0x00 & _sFaceIndexToHalfSpaceMask[i]) { + // uncomment this line to include shared faces: if (faceExclusions & _sFaceIndexToHalfSpaceMask[i]) { + int start = index; // Create the triangulated face, two tris, six indices referencing four vertices, both // with cw winding order, such that: @@ -174,8 +164,7 @@ void Cube::initializeTris( // Store triangle ABC TriElement *tri = new TriElement(); - if (tri) - { + if (tri) { tri->indices[0] = index++; tri->indices[1] = index++; tri->indices[2] = index; @@ -186,8 +175,7 @@ void Cube::initializeTris( // Now store triangle ACD tri = new TriElement(); - if (tri) - { + if (tri) { tri->indices[0] = start; tri->indices[1] = index++; tri->indices[2] = index++; @@ -199,39 +187,34 @@ void Cube::initializeTris( } } -void Cube::terminateTris() -{ +void Cube::terminateTris() { + TriElementList::iterator it = _tris.begin(); TriElementList::iterator end = _tris.end(); - for ( ; it != end; ++it) - { + for ( ; it != end; ++it) { delete *it; } _tris.clear(); } -VertexElementList const & Cube::vVertexElements() const -{ +VertexElementList const & Cube::vVertexElements() const { return _vertices; } -VertexElementIndexList & Cube::vVertexElementIndices() -{ +VertexElementIndexList& Cube::vVertexElementIndices() { return _vertexIndices; } -TriElementList & Cube::vTriElements() -{ +TriElementList& Cube::vTriElements() { return _tris; } -void Cube::vReleaseVertexElements() -{ +void Cube::vReleaseVertexElements() { terminateVertices(); } -unsigned char Cube::s_faceIndexToHalfSpaceMask[6] = { +unsigned char Cube::_sFaceIndexToHalfSpaceMask[6] = { OctreeElement::HalfSpace::Bottom, OctreeElement::HalfSpace::Top, OctreeElement::HalfSpace::Right, @@ -244,7 +227,7 @@ unsigned char Cube::s_faceIndexToHalfSpaceMask[6] = { #ifdef CW_CONSTRUCTION // Construction vectors ordered such that the vertices of each face are // CW in a right-handed coordinate system with B-L-N at 0,0,0. -float Cube::s_vertexIndexToConstructionVector[24][3] = { +float Cube::_sVertexIndexToConstructionVector[24][3] = { // Bottom { 0,0,0 }, { 1,0,0 }, @@ -279,7 +262,7 @@ float Cube::s_vertexIndexToConstructionVector[24][3] = { #else // CW_CONSTRUCTION // Construction vectors ordered such that the vertices of each face are // CCW in a right-handed coordinate system with B-L-N at 0,0,0. -float Cube::s_vertexIndexToConstructionVector[24][3] = { +float Cube::_sVertexIndexToConstructionVector[24][3] = { // Bottom { 0,0,0 }, { 0,0,1 }, @@ -314,7 +297,7 @@ float Cube::s_vertexIndexToConstructionVector[24][3] = { #endif // Normals for a right-handed coordinate system -float Cube::s_vertexIndexToNormalVector[6][3] = { +float Cube::_sVertexIndexToNormalVector[6][3] = { { 0,-1, 0 }, // Bottom { 0, 1, 0 }, // Top { 1, 0, 0 }, // Right @@ -323,29 +306,26 @@ float Cube::s_vertexIndexToNormalVector[6][3] = { { 0, 0, 1 }, // Far }; -Renderer::Renderer() -{} +Renderer::Renderer() { +} -Renderer::~Renderer() -{} +Renderer::~Renderer() { +} // Simple dispatch between API and SPI int Renderer::add( - Primitive *primitive - ) -{ + Primitive* primitive + ) { return vAdd(primitive); } void Renderer::remove( int id - ) -{ + ) { vRemove(id); } -void Renderer::render() -{ +void Renderer::render() { vRender(); } @@ -369,19 +349,19 @@ PrimitiveRenderer::PrimitiveRenderer( initialize(); } -PrimitiveRenderer::~PrimitiveRenderer() -{ +PrimitiveRenderer::~PrimitiveRenderer() { + terminate(); } -void PrimitiveRenderer::initialize() -{ +void PrimitiveRenderer::initialize() { + initializeGL(); initializeBookkeeping(); } -void PrimitiveRenderer::initializeGL() -{ +void PrimitiveRenderer::initializeGL() { + glGenBuffers(1, &_triBufferId); glGenBuffers(1, &_vertexBufferId); @@ -417,51 +397,54 @@ void PrimitiveRenderer::initializeGL() GLint err = glGetError(); } -void PrimitiveRenderer::initializeBookkeeping() -{ +void PrimitiveRenderer::initializeBookkeeping() { + + // Start primitive count at one, because zero is reserved for the degenerate triangle _primitiveCount = 1; _cpuMemoryUsage = sizeof(PrimitiveRenderer); } -void PrimitiveRenderer::terminate() -{ +void PrimitiveRenderer::terminate() { + terminateBookkeeping(); terminateGL(); } -void PrimitiveRenderer::terminateGL() -{ +void PrimitiveRenderer::terminateGL() { + glDeleteBuffers(1, &_vertexBufferId); glDeleteBuffers(1, &_triBufferId); GLint err = glGetError(); } -void PrimitiveRenderer::terminateBookkeeping() -{ +void PrimitiveRenderer::terminateBookkeeping() { + // Drain all of the queues, stop updating the counters - while (_availableVertexElementIndex.remove()); - while (_availableTriElementIndex.remove()); - while (_deconstructTriElementIndex.remove()); + while (_availableVertexElementIndex.remove() != 0) + ; + + while (_availableTriElementIndex.remove() != 0) + ; + + while (_deconstructTriElementIndex.remove() != 0) + ; std::map::iterator it = _indexToPrimitiveMap.begin(); std::map::iterator end = _indexToPrimitiveMap.end(); - for ( ; it != end; ++it) - { + for ( ; it != end; ++it) { Primitive *primitive = it->second; delete primitive; } } int PrimitiveRenderer::vAdd( - Primitive *primitive - ) -{ + Primitive* primitive + ) { + int index = getAvailablePrimitiveIndex(); - if (index != 0) - { - try - { + if (index != 0) { + try { // Take ownership of primitive, including responsibility // for destruction _indexToPrimitiveMap[index] = primitive; @@ -469,9 +452,7 @@ int PrimitiveRenderer::vAdd( // No need to keep an extra copy of the vertices primitive->releaseVertexElements(); - } - catch(...) - { + } catch(...) { // STL failed, recycle the index _availablePrimitiveIndex.add(index); index = 0; @@ -482,17 +463,15 @@ int PrimitiveRenderer::vAdd( void PrimitiveRenderer::vRemove( int index - ) -{ - try - { + ) { + + try { + // Locate the primitive by id in the associative map std::map::iterator it = _indexToPrimitiveMap.find(index); - if (it != _indexToPrimitiveMap.end()) - { + if (it != _indexToPrimitiveMap.end()) { Primitive *primitive = it->second; - if (primitive) - { + if (primitive) { _indexToPrimitiveMap[index] = 0; deconstructElements(primitive); _availablePrimitiveIndex.add(index); @@ -501,31 +480,27 @@ void PrimitiveRenderer::vRemove( // the index is going to be re-used, but if you want to... uncomment the following: //_indexToPrimitiveMap.erase(it); } - } - catch(...) - { + } catch(...) { // STL failed } } void PrimitiveRenderer::constructElements( - Primitive *primitive - ) -{ + Primitive* primitive + ) { + // Load vertex elements - VertexElementIndexList & vertexElementIndexList = primitive->vertexElementIndices(); + VertexElementIndexList& vertexElementIndexList = primitive->vertexElementIndices(); { VertexElementList const & vertices = primitive->vertexElements(); VertexElementList::const_iterator it = vertices.begin(); VertexElementList::const_iterator end = vertices.end(); - for ( ; it != end; ++it ) - { + for ( ; it != end; ++it ) { int index = getAvailableVertexElementIndex(); - if (index != 0) - { + if (index != 0) { vertexElementIndexList.push_back(index); - VertexElement *vertex = *it; + VertexElement* vertex = *it; transferVertexElement(index, vertex); } } @@ -533,16 +508,14 @@ void PrimitiveRenderer::constructElements( // Load tri elements { - TriElementList & tris = primitive->triElements(); + TriElementList& tris = primitive->triElements(); TriElementList::iterator it = tris.begin(); TriElementList::iterator end = tris.end(); - for ( ; it != end; ++it) - { - TriElement *tri = *it; + for ( ; it != end; ++it) { + TriElement* tri = *it; int index = getAvailableTriElementIndex(); - if (index != 0) - { + if (index != 0) { int k; k = tri->indices[0]; tri->indices[0] = vertexElementIndexList[k]; @@ -561,18 +534,17 @@ void PrimitiveRenderer::constructElements( } void PrimitiveRenderer::deconstructElements( - Primitive *primitive - ) -{ + Primitive* primitive + ) { + // Schedule the tri elements of the face for deconstruction { - TriElementList & tris = primitive->triElements(); + TriElementList& tris = primitive->triElements(); TriElementList::iterator it = tris.begin(); TriElementList::iterator end = tris.end(); - for ( ; it != end; ++it) - { - TriElement *tri = *it; + for ( ; it != end; ++it) { + TriElement* tri = *it; // Put the tri element index into decon queue _deconstructTriElementIndex.add(tri->id); @@ -581,12 +553,11 @@ void PrimitiveRenderer::deconstructElements( // Return the vertex element index to the available queue, it is not necessary // to zero the data { - VertexElementIndexList & vertexIndexList = primitive->vertexElementIndices(); + VertexElementIndexList& vertexIndexList = primitive->vertexElementIndices(); VertexElementIndexList::iterator it = vertexIndexList.begin(); VertexElementIndexList::iterator end = vertexIndexList.end(); - for ( ; it != end; ++it) - { + for ( ; it != end; ++it) { int index = *it; // Put the vertex element index into the available queue @@ -598,13 +569,12 @@ void PrimitiveRenderer::deconstructElements( delete primitive; } -int PrimitiveRenderer::getAvailablePrimitiveIndex() -{ +int PrimitiveRenderer::getAvailablePrimitiveIndex() { + // Check the available primitive index queue first for an available index. int index = _availablePrimitiveIndex.remove(); // Remember that the primitive index 0 is used not used. - if (index == 0) - { + if (index == 0) { // There are no primitive indices available from the queue, // make one up index = _primitiveCount++; @@ -612,37 +582,36 @@ int PrimitiveRenderer::getAvailablePrimitiveIndex() return index; } -int PrimitiveRenderer::getAvailableVertexElementIndex() -{ +int PrimitiveRenderer::getAvailableVertexElementIndex() { + // Check the available vertex element queue first for an available index. int index = _availableVertexElementIndex.remove(); // Remember that the vertex element 0 is used for degenerate triangles. - if (index == 0) - { + if (index == 0) { // There are no vertex elements available from the queue, // grab one from the end of the list - if (_vertexElementCount < _maxVertexElementCount) + if (_vertexElementCount < _maxVertexElementCount) { index = _vertexElementCount++; + } } return index; } -int PrimitiveRenderer::getAvailableTriElementIndex() -{ +int PrimitiveRenderer::getAvailableTriElementIndex() { + // Check the deconstruct tri element queue first for an available index. int index = _deconstructTriElementIndex.remove(); // Remember that the tri element 0 is used for degenerate triangles. - if (index == 0) - { + if (index == 0) { // There are no tri elements in the deconstruct tri element queue that are reusable. // Check the available tri element queue. index = _availableTriElementIndex.remove(); - if (index == 0) - { + if (index == 0) { // There are no reusable tri elements available from any queue, // grab one from the end of the list - if (_triElementCount < _maxTriElementCount) + if (_triElementCount < _maxTriElementCount) { index = _triElementCount++; + } } } return index; @@ -650,8 +619,8 @@ int PrimitiveRenderer::getAvailableTriElementIndex() void PrimitiveRenderer::deconstructTriElement( int idx - ) -{ + ) { + // Set the element to the degenerate case. int degenerate[3] = { 0, 0, 0 }; transferTriElement(idx, degenerate); @@ -660,9 +629,9 @@ void PrimitiveRenderer::deconstructTriElement( void PrimitiveRenderer::transferVertexElement( int idx, - VertexElement *vertex - ) -{ + VertexElement* vertex + ) { + glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferId); glBufferSubData(GL_ARRAY_BUFFER, idx * sizeof(VertexElement), sizeof(VertexElement), vertex); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -671,20 +640,19 @@ void PrimitiveRenderer::transferVertexElement( void PrimitiveRenderer::transferTriElement( int idx, int tri[3] -) -{ + ) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _triBufferId); glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, idx * sizeof(GLint) * 3, sizeof(GLint) * 3, tri); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void PrimitiveRenderer::vRender() -{ +void PrimitiveRenderer::vRender() { + // Now would be an appropriate time to set the element array buffer ids // scheduled for deconstruction to the degenerate case. int id; - while ((id = _deconstructTriElementIndex.remove())) - { + while ((id = _deconstructTriElementIndex.remove()) != 0) { deconstructTriElement(id); _availableTriElementIndex.add(id); } diff --git a/interface/src/PrimitiveRenderer.h b/interface/src/PrimitiveRenderer.h index e54842c229..24fee66184 100644 --- a/interface/src/PrimitiveRenderer.h +++ b/interface/src/PrimitiveRenderer.h @@ -1,24 +1,23 @@ -/** - * @file PrimitiveRenderer.h - * A geometric primitive renderer. - * - * @author: Norman Crafts - * @copyright 2014, High Fidelity, Inc. All rights reserved. - */ +/// +/// @file PrimitiveRenderer.h +/// A geometric primitive renderer. +/// +/// @author: Norman Crafts +/// @copyright 2014, High Fidelity, Inc. All rights reserved. +/// #ifndef __interface__PrimitiveRenderer__ #define __interface__PrimitiveRenderer__ #include -#include +#include "Queue.h" -/** Vertex element structure - * Using the array of structures approach to specifying - * vertex data to GL cuts down on the calls to glBufferSubData - */ +/// Vertex element structure. +/// Using the array of structures approach to specifying +/// vertex data to GL cuts down on the calls to glBufferSubData +/// typedef - struct __VertexElement - { + struct __VertexElement { struct __position { float x; float y; @@ -37,102 +36,98 @@ typedef } color; } VertexElement; -/** Triangle element index structure - * Specify the vertex indices of the triangle and its element index. - */ -typedef -struct __TriElement -{ - int indices[3]; - int id; +/// Triangle element index structure. +/// Specify the vertex indices of the triangle and its element index. +/// +typedef + struct __TriElement { + int indices[3]; + int id; -} TriElement; + } TriElement; typedef std::vector > VertexElementList; typedef std::vector > VertexElementIndexList; typedef std::vector > TriElementList; -/** - * @class Primitive - * Primitive Interface class - * Abstract class for accessing vertex and tri elements of geometric primitives - * - */ -class Primitive -{ +/// +/// @class Primitive +/// Primitive Interface class. +/// Abstract class for accessing vertex and tri elements of geometric primitives +/// +/// +class Primitive { public: virtual ~Primitive(); // API methods go here - /** Vertex element accessor - * @return A list of vertex elements of the primitive - */ + /// Vertex element accessor. + /// @return A list of vertex elements of the primitive + /// VertexElementList const & vertexElements() const; - /** Vertex element index accessor - * @return A list of vertex element indices of the primitive - */ - VertexElementIndexList & vertexElementIndices(); + /// Vertex element index accessor. + /// @return A list of vertex element indices of the primitive + /// + VertexElementIndexList& vertexElementIndices(); - /** Tri element accessor - * @return A list of tri elements of the primitive - */ - TriElementList & triElements(); + /// Tri element accessor. + /// @return A list of tri elements of the primitive + /// + TriElementList& triElements(); - /** Release vertex elements - */ + /// Release vertex elements. + /// void releaseVertexElements(); protected: - /** Default constructor prohibited to API user, restricted to service implementer - */ + /// Default constructor prohibited to API user, restricted to service implementer. + /// Primitive(); private: - /** Copy constructor prohibited - */ + /// Copy constructor prohibited. + /// Primitive( Primitive const & prim ); // SPI methods are defined here - /** Vertex element accessor - * Service implementer to provide private override for this method - * in derived class - */ + /// Vertex element accessor. + /// Service implementer to provide private override for this method + /// in derived class + /// virtual VertexElementList const & vVertexElements() const = 0; - /** Vertex element index accessor - * Service implementer to provide private override for this method - * in derived class - */ - virtual VertexElementIndexList & vVertexElementIndices() = 0; + /// Vertex element index accessor. + /// Service implementer to provide private override for this method + /// in derived class + /// + virtual VertexElementIndexList& vVertexElementIndices() = 0; - /** Tri element accessor - * Service implementer to provide private override for this method - * in derived class - */ - virtual TriElementList & vTriElements() = 0; + /// Tri element accessor. + /// Service implementer to provide private override for this method + /// in derived class + /// + virtual TriElementList& vTriElements() = 0; - /** Release vertex elements - */ + /// Release vertex elements. + /// virtual void vReleaseVertexElements() = 0; }; -/** - * @class Cube - * Class for accessing the vertex and tri elements of a cube - */ -class Cube: - public Primitive -{ +/// +/// @class Cube +/// Class for accessing the vertex and tri elements of a cube +/// +class Cube: public Primitive { public: - /** Configuration dependency injection constructor - */ + /// Configuration dependency injection constructor. + /// Cube( float x, float y, @@ -147,8 +142,8 @@ public: ~Cube(); private: - /** Copy constructor prohibited - */ + /// Copy constructor prohibited. + /// Cube ( Cube const & cube ); @@ -188,8 +183,8 @@ private: // SPI virtual override methods go here VertexElementList const & vVertexElements() const; - VertexElementIndexList & vVertexElementIndices(); - TriElementList & vTriElements(); + VertexElementIndexList& vVertexElementIndices(); + TriElementList& vTriElements(); void vReleaseVertexElements(); @@ -198,91 +193,90 @@ private: VertexElementIndexList _vertexIndices; ///< Vertex element index list TriElementList _tris; ///< Tri element list - static unsigned char s_faceIndexToHalfSpaceMask[6]; - static float s_vertexIndexToConstructionVector[24][3]; - static float s_vertexIndexToNormalVector[6][3]; + static const int _sNumFacesPerCube = 6; + static const int _sNumVerticesPerCube = 24; + static unsigned char _sFaceIndexToHalfSpaceMask[6]; + static float _sVertexIndexToConstructionVector[24][3]; + static float _sVertexIndexToNormalVector[6][3]; }; -/** - * @class Renderer - * GL renderer interface class - * Abstract class for rendering geometric primitives in GL - */ -class Renderer -{ +/// +/// @class Renderer +/// GL renderer interface class. +/// Abstract class for rendering geometric primitives in GL +/// +class Renderer { public: virtual ~Renderer(); // API methods go here - /** Add primitive to renderer database - */ + /// Add primitive to renderer database. + /// int add( - Primitive *primitive ///< Pointer to primitive + Primitive* primitive ///< Pointer to primitive ); - /** Remove primitive from renderer database - */ + /// Remove primitive from renderer database. + /// void remove( int id ///< Primitive id ); - /** Render primitive database - * The render method assumes appropriate GL context and state has - * already been provided for - */ + /// Render primitive database. + /// The render method assumes appropriate GL context and state has + /// already been provided for + /// void render(); protected: - /** Default constructor prohibited to API user, restricted to service implementer - */ + /// Default constructor prohibited to API user, restricted to service implementer. + /// Renderer(); private: - /** Copy constructor prohibited - */ + /// Copy constructor prohibited. + /// Renderer( Renderer const & primitive ); // SPI methods are defined here - /** Add primitive to renderer database - * Service implementer to provide private override for this method - * in derived class - */ + /// Add primitive to renderer database. + /// Service implementer to provide private override for this method + /// in derived class + /// virtual int vAdd( - Primitive *primitive ///< Pointer to primitive + Primitive* primitive ///< Pointer to primitive ) = 0; - /** Remove primitive from renderer database - * Service implementer to provide private override for this method - * in derived class - */ + /// Remove primitive from renderer database. + /// Service implementer to provide private override for this method + /// in derived class + /// virtual void vRemove( int id ///< Primitive id ) = 0; - /** Render primitive database - * Service implementer to provide private virtual override for this method - * in derived class - */ + /// Render primitive database. + /// Service implementer to provide private virtual override for this method + /// in derived class + /// virtual void vRender() = 0; }; -/** - * @class PrimitiveRenderer - * Renderer implementation class for the rendering of geometric primitives - * using GL element array and GL array buffers - */ -class PrimitiveRenderer : - public Renderer -{ +/// +/// @class PrimitiveRenderer +/// Renderer implementation class for the rendering of geometric primitives +/// using GL element array and GL array buffers +/// +class PrimitiveRenderer : public Renderer { public: - /** Configuration dependency injection constructor - */ + /// Configuration dependency injection constructor. + /// PrimitiveRenderer( int maxCount ); @@ -290,12 +284,12 @@ public: ~PrimitiveRenderer(); private: - /** Default constructor prohibited - */ + /// Default constructor prohibited. + /// PrimitiveRenderer(); - /** Copy constructor prohibited - */ + /// Copy constructor prohibited. + /// PrimitiveRenderer( PrimitiveRenderer const & renderer ); @@ -303,84 +297,84 @@ private: void initialize(); void terminate(); - /** Allocate and initialize GL buffers - */ + /// Allocate and initialize GL buffers. + /// void initializeGL(); - /** Terminate and deallocate GL buffers - */ + /// Terminate and deallocate GL buffers. + /// void terminateGL(); void initializeBookkeeping(); void terminateBookkeeping(); - /** Construct the elements of the faces of the primitive - */ + /// Construct the elements of the faces of the primitive. + /// void constructElements( - Primitive *primitive + Primitive* primitive ); - /** Deconstruct the elements of the faces of the primitive - */ + /// Deconstruct the elements of the faces of the primitive. + /// void deconstructElements( - Primitive *primitive + Primitive* primitive ); - /** Deconstruct the triangle element from the GL buffer - */ + /// Deconstruct the triangle element from the GL buffer. + /// void deconstructTriElement( int idx ); - /** Transfer the vertex element to the GL buffer - */ + /// Transfer the vertex element to the GL buffer. + /// void transferVertexElement( int idx, VertexElement *vertex ); - /** Transfer the triangle element to the GL buffer - */ + /// Transfer the triangle element to the GL buffer. + /// void transferTriElement( int idx, int tri[3] ); - /** Get available primitive index - * Get an available primitive index from either the recycling - * queue or incrementing the counter - */ + /// Get available primitive index. + /// Get an available primitive index from either the recycling + /// queue or incrementing the counter + /// int getAvailablePrimitiveIndex(); - /** Get available vertex element index - * Get an available vertex element index from either the recycling - * queue or incrementing the counter - */ + /// Get available vertex element index. + /// Get an available vertex element index from either the recycling + /// queue or incrementing the counter + /// int getAvailableVertexElementIndex(); - /** Get available triangle element index - * Get an available triangle element index from either the elements - * scheduled for deconstruction queue, the recycling - * queue or incrementing the counter - */ + /// Get available triangle element index. + /// Get an available triangle element index from either the elements + /// scheduled for deconstruction queue, the recycling + /// queue or incrementing the counter + /// int getAvailableTriElementIndex(); // SPI virtual override methods go here - /** Add primitive to renderer database - */ + /// Add primitive to renderer database. + /// int vAdd( - Primitive *primitive + Primitive* primitive ); - /** Remove primitive from renderer database - */ + /// Remove primitive from renderer database. + /// void vRemove( int id ); - /** Render triangle database - */ + /// Render triangle database. + /// void vRender(); private: @@ -400,7 +394,7 @@ private: int _triElementCount; ///< Count of triangles int _maxTriElementCount; ///< Max count of triangles - std::map _indexToPrimitiveMap; ///< Associative map between index and primitive + std::map _indexToPrimitiveMap; ///< Associative map between index and primitive int _primitiveCount; ///< Count of primitives Queue _availablePrimitiveIndex; ///< Queue of primitive indices available diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 454f82f6b6..d128627b42 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -1050,15 +1050,13 @@ int VoxelSystem::updateNodeInArrays(VoxelTreeElement* node, bool reuseIndex, boo if (primitiveIndex) { _renderer->remove(primitiveIndex); node->setPrimitiveIndex(0); - } - else { + } else { node->setVoxelSystem(this); } inspectForInteriorOcclusionsOperation(node, 0); - if (node->getInteriorOcclusions() != OctreeElement::HalfSpace::All) - { - Cube *cube = new Cube( + if (node->getInteriorOcclusions() != OctreeElement::HalfSpace::All) { + Cube* cube = new Cube( startVertex.x, startVertex.y, startVertex.z, voxelScale, color[RED_INDEX], color[GREEN_INDEX], color[BLUE_INDEX], node->getInteriorOcclusions()); @@ -1067,8 +1065,7 @@ int VoxelSystem::updateNodeInArrays(VoxelTreeElement* node, bool reuseIndex, boo node->setPrimitiveIndex(primitiveIndex); } } - } - else { + } else { glBufferIndex nodeIndex = GLBUFFER_INDEX_UNKNOWN; if (reuseIndex && node->isKnownBufferIndex()) { nodeIndex = node->getBufferIndex(); @@ -1531,12 +1528,12 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, } // Bit mask of occluded shared faces indexed by child - unsigned char occludedSharedFace[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + unsigned char occludedSharedFace[NUMBER_OF_CHILDREN] = { 0, 0, 0, 0, 0, 0, 0, 0 }; // Traverse all pair combinations of children for (int i = NUMBER_OF_CHILDREN; --i >= 0; ) { - VoxelTreeElement *childA = voxel->getChildAtIndex(i); + VoxelTreeElement* childA = voxel->getChildAtIndex(i); if (childA) { // Get the child A's occluding faces, for a leaf that will be @@ -1551,7 +1548,7 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, for (int j = i; --j >= 0; ) { - VoxelTreeElement *childB = voxel->getChildAtIndex(j); + VoxelTreeElement* childB = voxel->getChildAtIndex(j); if (childB) { // Get child B's occluding faces @@ -1564,22 +1561,22 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, // Determine the shared halfspace partition between siblings A and B, // i.e., near/far, left/right, or top/bottom - unsigned char partition = octantIndexToSharedBitMask[i][j] & + unsigned char partition = _sOctantIndexToSharedBitMask[i][j] & exteriorOcclusionsA & exteriorOcclusionsB; - // Determine which face of each sibling is occluded. + // Determine which face of each sibling is occluded. // Note the intentionally crossed indicies. It is necessary because - // the octantIndexToBitMask is a partition occupancy mask. For + // the _sOctantIndexToBitMask is a partition occupancy mask. For // example, if the near-left-top (NLT) and near-left-bottom (NLB) child voxels // exist, the shared partition is top-bottom (TB), and thus the occluded // shared face of the NLT voxel is its bottom face. - occludedSharedFace[i] |= (partition & octantIndexToBitMask[j]); - occludedSharedFace[j] |= (partition & octantIndexToBitMask[i]); + occludedSharedFace[i] |= (partition & _sOctantIndexToBitMask[j]); + occludedSharedFace[j] |= (partition & _sOctantIndexToBitMask[i]); } } // Combine this voxel's interior excluded shared face only to those children which are coincident // with the excluded face. - occludedSharedFace[i] |= (voxel->getInteriorOcclusions() & octantIndexToBitMask[i]); + occludedSharedFace[i] |= (voxel->getInteriorOcclusions() & _sOctantIndexToBitMask[i]); // Inform the child childA->setInteriorOcclusions(occludedSharedFace[i]); @@ -1610,13 +1607,13 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, // Traverse all children for (int i = NUMBER_OF_CHILDREN; --i >= 0; ) { - VoxelTreeElement *child = voxel->getChildAtIndex(i); + VoxelTreeElement* child = voxel->getChildAtIndex(i); if (child) { // Get the child's occluding faces, for a leaf, that will be // all six voxel faces, and for a non leaf, that will be // all faces which are completely covered by four child octants. unsigned char exteriorOcclusionsOfChild = child->getExteriorOcclusions(); - exteriorOcclusionsOfChild &= octantIndexToBitMask[i]; + exteriorOcclusionsOfChild &= _sOctantIndexToBitMask[i]; for (int j = 6; --j >= 0; ) { @@ -1656,9 +1653,7 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, // occupied. Hence, the subtree from this node could be // pruned and replaced by a leaf voxel, if the visible // properties of the children are the same - } - else - if (exteriorOcclusions) { + } else if (exteriorOcclusions) { //const glm::vec3& v = voxel->getCorner(); //float s = voxel->getScale(); @@ -1682,8 +1677,7 @@ bool VoxelSystem::clearOcclusionsOperation(OctreeElement* element, void* extraDa // And the sibling occluders voxel->setInteriorOcclusions(0); rc = false; - } - else { + } else { voxel->setExteriorOcclusions(0); voxel->setInteriorOcclusions(0); rc = true; @@ -1711,8 +1705,7 @@ void VoxelSystem::cullSharedFaces() { _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation); unlockTree(); qDebug("culling shared faces in %d nodes", _nodeCount); - } - else { + } else { cleanupVoxelMemory(); _usePrimitiveRenderer = false; initVoxelMemory(); @@ -3112,7 +3105,7 @@ void VoxelSystem::beginLoadingLocalVoxelCache() { // Octant bitmask array indexed by octant. The mask value indicates the octant's halfspace partitioning. The index // value corresponds to the voxel's octal code derived in "pointToVoxel" in SharedUtil.cpp, which, BTW, does *not* // correspond to the "ChildIndex" enum value in OctreeElement.h -unsigned char VoxelSystem::octantIndexToBitMask[8] = { +unsigned char VoxelSystem::_sOctantIndexToBitMask[8] = { OctreeElement::HalfSpace::Bottom | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Near, OctreeElement::HalfSpace::Bottom | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Far, OctreeElement::HalfSpace::Top | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Near, @@ -3125,7 +3118,7 @@ unsigned char VoxelSystem::octantIndexToBitMask[8] = { // Two dimensional array map indexed by octant row and column. The mask value // indicates the two faces shared by the octants -unsigned char VoxelSystem::octantIndexToSharedBitMask[8][8] = { +unsigned char VoxelSystem::_sOctantIndexToSharedBitMask[8][8] = { { // Index 0: Bottom-Left-Near 0, // Bottom-Left-Near OctreeElement::HalfSpace::Near | OctreeElement::HalfSpace::Far, // Bottom-Left-Far diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index da92b8921e..ee8c28178e 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -315,11 +315,11 @@ private: void lockTree(); void unlockTree(); - bool _usePrimitiveRenderer; - PrimitiveRenderer *_renderer; ///< Voxel renderer + bool _usePrimitiveRenderer; ///< Flag primitive renderer for use + PrimitiveRenderer* _renderer; ///< Voxel renderer - static unsigned char octantIndexToBitMask[8]; ///< Map octant index to partition mask - static unsigned char octantIndexToSharedBitMask[8][8]; ///< Map octant indices to shared partition mask + static unsigned char _sOctantIndexToBitMask[8]; ///< Map octant index to partition mask + static unsigned char _sOctantIndexToSharedBitMask[8][8]; ///< Map octant indices to shared partition mask }; diff --git a/libraries/voxels/src/VoxelTreeElement.h b/libraries/voxels/src/VoxelTreeElement.h index 208148fa7d..a3c112fcde 100644 --- a/libraries/voxels/src/VoxelTreeElement.h +++ b/libraries/voxels/src/VoxelTreeElement.h @@ -99,8 +99,8 @@ protected: private: int _primitiveIndex; - unsigned char _exteriorOcclusions; ///< exterior shared partition boundaries that are completely occupied - unsigned char _interiorOcclusions; ///< interior shared partition boundaries with siblings + unsigned char _exteriorOcclusions; /// exterior shared partition boundaries that are completely occupied + unsigned char _interiorOcclusions; /// interior shared partition boundaries with siblings }; inline void VoxelTreeElement::setExteriorOcclusions(unsigned char exteriorOcclusions) {