Skip to content

Fix polygon manipulator aabb computation #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions include/nbl/asset/utils/CPolygonGeometryManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,48 @@ class NBL_API2 CPolygonGeometryManipulator
}

//
static inline IGeometryBase::SAABBStorage computeAABB(const ICPUPolygonGeometry* geo)
{
if (!geo || !geo->getPositionView() || geo->getPositionView().composed.rangeFormat>=IGeometryBase::EAABBFormat::Count)
return {};
// the AABB shall be the same format as the Position View's range Format
IGeometryBase::SAABBStorage retval;
//if (geo->getIndexView() || geo->isSkinned())
{
// TODO: kevinyu
}
//else
retval = geo->getPositionView().composed.encodedDataRange;
return retval;
}
static inline IGeometryBase::SAABBStorage computeAABB(const ICPUPolygonGeometry* geo)
{
if (!geo || !geo->getPositionView() || geo->getPositionView().composed.rangeFormat>=IGeometryBase::EAABBFormat::Count)
return {};
// the AABB shall be the same format as the Position View's range Format
if (geo->getIndexView() || geo->isSkinned())
{
auto addToAABB = [&](auto& aabb)->void
{
using aabb_t = std::remove_reference_t<decltype(aabb)>;
for (auto i = 0; i != geo->getIndexView().getElementCount(); i++)
{
uint32_t vertex_i;
const auto indexBuffer = geo->getIndexView().getPointer();
switch (geo->getIndexType())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is meant to be for Graphics Pipelines, use non-index-view specific methods (decodeElement like a normal view) to decode indices (this way you'll be able to support int8 indices

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
case EIT_16BIT:
vertex_i = reinterpret_cast<const uint16_t*>(indexBuffer)[i];
break;
case EIT_32BIT:
vertex_i = reinterpret_cast<const uint32_t*>(indexBuffer)[i];
break;
default:
assert(false);
break;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its better to pack up the whole for loop into a templated lambda, and hoist the switch above (so it dispatches a separate specialized for loop per case)

this way you avoid dealing with the switch and different inted buffer decodes at every index

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated

typename aabb_t::point_t pt;
geo->getPositionView().decodeElement(vertex_i, pt);
aabb.addPoint(pt);
}
};
IGeometryBase::SDataViewBase tmp = geo->getPositionView().composed;
tmp.resetRange();
tmp.visitRange(addToAABB);
return tmp.encodedDataRange;
}
else
{
return geo->getPositionView().composed.encodedDataRange;
}
}

static inline void recomputeAABB(const ICPUPolygonGeometry* geo)
{
if (geo->isMutable())
Expand Down
Loading