From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02800.html | 2548 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2548 insertions(+) create mode 100644 docs/doxygen/nel/a02800.html (limited to 'docs/doxygen/nel/a02800.html') diff --git a/docs/doxygen/nel/a02800.html b/docs/doxygen/nel/a02800.html new file mode 100644 index 00000000..5f784a9e --- /dev/null +++ b/docs/doxygen/nel/a02800.html @@ -0,0 +1,2548 @@ + + +NeL: NL3D::CLodCharacterManager class Reference + + + +
+

NL3D::CLodCharacterManager Class Reference

#include <lod_character_manager.h> +

+


Detailed Description

+A Manager used to display CLodCharacter instances.
Author:
Lionel Berenguier

+Nevrax France

+
Date:
2002
+ +

+ +

+Definition at line 107 of file lod_character_manager.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Instance texturing.

CRGBAgetTextureInstance (CLodCharacterInstance &instance)
CSmartPtr< CTextureBlank_BigTexture
std::vector< uint_FreeIds
CLodCharacterTmpBitmap _TmpBitmaps [256]

Public Member Functions

 CLodCharacterManager ()
 Constructor.

 ~CLodCharacterManager ()
render process
bool addRenderCharacterKey (CLodCharacterInstance &instance, const CMatrix &worldMatrix, CRGBA ambient, CRGBA diffuse, const CVector &lightDir)
void beginRender (IDriver *driver, const CVector &managerPos)
void endRender ()
uint32 getMaxVertex () const
 see setMaxVertex()

uint32 getVertexStreamNumVBHard () const
 see setVertexStreamNumVBHard

bool isRendering () const
 tells if we are beetween a beginRender() and a endRender()

void setMaxVertex (uint32 maxVertex)
void setupNormalCorrectionMatrix (const CMatrix &normalMatrix)
void setVertexStreamNumVBHard (uint32 numVBHard)
Instance texturing.
void addTextureCompute (CLodCharacterInstance &instance, const CLodCharacterTexture &lodTexture)
 add a texture from an instance. Texture Lookup are made in _TmpBitmaps

void endTextureCompute (CLodCharacterInstance &instance, uint numBmpToReset)
 end and compile. reset/free memory of _TmpBitmaps up to numBmpToReset.

CLodCharacterTmpBitmapgetTmpBitmap (uint8 id)
 get a tmp bitmap for a special slot. caller can fill RGBA texture for the associated material Id in it.

void initInstance (CLodCharacterInstance &instance)
 Init the instance texturing with this manager. A texture space is reserved (if possible), and UVs are generated.

void releaseInstance (CLodCharacterInstance &instance)
 Release a lod instance. Free texture space.

bool startTextureCompute (CLodCharacterInstance &instance)
 reset the textureSpace. Instance must have been inited (nlassert). return false if no more texture space available

build process
bool compile ()
uint32 createShapeBank ()
void deleteShapeBank (uint32 bankId)
 delete a Shape Bank. No-op if bad id.

const CLodCharacterShapegetShape (uint32 shapeId) const
 Get a const ref on a shape. Ptr not valid if shape Banks are modfied. NULL if not found.

CLodCharacterShapeBankgetShapeBank (uint32 bankId)
 get a shape Bank. UseFull for serialisation for example. return NULL if not found

const CLodCharacterShapeBankgetShapeBank (uint32 bankId) const
 get a shape Bank. UseFull for serialisation for example. return NULL if not found

sint32 getShapeIdByName (const std::string &name) const
void reset ()
 reset the manager.


Private Types

typedef TStrIdMap::const_iterator CstItStrIdMap
typedef TStrIdMap::iterator ItStrIdMap
typedef std::map< std::string,
+ uint32
TStrIdMap
 Map name To Id.


Private Attributes

std::vector< CLodCharacterShapeBank * > _ShapeBankArray
 Array of shapeBank.

TStrIdMap _ShapeMap
 Map of shape id.

render process
uint _CurrentTriId
uint _CurrentVertexId
CMatrix _LightCorrectionMatrix
bool _LockDone
CVector _ManagerMatrixPos
CMaterial _Material
uint _MaxNumVertices
uint _NumVBHard
bool _Rendering
std::vector< uint32_Triangles
uint8_VertexData
uint _VertexSize
CVertexStreamManager _VertexStream
+


Member Typedef Documentation

+

+ + + + +
+ + +
typedef TStrIdMap::const_iterator NL3D::CLodCharacterManager::CstItStrIdMap [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 247 of file lod_character_manager.h. +

+Referenced by getShapeIdByName().

+

+ + + + +
+ + +
typedef TStrIdMap::iterator NL3D::CLodCharacterManager::ItStrIdMap [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 246 of file lod_character_manager.h. +

+Referenced by compile().

+

+ + + + +
+ + +
typedef std::map<std::string, uint32> NL3D::CLodCharacterManager::TStrIdMap [private] +
+
+ + + + + +
+   + + +

+Map name To Id. +

+ +

+Definition at line 245 of file lod_character_manager.h.

+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
NL3D::CLodCharacterManager::CLodCharacterManager  ) 
+
+ + + + + +
+   + + +

+Constructor. +

+ +

+Definition at line 68 of file lod_character_manager.cpp. +

+References _BigTexture, _FreeIds, _LightCorrectionMatrix, _LockDone, _MaxNumVertices, _NumVBHard, _Rendering, NL3D::CMaterial::initUnlit(), NLMISC::CMatrix::invert(), NL3D_CLOD_BIGTEXT_HEIGHT, NL3D_CLOD_BIGTEXT_WIDTH, NL3D_CLOD_TEXT_NUM_IDS, NLMISC::Pi, NLMISC::CMatrix::rotateZ(), NL3D::CMaterial::setAlphaTest(), NL3D::CMaterial::setDoubleSided(), NL3D::CMaterial::setTexture(), and uint. +

+

00069 {
+00070         _MaxNumVertices= 3000;
+00071         _NumVBHard= 8;
+00072         _Rendering= false;
+00073         _LockDone= false;
+00074 
+00075         // setup the texture.
+00076         _BigTexture= new CTextureBlank;
+00077         // The texture always reside in memory... This take 1Mo of RAM. (16*32*16*32 * 4)
+00078         // NB: this is simplier like that, and this is not a problem, since only 1 or 2 Mo are allocated :o)
+00079         _BigTexture->setReleasable(false);
+00080         // create the bitmap.
+00081         _BigTexture->resize(NL3D_CLOD_BIGTEXT_WIDTH, NL3D_CLOD_BIGTEXT_HEIGHT, CBitmap::RGBA);
+00082         // Format of texture, 16 bits and no mipmaps.
+00083         _BigTexture->setUploadFormat(ITexture::RGB565);
+00084         _BigTexture->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
+00085         _BigTexture->setWrapS(ITexture::Clamp);
+00086         _BigTexture->setWrapT(ITexture::Clamp);
+00087 
+00088         // Alloc free Ids
+00089         _FreeIds.resize(NL3D_CLOD_TEXT_NUM_IDS);
+00090         for(uint i=0;i<_FreeIds.size();i++)
+00091         {
+00092                 _FreeIds[i]= i;
+00093         }
+00094 
+00095         // setup the material
+00096         _Material.initUnlit();
+00097         _Material.setAlphaTest(true);
+00098         _Material.setDoubleSided(true);
+00099         _Material.setTexture(0, _BigTexture);
+00100 
+00101         // setup for lighting, Default for Ryzom setup
+00102         _LightCorrectionMatrix.rotateZ((float)Pi/2);
+00103         _LightCorrectionMatrix.invert();
+00104 }
+
+

+ + + + +
+ + + + + + + + + +
NL3D::CLodCharacterManager::~CLodCharacterManager  ) 
+
+ + + + + +
+   + + +

+ +

+Definition at line 108 of file lod_character_manager.cpp. +

+References reset(). +

+

00109 {
+00110         reset();
+00111 }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool NL3D::CLodCharacterManager::addRenderCharacterKey CLodCharacterInstance instance,
const CMatrix worldMatrix,
CRGBA  ambient,
CRGBA  diffuse,
const CVector lightDir
+
+ + + + + +
+   + + +

+Add an instance to the render list. nlassert if not isRendering() initInstance() must have been called before (nlassert)

Parameters:
+ + + + + + +
instance the lod instance information (with precomputed color/Uvs)
worldMatrix is the world matrix, used to display the mesh
ambient is the ambient used to simulate the lighting on the lod.
diffuse is the diffuse used to simulate the lighting on the lod.
lightDir is the diffuse used to simulate the lighting on the lod (should be the bigger light influence) Don't need to be normalized (must do it internally)
+
+
Returns:
false if the key can't be added to this pass BECAUSE OF TOO MANY VERTICES reason. If the shapeId or animId are bad id, it return true!! You may call endRender(), then restart a block. Or you may just stop the process if you want.
+ +

+Definition at line 359 of file lod_character_manager.cpp. +

+References _CurrentTriId, _CurrentVertexId, _LightCorrectionMatrix, _LockDone, _ManagerMatrixPos, _MaxNumVertices, _VertexData, _VertexSize, _VertexStream, NLMISC::CRGBA::A, a00, a01, a02, a10, a11, a12, a20, a21, a22, NL3D::CLodCharacterInstance::AnimId, NL3D::CLodCharacterInstance::AnimTime, NL3D::computeLodLighting(), NLMISC::CMatrix::get(), NL3D::CLodCharacterShape::getAnimKey(), NL3D::CVertexStreamManager::getDriver(), NL3D::CLodCharacterShape::getNormals(), NL3D::CLodCharacterShape::getNumTriangles(), NL3D::CLodCharacterShape::getNumVertices(), NLMISC::CMatrix::getPos(), getShape(), NL3D::CLodCharacterShape::getTriangleArray(), NL3D::CLodCharacterInstance::getUVs(), H_AUTO, isRendering(), NL3D::CVertexStreamManager::lock(), NLMISC::CMatrix::mulVector(), NL3D_CLOD_COLOR_OFF, NL3D_CLOD_UV_OFF, NL3D_CLOD_VERTEX_SIZE, nlassert, NLMISC::CVector::normalize(), NL3D::CLodCharacterInstance::ShapeId, sint, uint, uint32, uint64, uint8, NL3D::CLodCharacterInstance::VertexAlphas, NL3D::CLodCharacterInstance::WrapMode, NL3D::CLodCharacterShape::CVector3s::x, NLMISC::CVector::x, NL3D::CLodCharacterShape::CVector3s::y, NLMISC::CVector::y, NL3D::CLodCharacterShape::CVector3s::z, and NLMISC::CVector::z. +

+Referenced by NL3D::CSkeletonModel::renderCLod(). +

+

00361 {
+00362         H_AUTO ( NL3D_CharacterLod_AddRenderKey )
+00363 
+00364         nlassert(_VertexStream.getDriver());
+00365         // we must be beewteen beginRender() and endRender()
+00366         nlassert(isRendering());
+00367 
+00368 
+00369         // regroup all variables that will be accessed in the ASM loop (minimize cache problems)
+00370         uint                    numVertices;
+00371         const CLodCharacterShape::CVector3s             *vertPtr;
+00372         const CVector   *normalPtr;
+00373         const CUV               *uvPtr;
+00374         const uint8             *alphaPtr;
+00375         CVector                 lightObjectSpace;
+00376         CVector                 matPos;
+00377         float                   a00, a01, a02; 
+00378         float                   a10, a11, a12; 
+00379         float                   a20, a21, a22; 
+00380         sint                    f8;
+00381         uint64                  blank= 0;
+00382         CRGBA                   ambient= paramAmbient;
+00383         CRGBA                   diffuse= paramDiffuse;
+00384         // For ASM / MMX, must set 0 to alpha part, because replaced by *alphaPtr (with add)
+00385         ambient.A= 0;
+00386         diffuse.A= 0;
+00387         
+00388 
+00389         // Get the Shape and current key.
+00390         //=============
+00391 
+00392         // get the shape
+00393         const CLodCharacterShape        *clod= getShape(instance.ShapeId);
+00394         // if not found quit, return true
+00395         if(!clod)
+00396                 return true;
+00397 
+00398         // get UV/Normal array. NULL => error
+00399         normalPtr= clod->getNormals();
+00400         // get UV of the instance
+00401         uvPtr= instance.getUVs();
+00402         // uvPtr is NULL means that initInstance() has not been called!!
+00403         nlassert(normalPtr && uvPtr);
+00404 
+00405         // get the anim key
+00406         CVector         unPackScaleFactor;
+00407         vertPtr= clod->getAnimKey(instance.AnimId, instance.AnimTime, instance.WrapMode, unPackScaleFactor);
+00408         // if not found quit, return true
+00409         if(!vertPtr)
+00410                 return true;
+00411         // get num verts
+00412         numVertices= clod->getNumVertices();
+00413 
+00414         // empty shape??
+00415         if(numVertices==0)
+00416                 return true;
+00417 
+00418         // If too many vertices, quit, returning false.
+00419         if(_CurrentVertexId+numVertices > _MaxNumVertices)
+00420                 return false;
+00421 
+00422         // get alpha array
+00423         static  vector<uint8>   defaultAlphaArray;
+00424         // get the instance alpha if correctly setuped
+00425         if(instance.VertexAlphas.size() == numVertices)
+00426         {
+00427                 alphaPtr= &instance.VertexAlphas[0];
+00428         }
+00429         // if error, take 255 as alpha.
+00430         else
+00431         {
+00432                 // NB: still use an array. This case should never arise, but support it not at full optim.
+00433                 if(defaultAlphaArray.size()<numVertices)
+00434                         defaultAlphaArray.resize(numVertices, 255);
+00435                 alphaPtr= &defaultAlphaArray[0];
+00436         }
+00437 
+00438         // Lock Buffer if not done
+00439         //=============
+00440         
+00441         // Do this after code above because we are sure that we will fill something (numVertices>0)
+00442         if(!_LockDone)
+00443         {
+00444                 _VertexData= _VertexStream.lock();
+00445                 _LockDone= true;
+00446         }
+00447 
+00448         // Prepare Transform
+00449         //=============
+00450 
+00451         // HTimerInfo: all this block takes 0.1%
+00452 
+00453         // Get matrix pos.
+00454         matPos= worldMatrix.getPos();
+00455         // compute in manager space.
+00456         matPos -= _ManagerMatrixPos;
+00457         // Get rotation line vectors
+00458         const float *worldM= worldMatrix.get();
+00459         a00= worldM[0]; a01= worldM[4]; a02= worldM[8]; 
+00460         a10= worldM[1]; a11= worldM[5]; a12= worldM[9]; 
+00461         a20= worldM[2]; a21= worldM[6]; a22= worldM[10];
+00462 
+00463         // get the light in object space.
+00464         // Multiply light dir with transpose of worldMatrix. This may be not exact (not uniform scale) but sufficient.
+00465         lightObjectSpace.x= a00 * lightDir.x + a10 * lightDir.y + a20 * lightDir.z;
+00466         lightObjectSpace.y= a01 * lightDir.x + a11 * lightDir.y + a21 * lightDir.z;
+00467         lightObjectSpace.z= a02 * lightDir.x + a12 * lightDir.y + a22 * lightDir.z;
+00468         // animation User correction
+00469         lightObjectSpace= _LightCorrectionMatrix.mulVector(lightObjectSpace);
+00470         // normalize, and neg for Dot Product.
+00471         lightObjectSpace.normalize();
+00472         lightObjectSpace= -lightObjectSpace;
+00473         // preMul by 255 for RGBA uint8
+00474         lightObjectSpace*= 255;
+00475 
+00476         // multiply matrix with scale factor for Pos.
+00477         a00*= unPackScaleFactor.x; a01*= unPackScaleFactor.y; a02*= unPackScaleFactor.z; 
+00478         a10*= unPackScaleFactor.x; a11*= unPackScaleFactor.y; a12*= unPackScaleFactor.z; 
+00479         a20*= unPackScaleFactor.x; a21*= unPackScaleFactor.y; a22*= unPackScaleFactor.z; 
+00480         
+00481         // get dst Array.
+00482         uint8   *dstPtr;
+00483         dstPtr= _VertexData + _CurrentVertexId * _VertexSize;
+00484 
+00485 
+00486         /* PreCaching Note: CFastMem::precache() has been tested (done on the 4 arrays) but not very interesting, 
+00487                 maybe because the cache miss improve //ism a bit below.
+00488         */
+00489 
+00490         // Fill the VB
+00491         //=============
+00492 #ifdef NL_OS_WINDOWS
+00493         // optimized version
+00494         if(CSystemInfo::hasMMX())
+00495         {   
+00496                 H_AUTO( NL3D_CharacterLod_vertexFill );
+00497 
+00498                 if(numVertices)
+00499                 {
+00500                         /* NB: order is important for AGP filling optimisation in dstPtr
+00501 
+00502                                 Pentium2+ optimisation notes:
+00503 
+00504                                 - "uop" comment formating: 
+00505                                         A/B means "A micro-ops in port 0, and B micro-ops in port 2".  (port 1 is very rare for FPU)
+00506                                         A/B/C/D means "A micro-ops in port 0, B in port 2, C in port 3 and D in port 4".
+00507                                         The number in () is the delay (if any).
+00508                                 - the "compute lighting part" must done first, because of the "fistp f8" mem writes that must
+00509                                                 be place far away from the "mov eax, f8" read in clamp lighting part
+00510                                                 (else seems that it crashes all the //ism)
+00511                                 - No need to Interleave on Pentium2+. But prevents "write/read stall" by putting the write 
+00512                                         far away from the next read. Else stall of 3 cycles + BIG BREAK OF //ism (I think).
+00513                                         This had save me 120 cycles / 240 !!!
+00514 
+00515                                 BenchResults:
+00516                                 - The "transform vertex part" and "all next part" cost 42 cycles, but is somewhat optimal:
+00517                                         63 uop (=> min 21 cycles), but 36 uop in the P0 port (=> this is the bottleneck)
+00518                                 - The lighting part adds 1 cycle only ?????  (44 cycles) But still relevant and optimal:
+00519                                         43 uop in port P0!!!! 
+00520                                 - The UV part adds 4 cycles (47) (should not since 0 in Port P0), still acceptable.
+00521                                 - The clamp part adds 3 cycles (50), and add 11 cycles in "P0 or P1" (but heavy dependency)
+00522                                         If we assume all goes into P1, it should takes 0... still acceptable (optimal==43?)
+00523                                 - The alpha part adds 2 cycles (52, optimal=45). OK.
+00524                                 - The modulate part adds 15 cycles. OK
+00525 
+00526                                 TOTAL: 67 cycles in theory (write in RAM, no cache miss problem)
+00527                                 BENCH: ASM version: 91 cycles (Write in AGP, some cache miss problems, still good against 67)
+00528                                            C version: 316 cycles.
+00529                         */
+00530                         __asm
+00531                         {
+00532                                 mov             edi, dstPtr
+00533                         theLoop:
+00534                                 // **** compute lighting
+00535                                 mov             esi,normalPtr                   // uop: 0/1
+00536                                 // dot3
+00537                                 fld             dword ptr [esi]                 // uop: 0/1
+00538                                 fmul    lightObjectSpace.x              // uop: 1/1 (5)
+00539                                 fld             dword ptr [esi+4]               // uop: 0/1
+00540                                 fmul    lightObjectSpace.y              // uop: 1/1 (5)
+00541                                 faddp   st(1),st                                // uop: 1/0 (3)
+00542                                 fld             dword ptr [esi+8]               // uop: 0/1
+00543                                 fmul    lightObjectSpace.z              // uop: 1/1 (5)
+00544                                 faddp   st(1),st                                // uop: 1/0 (3)
+00545                                 fistp   f8                                              // uop: 2/0/1/1 (5)
+00546                                 // next
+00547                                 add             esi, 12                                 // uop: 1/0
+00548                                 mov             normalPtr, esi                  // uop: 0/0/1/1
+00549 
+00550                                 
+00551                                 // **** transform vertex, and store
+00552                                 mov             esi, vertPtr                    // uop: 0/1
+00553                                 fild    word ptr[esi]                   // uop: 3/1 (5)
+00554                                 fild    word ptr[esi+2]                 // uop: 3/1 (5)
+00555                                 fild    word ptr[esi+4]                 // uop: 3/1 (5)
+00556                                 // x
+00557                                 fld             a00                                             // uop: 0/1
+00558                                 fmul    st, st(3)                               // uop: 1/0 (5)
+00559                                 fld             a01                                             // uop: 0/1
+00560                                 fmul    st, st(3)                               // uop: 1/0 (5)
+00561                                 faddp   st(1), st                               // uop: 1/0 (3)
+00562                                 fld             a02                                             // uop: 0/1
+00563                                 fmul    st, st(2)                               // uop: 1/0 (5)
+00564                                 faddp   st(1), st                               // uop: 1/0 (3)
+00565                                 fld             matPos.x                                // uop: 0/1
+00566                                 faddp   st(1), st                               // uop: 1/0 (3)
+00567                                 fstp    dword ptr[edi]                  // uop: 0/0/1/1
+00568                                 // y
+00569                                 fld             a10
+00570                                 fmul    st, st(3)
+00571                                 fld             a11
+00572                                 fmul    st, st(3)
+00573                                 faddp   st(1), st
+00574                                 fld             a12
+00575                                 fmul    st, st(2)
+00576                                 faddp   st(1), st
+00577                                 fld             matPos.y
+00578                                 faddp   st(1), st
+00579                                 fstp    dword ptr[edi+4]
+00580                                 // z
+00581                                 fld             a20
+00582                                 fmul    st, st(3)
+00583                                 fld             a21
+00584                                 fmul    st, st(3)
+00585                                 faddp   st(1), st
+00586                                 fld             a22
+00587                                 fmul    st, st(2)
+00588                                 faddp   st(1), st
+00589                                 fld             matPos.z
+00590                                 faddp   st(1), st
+00591                                 fstp    dword ptr[edi+8]
+00592                                 // flush stack
+00593                                 fstp    st                                              // uop: 1/0
+00594                                 fstp    st                                              // uop: 1/0
+00595                                 fstp    st                                              // uop: 1/0
+00596                                 // next
+00597                                 add             esi, 6                                  // uop: 1/0
+00598                                 mov             vertPtr, esi                    // uop: 0/0/1/1
+00599 
+00600                         
+00601                                 // **** copy uv
+00602                                 mov             esi, uvPtr                                                      // uop: 0/1
+00603                                 mov             eax, [esi]                                                      // uop: 0/1
+00604                                 mov             [edi+NL3D_CLOD_UV_OFF], eax                     // uop: 0/0/1/1
+00605                                 mov             ebx, [esi+4]                                            // uop: 0/1
+00606                                 mov             [edi+NL3D_CLOD_UV_OFF+4], ebx           // uop: 0/0/1/1
+00607                                 // next
+00608                                 add             esi, 8                                  // uop: 1/0
+00609                                 mov             uvPtr, esi                              // uop: 0/0/1/1
+00610 
+00611 
+00612                                 // **** Clamp lighting
+00613                                 // clamp to 0 only. will be clamped to 255 by MMX
+00614                                 mov             eax, f8                                 // uop: 0/1
+00615                                 cmp             eax, 0x80000000                 // if>=0 => CF=1
+00616                                 sbb             ebx, ebx                                // if>=0 => CF==1 => ebx=0xFFFFFFFF
+00617                                 and             eax, ebx                                // if>=0 => eax unchanged, else eax=0 (clamped)
+00618                                 
+00619                                 
+00620                                 // **** Modulate lighting modulate with diffuse color, add ambient term, using MMX
+00621                                 movd                    mm0, eax                // 0000000L             uop: 1/0
+00622                                 packuswb                mm0, mm0                // 000L000L             uop: 1/0 (p1)
+00623                                 packuswb                mm0, mm0                // 0L0L0L0L             uop: 1/0 (p1)
+00624                                 movd                    mm1, diffuse    //                              uop: 0/1
+00625                                 punpcklbw               mm1, blank              //                              uop: 1/1 (p1)
+00626                                 pmullw                  mm0, mm1                // diffuse*L    uop: 1/0 (3)
+00627                                 psrlw                   mm0, 8                  // 0A0B0G0R             uop: 1/0 (p1)
+00628                                 packuswb                mm0, blank              // 0000ABGR             uop: 1/1 (p1)
+00629                                 movd                    mm2, ambient    //                              uop: 0/1
+00630                                 paddusb                 mm0, mm2                //                              uop: 1/0
+00631                                 movd                    ebx, mm0                // ebx= AABBGGRR        uop: 1/0
+00632                                 // NB: emms is not so bad on P2+: delay of 6, +11 (NB: far better than no MMX instructions)
+00633                                 emms                                                    // uop: 11/0 (6).  (?????)
+00634                                 
+00635                                 
+00636                                 // **** append alpha, and store
+00637                                 mov             esi, alphaPtr                                           // uop: 0/1
+00638                                 movzx   eax, byte ptr[esi]                                      // uop: 0/1
+00639                                 shl             eax, 24                                                         // uop: 1/0
+00640                                 add             ebx, eax                                                        // uop: 1/0
+00641                                 // now, ebx=  AABBGGRR
+00642                                 mov             [edi+NL3D_CLOD_COLOR_OFF], ebx          // uop: 0/0/1/1
+00643                                 // next
+00644                                 add             esi, 1                                  // uop: 1/0
+00645                                 mov             alphaPtr, esi                   // uop: 0/0/1/1
+00646                                 
+00647                                 
+00648                                 // **** next
+00649                                 add             edi, NL3D_CLOD_VERTEX_SIZE              // uop: 1/0
+00650 
+00651                                 mov             eax, numVertices                // uop: 0/1
+00652                                 dec             eax                                             // uop: 1/0
+00653                                 mov             numVertices, eax                // uop: 0/0/1/1
+00654 
+00655                                 jnz             theLoop                                 // uop: 1/1 (p1)
+00656 
+00657                                 // To have same behavior than c code
+00658                                 mov             dstPtr, edi
+00659                         }
+00660                 }
+00661         }
+00662         else
+00663 #endif
+00664         {
+00665                 H_AUTO( NL3D_CharacterLod_vertexFill );
+00666 
+00667                 CVector         fVect;
+00668                 
+00669                 for(;numVertices>0;)
+00670                 {
+00671                         // NB: order is important for AGP filling optimisation
+00672                         // transform vertex, and store.
+00673                         CVector         *dstVector= (CVector*)dstPtr;
+00674                         fVect.x= vertPtr->x; fVect.y= vertPtr->y; fVect.z= vertPtr->z; 
+00675                         ++vertPtr;
+00676                         dstVector->x= a00 * fVect.x + a01 * fVect.y + a02 * fVect.z + matPos.x;
+00677                         dstVector->y= a10 * fVect.x + a11 * fVect.y + a12 * fVect.z + matPos.y;
+00678                         dstVector->z= a20 * fVect.x + a21 * fVect.y + a22 * fVect.z + matPos.z;
+00679                         // Copy UV
+00680                         *(CUV*)(dstPtr + NL3D_CLOD_UV_OFF)= *uvPtr;
+00681                         ++uvPtr;
+00682                         
+00683                         // Compute Lighting.
+00684                         CRGBA   lightRes;
+00685                         computeLodLighting(lightRes, lightObjectSpace, *normalPtr, ambient, diffuse);
+00686                         ++normalPtr;
+00687                         lightRes.A= *alphaPtr;
+00688                         ++alphaPtr;
+00689                         // store.
+00690                         *((CRGBA*)(dstPtr + NL3D_CLOD_COLOR_OFF))= lightRes;
+00691 
+00692                         // next
+00693                         dstPtr+= NL3D_CLOD_VERTEX_SIZE;
+00694                         numVertices--;
+00695                 }
+00696         }
+00697 
+00698         // Add Primitives.
+00699         //=============
+00700 
+00701         {
+00702                 H_AUTO( NL3D_CharacterLod_primitiveFill )
+00703                         
+00704                 // get number of tri indexes
+00705                 uint    numTriIdxs= clod->getNumTriangles() * 3;
+00706 
+00707                 // realloc tris if needed.
+00708                 if(_CurrentTriId+numTriIdxs > _Triangles.size())
+00709                 {
+00710                         _Triangles.resize(_CurrentTriId+numTriIdxs);
+00711                 }
+00712 
+00713                 // reindex and copy tris
+00714                 const uint32    *srcIdx= clod->getTriangleArray();
+00715                 uint32                  *dstIdx= &_Triangles[_CurrentTriId];
+00716                 for(;numTriIdxs>0;numTriIdxs--, srcIdx++, dstIdx++)
+00717                 {
+00718                         *dstIdx= *srcIdx + _CurrentVertexId;
+00719                 }
+00720         }
+00721 
+00722         // Next
+00723         //=============
+00724 
+00725         // Inc Vertex count.
+00726         _CurrentVertexId+= clod->getNumVertices();
+00727         // Inc Prim count.
+00728         _CurrentTriId+= clod->getNumTriangles() * 3;
+00729 
+00730 
+00731         // key added
+00732         return true;
+00733 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NL3D::CLodCharacterManager::addTextureCompute CLodCharacterInstance instance,
const CLodCharacterTexture lodTexture
+
+ + + + + +
+   + + +

+add a texture from an instance. Texture Lookup are made in _TmpBitmaps +

+ +

+Definition at line 955 of file lod_character_manager.cpp. +

+References _TmpBitmaps, NLMISC::CRGBA::A, NL3D::CLodCharacterTmpBitmap::getPixel(), getTextureInstance(), NL3D_CLOD_BIGTEXT_WIDTH, NL3D_CLOD_TEXT_HEIGHT, NL3D_CLOD_TEXT_SIZE, NL3D_CLOD_TEXT_WIDTH, nlassert, NL3D::CLodCharacterTexture::CTUVQ::Q, NL3D::CLodCharacterTexture::CTUVQ::T, NL3D::CLodCharacterTexture::Texture, NL3D::CLodCharacterTexture::CTUVQ::U, uint, NL3D::CLodCharacterTexture::CTUVQ::V, x, and y. +

+Referenced by NL3D::CSkeletonModel::computeLodTexture(). +

+

00956 {
+00957         CRGBA   *dst= getTextureInstance(instance);
+00958         if(!dst)
+00959                 return;
+00960 
+00961         // get lookup ptr.
+00962         nlassert(lodTexture.Texture.size()==NL3D_CLOD_TEXT_SIZE);
+00963         const CLodCharacterTexture::CTUVQ               *lookUpPtr= &lodTexture.Texture[0];
+00964 
+00965         // apply the lodTexture, taking only better quality (ie nearer 0)
+00966         for(uint y=0;y<NL3D_CLOD_TEXT_HEIGHT;y++)
+00967         {
+00968                 // erase the line
+00969                 for(uint x=0;x<NL3D_CLOD_TEXT_WIDTH;x++)
+00970                 {
+00971                         CLodCharacterTexture::CTUVQ             lut= *lookUpPtr;
+00972                         // if this quality is better than the one stored
+00973                         if(lut.Q<dst[x].A)
+00974                         {
+00975                                 // get what texture to read, and read the pixel.
+00976                                 CRGBA   col= _TmpBitmaps[lut.T].getPixel(lut.U, lut.V);
+00977                                 // set quality.
+00978                                 col.A= lut.Q;
+00979                                 // set in dest
+00980                                 dst[x]= col;
+00981                         }
+00982 
+00983                         // next lookup
+00984                         lookUpPtr++;
+00985                 }
+00986                 // Next line
+00987                 dst+= NL3D_CLOD_BIGTEXT_WIDTH;
+00988         }
+00989 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NL3D::CLodCharacterManager::beginRender IDriver driver,
const CVector managerPos
+
+ + + + + +
+   + + +

+Start the rendering process, freeing VBuffer. nlassert if isRendering() NB: VBhard is locked here, so you must call endRender to unlock him (even if 0 meshes are rendered)

+

Parameters:
+ + +
managerPos is to help ZBuffer Precision (see IDriver::setupViewMatrixEx). This vector is removed from all instance worldMatrixes, and a IDriver::setupModelMatrix() will be done with this position. Hence, whatever value you give, the result will be the same. But if you give a value near the camera position, ZBuffer precision will be enhanced.
+
+ +

+Definition at line 276 of file lod_character_manager.cpp. +

+References _CurrentTriId, _CurrentVertexId, _LockDone, _ManagerMatrixPos, _MaxNumVertices, _NumVBHard, _Rendering, _VertexSize, _VertexStream, NL3D::CVertexBuffer::getColorOff(), NL3D::CVertexStreamManager::getDriver(), NL3D::CVertexStreamManager::getMaxVertices(), NL3D::CVertexStreamManager::getNumVBHard(), NL3D::CVertexBuffer::getTexCoordOff(), NL3D::CVertexStreamManager::getVertexSize(), H_AUTO, NL3D::CVertexStreamManager::init(), isRendering(), NL3D_CLOD_COLOR_OFF, NL3D_CLOD_UV_OFF, NL3D_CLOD_VERTEX_FORMAT, NL3D_CLOD_VERTEX_SIZE, nlassert, NL3D::CVertexStreamManager::release(), and NL3D::CVertexBuffer::setVertexFormat(). +

+Referenced by NL3D::CSkeletonModel::renderCLod(), and NL3D::CRenderTrav::traverse(). +

+

00277 {
+00278         H_AUTO( NL3D_CharacterLod_beginRender );
+00279 
+00280         // we must not be beewteen beginRender() and endRender()
+00281         nlassert(!isRendering());
+00282 
+00283         // Reset render
+00284         //=================
+00285         _CurrentVertexId=0;
+00286         _CurrentTriId= 0;
+00287 
+00288         // update Driver.
+00289         //=================
+00290         nlassert(driver);
+00291 
+00292         // test change of vertexStream setup
+00293         bool    mustChangeVertexStream= _VertexStream.getDriver() != driver;
+00294         if(!mustChangeVertexStream)
+00295         {
+00296                 mustChangeVertexStream= _MaxNumVertices != _VertexStream.getMaxVertices();
+00297                 mustChangeVertexStream= mustChangeVertexStream || _NumVBHard != _VertexStream.getNumVBHard();
+00298         }
+00299         // re-init?
+00300         if( mustChangeVertexStream )
+00301         {
+00302                 // chech offset
+00303                 CVertexBuffer   vb;
+00304                 vb.setVertexFormat(NL3D_CLOD_VERTEX_FORMAT);
+00305                 // NB: addRenderCharacterKey() loop hardCoded for Vertex+UV+Normal+Color only.
+00306                 nlassert( NL3D_CLOD_UV_OFF == vb.getTexCoordOff());
+00307                 nlassert( NL3D_CLOD_COLOR_OFF == vb.getColorOff());
+00308 
+00309                 // Setup the vertex stream
+00310                 _VertexStream.release();
+00311                 _VertexStream.init(driver, NL3D_CLOD_VERTEX_FORMAT, _MaxNumVertices, _NumVBHard, "CLodManagerVB");
+00312         }
+00313         
+00314         // prepare for render.
+00315         //=================
+00316 
+00317         // Do not Lock Buffer now (will be done at the first instance added)
+00318         nlassert(!_LockDone);
+00319         _VertexSize= _VertexStream.getVertexSize();
+00320         // NB: addRenderCharacterKey() loop hardCoded for Vertex+UV+Normal+Color only.
+00321         nlassert( _VertexSize == NL3D_CLOD_VERTEX_SIZE );       // Vector + Normal + UV + RGBA
+00322 
+00323 
+00324         // Alloc a minimum of primitives (2*vertices), to avoid as possible reallocation in addRenderCharacterKey
+00325         if(_Triangles.size()<_MaxNumVertices * 2)
+00326                 _Triangles.resize(_MaxNumVertices * 2);
+00327 
+00328         // Local manager matrix
+00329         _ManagerMatrixPos= managerPos;
+00330 
+00331         // Ok, start rendering
+00332         _Rendering= true;
+00333 }
+
+

+ + + + +
+ + + + + + + + + +
bool NL3D::CLodCharacterManager::compile  ) 
+
+ + + + + +
+   + + +

+re-compile the shape map. This must be called after changing shape bank list. It return false if same names have been found, but it is still correctly builded. +

+Definition at line 212 of file lod_character_manager.cpp. +

+References _ShapeBankArray, _ShapeMap, NL3D::CLodCharacterShape::getName(), ItStrIdMap, nlwarning, and uint. +

+Referenced by NL3D::CSceneUser::deleteCLodShapeBank(), and NL3D::CSceneUser::loadCLodShapeBank(). +

+

00213 {
+00214         bool    error= false;
+00215 
+00216         // clear the map
+00217         contReset(_ShapeMap);
+00218 
+00219         // build the map
+00220         for(uint i=0; i<_ShapeBankArray.size(); i++)
+00221         {
+00222                 if(_ShapeBankArray[i])
+00223                 {
+00224                         // Parse all Shapes
+00225                         for(uint j=0; j<_ShapeBankArray[i]->getNumShapes(); j++)
+00226                         {
+00227                                 // build the shape Id
+00228                                 uint    shapeId= (i<<16) + j;
+00229 
+00230                                 // get the shape
+00231                                 const CLodCharacterShape        *shape= _ShapeBankArray[i]->getShape(j);
+00232                                 if(shape)
+00233                                 {
+00234                                         const string &name= shape->getName();
+00235                                         ItStrIdMap      it= _ShapeMap.find(name);
+00236                                         if(it == _ShapeMap.end())
+00237                                                 // insert the id in the map
+00238                                                 _ShapeMap.insert(make_pair(name, shapeId));
+00239                                         else
+00240                                         {
+00241                                                 error= true;
+00242                                                 nlwarning("Found a Character Lod with same name in the manager: %s", name.c_str());
+00243                                         }
+00244                                 }
+00245                         }
+00246                 }
+00247         }
+00248 
+00249         return error;
+00250 }
+
+

+ + + + +
+ + + + + + + + + +
uint32 NL3D::CLodCharacterManager::createShapeBank  ) 
+
+ + + + + +
+   + + +

+create a Shape Bank. NB: a vector of ShapeBank is maintained internally, hence, not so many shapeBank should be created at same Time.

Returns:
id of the shape Bank.
+ +

+Definition at line 134 of file lod_character_manager.cpp. +

+References _ShapeBankArray, uint, and uint32. +

+Referenced by NL3D::CSceneUser::loadCLodShapeBank(). +

+

00135 {
+00136         // search a free entry
+00137         for(uint i=0;i<_ShapeBankArray.size();i++)
+00138         {
+00139                 // if ree, use it.
+00140                 if(_ShapeBankArray[i]==NULL)
+00141                 {
+00142                         _ShapeBankArray[i]= new CLodCharacterShapeBank;
+00143                         return i;
+00144                 }
+00145         }
+00146 
+00147         // no free entrey, resize array.
+00148         _ShapeBankArray.push_back(new CLodCharacterShapeBank);
+00149         return _ShapeBankArray.size()-1;
+00150 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLodCharacterManager::deleteShapeBank uint32  bankId  ) 
+
+ + + + + +
+   + + +

+delete a Shape Bank. No-op if bad id. +

+ +

+Definition at line 171 of file lod_character_manager.cpp. +

+References _ShapeBankArray, and uint32. +

+Referenced by NL3D::CSceneUser::deleteCLodShapeBank(). +

+

00172 {
+00173         if(bankId>=_ShapeBankArray.size())
+00174         {
+00175                 if(_ShapeBankArray[bankId])
+00176                 {
+00177                         delete _ShapeBankArray[bankId];
+00178                         _ShapeBankArray[bankId]= NULL;
+00179                 }
+00180         }
+00181 }
+
+

+ + + + +
+ + + + + + + + + +
void NL3D::CLodCharacterManager::endRender  ) 
+
+ + + + + +
+   + + +

+compile the rendering process, effectively rendering into driver the lods. nlassert if not isRendering(). The VBHard is unlocked here. +

+Definition at line 736 of file lod_character_manager.cpp. +

+References _CurrentTriId, _CurrentVertexId, _LockDone, _ManagerMatrixPos, _Rendering, _VertexStream, NL3D::CVertexStreamManager::activate(), NL3D::CVertexStreamManager::getDriver(), H_AUTO, isRendering(), nlassert, NL3D::IDriver::renderTriangles(), NLMISC::CMatrix::setPos(), NL3D::IDriver::setupModelMatrix(), NL3D::CVertexStreamManager::swapVBHard(), and NL3D::CVertexStreamManager::unlock(). +

+Referenced by NL3D::CSkeletonModel::renderCLod(), and NL3D::CRenderTrav::traverse(). +

+

00737 {
+00738         H_AUTO ( NL3D_CharacterLod_endRender );
+00739         
+00740         IDriver         *driver= _VertexStream.getDriver();
+00741         nlassert(driver);
+00742         // we must be beewteen beginRender() and endRender()
+00743         nlassert(isRendering());
+00744 
+00745         // if something rendered
+00746         if(_LockDone)
+00747         {
+00748                 // UnLock Buffer.
+00749                 _VertexStream.unlock(_CurrentVertexId);
+00750                 _LockDone= false;
+00751                 
+00752                 // Render the VBuffer and the primitives.
+00753                 if(_CurrentTriId>0)
+00754                 {
+00755                         // setup matrix.
+00756                         CMatrix         managerMatrix; 
+00757                         managerMatrix.setPos(_ManagerMatrixPos);
+00758                         driver->setupModelMatrix(managerMatrix);
+00759                         
+00760                         // active VB
+00761                         _VertexStream.activate();
+00762                         
+00763                         // render triangles
+00764                         driver->renderTriangles(_Material, &_Triangles[0], _CurrentTriId/3);
+00765                 }
+00766                 
+00767                 // swap Stream VBHard
+00768                 _VertexStream.swapVBHard();
+00769         }
+00770 
+00771         // Ok, end rendering
+00772         _Rendering= false;
+00773 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NL3D::CLodCharacterManager::endTextureCompute CLodCharacterInstance instance,
uint  numBmpToReset
+
+ + + + + +
+   + + +

+end and compile. reset/free memory of _TmpBitmaps up to numBmpToReset. +

+ +

+Definition at line 992 of file lod_character_manager.cpp. +

+References _BigTexture, NL3D::CLodCharacterInstance::_TextureId, _TmpBitmaps, NLMISC::CRGBA::A, getTextureInstance(), NL3D_CLOD_BIGTEXT_WIDTH, NL3D_CLOD_DEFAULT_TEXCOLOR, NL3D_CLOD_TEXT_HEIGHT, NL3D_CLOD_TEXT_NLOD_WIDTH, NL3D_CLOD_TEXT_WIDTH, NL3D::CLodCharacterTmpBitmap::reset(), uint, x, and y. +

+Referenced by NL3D::CSkeletonModel::computeLodTexture(). +

+

00993 {
+00994         CRGBA   *dst= getTextureInstance(instance);
+00995         if(!dst)
+00996                 return;
+00997 
+00998         // reset All Alpha values to 255 => no AlphaTest problems
+00999         for(uint y=0;y<NL3D_CLOD_TEXT_HEIGHT;y++)
+01000         {
+01001                 // erase the line
+01002                 for(uint x=0;x<NL3D_CLOD_TEXT_WIDTH;x++)
+01003                 {
+01004                         dst[x].A= 255;
+01005                 }
+01006                 // Next line
+01007                 dst+= NL3D_CLOD_BIGTEXT_WIDTH;
+01008         }
+01009 
+01010         // If the id == 0 then must reset the 0,0 Pixel to black. for the "Not Enough memory" case in initInstance().
+01011         if(instance._TextureId==0)
+01012                 *(CRGBA*)&_BigTexture->getPixels(0)[0]= NL3D_CLOD_DEFAULT_TEXCOLOR;
+01013 
+01014         // get the x/y.
+01015         uint    xId= instance._TextureId % NL3D_CLOD_TEXT_NLOD_WIDTH;
+01016         uint    yId= instance._TextureId / NL3D_CLOD_TEXT_NLOD_WIDTH;
+01017         // touch the texture for Driver update.
+01018         _BigTexture->touchRect(
+01019                 CRect(xId*NL3D_CLOD_TEXT_WIDTH, yId*NL3D_CLOD_TEXT_HEIGHT, NL3D_CLOD_TEXT_WIDTH, NL3D_CLOD_TEXT_HEIGHT) );
+01020 
+01021         // reset tmpBitmaps / free memory.
+01022         for(uint i=0; i<numBmpToReset; i++)
+01023         {
+01024                 _TmpBitmaps[i].reset();
+01025         }
+01026 
+01027         // TestYoyo
+01028         /*NLMISC::COFile        f("tam.tga");
+01029         _BigTexture->writeTGA(f,32);*/
+01030 }
+
+

+ + + + +
+ + + + + + + + + +
uint32 NL3D::CLodCharacterManager::getMaxVertex  )  const [inline]
+
+ + + + + +
+   + + +

+see setMaxVertex() +

+ +

+Definition at line 163 of file lod_character_manager.h. +

+References _MaxNumVertices, and uint32. +

+

00163 {return _MaxNumVertices;}
+
+

+ + + + +
+ + + + + + + + + + +
const CLodCharacterShape * NL3D::CLodCharacterManager::getShape uint32  shapeId  )  const
+
+ + + + + +
+   + + +

+Get a const ref on a shape. Ptr not valid if shape Banks are modfied. NULL if not found. +

+ +

+Definition at line 194 of file lod_character_manager.cpp. +

+References NL3D::CLodCharacterShapeBank::getShape(), getShapeBank(), uint, and uint32. +

+Referenced by addRenderCharacterKey(), NL3D::CSkeletonModel::computeCLodVertexAlpha(), NL3D::CSceneUser::getCLodAnimIdByName(), and initInstance(). +

+

00195 {
+00196         // split the id
+00197         uint    bankId= shapeId >> 16;
+00198         uint    shapeInBankId= shapeId &0xFFFF;
+00199 
+00200         // if valid bankId
+00201         const CLodCharacterShapeBank    *shapeBank= getShapeBank(bankId);
+00202         if(shapeBank)
+00203         {
+00204                 // return the shape from the bank
+00205                 return shapeBank->getShape(shapeInBankId);
+00206         }
+00207         else
+00208                 return NULL;
+00209 }
+
+

+ + + + +
+ + + + + + + + + + +
CLodCharacterShapeBank * NL3D::CLodCharacterManager::getShapeBank uint32  bankId  ) 
+
+ + + + + +
+   + + +

+get a shape Bank. UseFull for serialisation for example. return NULL if not found +

+ +

+Definition at line 162 of file lod_character_manager.cpp. +

+References _ShapeBankArray, and uint32. +

+

00163 {
+00164         if(bankId>=_ShapeBankArray.size())
+00165                 return NULL;
+00166         else
+00167                 return _ShapeBankArray[bankId];
+00168 }
+
+

+ + + + +
+ + + + + + + + + + +
const CLodCharacterShapeBank * NL3D::CLodCharacterManager::getShapeBank uint32  bankId  )  const
+
+ + + + + +
+   + + +

+get a shape Bank. UseFull for serialisation for example. return NULL if not found +

+ +

+Definition at line 153 of file lod_character_manager.cpp. +

+References _ShapeBankArray, and uint32. +

+Referenced by getShape(), and NL3D::CSceneUser::loadCLodShapeBank(). +

+

00154 {
+00155         if(bankId>=_ShapeBankArray.size())
+00156                 return NULL;
+00157         else
+00158                 return _ShapeBankArray[bankId];
+00159 }
+
+

+ + + + +
+ + + + + + + + + + +
sint32 NL3D::CLodCharacterManager::getShapeIdByName const std::string &  name  )  const
+
+ + + + + +
+   + + +

+Get a shapeId by its name. -1 if not found. Call valid only if compile() has been correctly called +

+Definition at line 184 of file lod_character_manager.cpp. +

+References _ShapeMap, CstItStrIdMap, and sint32. +

+Referenced by NL3D::CSceneUser::getCLodShapeIdByName(). +

+

00185 {
+00186         CstItStrIdMap   it= _ShapeMap.find(name);
+00187         if(it==_ShapeMap.end())
+00188                 return -1;
+00189         else
+00190                 return it->second;
+00191 }
+
+

+ + + + +
+ + + + + + + + + + +
CRGBA * NL3D::CLodCharacterManager::getTextureInstance CLodCharacterInstance instance  )  [private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 915 of file lod_character_manager.cpp. +

+References _BigTexture, NL3D::CLodCharacterInstance::_Owner, NL3D::CLodCharacterInstance::_TextureId, NL3D_CLOD_BIGTEXT_WIDTH, NL3D_CLOD_TEXT_HEIGHT, NL3D_CLOD_TEXT_NLOD_WIDTH, NL3D_CLOD_TEXT_NUM_IDS, NL3D_CLOD_TEXT_WIDTH, nlassert, and uint. +

+Referenced by addTextureCompute(), endTextureCompute(), and startTextureCompute(). +

+

00916 {
+00917         nlassert(instance._Owner==this);
+00918         nlassert(instance._TextureId!=-1);
+00919         // if the texture id is a "not enough memory", quit.
+00920         if(instance._TextureId==NL3D_CLOD_TEXT_NUM_IDS)
+00921                 return NULL;
+00922 
+00923         // get the x/y.
+00924         uint    xId= instance._TextureId % NL3D_CLOD_TEXT_NLOD_WIDTH;
+00925         uint    yId= instance._TextureId / NL3D_CLOD_TEXT_NLOD_WIDTH;
+00926 
+00927         // get the ptr on the correct pixel.
+00928         CRGBA   *pix= (CRGBA*)&_BigTexture->getPixels(0)[0];
+00929         return pix + yId*NL3D_CLOD_TEXT_HEIGHT*NL3D_CLOD_BIGTEXT_WIDTH + xId*NL3D_CLOD_TEXT_WIDTH;
+00930 }
+
+

+ + + + +
+ + + + + + + + + + +
CLodCharacterTmpBitmap& NL3D::CLodCharacterManager::getTmpBitmap uint8  id  )  [inline]
+
+ + + + + +
+   + + +

+get a tmp bitmap for a special slot. caller can fill RGBA texture for the associated material Id in it. +

+ +

+Definition at line 233 of file lod_character_manager.h. +

+References _TmpBitmaps, and uint8. +

+Referenced by NL3D::CSkeletonModel::computeLodTexture(). +

+

00233 {return _TmpBitmaps[id];}
+
+

+ + + + +
+ + + + + + + + + +
uint32 NL3D::CLodCharacterManager::getVertexStreamNumVBHard  )  const [inline]
+
+ + + + + +
+   + + +

+see setVertexStreamNumVBHard +

+ +

+Definition at line 173 of file lod_character_manager.h. +

+References _NumVBHard, and uint32. +

+

00173 {return _NumVBHard;}
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLodCharacterManager::initInstance CLodCharacterInstance instance  ) 
+
+ + + + + +
+   + + +

+Init the instance texturing with this manager. A texture space is reserved (if possible), and UVs are generated. +

+ +

+Definition at line 844 of file lod_character_manager.cpp. +

+References _FreeIds, NL3D::CLodCharacterInstance::_Owner, NL3D::CLodCharacterInstance::_TextureId, NL3D::CLodCharacterInstance::_UVs, NL3D::CLodCharacterShape::getNumVertices(), getShape(), NL3D::CLodCharacterShape::getUVs(), NL3D_CLOD_TEXT_NLOD_HEIGHT, NL3D_CLOD_TEXT_NLOD_WIDTH, NL3D_CLOD_TEXT_NUM_IDS, nlassert, releaseInstance(), NL3D::CLodCharacterInstance::ShapeId, NLMISC::CUV::U, uint, and NLMISC::CUV::V. +

+Referenced by NL3D::CSkeletonModel::setLodCharacterShape(). +

+

00845 {
+00846         // first release in (maybe) other manager.
+00847         if(instance._Owner)
+00848                 instance._Owner->releaseInstance(instance);
+00849 
+00850         // get the shape
+00851         const CLodCharacterShape        *clod= getShape(instance.ShapeId);
+00852         // if not found quit
+00853         if(!clod)
+00854                 return;
+00855         // get Uvs.
+00856         const CUV       *uvSrc= clod->getUVs();
+00857         nlassert(uvSrc);
+00858 
+00859 
+00860         // Ok, init header
+00861         instance._Owner= this;
+00862         instance._UVs.resize(clod->getNumVertices());
+00863 
+00864         // allocate an id. If cannot, then fill Uvs with 0 => filled with Black. (see endTextureCompute() why).
+00865         if(_FreeIds.empty())
+00866         {
+00867                 // set a "Not enough memory" id
+00868                 instance._TextureId= NL3D_CLOD_TEXT_NUM_IDS;
+00869                 CUV             uv(0,0);
+00870                 fill(instance._UVs.begin(), instance._UVs.end(), uv);
+00871         }
+00872         // else OK, can instanciate the Uvs.
+00873         else
+00874         {
+00875                 // get the id.
+00876                 instance._TextureId= _FreeIds.back();
+00877                 _FreeIds.pop_back();
+00878                 // get the x/y.
+00879                 uint    xId= instance._TextureId % NL3D_CLOD_TEXT_NLOD_WIDTH;
+00880                 uint    yId= instance._TextureId / NL3D_CLOD_TEXT_NLOD_WIDTH;
+00881                 // compute the scale/bias to apply to Uvs.
+00882                 float   scaleU= 1.0f / NL3D_CLOD_TEXT_NLOD_WIDTH;
+00883                 float   scaleV= 1.0f / NL3D_CLOD_TEXT_NLOD_HEIGHT;
+00884                 float   biasU= (float)xId / NL3D_CLOD_TEXT_NLOD_WIDTH;
+00885                 float   biasV= (float)yId / NL3D_CLOD_TEXT_NLOD_HEIGHT;
+00886                 // apply it to each UVs.
+00887                 CUV             *uvDst= &instance._UVs[0];
+00888                 for(uint i=0; i<instance._UVs.size();i++)
+00889                 {
+00890                         uvDst[i].U= biasU + uvSrc[i].U*scaleU;
+00891                         uvDst[i].V= biasV + uvSrc[i].V*scaleV;
+00892                 }
+00893         }
+00894 }
+
+

+ + + + +
+ + + + + + + + + +
bool NL3D::CLodCharacterManager::isRendering  )  const [inline]
+
+ + + + + +
+   + + +

+tells if we are beetween a beginRender() and a endRender() +

+ +

+Definition at line 209 of file lod_character_manager.h. +

+References _Rendering. +

+Referenced by addRenderCharacterKey(), beginRender(), endRender(), NL3D::CSkeletonModel::renderCLod(), reset(), setMaxVertex(), and setVertexStreamNumVBHard(). +

+

00209 {return _Rendering;}
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLodCharacterManager::releaseInstance CLodCharacterInstance instance  ) 
+
+ + + + + +
+   + + +

+Release a lod instance. Free texture space. +

+ +

+Definition at line 897 of file lod_character_manager.cpp. +

+References _FreeIds, NL3D::CLodCharacterInstance::_Owner, NL3D::CLodCharacterInstance::_TextureId, NL3D::CLodCharacterInstance::_UVs, NL3D_CLOD_TEXT_NUM_IDS, and nlassert. +

+Referenced by initInstance(), NL3D::CSkeletonModel::setLodCharacterShape(), and NL3D::CLodCharacterInstance::~CLodCharacterInstance(). +

+

00898 {
+00899         if(instance._Owner==NULL)
+00900                 return;
+00901         nlassert(this==instance._Owner);
+00902 
+00903         // if the id is not a "Not enough memory" id, release it.
+00904         if(instance._TextureId>=0 && instance._TextureId<NL3D_CLOD_TEXT_NUM_IDS)
+00905                 _FreeIds.push_back(instance._TextureId);
+00906 
+00907         // reset the instance
+00908         instance._Owner= NULL;
+00909         instance._TextureId= -1;
+00910         contReset(instance._UVs);
+00911 }
+
+

+ + + + +
+ + + + + + + + + +
void NL3D::CLodCharacterManager::reset  ) 
+
+ + + + + +
+   + + +

+reset the manager. +

+ +

+Definition at line 114 of file lod_character_manager.cpp. +

+References _ShapeBankArray, _ShapeMap, _VertexStream, isRendering(), nlassert, NL3D::CVertexStreamManager::release(), and uint. +

+Referenced by NL3D::CScene::release(), NL3D::CSceneUser::resetCLodManager(), and ~CLodCharacterManager(). +

+

00115 {
+00116         nlassert(!isRendering());
+00117 
+00118         // delete shapeBanks.
+00119         for(uint i=0;i<_ShapeBankArray.size();i++)
+00120         {
+00121                 if(_ShapeBankArray[i])
+00122                         delete _ShapeBankArray[i];
+00123         }
+00124 
+00125         // clears containers
+00126         contReset(_ShapeBankArray);
+00127         contReset(_ShapeMap);
+00128 
+00129         // reset render part.
+00130         _VertexStream.release();
+00131 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLodCharacterManager::setMaxVertex uint32  maxVertex  ) 
+
+ + + + + +
+   + + +

+set the max number of vertices the manager can render in one time. Default is 3000 vertices. nlassert if isRendering() +

+Definition at line 260 of file lod_character_manager.cpp. +

+References _MaxNumVertices, isRendering(), nlassert, and uint32. +

+

00261 {
+00262         // we must not be beewteen beginRender() and endRender()
+00263         nlassert(!isRendering());
+00264         _MaxNumVertices= maxVertex;
+00265 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLodCharacterManager::setupNormalCorrectionMatrix const CMatrix normalMatrix  ) 
+
+ + + + + +
+   + + +

+Setup a correction matrix for Lighting. Normals are multiplied with this matrix before lighting. This is important in Ryzom because models (and so Lods) are building with eye looking in Y<0. But they are animated with eye looking in X>0. The default setup is hence a matrix wich do a RotZ+=90.

See also:
addRenderCharacterKey
+ +

+Definition at line 776 of file lod_character_manager.cpp. +

+References _LightCorrectionMatrix, NLMISC::CMatrix::invert(), and NLMISC::CMatrix::setPos(). +

+

00777 {
+00778         _LightCorrectionMatrix= normalMatrix;
+00779         _LightCorrectionMatrix.setPos(CVector::Null);
+00780         _LightCorrectionMatrix.invert();
+00781 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLodCharacterManager::setVertexStreamNumVBHard uint32  numVBHard  ) 
+
+ + + + + +
+   + + +

+set the number of vbhard to allocate for the vertexStream. The more, the better (no lock stall). Default is 8. With MaxVertices==3000 and numVBHard==8, this led us with 576 Ko in AGP. And this is sufficient cause it can handle 300 entities of approx 80 vertices each frame with no lock at all. +

+Definition at line 268 of file lod_character_manager.cpp. +

+References _NumVBHard, isRendering(), nlassert, and uint32. +

+

00269 {
+00270         // we must not be beewteen beginRender() and endRender()
+00271         nlassert(!isRendering());
+00272         _NumVBHard= numVBHard;
+00273 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NL3D::CLodCharacterManager::startTextureCompute CLodCharacterInstance instance  ) 
+
+ + + + + +
+   + + +

+reset the textureSpace. Instance must have been inited (nlassert). return false if no more texture space available +

+ +

+Definition at line 934 of file lod_character_manager.cpp. +

+References getTextureInstance(), NL3D_CLOD_BIGTEXT_WIDTH, NL3D_CLOD_DEFAULT_TEXCOLOR, NL3D_CLOD_TEXT_HEIGHT, NL3D_CLOD_TEXT_WIDTH, uint, x, and y. +

+Referenced by NL3D::CSkeletonModel::computeLodTexture(). +

+

00935 {
+00936         CRGBA   *dst= getTextureInstance(instance);
+00937         if(!dst)
+00938                 return false;
+00939 
+00940         // erase the texture with 0,0,0,255. Alpha is actually the min "Quality" part of the CTUVQ.
+00941         CRGBA   col= NL3D_CLOD_DEFAULT_TEXCOLOR;
+00942         for(uint y=0;y<NL3D_CLOD_TEXT_HEIGHT;y++)
+00943         {
+00944                 // erase the line
+00945                 for(uint x=0;x<NL3D_CLOD_TEXT_WIDTH;x++)
+00946                         dst[x]= col;
+00947                 // Next line
+00948                 dst+= NL3D_CLOD_BIGTEXT_WIDTH;
+00949         }
+00950 
+00951         return true;
+00952 }
+
+


Field Documentation

+

+ + + + +
+ + +
CSmartPtr<CTextureBlank> NL3D::CLodCharacterManager::_BigTexture [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 290 of file lod_character_manager.h. +

+Referenced by CLodCharacterManager(), endTextureCompute(), and getTextureInstance().

+

+ + + + +
+ + +
uint NL3D::CLodCharacterManager::_CurrentTriId [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 277 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), beginRender(), and endRender().

+

+ + + + +
+ + +
uint NL3D::CLodCharacterManager::_CurrentVertexId [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 267 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), beginRender(), and endRender().

+

+ + + + +
+ + +
std::vector<uint> NL3D::CLodCharacterManager::_FreeIds [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 292 of file lod_character_manager.h. +

+Referenced by CLodCharacterManager(), initInstance(), and releaseInstance().

+

+ + + + +
+ + +
CMatrix NL3D::CLodCharacterManager::_LightCorrectionMatrix [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 281 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), CLodCharacterManager(), and setupNormalCorrectionMatrix().

+

+ + + + +
+ + +
bool NL3D::CLodCharacterManager::_LockDone [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 274 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), beginRender(), CLodCharacterManager(), and endRender().

+

+ + + + +
+ + +
CVector NL3D::CLodCharacterManager::_ManagerMatrixPos [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 262 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), beginRender(), and endRender().

+

+ + + + +
+ + +
CMaterial NL3D::CLodCharacterManager::_Material [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 265 of file lod_character_manager.h.

+

+ + + + +
+ + +
uint NL3D::CLodCharacterManager::_MaxNumVertices [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 268 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), beginRender(), CLodCharacterManager(), getMaxVertex(), and setMaxVertex().

+

+ + + + +
+ + +
uint NL3D::CLodCharacterManager::_NumVBHard [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 269 of file lod_character_manager.h. +

+Referenced by beginRender(), CLodCharacterManager(), getVertexStreamNumVBHard(), and setVertexStreamNumVBHard().

+

+ + + + +
+ + +
bool NL3D::CLodCharacterManager::_Rendering [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 273 of file lod_character_manager.h. +

+Referenced by beginRender(), CLodCharacterManager(), endRender(), and isRendering().

+

+ + + + +
+ + +
std::vector<CLodCharacterShapeBank*> NL3D::CLodCharacterManager::_ShapeBankArray [private] +
+
+ + + + + +
+   + + +

+Array of shapeBank. +

+ +

+Definition at line 253 of file lod_character_manager.h. +

+Referenced by compile(), createShapeBank(), deleteShapeBank(), getShapeBank(), and reset().

+

+ + + + +
+ + +
TStrIdMap NL3D::CLodCharacterManager::_ShapeMap [private] +
+
+ + + + + +
+   + + +

+Map of shape id. +

+ +

+Definition at line 256 of file lod_character_manager.h. +

+Referenced by compile(), getShapeIdByName(), and reset().

+

+ + + + +
+ + +
CLodCharacterTmpBitmap NL3D::CLodCharacterManager::_TmpBitmaps[256] [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 295 of file lod_character_manager.h. +

+Referenced by addTextureCompute(), endTextureCompute(), and getTmpBitmap().

+

+ + + + +
+ + +
std::vector<uint32> NL3D::CLodCharacterManager::_Triangles [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 278 of file lod_character_manager.h.

+

+ + + + +
+ + +
uint8* NL3D::CLodCharacterManager::_VertexData [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 271 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey().

+

+ + + + +
+ + +
uint NL3D::CLodCharacterManager::_VertexSize [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 272 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), and beginRender().

+

+ + + + +
+ + +
CVertexStreamManager NL3D::CLodCharacterManager::_VertexStream [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 270 of file lod_character_manager.h. +

+Referenced by addRenderCharacterKey(), beginRender(), endRender(), and reset().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 06:49:53 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1