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