# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

vertex_buffer.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_VERTEX_BUFFER_H
00027 #define NL_VERTEX_BUFFER_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/misc/rgba.h"
00032 #include "nel/misc/vector.h"
00033 #include "nel/misc/vectord.h"
00034 #include "nel/misc/debug.h"
00035 #include "nel/misc/uv.h"
00036 #include <vector>
00037 #include <list>
00038 
00039 namespace NLMISC 
00040 {
00041         class CUV;
00042 }
00043 
00044 
00045 namespace NL3D 
00046 {
00047 
00048 using NLMISC::CRefCount;
00049 using NLMISC::CRefPtr;
00050 using NLMISC::CRGBA;
00051 using NLMISC::CVector;
00052 using NLMISC::CVectorD;
00053 using NLMISC::CUV;
00054 
00055 
00056 class   IDriver;
00057 
00058 // --------------------------------------------------
00059 
00060 
00061 // List typedef.
00062 class   IVBDrvInfos;
00063 typedef std::list<IVBDrvInfos*>                 TVBDrvInfoPtrList;
00064 typedef TVBDrvInfoPtrList::iterator             ItVBDrvInfoPtrList;
00065 
00066 
00067 // *** IMPORTANT ********************
00068 // *** IF YOU MODIFY THE STRUCTURE OF THIS CLASS, PLEASE INCREMENT IDriver::InterfaceVersion TO INVALIDATE OLD DRIVER DLL
00069 // **********************************
00070 class IVBDrvInfos : public CRefCount
00071 {
00072 private:
00073         IDriver                         *_Driver;
00074         ItVBDrvInfoPtrList      _DriverIterator;
00075 
00076 public:
00077         IVBDrvInfos(IDriver     *drv, ItVBDrvInfoPtrList it) {_Driver= drv; _DriverIterator= it;}
00078         // The virtual dtor is important.
00079         virtual ~IVBDrvInfos();
00080 };
00081 
00082 
00083 // ***************************************************************************
00087 struct  CPaletteSkin
00088 {
00089         uint8   MatrixId[4];
00090 
00091         void    serial(NLMISC::IStream &f);
00092 };
00093 
00094 // ***************************************************************************
00095 
00100 /* *** IMPORTANT ********************
00101  * *** IF YOU MODIFY THE STRUCTURE OF THIS CLASS, PLEASE INCREMENT IDriver::InterfaceVersion TO INVALIDATE OLD DRIVER DLL
00102  * **********************************
00103  */
00104 // All these flags are similar to DX8
00105 class CVertexBuffer : public CRefCount
00106 {
00107 public:
00108 
00112         enum TValue
00113         { 
00114                 Position                =0, 
00115                 Normal                  =1, 
00116                 TexCoord0               =2,
00117                 TexCoord1               =3, 
00118                 TexCoord2               =4,
00119                 TexCoord3               =5, 
00120                 TexCoord4               =6, 
00121                 TexCoord5               =7, 
00122                 TexCoord6               =8, 
00123                 TexCoord7               =9,
00124                 PrimaryColor    =10, 
00125                 SecondaryColor  =11, 
00126                 Weight                  =12,
00127                 PaletteSkin             =13,
00128                 Fog                             =14, 
00129                 Empty                   =15,
00130                 NumValue                =16
00131         };
00132 
00136         enum
00137         {
00138                 FirstTexCoordValue = TexCoord0,
00139                 LastTexCoordValue  = TexCoord7,         
00140         };
00141 
00145         enum 
00146         {
00147                 PositionFlag            =       1<<Position, 
00148                 NormalFlag                      =       1<<Normal, 
00149                 TexCoord0Flag           =       1<<TexCoord0, 
00150                 TexCoord1Flag           =       1<<TexCoord1, 
00151                 TexCoord2Flag           =       1<<TexCoord2, 
00152                 TexCoord3Flag           =       1<<TexCoord3, 
00153                 TexCoord4Flag           =       1<<TexCoord4, 
00154                 TexCoord5Flag           =       1<<TexCoord5, 
00155                 TexCoord6Flag           =       1<<TexCoord6, 
00156                 TexCoord7Flag           =       1<<TexCoord7,
00157                 PrimaryColorFlag        =       1<<PrimaryColor, 
00158                 SecondaryColorFlag      =       1<<SecondaryColor, 
00159                 WeightFlag                      =       1<<Weight,
00160                 PaletteSkinFlag         =       (1<<PaletteSkin)|(1<<Weight),
00161                 FogFlag                         =       1<<Fog, 
00162                 EmptyFlag                       =       1<<Empty,
00163         };
00164 
00165         
00166 
00170         enum TType
00171         { 
00172                 Double1=0, 
00173                 Float1, 
00174                 Short1, 
00175                 Double2, 
00176                 Float2, 
00177                 Short2, 
00178                 Double3, 
00179                 Float3, 
00180                 Short3,
00181                 Double4, 
00182                 Float4, 
00183                 Short4,
00184                 UChar4,
00185                 NumType
00186         };
00187 
00191         enum
00192         {
00193                 // Max count of texture coordinates
00194                 MaxStage = 8,
00195 
00196                 // Max count of skinning weight
00197                 MaxWeight = 4,
00198         };
00199 
00203         static const uint SizeType[NumType];
00204 
00208         static const TType DefaultValueType[NumValue];
00209 
00213         static const uint  NumComponentsType[NumType];
00214 
00215 private:
00216 
00220         enum
00221         {
00223                 TouchedVertexFormat             = 1,
00224 
00226                 TouchedNumVertices              = 2,
00227 
00229                 TouchedAll                              = 0xFFFF
00230         };
00231 
00232         // Type of data stored in each value
00233         uint8                                   _Type[NumValue];        // Offset 0 : aligned
00234         uint8                                   _Pad;                           // Offset 13 : aligned
00235 
00236         // Size of the vertex (sum of the size of each value
00237         uint16                                  _VertexSize;            // Offset 14 : aligned
00238 
00239         // Flags: bit #n is 1 if the value #n is used
00240         uint16                                  _Flags;                         // Offset 16 : aligned
00241 
00242         // Internal flags
00243         uint16                                  _InternalFlags;         // Offset 18 : aligned
00244 
00245         // Vertex count in the buffer
00246         uint32                                  _NbVerts;                       // Offset 20 : aligned
00247 
00248         // Capacity of the buffer
00249         uint32                                  _Capacity;
00250 
00251         // Vertex array
00252         std::vector<uint8>              _Verts;
00253 
00254         // Offset of each value
00255         uint16                                  _Offset[NumValue];
00256 
00257 public:
00258         // \name Private. For Driver only.
00259         // @{
00260         CRefPtr<IVBDrvInfos>    DrvInfos;
00261         uint                                    getTouchFlags() const { return _InternalFlags&TouchedAll; }
00262         void                                    resetTouchFlags() {_InternalFlags &= ~TouchedAll;}
00263         // @}
00264 
00265 public:
00266 
00270         CVertexBuffer(void);
00271 
00276         CVertexBuffer(const CVertexBuffer &vb);
00277 
00281         ~CVertexBuffer(void);
00282 
00287         CVertexBuffer                   &operator=(const CVertexBuffer &vb);
00288 
00293         // @{
00294 
00304                 bool                                    setVertexFormat (uint32 Flags);
00305 
00315                 uint16                                  getVertexFormat (void) const  { return(_Flags); };
00316 
00317 
00319                 uint                                    getNumTexCoordUsed() const;
00320 
00321                 // It is an error (assert) to set a vertex component if not setuped in setVertexFormat().
00322                 inline void                             setVertexCoord(uint idx, float x, float y, float z);
00323                 inline void                             setVertexCoord(uint idx, const CVector &v);
00324                 inline void                             setNormalCoord(uint idx, const CVector &v);
00325                 inline void                             setTexCoord(uint idx, uint8 stage, float u, float v);
00326                 inline void                             setTexCoord(uint idx, uint8 stage, const CUV &uv);
00327                 inline void                             setColor(uint idx, CRGBA rgba);
00328                 inline void                             setSpecular(uint idx, CRGBA rgba);
00329                 inline void                             setWeight(uint idx, uint8 wgt, float w);
00330                 inline void                             setPaletteSkin(uint idx, CPaletteSkin ps);
00331 
00332                 // It is an error (assert) to query a vertex offset of a vertex component not setuped in setVertexFormat().
00333                 // NB: The Vertex offset is always 0.
00334                 sint                                    getNormalOff() const {nlassert(_Flags & NormalFlag); return _Offset[Normal];}
00335                 sint                                    getTexCoordOff(uint8 stage=0) const  {nlassert(_Flags & (TexCoord0Flag<<stage)); return _Offset[TexCoord0+stage]; }
00336                 sint                                    getColorOff() const {nlassert(_Flags & PrimaryColorFlag); return _Offset[PrimaryColor];}
00337                 sint                                    getSpecularOff() const {nlassert(_Flags & SecondaryColorFlag); return _Offset[SecondaryColor];}
00339                 sint                                    getWeightOff(sint wgt) const {nlassert(_Flags & WeightFlag); return _Offset[Weight]+(wgt*sizeof(float));}
00340                 sint                                    getPaletteSkinOff() const {nlassert(_Flags & PaletteSkin); return _Offset[PaletteSkin];}
00341 
00351                 void*                                   getVertexCoordPointer(uint idx=0);
00352                 void*                                   getNormalCoordPointer(uint idx=0);
00353                 void*                                   getTexCoordPointer(uint idx=0, uint8 stage=0);
00354                 void*                                   getColorPointer(uint idx=0);
00355                 void*                                   getSpecularPointer(uint idx=0);
00356                 void*                                   getWeightPointer(uint idx=0, uint8 wgt=0);
00357                 void*                                   getPaletteSkinPointer(uint idx=0);
00358 
00359                 const void*                             getVertexCoordPointer(uint idx=0) const ;
00360                 const void*                             getNormalCoordPointer(uint idx=0) const ;
00361                 const void*                             getTexCoordPointer(uint idx=0, uint8 stage=0) const ;
00362                 const void*                             getColorPointer(uint idx=0) const ;
00363                 const void*                             getSpecularPointer(uint idx=0) const ;
00364                 const void*                             getWeightPointer(uint idx=0, uint8 wgt=0) const ;
00365                 const void*                             getPaletteSkinPointer(uint idx=0) const ;
00366         // @}
00367 
00373         // @{
00374 
00381                 static TValue           getValueIdByNumberEx (uint valueNumber);
00382 
00387                 void                            clearValueEx ();                
00388 
00395                 void                            addValueEx (TValue valueId, TType type);
00396 
00398                 bool                            hasValueEx(TValue valueId) const;               
00399 
00403                 void                            initEx ();
00404 
00408                 inline void                     setValueDouble1Ex (TValue valueId, uint idx, double value);
00409                 inline void                     setValueDouble2Ex (TValue valueId, uint idx, double x, double y);
00410                 inline void                     setValueDouble3Ex (TValue valueId, uint idx, double x, double y, double z);
00411                 inline void                     setValueDouble3Ex (TValue valueId, uint idx, const CVectorD& vector);
00412                 inline void                     setValueDouble4Ex (TValue valueId, uint idx, double x, double y, double z, double w);
00413                 inline void                     setValueFloat1Ex (TValue valueId, uint idx, float value);
00414                 inline void                     setValueFloat2Ex (TValue valueId, uint idx, float x, float y);
00415                 inline void                     setValueFloat3Ex (TValue valueId, uint idx, float x, float y, float z);
00416                 inline void                     setValueFloat3Ex (TValue valueId, uint idx, const CVector& vector);
00417                 inline void                     setValueFloat4Ex (TValue valueId, uint idx, float x, float y, float z, float w);
00418                 inline void                     setValueShort1Ex (TValue valueId, uint idx, uint16 value);
00419                 inline void                     setValueShort2Ex (TValue valueId, uint idx, uint16 x, uint16 y);
00420                 inline void                     setValueShort3Ex (TValue valueId, uint idx, uint16 x, uint16 y, uint16 z);
00421                 inline void                     setValueShort4Ex (TValue valueId, uint idx, uint16 x, uint16 y, uint16 z, uint16 w);
00422                 inline void                     setValueUChar4Ex (TValue valueId, uint idx, CRGBA rgba);
00423 
00427                 void*                           getValueEx (TValue valueId, uint idx=0) { nlassert (_Flags & (1<<valueId));     return (void*)((&(*_Verts.begin()))+idx*_VertexSize+getValueOffEx (valueId)); }
00428 
00432                 const void*                     getValueEx (TValue valueId, uint idx=0) const { nlassert (_Flags & (1<<valueId));       return (void*)((&(*_Verts.begin()))+idx*_VertexSize+getValueOffEx (valueId)); };
00433 
00437                 sint                            getValueOffEx (TValue valueId) const { nlassert(_Flags & (1<<valueId)); return _Offset[valueId]; };
00438 
00439         // @}
00440 
00444         void                                    setNumVertices(uint32 n);
00445         
00449         uint32                                  getNumVertices(void) const  { return(_NbVerts); }
00450 
00454         void                                    deleteAllVertices();
00455 
00459         void                                    reserve(uint32 nVerts);
00460         
00464         uint32                                  capacity() { return _Capacity; }
00465 
00469         uint16                                  getVertexSize (void) const { return(_VertexSize); }
00470 
00474         TType                                   getValueType (uint value) const { nlassert (value<NumValue); return((TType)_Type[value]); }
00475 
00479         const uint8                             *getValueTypePointer () const { return _Type; }
00480 
00484         uint8                                   getNumWeight () const;
00485 
00486         void            serial(NLMISC::IStream &f);
00487 
00488 
00490         // @{
00492         void            serialHeader(NLMISC::IStream &f);
00496         void            serialSubset(NLMISC::IStream &f, uint vertexStart, uint vertexEnd);
00497         // @}
00498 
00499 
00500 private:
00502         void            serialOldV1Minus(NLMISC::IStream &f, sint ver);
00503 
00505         uint16          remapV2Flags (uint32 oldFlags, uint& weightCount);
00506 };
00507 
00508 
00510 // implementation of inline methods //
00512 // --------------------------------------------------
00513 
00514 inline void CVertexBuffer::setVertexCoord(uint idx, float x, float y, float z)
00515 {
00516         float*  ptr;
00517 
00518         nlassert (_Flags & PositionFlag);
00519         nlassert (_Type[Position]==Float3);
00520 
00521         ptr=(float*)(&_Verts[idx*_VertexSize]);
00522         *ptr=x;
00523         ptr++;
00524         *ptr=y;
00525         ptr++;
00526         *ptr=z;
00527 }
00528 
00529 // --------------------------------------------------
00530 
00531 inline void CVertexBuffer::setVertexCoord(uint idx, const CVector &v)
00532 {
00533         uint8*  ptr;
00534 
00535         nlassert (_Flags & PositionFlag);
00536         nlassert (_Type[Position]==Float3);
00537 
00538         ptr=&_Verts[idx*_VertexSize];
00539         memcpy(ptr, &(v.x), 3*sizeof(float));
00540 }
00541 
00542 // --------------------------------------------------
00543 
00544 inline void CVertexBuffer::setNormalCoord(uint idx, const CVector &v)
00545 {
00546         uint8*  ptr;
00547 
00548         nlassert (_Flags & NormalFlag);
00549         nlassert (_Type[Normal]==Float3);
00550 
00551         ptr=&_Verts[idx*_VertexSize];
00552         ptr+=_Offset[Normal];
00553         memcpy(ptr, &(v.x), 3*sizeof(float));
00554 }
00555 
00556 // --------------------------------------------------
00557 
00558 inline void CVertexBuffer::setColor(uint idx, CRGBA rgba)
00559 {
00560         uint8*  ptr;
00561         CRGBA   *pCol;
00562 
00563         nlassert(_Flags & PrimaryColorFlag);
00564         nlassert (_Type[PrimaryColor]==UChar4);
00565 
00566         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00567         ptr+=_Offset[PrimaryColor];
00568         pCol= (CRGBA*)ptr;
00569         *pCol= rgba;
00570 }
00571 
00572 // --------------------------------------------------
00573 
00574 inline void CVertexBuffer::setSpecular(uint idx, CRGBA rgba)
00575 {
00576         uint8*  ptr;
00577         CRGBA   *pCol;
00578 
00579         nlassert(_Flags & SecondaryColorFlag);
00580         nlassert (_Type[SecondaryColor]==UChar4);
00581 
00582         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00583         ptr+=_Offset[SecondaryColor];
00584         pCol= (CRGBA*)ptr;
00585         *pCol= rgba;
00586 }
00587 
00588 // --------------------------------------------------
00589 
00590 inline void CVertexBuffer::setTexCoord(uint idx, uint8 stage, float u, float v)
00591 {
00592         uint8*  ptr;
00593         float*  ptrf;
00594 
00595         nlassert(stage<MaxStage);
00596         nlassert(_Flags & (TexCoord0Flag<<stage));
00597         nlassert (_Type[TexCoord0+stage]==Float2);
00598 
00599         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00600         ptr+=_Offset[TexCoord0+stage];
00601         ptrf=(float*)ptr;
00602         *ptrf=u;
00603         ptrf++;
00604         *ptrf=v;
00605 }
00606 
00607 // --------------------------------------------------
00608 
00609 inline void     CVertexBuffer::setTexCoord(uint idx, uint8 stage, const CUV &uv)
00610 {
00611         uint8*  ptr;
00612         CUV*    ptruv;
00613 
00614         nlassert(stage<MaxStage);
00615         nlassert(_Flags & (TexCoord0Flag<<stage));
00616         nlassert (_Type[TexCoord0+stage]==Float2);
00617 
00618         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00619         ptr+=_Offset[TexCoord0+stage];
00620         ptruv=(CUV*)ptr;
00621         *ptruv=uv;
00622 }
00623 
00624 
00625 // --------------------------------------------------
00626 
00627 inline void CVertexBuffer::setWeight(uint idx, uint8 wgt, float w)
00628 {
00629         uint8*  ptr;
00630         float*  ptrf;
00631 
00632         nlassert(wgt<MaxWeight);
00633         nlassert(_Flags & (WeightFlag));
00634 
00635         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00636         ptr+=_Offset[Weight]+sizeof(float)*wgt;
00637         ptrf=(float*)ptr;
00638         *ptrf=w;
00639 }
00640 
00641 // --------------------------------------------------
00642 
00643 inline void     CVertexBuffer::setPaletteSkin(uint idx, CPaletteSkin ps)
00644 {
00645         uint8*  ptr;
00646         CPaletteSkin    *pPalSkin;
00647 
00648         nlassert ( (_Flags & PaletteSkinFlag) == CVertexBuffer::PaletteSkinFlag);
00649         nlassert (_Type[PaletteSkin]==UChar4);
00650 
00651         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00652         ptr+=_Offset[PaletteSkin];
00653         pPalSkin= (CPaletteSkin*)ptr;
00654         *pPalSkin= ps;
00655 }
00656 
00657 // --------------------------------------------------
00658 
00659 inline void CVertexBuffer::setValueDouble1Ex (TValue valueId, uint idx, double value)
00660 {
00661         uint8*  ptr;
00662         double* ptrd;
00663 
00664         nlassert(valueId<NumValue);
00665         nlassert(_Flags & (1<<(uint)valueId));
00666         nlassert((_Type[valueId]==Double4)||(_Type[valueId]==Double3)||(_Type[valueId]==Double2)||(_Type[valueId]==Double1));
00667 
00668         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00669         ptr+=_Offset[valueId];
00670         ptrd=(double*)ptr;
00671         *ptrd=value;
00672 }
00673 
00674 // --------------------------------------------------
00675 
00676 inline void CVertexBuffer::setValueDouble2Ex (TValue valueId, uint idx, double x, double y)
00677 {
00678         uint8*  ptr;
00679         double* ptrd;
00680 
00681         nlassert(valueId<NumValue);
00682         nlassert(_Flags & (1<<(uint)valueId));
00683         nlassert((_Type[valueId]==Double4)||(_Type[valueId]==Double3)||(_Type[valueId]==Double2));
00684 
00685         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00686         ptr+=_Offset[valueId];
00687         ptrd=(double*)ptr;
00688         ptrd[0]=x;
00689         ptrd[1]=y;
00690 }
00691 
00692 // --------------------------------------------------
00693 
00694 inline void CVertexBuffer::setValueDouble3Ex (TValue valueId, uint idx, double x, double y, double z)
00695 {
00696         uint8*  ptr;
00697         double* ptrd;
00698 
00699         nlassert(valueId<NumValue);
00700         nlassert(_Flags & (1<<(uint)valueId));
00701         nlassert((_Type[valueId]==Double4)||(_Type[valueId]==Double3));
00702 
00703         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00704         ptr+=_Offset[valueId];
00705         ptrd=(double*)ptr;
00706         ptrd[0]=x;
00707         ptrd[1]=y;
00708         ptrd[2]=z;
00709 }
00710 
00711 // --------------------------------------------------
00712 
00713 inline void CVertexBuffer::setValueDouble3Ex (TValue valueId, uint idx, const NLMISC::CVectorD& vector)
00714 {
00715         uint8*  ptr;
00716         double* ptrd;
00717 
00718         nlassert(valueId<NumValue);
00719         nlassert(_Flags & (1<<(uint)valueId));
00720         nlassert((_Type[valueId]==Double4)||(_Type[valueId]==Double3));
00721 
00722         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00723         ptr+=_Offset[valueId];
00724         ptrd=(double*)ptr;
00725         memcpy (ptrd, &vector, sizeof(double)*3);
00726 }
00727 
00728 // --------------------------------------------------
00729 
00730 inline void CVertexBuffer::setValueDouble4Ex (TValue valueId, uint idx, double x, double y, double z, double w)
00731 {
00732         uint8*  ptr;
00733         double* ptrd;
00734 
00735         nlassert(valueId<NumValue);
00736         nlassert(_Flags & (1<<(uint)valueId));
00737         nlassert(_Type[valueId]==Double4);
00738 
00739         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00740         ptr+=_Offset[valueId];
00741         ptrd=(double*)ptr;
00742         ptrd[0]=x;
00743         ptrd[1]=y;
00744         ptrd[2]=z;
00745         ptrd[3]=w;
00746 }
00747 
00748 // --------------------------------------------------
00749 
00750 inline void CVertexBuffer::setValueFloat1Ex (TValue valueId, uint idx, float value)
00751 {
00752         uint8*  ptr;
00753         float*  ptrf;
00754 
00755         nlassert(valueId<NumValue);
00756         nlassert(_Flags & (1<<(uint)valueId));
00757         nlassert((_Type[valueId]==Float4)||(_Type[valueId]==Float3)||(_Type[valueId]==Float2)||(_Type[valueId]==Float1));
00758 
00759         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00760         ptr+=_Offset[valueId];
00761         ptrf=(float*)ptr;
00762         *ptrf=value;
00763 }
00764 
00765 // --------------------------------------------------
00766 
00767 inline void CVertexBuffer::setValueFloat2Ex (TValue valueId, uint idx, float x, float y)
00768 {
00769         uint8*  ptr;
00770         float*  ptrf;
00771 
00772         nlassert(valueId<NumValue);
00773         nlassert(_Flags & (1<<(uint)valueId));
00774         nlassert((_Type[valueId]==Float4)||(_Type[valueId]==Float3)||(_Type[valueId]==Float2));
00775 
00776         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00777         ptr+=_Offset[valueId];
00778         ptrf=(float*)ptr;
00779         ptrf[0]=x;
00780         ptrf[1]=y;
00781 }
00782 
00783 // --------------------------------------------------
00784 
00785 inline void CVertexBuffer::setValueFloat3Ex (TValue valueId, uint idx, float x, float y, float z)
00786 {
00787         uint8*  ptr;
00788         float*  ptrf;
00789 
00790         nlassert(valueId<NumValue);
00791         nlassert(_Flags & (1<<(uint)valueId));
00792         nlassert((_Type[valueId]==Float4)||(_Type[valueId]==Float3));
00793 
00794         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00795         ptr+=_Offset[valueId];
00796         ptrf=(float*)ptr;
00797         ptrf[0]=x;
00798         ptrf[1]=y;
00799         ptrf[2]=z;
00800 }
00801 
00802 // --------------------------------------------------
00803 
00804 inline void CVertexBuffer::setValueFloat3Ex (TValue valueId, uint idx, const NLMISC::CVector& vector)
00805 {
00806         uint8*  ptr;
00807         float*  ptrf;
00808 
00809         nlassert(valueId<NumValue);
00810         nlassert(_Flags & (1<<(uint)valueId));
00811         nlassert((_Type[valueId]==Float4)||(_Type[valueId]==Float3));
00812 
00813         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00814         ptr+=_Offset[valueId];
00815         ptrf=(float*)ptr;
00816         memcpy (ptrf, &vector, sizeof(float)*3);
00817 }
00818 
00819 // --------------------------------------------------
00820 
00821 inline void CVertexBuffer::setValueFloat4Ex (TValue valueId, uint idx, float x, float y, float z, float w)
00822 {
00823         uint8*  ptr;
00824         float*  ptrf;
00825 
00826         nlassert(valueId<NumValue);
00827         nlassert(_Flags & (1<<(uint)valueId));
00828         nlassert(_Type[valueId]==Float4);
00829 
00830         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00831         ptr+=_Offset[valueId];
00832         ptrf=(float*)ptr;
00833         ptrf[0]=x;
00834         ptrf[1]=y;
00835         ptrf[2]=z;
00836         ptrf[3]=w;
00837 }
00838 
00839 // --------------------------------------------------
00840 
00841 inline void CVertexBuffer::setValueShort1Ex (TValue valueId, uint idx, uint16 value)
00842 {
00843         uint8*  ptr;
00844         uint16* ptri;
00845 
00846         nlassert(valueId<NumValue);
00847         nlassert(_Flags & (1<<(uint)valueId));
00848         nlassert((_Type[valueId]==Short4)||(_Type[valueId]==Short3)||(_Type[valueId]==Short2)||(_Type[valueId]==Short1));
00849 
00850         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00851         ptr+=_Offset[valueId];
00852         ptri=(uint16*)ptr;
00853         *ptri=value;
00854 }
00855 
00856 // --------------------------------------------------
00857 
00858 inline void CVertexBuffer::setValueShort2Ex (TValue valueId, uint idx, uint16 x, uint16 y)
00859 {
00860         uint8*  ptr;
00861         uint16* ptri;
00862 
00863         nlassert(valueId<NumValue);
00864         nlassert(_Flags & (1<<(uint)valueId));
00865         nlassert((_Type[valueId]==Short4)||(_Type[valueId]==Short3)||(_Type[valueId]==Short2));
00866 
00867         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00868         ptr+=_Offset[valueId];
00869         ptri=(uint16*)ptr;
00870         ptri[0]=x;
00871         ptri[1]=y;
00872 }
00873 
00874 // --------------------------------------------------
00875 
00876 inline void CVertexBuffer::setValueShort3Ex (TValue valueId, uint idx, uint16 x, uint16 y, uint16 z)
00877 {
00878         uint8*  ptr;
00879         uint16* ptri;
00880 
00881         nlassert(valueId<NumValue);
00882         nlassert(_Flags & (1<<(uint)valueId));
00883         nlassert((_Type[valueId]==Short4)||(_Type[valueId]==Short3));
00884 
00885         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00886         ptr+=_Offset[valueId];
00887         ptri=(uint16*)ptr;
00888         ptri[0]=x;
00889         ptri[1]=y;
00890         ptri[2]=z;
00891 }
00892 
00893 // --------------------------------------------------
00894 
00895 inline void CVertexBuffer::setValueShort4Ex (TValue valueId, uint idx, uint16 x, uint16 y, uint16 z, uint16 w)
00896 {
00897         uint8*  ptr;
00898         uint16* ptri;
00899 
00900         nlassert(valueId<NumValue);
00901         nlassert(_Flags & (1<<(uint)valueId));
00902         nlassert(_Type[valueId]==Short4);
00903 
00904         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00905         ptr+=_Offset[valueId];
00906         ptri=(uint16*)ptr;
00907         ptri[0]=x;
00908         ptri[1]=y;
00909         ptri[2]=z;
00910         ptri[3]=w;
00911 }
00912 
00913 // --------------------------------------------------
00914 
00915 inline void CVertexBuffer::setValueUChar4Ex (TValue valueId, uint idx, CRGBA rgba)
00916 {
00917         uint8*  ptr;
00918         CRGBA*  ptrr;
00919 
00920         nlassert(valueId<NumValue);
00921         nlassert(_Flags & (1<<(uint)valueId));
00922         nlassert(_Type[valueId]==UChar4);
00923 
00924         ptr=(uint8*)(&_Verts[idx*_VertexSize]);
00925         ptr+=_Offset[valueId];
00926         ptrr=(CRGBA*)ptr;
00927         *ptrr=rgba;
00928 }
00929 
00930 // --------------------------------------------------
00931 
00932 } // NL3D
00933 
00934 
00935 #endif // NL_VERTEX_BUFFER_H
00936 
00937 /* End of vertex_buffer.h */