CVertexBuffer: Make use of size_t where applicable
Same behavior, less truncations.
This commit is contained in:
parent
d081dd87cf
commit
a17d43a87d
|
@ -270,7 +270,7 @@ void CVertexBuffer::SetSkin(CSkin *pSkin)
|
||||||
mpSkin = pSkin;
|
mpSkin = pSkin;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 CVertexBuffer::Size() const
|
size_t CVertexBuffer::Size() const
|
||||||
{
|
{
|
||||||
return mPositions.size();
|
return mPositions.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
FVertexDescription VertexDesc() const;
|
FVertexDescription VertexDesc() const;
|
||||||
void SetVertexDesc(FVertexDescription Desc);
|
void SetVertexDesc(FVertexDescription Desc);
|
||||||
void SetSkin(CSkin *pSkin);
|
void SetSkin(CSkin *pSkin);
|
||||||
uint32 Size() const;
|
size_t Size() const;
|
||||||
GLuint CreateVAO();
|
GLuint CreateVAO();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "CCollisionRenderData.h"
|
#include "CCollisionRenderData.h"
|
||||||
#include <Core/Render/CDrawUtil.h>
|
#include <Core/Render/CDrawUtil.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/** Build from collision data */
|
/** Build from collision data */
|
||||||
void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData)
|
void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData)
|
||||||
|
@ -21,10 +23,10 @@ void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData
|
||||||
|
|
||||||
// Build list of triangle indices sorted by material index
|
// Build list of triangle indices sorted by material index
|
||||||
// Apparently some collision meshes have more triangle indices than actual triangles
|
// Apparently some collision meshes have more triangle indices than actual triangles
|
||||||
uint NumTris = Math::Min(kIndexData.TriangleIndices.size() / 3, kIndexData.TriangleMaterialIndices.size());
|
const uint NumTris = std::min(kIndexData.TriangleIndices.size() / 3, kIndexData.TriangleMaterialIndices.size());
|
||||||
std::vector<uint16> SortedTris(NumTris, 0);
|
std::vector<uint16> SortedTris(NumTris);
|
||||||
|
|
||||||
for (uint16 i=0; i<SortedTris.size(); i++)
|
for (uint16 i = 0; i < SortedTris.size(); i++)
|
||||||
{
|
{
|
||||||
SortedTris[i] = i;
|
SortedTris[i] = i;
|
||||||
}
|
}
|
||||||
|
@ -39,31 +41,30 @@ void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData
|
||||||
mMaterialIndexOffsets.reserve(kIndexData.Materials.size());
|
mMaterialIndexOffsets.reserve(kIndexData.Materials.size());
|
||||||
uint8 CurrentMatIdx = 0xFF;
|
uint8 CurrentMatIdx = 0xFF;
|
||||||
|
|
||||||
for (uint i=0; i < SortedTris.size(); i++)
|
for (const size_t TriIdx : SortedTris)
|
||||||
{
|
{
|
||||||
uint TriIdx = SortedTris[i];
|
const uint8 MaterialIdx = kIndexData.TriangleMaterialIndices[TriIdx];
|
||||||
uint8 MaterialIdx = kIndexData.TriangleMaterialIndices[TriIdx];
|
|
||||||
const CCollisionMaterial& kMaterial = kIndexData.Materials[MaterialIdx];
|
const CCollisionMaterial& kMaterial = kIndexData.Materials[MaterialIdx];
|
||||||
|
|
||||||
if (MaterialIdx != CurrentMatIdx)
|
if (MaterialIdx != CurrentMatIdx)
|
||||||
{
|
{
|
||||||
// Note some collision materials have no geometry associated with them as
|
// Note some collision materials have no geometry associated with them as
|
||||||
// some materials are exclusively used with edges/vertices.
|
// some materials are exclusively used with edges/vertices.
|
||||||
ASSERT( CurrentMatIdx < MaterialIdx || CurrentMatIdx == 0xFF );
|
ASSERT(CurrentMatIdx < MaterialIdx || CurrentMatIdx == 0xFF);
|
||||||
|
|
||||||
while (CurrentMatIdx != MaterialIdx)
|
while (CurrentMatIdx != MaterialIdx)
|
||||||
{
|
{
|
||||||
mMaterialIndexOffsets.push_back( mIndexBuffer.GetSize() );
|
mMaterialIndexOffsets.push_back(mIndexBuffer.GetSize());
|
||||||
CurrentMatIdx++;
|
CurrentMatIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 LineA = kIndexData.TriangleIndices[ (TriIdx*3)+0 ];
|
const size_t LineA = kIndexData.TriangleIndices[(TriIdx * 3) + 0];
|
||||||
uint16 LineB = kIndexData.TriangleIndices[ (TriIdx*3)+1 ];
|
const size_t LineB = kIndexData.TriangleIndices[(TriIdx * 3) + 1];
|
||||||
uint16 LineAVertA = kIndexData.EdgeIndices[ (LineA*2)+0 ];
|
const uint16 LineAVertA = kIndexData.EdgeIndices[(LineA * 2) + 0];
|
||||||
uint16 LineAVertB = kIndexData.EdgeIndices[ (LineA*2)+1 ];
|
const uint16 LineAVertB = kIndexData.EdgeIndices[(LineA * 2) + 1];
|
||||||
uint16 LineBVertA = kIndexData.EdgeIndices[ (LineB*2)+0 ];
|
const uint16 LineBVertA = kIndexData.EdgeIndices[(LineB * 2) + 0];
|
||||||
uint16 LineBVertB = kIndexData.EdgeIndices[ (LineB*2)+1 ];
|
const uint16 LineBVertB = kIndexData.EdgeIndices[(LineB * 2) + 1];
|
||||||
uint16 VertIdx0 = LineAVertA;
|
uint16 VertIdx0 = LineAVertA;
|
||||||
uint16 VertIdx1 = LineAVertB;
|
uint16 VertIdx1 = LineAVertB;
|
||||||
uint16 VertIdx2 = (LineBVertA != LineAVertA && LineBVertA != LineAVertB ? LineBVertA : LineBVertB);
|
uint16 VertIdx2 = (LineBVertA != LineAVertA && LineBVertA != LineAVertB ? LineBVertA : LineBVertB);
|
||||||
|
@ -71,21 +72,19 @@ void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData
|
||||||
// Reverse vertex order if material indicates tri is flipped
|
// Reverse vertex order if material indicates tri is flipped
|
||||||
if (kMaterial & eCF_FlippedTri)
|
if (kMaterial & eCF_FlippedTri)
|
||||||
{
|
{
|
||||||
uint16 Tmp = VertIdx0;
|
std::swap(VertIdx0, VertIdx2);
|
||||||
VertIdx0 = VertIdx2;
|
|
||||||
VertIdx2 = Tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate vertex data
|
// Generate vertex data
|
||||||
const CVector3f& kVert0 = kIndexData.Vertices[VertIdx0];
|
const CVector3f& kVert0 = kIndexData.Vertices[VertIdx0];
|
||||||
const CVector3f& kVert1 = kIndexData.Vertices[VertIdx1];
|
const CVector3f& kVert1 = kIndexData.Vertices[VertIdx1];
|
||||||
const CVector3f& kVert2 = kIndexData.Vertices[VertIdx2];
|
const CVector3f& kVert2 = kIndexData.Vertices[VertIdx2];
|
||||||
CVector3f V0toV1 = (kVert1 - kVert0);
|
const CVector3f V0toV1 = (kVert1 - kVert0);
|
||||||
CVector3f V0toV2 = (kVert2 - kVert0);
|
const CVector3f V0toV2 = (kVert2 - kVert0);
|
||||||
CVector3f TriNormal = V0toV1.Cross(V0toV2).Normalized();
|
const CVector3f TriNormal = V0toV1.Cross(V0toV2).Normalized();
|
||||||
uint16 Index0 = mVertexBuffer.Size();
|
const uint16 Index0 = static_cast<uint16>(mVertexBuffer.Size());
|
||||||
uint16 Index1 = Index0 + 1;
|
const uint16 Index1 = Index0 + 1;
|
||||||
uint16 Index2 = Index1 + 1;
|
const uint16 Index2 = Index1 + 1;
|
||||||
|
|
||||||
CVertex Vtx;
|
CVertex Vtx;
|
||||||
Vtx.Normal = TriNormal;
|
Vtx.Normal = TriNormal;
|
||||||
|
@ -168,7 +167,7 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
|
||||||
pkNode->Transform * CTransform4f::ScaleMatrix(pkNode->Radii);
|
pkNode->Transform * CTransform4f::ScaleMatrix(pkNode->Radii);
|
||||||
|
|
||||||
// Transform a 1x1x1 unit cube using the transform...
|
// Transform a 1x1x1 unit cube using the transform...
|
||||||
static const CVector3f skUnitCubeVertices[] = {
|
static constexpr std::array skUnitCubeVertices{
|
||||||
CVector3f(-1, -1, -1),
|
CVector3f(-1, -1, -1),
|
||||||
CVector3f(-1, -1, 1),
|
CVector3f(-1, -1, 1),
|
||||||
CVector3f(-1, 1, -1),
|
CVector3f(-1, 1, -1),
|
||||||
|
@ -179,14 +178,14 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
|
||||||
CVector3f( 1, 1, 1)
|
CVector3f( 1, 1, 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
for (uint i=0; i<8; i++)
|
for (const auto& vert : skUnitCubeVertices)
|
||||||
{
|
{
|
||||||
CVector3f Transformed = CombinedTransform * skUnitCubeVertices[i];
|
const CVector3f Transformed = CombinedTransform * vert;
|
||||||
mBoundingVertexBuffer.AddVertex( CVertex(Transformed) );
|
mBoundingVertexBuffer.AddVertex(CVertex(Transformed));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add corresponding indices
|
// Add corresponding indices
|
||||||
static const uint16 skUnitCubeWireIndices[24] = {
|
static constexpr std::array<uint16, 24> skUnitCubeWireIndices{
|
||||||
0, 1,
|
0, 1,
|
||||||
1, 3,
|
1, 3,
|
||||||
3, 2,
|
3, 2,
|
||||||
|
@ -200,10 +199,11 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
|
||||||
2, 6,
|
2, 6,
|
||||||
3, 7
|
3, 7
|
||||||
};
|
};
|
||||||
uint FirstIndex = mBoundingVertexBuffer.Size() - 8;
|
|
||||||
for (uint i=0; i<24; i++)
|
const size_t FirstIndex = mBoundingVertexBuffer.Size() - 8;
|
||||||
|
for (const uint16 index : skUnitCubeWireIndices)
|
||||||
{
|
{
|
||||||
mBoundingIndexBuffer.AddIndex(skUnitCubeWireIndices[i] + FirstIndex);
|
mBoundingIndexBuffer.AddIndex(static_cast<uint16>(index + FirstIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue