diff --git a/components/sceneutil/pathgridutil.cpp b/components/sceneutil/pathgridutil.cpp index f78eea47c4..b4de250e77 100644 --- a/components/sceneutil/pathgridutil.cpp +++ b/components/sceneutil/pathgridutil.cpp @@ -5,6 +5,8 @@ #include +#include + namespace SceneUtil { namespace @@ -40,24 +42,15 @@ namespace SceneUtil const osg::Vec4f DiamondEdgeColor = osg::Vec4f(0.5f, 1.f, 1.f, 1.f); const osg::Vec4f DiamondWireColor = osg::Vec4f(0.72f, 0.f, 0.96f, 1.f); const osg::Vec4f DiamondFocusWireColor = osg::Vec4f(0.91f, 0.66f, 1.f, 1.f); - } - - osg::ref_ptr createPathgridGeometry(const ESM::Pathgrid& pathgrid) - { - const size_t vertexCount = pathgrid.mPoints.size() * DiamondTotalVertexCount; - const size_t pointIndexCount = pathgrid.mPoints.size() * DiamondIndexCount; - const size_t edgeIndexCount = pathgrid.mEdges.size() * 2; - osg::ref_ptr gridGeometry = new osg::Geometry(); - - if (pointIndexCount || edgeIndexCount) + template + void addPathgridToGeometry(const size_t vertexCount, const size_t pointIndexCount, const size_t edgeIndexCount, + osg::ref_ptr& gridGeometry, const ESM::Pathgrid& pathgrid) { osg::ref_ptr vertices = new osg::Vec3Array(vertexCount); osg::ref_ptr colors = new osg::Vec4Array(vertexCount); - osg::ref_ptr pointIndices - = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, pointIndexCount); - osg::ref_ptr lineIndices - = new osg::DrawElementsUInt(osg::PrimitiveSet::LINES, edgeIndexCount); + osg::ref_ptr pointIndices = new PType(osg::PrimitiveSet::TRIANGLES, pointIndexCount); + osg::ref_ptr lineIndices = new LType(osg::PrimitiveSet::LINES, edgeIndexCount); // Add each point/node for (size_t pointIndex = 0; pointIndex < pathgrid.mPoints.size(); ++pointIndex) @@ -140,27 +133,14 @@ namespace SceneUtil gridGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); } - osg::ref_ptr material = new osg::Material; - material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - gridGeometry->getOrCreateStateSet()->setAttribute(material); - - return gridGeometry; - } - - osg::ref_ptr createPathgridSelectedWireframe( - const ESM::Pathgrid& pathgrid, const std::vector& selected) - { - const size_t vertexCount = selected.size() * DiamondVertexCount; - const size_t indexCount = selected.size() * DiamondWireframeIndexCount; - - osg::ref_ptr wireframeGeometry = new osg::Geometry(); - - if (indexCount) + template + void addWireFrameGeometry(const size_t vertexCount, const size_t indexCount, + osg::ref_ptr& wireframeGeometry, const ESM::Pathgrid& pathgrid, + const std::vector& selected) { osg::ref_ptr vertices = new osg::Vec3Array(vertexCount); osg::ref_ptr colors = new osg::Vec4Array(vertexCount); - osg::ref_ptr indices - = new osg::DrawElementsUInt(osg::PrimitiveSet::LINES, indexCount); + osg::ref_ptr indices = new T(osg::PrimitiveSet::LINES, indexCount); osg::Vec3f wireOffset = osg::Vec3f(0, 0, (1 - DiamondWireframeScalar) * DiamondHalfHeight); @@ -195,6 +175,58 @@ namespace SceneUtil wireframeGeometry->addPrimitiveSet(indices); wireframeGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); } + } + + osg::ref_ptr createPathgridGeometry(const ESM::Pathgrid& pathgrid) + { + const size_t vertexCount = pathgrid.mPoints.size() * DiamondTotalVertexCount; + const size_t pointIndexCount = pathgrid.mPoints.size() * DiamondIndexCount; + const size_t edgeIndexCount = pathgrid.mEdges.size() * 2; + + osg::ref_ptr gridGeometry = new osg::Geometry(); + + if (pointIndexCount || edgeIndexCount) + { + const bool useIntPoints = pointIndexCount > std::numeric_limits::max(); + const bool useIntVertices = vertexCount > std::numeric_limits::max(); + if (useIntPoints && useIntVertices) + addPathgridToGeometry( + vertexCount, pointIndexCount, edgeIndexCount, gridGeometry, pathgrid); + else if (useIntPoints) + addPathgridToGeometry( + vertexCount, pointIndexCount, edgeIndexCount, gridGeometry, pathgrid); + else if (useIntVertices) + addPathgridToGeometry( + vertexCount, pointIndexCount, edgeIndexCount, gridGeometry, pathgrid); + else + addPathgridToGeometry( + vertexCount, pointIndexCount, edgeIndexCount, gridGeometry, pathgrid); + } + + osg::ref_ptr material = new osg::Material; + material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); + gridGeometry->getOrCreateStateSet()->setAttribute(material); + + return gridGeometry; + } + + osg::ref_ptr createPathgridSelectedWireframe( + const ESM::Pathgrid& pathgrid, const std::vector& selected) + { + const size_t vertexCount = selected.size() * DiamondVertexCount; + const size_t indexCount = selected.size() * DiamondWireframeIndexCount; + + osg::ref_ptr wireframeGeometry = new osg::Geometry(); + + if (indexCount) + { + if (vertexCount > std::numeric_limits::max()) + addWireFrameGeometry( + vertexCount, indexCount, wireframeGeometry, pathgrid, selected); + else + addWireFrameGeometry( + vertexCount, indexCount, wireframeGeometry, pathgrid, selected); + } return wireframeGeometry; }