tsSortedMesh.cpp
Engine/source/ts/tsSortedMesh.cpp
Public Defines
define
tsalloc()
Public Functions
Detailed Description
Public Defines
tsalloc()
Public Functions
forceFaceCamera()
forceFaceCameraZAxis()
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "ts/tsSortedMesh.h" 25#include "math/mMath.h" 26#include "ts/tsShapeInstance.h" 27 28// Not worth the effort, much less the effort to comment, but if the draw types 29// are consecutive use addition rather than a table to go from index to command value... 30/* 31#if ((GL_TRIANGLES+1==GL_TRIANGLE_STRIP) && (GL_TRIANGLE_STRIP+1==GL_TRIANGLE_FAN)) 32 #define getDrawType(a) (GL_TRIANGLES+(a)) 33#else 34 U32 drawTypes[] = { GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN }; 35 #define getDrawType(a) (drawTypes[a]) 36#endif 37*/ 38 39// found in tsmesh 40extern void forceFaceCamera(); 41extern void forceFaceCameraZAxis(); 42 43//----------------------------------------------------- 44// TSSortedMesh render methods 45//----------------------------------------------------- 46 47void TSSortedMesh::render(S32 frame, S32 matFrame, TSMaterialList * materials) 48{ 49} 50 51//----------------------------------------------------- 52// TSSortedMesh collision methods 53//----------------------------------------------------- 54 55bool TSSortedMesh::buildPolyList( S32 frame, AbstractPolyList *polyList, U32 &surfaceKey, TSMaterialList *materials ) 56{ 57 TORQUE_UNUSED(frame); 58 TORQUE_UNUSED(polyList); 59 TORQUE_UNUSED(surfaceKey); 60 TORQUE_UNUSED(materials); 61 62 return false; 63} 64 65bool TSSortedMesh::castRay( S32 frame, const Point3F &start, const Point3F &end, RayInfo *rayInfo, TSMaterialList *materials ) 66{ 67 TORQUE_UNUSED(frame); 68 TORQUE_UNUSED(start); 69 TORQUE_UNUSED(end); 70 TORQUE_UNUSED(rayInfo); 71 TORQUE_UNUSED(materials); 72 73 return false; 74} 75 76bool TSSortedMesh::buildConvexHull() 77{ 78 return false; 79} 80 81S32 TSSortedMesh::getNumPolys() 82{ 83 S32 count = 0; 84 S32 cIdx = !clusters.size() ? -1 : 0; 85 while (cIdx>=0) 86 { 87 Cluster & cluster = clusters[cIdx]; 88 for (S32 i=cluster.startPrimitive; i<cluster.endPrimitive; i++) 89 { 90 if (mPrimitives[i].matIndex & TSDrawPrimitive::Triangles) 91 count += mPrimitives[i].numElements / 3; 92 else 93 count += mPrimitives[i].numElements - 2; 94 } 95 cIdx = cluster.frontCluster; // always use frontCluster...we assume about the same no matter what 96 } 97 return count; 98} 99 100//----------------------------------------------------- 101// TSSortedMesh assembly/dissembly methods 102// used for transfer to/from memory buffers 103//----------------------------------------------------- 104 105#define tsalloc TSShape::smTSAlloc 106 107void TSSortedMesh::assemble(bool skip) 108{ 109 bool save1 = TSMesh::smUseTriangles; 110 bool save2 = TSMesh::smUseOneStrip; 111 TSMesh::smUseTriangles = false; 112 TSMesh::smUseOneStrip = false; 113 114 TSMesh::assemble(skip); 115 116 TSMesh::smUseTriangles = save1; 117 TSMesh::smUseOneStrip = save2; 118 119 S32 numClusters = tsalloc.get32(); 120 S32 * ptr32 = tsalloc.copyToShape32(numClusters*8); 121 clusters.set(ptr32,numClusters); 122 123 S32 sz = tsalloc.get32(); 124 ptr32 = tsalloc.copyToShape32(sz); 125 startCluster.set(ptr32,sz); 126 127 sz = tsalloc.get32(); 128 ptr32 = tsalloc.copyToShape32(sz); 129 firstVerts.set(ptr32,sz); 130 131 sz = tsalloc.get32(); 132 ptr32 = tsalloc.copyToShape32(sz); 133 numVerts.set(ptr32,sz); 134 135 sz = tsalloc.get32(); 136 ptr32 = tsalloc.copyToShape32(sz); 137 firstTVerts.set(ptr32,sz); 138 139 alwaysWriteDepth = tsalloc.get32()!=0; 140 141 tsalloc.checkGuard(); 142} 143 144void TSSortedMesh::disassemble() 145{ 146 TSMesh::disassemble(); 147 148 tsalloc.set32(clusters.size()); 149 tsalloc.copyToBuffer32((S32*)clusters.address(),clusters.size()*8); 150 151 tsalloc.set32(startCluster.size()); 152 tsalloc.copyToBuffer32((S32*)startCluster.address(),startCluster.size()); 153 154 tsalloc.set32(firstVerts.size()); 155 tsalloc.copyToBuffer32((S32*)firstVerts.address(),firstVerts.size()); 156 157 tsalloc.set32(numVerts.size()); 158 tsalloc.copyToBuffer32((S32*)numVerts.address(),numVerts.size()); 159 160 tsalloc.set32(firstTVerts.size()); 161 tsalloc.copyToBuffer32((S32*)firstTVerts.address(),firstTVerts.size()); 162 163 tsalloc.set32(alwaysWriteDepth ? 1 : 0); 164 165 tsalloc.setGuard(); 166} 167 168 169 170