MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / _drawSolidPolyhedron

Method _drawSolidPolyhedron

Engine/source/gfx/gfxDrawUtil.cpp:1005–1093  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1003}
1004
1005void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const AnyPolyhedron &poly, const ColorI &color, const MatrixF *xfm )
1006{
1007 GFXDEBUGEVENT_SCOPE( GFXDrawUtil_DrawSolidPolyhedron, ColorI::GREEN );
1008
1009 const U32 numPoints = poly.getNumPoints();
1010 const Point3F* points = poly.getPoints();
1011 const PlaneF* planes = poly.getPlanes();
1012 const Point3F viewDir = GFX->getViewMatrix().getForwardVector();
1013
1014 // Create a temp buffer for the vertices and
1015 // put all the polyhedron's points in there.
1016
1017 GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numPoints, GFXBufferTypeVolatile );
1018 verts.lock();
1019 for( U32 i = 0; i < numPoints; ++ i )
1020 {
1021 verts[ i ].point = points[ i ];
1022 verts[ i ].color = color;
1023 }
1024
1025 if( xfm )
1026 {
1027 for( U32 i = 0; i < numPoints; ++ i )
1028 xfm->mulP( verts[ i ].point );
1029 }
1030 verts.unlock();
1031
1032 // Allocate a temp buffer for the face indices.
1033
1034 const U32 numIndices = poly.getNumEdges() * 3;
1035 const U32 numPlanes = poly.getNumPlanes();
1036
1037 GFXPrimitiveBufferHandle prims( mDevice, numIndices, 0, GFXBufferTypeVolatile );
1038
1039 // Unfortunately, since polygons may have varying numbers of
1040 // vertices, we also need to retain that information.
1041
1042 FrameTemp< U32 > numIndicesForPoly( numPlanes );
1043 U32 numPolys = 0;
1044
1045 // Create all the polygon indices.
1046
1047 U16* indices;
1048 prims.lock( &indices );
1049 U32 idx = 0;
1050 for( U32 i = 0; i < numPlanes; ++ i )
1051 {
1052 // Since face extraction is somewhat costly, don't bother doing it for
1053 // backfacing polygons if culling is enabled.
1054
1055 if( !desc.cullDefined || desc.cullMode != GFXCullNone )
1056 {
1057 F32 dot = mDot( planes[ i ], viewDir );
1058
1059 // See if it faces *the same way* as the view direction. This would
1060 // normally mean that the face is *not* backfacing but since we expect
1061 // planes on the polyhedron to be facing *inwards*, we need to reverse
1062 // the logic here.

Callers

nothing calls this directly

Calls 15

mulPMethod · 0.80
extractFaceMethod · 0.80
setStateBlockByDescMethod · 0.80
setVertexBufferMethod · 0.80
setPrimitiveBufferMethod · 0.80
mDotFunction · 0.50
getNumPointsMethod · 0.45
getPointsMethod · 0.45
getPlanesMethod · 0.45
getForwardVectorMethod · 0.45
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected