@@ -822,56 +822,47 @@ Defines ATTR_POSITION, ATTR_TEXCOORD, and maybe ATTR_QTANGENT
822822*/
823823static void Tess_SurfaceMDV ( mdvSurface_t *srf )
824824{
825- int i, j;
826- int numIndexes = 0 ;
827- int numVertexes;
828- mdvXyz_t *oldVert, *newVert;
829- mdvNormal_t *oldNormal, *newNormal;
830- mdvSt_t *st;
831- srfTriangle_t *tri;
832- float backlerp;
833- float oldXyzScale, newXyzScale;
834-
835825 GLIMP_LOGCOMMENT ( " --- Tess_SurfaceMDV ---" );
836826
837- if ( backEnd.currentEntity ->e .oldframe == backEnd.currentEntity ->e .frame )
838- {
839- backlerp = 0 ;
840- }
841- else
827+ float backlerp = 0 .0f ;
828+
829+ if ( backEnd.currentEntity ->e .oldframe != backEnd.currentEntity ->e .frame )
842830 {
843831 backlerp = backEnd.currentEntity ->e .backlerp ;
844832 }
845833
846- newXyzScale = ( 1 .0f - backlerp );
847- oldXyzScale = backlerp;
834+ float newXyzScale = ( 1 .0f - backlerp );
835+ float oldXyzScale = backlerp;
848836
849837 Tess_CheckOverflow ( srf->numVerts , srf->numTriangles * 3 );
850838
851- numIndexes = srf->numTriangles * 3 ;
839+ int numIndexes = srf->numTriangles * 3 ;
852840
853- for ( i = 0 , tri = srf->triangles ; i < srf->numTriangles ; i++, tri++ )
854841 {
855- tess.indexes [ tess.numIndexes + i * 3 + 0 ] = tess.numVertexes + tri->indexes [ 0 ];
856- tess.indexes [ tess.numIndexes + i * 3 + 1 ] = tess.numVertexes + tri->indexes [ 1 ];
857- tess.indexes [ tess.numIndexes + i * 3 + 2 ] = tess.numVertexes + tri->indexes [ 2 ];
842+ srfTriangle_t *tri = srf->triangles ;
843+ for ( size_t i = 0 ; i < srf->numTriangles ; i++, tri++ )
844+ {
845+ tess.indexes [ tess.numIndexes + i * 3 + 0 ] = tess.numVertexes + tri->indexes [ 0 ];
846+ tess.indexes [ tess.numIndexes + i * 3 + 1 ] = tess.numVertexes + tri->indexes [ 1 ];
847+ tess.indexes [ tess.numIndexes + i * 3 + 2 ] = tess.numVertexes + tri->indexes [ 2 ];
848+ }
858849 }
859850
860- newVert = srf->verts + ( backEnd.currentEntity ->e .frame * srf->numVerts );
861- oldVert = srf->verts + ( backEnd.currentEntity ->e .oldframe * srf->numVerts );
862- newNormal = srf->normals + ( backEnd.currentEntity ->e .frame * srf->numVerts );
863- oldNormal = srf->normals + ( backEnd.currentEntity ->e .oldframe * srf->numVerts );
864- st = srf->st ;
851+ mdvXyz_t * newVert = srf->verts + ( backEnd.currentEntity ->e .frame * srf->numVerts );
852+ mdvXyz_t * oldVert = srf->verts + ( backEnd.currentEntity ->e .oldframe * srf->numVerts );
853+ mdvNormal_t * newNormal = srf->normals + ( backEnd.currentEntity ->e .frame * srf->numVerts );
854+ mdvNormal_t * oldNormal = srf->normals + ( backEnd.currentEntity ->e .oldframe * srf->numVerts );
855+ mdvSt_t * st = srf->st ;
865856
866- numVertexes = srf->numVerts ;
857+ int numVertexes = srf->numVerts ;
867858
868859 if (tess.skipTangents )
869860 {
870- for (j = 0 ; j < numVertexes; j++, newVert++, oldVert++, st++)
861+ for ( size_t j = 0 ; j < numVertexes; j++, newVert++, oldVert++, st++ )
871862 {
872863 vec3_t tmpVert;
873864
874- if (backlerp == 0 )
865+ if ( backlerp == 0 . 0f )
875866 {
876867 // just copy
877868 VectorCopy (newVert->xyz , tmpVert);
@@ -894,25 +885,17 @@ static void Tess_SurfaceMDV( mdvSurface_t *srf )
894885 else
895886 {
896887 // calc tangent spaces
897- float *v;
898- const float *v0, *v1, *v2;
899- const float *t0, *t1, *t2;
900- vec3_t * xyz;
901- vec3_t tangent, *tangents;
902- vec3_t binormal, *binormals;
903- vec3_t *normals;
888+ vec3_t *xyz = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof (vec3_t ) );
889+ vec3_t *tangents = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof ( vec3_t ) );
890+ vec3_t *binormals = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof ( vec3_t ) );
891+ vec3_t *normals = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof ( vec3_t ) );
904892
905- xyz = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof (vec3_t ) );
906- tangents = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof ( vec3_t ) );
907- binormals = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof ( vec3_t ) );
908- normals = (vec3_t *)ri.Hunk_AllocateTempMemory ( numVertexes * sizeof ( vec3_t ) );
909-
910- for ( i = 0 ; i < numVertexes; i++, newVert++, oldVert++, oldNormal++, newNormal++ )
893+ for ( size_t i = 0 ; i < numVertexes; i++, newVert++, oldVert++, oldNormal++, newNormal++ )
911894 {
912895 VectorClear ( tangents[ i ] );
913896 VectorClear ( binormals[ i ] );
914897
915- if ( backlerp == 0 )
898+ if ( backlerp == 0 . 0f )
916899 {
917900 // just copy
918901 VectorCopy ( newNormal->normal , normals[ i ] );
@@ -925,7 +908,7 @@ static void Tess_SurfaceMDV( mdvSurface_t *srf )
925908 VectorNormalizeFast ( normals[ i ] );
926909 }
927910
928- if ( backlerp == 0 )
911+ if ( backlerp == 0 . 0f )
929912 {
930913 // just copy
931914 VectorCopy (newVert->xyz , xyz[i]);
@@ -938,32 +921,37 @@ static void Tess_SurfaceMDV( mdvSurface_t *srf )
938921 }
939922 }
940923
941- for (i = 0 , tri = srf-> triangles ; i < srf-> numTriangles ; i++, tri++)
924+ auto task0 = [&]( const size_t & i ) -> void
942925 {
943- int * indices = tri->indexes ;
944- v0 = xyz[ indices[0 ] ];
945- v1 = xyz[ indices[1 ] ];
946- v2 = xyz[ indices[2 ] ];
926+ srfTriangle_t *tri = srf->triangles + i;
927+ int *indices = tri->indexes ;
928+ const float *v0 = xyz[ indices[ 0 ] ];
929+ const float *v1 = xyz[ indices[ 1 ] ];
930+ const float *v2 = xyz[ indices[ 2 ] ];
947931
948- t0 = st[ indices[ 0 ] ].st ;
949- t1 = st[ indices[ 1 ] ].st ;
950- t2 = st[ indices[ 2 ] ].st ;
932+ const float * t0 = st[ indices[ 0 ] ].st ;
933+ const float * t1 = st[ indices[ 1 ] ].st ;
934+ const float * t2 = st[ indices[ 2 ] ].st ;
951935
936+ vec3_t tangent, binormal;
952937 R_CalcTangents ( tangent, binormal, v0, v1, v2, t0, t1, t2 );
953938
954- for ( j = 0 ; j < 3 ; j++ )
939+ for ( size_t j = 0 ; j < 3 ; j++ )
955940 {
941+ float *v;
942+
956943 v = tangents[ indices[ j ] ];
957944 VectorAdd ( v, tangent, v );
958945
959946 v = binormals[ indices[ j ] ];
960947 VectorAdd ( v, binormal, v );
961948 }
962- }
949+ };
963950
964- for ( i = 0 ; i < numVertexes; i++ )
965- {
951+ Omp::Tasker ( task0, srf->numTriangles );
966952
953+ auto task1 = [&]( const size_t & i ) -> void
954+ {
967955 i16vec4_t qtangents;
968956
969957 R_TBNtoQtangents ( tangents[ i ], binormals[ i ],
@@ -973,7 +961,9 @@ static void Tess_SurfaceMDV( mdvSurface_t *srf )
973961 Vector4Copy (qtangents, tess.verts [tess.numVertexes + i].qtangents );
974962 tess.verts [tess.numVertexes + i].texCoords [0 ] = st[i].st [0 ];
975963 tess.verts [tess.numVertexes + i].texCoords [1 ] = st[i].st [1 ];
976- }
964+ };
965+
966+ Omp::Tasker ( task1, numVertexes );
977967
978968 ri.Hunk_FreeTempMemory ( normals );
979969 ri.Hunk_FreeTempMemory ( binormals );
0 commit comments