tsSortedMesh.cpp 5.1 KB

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