From 7f9ce5a4cd3749482a9e7446aa0a3a064620b51d Mon Sep 17 00:00:00 2001 From: LaShonda Hopper Date: Mon, 2 Oct 2017 17:47:51 -0400 Subject: [PATCH] [WL21389][BuildFix] Minor refactor due to render-utils lib change (details below). As of Commit b93e91b9, render-utils no longer knows about entity lib. This commit adjusts for that by altering the signature of GeometryCache::computeSimpleHullPointListForShape to take in portions of ShapeEntityItem data as opposed to the entity pointer. Fixes build failure mentioned in: https://github.com/highfidelity/hifi/pull/11336#issuecomment-333635794 Reviewed-by: Leander Hasty Changes Committed: modified: interface/src/Util.cpp modified: libraries/render-utils/src/GeometryCache.cpp modified: libraries/render-utils/src/GeometryCache.h --- interface/src/Util.cpp | 9 +++++- libraries/render-utils/src/GeometryCache.cpp | 34 +++++++++++--------- libraries/render-utils/src/GeometryCache.h | 3 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 6077c8ec42..9fdd5e4b76 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -396,11 +396,18 @@ void runUnitTests() { } void shapeInfoCalculator(const ShapeEntityItem * const shapeEntity, ShapeInfo &shapeInfo) { + + if (shapeEntity == nullptr) { + + //--EARLY EXIT-- + return; + } + ShapeInfo::PointCollection pointCollection; ShapeInfo::PointList points; pointCollection.push_back(points); - GeometryCache::computeSimpleHullPointListForShape(shapeEntity, pointCollection.back()); + GeometryCache::computeSimpleHullPointListForShape((int)shapeEntity->getShape(), shapeEntity->getDimensions() * 0.5f, pointCollection.back()); shapeInfo.setPointCollection(pointCollection); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8164a54a57..6a624e2cd8 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -23,7 +23,6 @@ #include #include -#include #include "TextureCache.h" #include "RenderUtilsLogging.h" @@ -53,7 +52,12 @@ //#define WANT_DEBUG -static std::array MAPPING{ { +// @note: Originally size entity::NUM_SHAPES +// As of Commit b93e91b9, render-utils no longer retains knowledge of +// entity lib, and thus doesn't know about entity::NUM_SHAPES. Should +// the enumerations be altered, this will need to be updated. +// @see ShapeEntityItem.h +static std::array MAPPING{ { GeometryCache::Triangle, GeometryCache::Quad, GeometryCache::Hexagon, @@ -88,16 +92,11 @@ static gpu::Stream::FormatPointer INSTANCED_SOLID_FADE_STREAM_FORMAT; static const uint SHAPE_VERTEX_STRIDE = sizeof(glm::vec3) * 2; // vertices and normals static const uint SHAPE_NORMALS_OFFSET = sizeof(glm::vec3); -void GeometryCache::computeSimpleHullPointListForShape(const ShapeEntityItem * const shapePtr, QVector &outPointList){ - - if (shapePtr == nullptr){ - //--EARLY EXIT-- - return; - } +void GeometryCache::computeSimpleHullPointListForShape(const int entityShape, const glm::vec3 &entityHalfExtents, QVector &outPointList) { auto geometryCache = DependencyManager::get(); - const GeometryCache::Shape entityGeometryShape = GeometryCache::getShapeForEntityShape(shapePtr->getShape()); - const GeometryCache::ShapeData * shapeData = geometryCache->getShapeData( entityGeometryShape ); + const GeometryCache::Shape geometryShape = GeometryCache::getShapeForEntityShape( entityShape ); + const GeometryCache::ShapeData * shapeData = geometryCache->getShapeData( geometryShape ); if (!shapeData){ //--EARLY EXIT--( data isn't ready for some reason... ) return; @@ -107,12 +106,11 @@ void GeometryCache::computeSimpleHullPointListForShape(const ShapeEntityItem * c assert(shapeVerts._size == shapeNorms._size); const gpu::BufferView::Size numItems = shapeVerts.getNumElements(); - const glm::vec3 halfExtents = shapePtr->getDimensions() * 0.5f; outPointList.reserve((int)numItems); for (gpu::BufferView::Index i = 0; i < (gpu::BufferView::Index)numItems; ++i) { const geometry::Vec &curNorm = shapeNorms.get(i); - outPointList.push_back(curNorm * halfExtents); + outPointList.push_back(curNorm * entityHalfExtents); } } @@ -488,14 +486,17 @@ void GeometryCache::buildShapes() { extrudePolygon<64>(_shapes[Cone], _shapeVertices, _shapeIndices, true); //Circle drawCircle(_shapes[Circle], _shapeVertices, _shapeIndices); - // Not implememented yet: + // Not implemented yet: //Quad, //Torus, } const GeometryCache::ShapeData * GeometryCache::getShapeData(const Shape shape) const { - if (((int)shape < 0) || ((int)shape >= (int)_shapes.size())){ + if (((int)shape < 0) || ((int)shape >= (int)_shapes.size())) { + qCWarning(renderutils) << "GeometryCache::getShapeData - Invalid shape " << shape << " specified. Returning default fallback."; + + //--EARLY EXIT--( No valid shape data for shape ) return nullptr; } @@ -503,7 +504,10 @@ const GeometryCache::ShapeData * GeometryCache::getShapeData(const Shape shape) } GeometryCache::Shape GeometryCache::getShapeForEntityShape(int entityShape) { - if ((entityShape < 0) || (entityShape >= (int)MAPPING.size())){ + if ((entityShape < 0) || (entityShape >= (int)MAPPING.size())) { + qCWarning(renderutils) << "GeometryCache::getShapeForEntityShape - Invalid shape " << entityShape << " specified. Returning default fallback."; + + //--EARLY EXIT--( fall back to default assumption ) return GeometryCache::Sphere; } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 867c4bc3ee..2e81c825be 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -32,7 +32,6 @@ #include class SimpleProgramKey; -class ShapeEntityItem; typedef QPair Vec2FloatPair; typedef QPair Vec2FloatPairPair; @@ -155,7 +154,7 @@ public: /// specified entityShapeEnum static GeometryCache::Shape getShapeForEntityShape(int entityShapeEnum); - static void computeSimpleHullPointListForShape(const ShapeEntityItem * const shapePtr, QVector &outPointList); + static void computeSimpleHullPointListForShape(int entityShape, const glm::vec3 &entityHalfExtents, QVector &outPointList); static uint8_t CUSTOM_PIPELINE_NUMBER; static render::ShapePipelinePointer shapePipelineFactory(const render::ShapePlumber& plumber, const render::ShapeKey& key);