Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / 3d / shadow_skin.cpp
blob204e39d917fa204fbdafaeaaa662879f3bb2200d
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
19 #include "nel/3d/shadow_skin.h"
20 #include "nel/3d/skeleton_model.h"
21 #include "nel/3d/ray_mesh.h"
22 #include "nel/misc/fast_mem.h"
23 #include "nel/misc/vector_2f.h"
25 using namespace NLMISC;
26 using namespace std;
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 namespace NL3D
36 // ***************************************************************************
37 // The number of byte to process per block
38 const uint NL_BlockByteL1= 4096;
40 // Number of vertices per block to process For ShadowMap generation
41 uint CShadowSkin::NumCacheVertexShadow= NL_BlockByteL1 / sizeof(CShadowVertex);
44 // ***************************************************************************
45 void CShadowSkin::applySkin(CVector *dst, std::vector<CMatrix3x4> &boneMat3x4)
47 if(Vertices.empty())
48 return;
49 uint numVerts= (uint)Vertices.size();
50 CShadowVertex *src= &Vertices[0];
52 // Then do the skin
53 for(;numVerts>0;)
55 // number of vertices to process for this block.
56 uint nBlockInf= min(NumCacheVertexShadow, numVerts);
57 // next block.
58 numVerts-= nBlockInf;
60 // cache the data in L1 cache.
61 CFastMem::precache(src, nBlockInf * sizeof(CShadowVertex));
63 // for all InfluencedVertices only.
64 for(;nBlockInf>0;nBlockInf--, src++, dst++)
66 boneMat3x4[ src->MatrixId ].mulSetPoint( src->Vertex, *dst );
72 // ***************************************************************************
73 bool CShadowSkin::getRayIntersection(const CMatrix &toRaySpace, CSkeletonModel &skeleton,
74 const std::vector<uint32> &matrixInfluences, float &dist2D, float &distZ, bool computeDist2D)
76 // *** render the shadow skin into a temp RAM buffer
77 // enlarge temp buffer
78 static std::vector<CVector> skinInRaySpace;
79 if(Vertices.size()>skinInRaySpace.size())
80 skinInRaySpace.resize(Vertices.size());
82 // compute matrixes
83 static vector<CMatrix3x4> boneMat3x4;
84 computeBoneMatrixes3x4PreMul(boneMat3x4, toRaySpace, matrixInfluences, &skeleton);
86 // apply the skinning
87 applySkin(&skinInRaySpace[0], boneMat3x4);
89 // *** return the distance to the ray intersection
90 return CRayMesh::getRayIntersection(skinInRaySpace, Triangles, dist2D, distZ, computeDist2D);
95 } // NL3D