tsDecal.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/tsDecal.h"
  23. #include "math/mMath.h"
  24. #include "math/mathIO.h"
  25. #include "ts/tsShapeInstance.h"
  26. #include "core/frameAllocator.h"
  27. //-----------------------------------------------------
  28. // TSDecalMesh assembly/dissembly methods
  29. // used for transfer to/from memory buffers
  30. //-----------------------------------------------------
  31. #define tsalloc TSShape::smTSAlloc
  32. void TSDecalMesh::assemble(bool)
  33. {
  34. if (TSShape::smReadVersion<20)
  35. {
  36. // read empty mesh...decals used to be derived from meshes
  37. tsalloc.checkGuard();
  38. tsalloc.getPointer32(15);
  39. }
  40. S32 sz = tsalloc.get32();
  41. S32 * ptr32 = tsalloc.copyToShape32(0); // get current shape address w/o doing anything
  42. for (S32 i=0; i<sz; i++)
  43. {
  44. tsalloc.getPointer16(2);
  45. tsalloc.getPointer32(1);
  46. }
  47. tsalloc.align32();
  48. primitives.set(ptr32,sz);
  49. sz = tsalloc.get32();
  50. S16 * ptr16 = tsalloc.getPointer16(sz);
  51. tsalloc.align32();
  52. indices.set(ptr16,sz);
  53. if (TSShape::smReadVersion<20)
  54. {
  55. // read more empty mesh stuff...decals used to be derived from meshes
  56. tsalloc.getPointer32(3);
  57. tsalloc.checkGuard();
  58. }
  59. sz = tsalloc.get32();
  60. ptr32 = tsalloc.getPointer32(sz);
  61. startPrimitive.set(ptr32,sz);
  62. if (TSShape::smReadVersion>=19)
  63. {
  64. ptr32 = tsalloc.getPointer32(sz*4);
  65. texgenS.set(ptr32,startPrimitive.size());
  66. ptr32 = tsalloc.getPointer32(sz*4);
  67. texgenT.set(ptr32,startPrimitive.size());
  68. }
  69. else
  70. {
  71. texgenS.set(NULL,0);
  72. texgenT.set(NULL,0);
  73. }
  74. materialIndex = tsalloc.get32();
  75. tsalloc.checkGuard();
  76. }
  77. void TSDecalMesh::disassemble()
  78. {
  79. tsalloc.set32(primitives.size());
  80. tsalloc.copyToBuffer32((S32*)primitives.address(),primitives.size());
  81. tsalloc.set32(indices.size());
  82. tsalloc.copyToBuffer32((S32*)indices.address(),indices.size());
  83. tsalloc.set32(startPrimitive.size());
  84. tsalloc.copyToBuffer32((S32*)startPrimitive.address(),startPrimitive.size());
  85. tsalloc.copyToBuffer32((S32*)texgenS.address(),texgenS.size()*4);
  86. tsalloc.copyToBuffer32((S32*)texgenT.address(),texgenT.size()*4);
  87. tsalloc.set32(materialIndex);
  88. tsalloc.setGuard();
  89. }