00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __NEVERTEXDECL_H
00028 #define __NEVERTEXDECL_H
00029
00030 #include "base.h"
00031 #include "nemath.h"
00032
00033
00039 namespace NeoEngine
00040 {
00041
00042
00048 class NEOENGINE_API VertexElement
00049 {
00050 public:
00051
00056 enum VERTEXDATATYPE
00057 {
00059 FLOAT = 0,
00060
00062 FLOAT2 = 1,
00063
00065 FLOAT3 = 2,
00066
00068 FLOAT4 = 3,
00069
00071 COLOR32 = 4,
00072
00074 UNKNOWNTYPE = 255
00075 };
00076
00077
00082 enum VERTEXDATAUSAGE
00083 {
00085 POSITION = 0,
00086
00088 NORMAL = 1,
00089
00091 TEXCOORD = 2,
00092
00094 DIFFUSECOLOR = 3,
00095
00097 TANGENT = 4,
00098
00100 BINORMAL = 5,
00101
00103 UNKNOWNUSAGE = 255
00104 };
00105
00106
00108 unsigned int m_uiType;
00109
00111 unsigned int m_uiUsage;
00112
00114 unsigned int m_uiIndex;
00115
00117 unsigned int m_uiOffset;
00118
00121 VertexElement() : m_uiType( UNKNOWNTYPE ), m_uiUsage( UNKNOWNUSAGE ), m_uiIndex( 0 ), m_uiOffset( 0 ) {}
00122
00129 VertexElement( unsigned int uiType, unsigned int uiUsage, unsigned int uiIndex, unsigned int uiOffset ) : m_uiType( uiType ), m_uiUsage( uiUsage ), m_uiIndex( uiIndex ), m_uiOffset( uiOffset ) {}
00130
00135 inline bool operator == ( const VertexElement &rkElement ) const { return( ( m_uiType == rkElement.m_uiType ) && ( m_uiUsage == rkElement.m_uiUsage ) && ( m_uiIndex == rkElement.m_uiIndex ) && ( m_uiOffset == rkElement.m_uiOffset ) ); }
00136 };
00137
00138
00139
00140
00147 class NEOENGINE_API VertexDeclaration
00148 {
00149 public:
00150
00152 VertexElement *m_pkElements;
00153
00155 unsigned int m_uiNumElements;
00156
00157
00161 VertexDeclaration( unsigned int uiNumElements );
00162
00166 VertexDeclaration( const VertexDeclaration &rkDeclaration );
00167
00170 virtual ~VertexDeclaration();
00171
00178 VertexElement *GetElement( unsigned int uiType = VertexElement::UNKNOWNTYPE, unsigned int uiUsage = VertexElement::UNKNOWNUSAGE );
00179
00186 const VertexElement *GetElement( unsigned int uiType = VertexElement::UNKNOWNTYPE, unsigned int uiUsage = VertexElement::UNKNOWNUSAGE ) const;
00187
00192 unsigned int GetVertexSize() const;
00193
00198 virtual VertexDeclaration *Duplicate() const;
00199
00203 VertexDeclaration &operator = ( const VertexDeclaration &rkDeclaration );
00204
00209 bool operator == ( const VertexDeclaration &rkDeclaration ) const;
00210
00218 inline void Interpolate( unsigned char *pucFrom, unsigned char *pucTo, unsigned char *pucDest, float fFactor ) const
00219 {
00220 for( unsigned int uiElement = 0; uiElement < m_uiNumElements; ++uiElement )
00221 {
00222 const VertexElement &kElement = m_pkElements[ uiElement ];
00223
00224 if( kElement.m_uiType < VertexElement::COLOR32 )
00225 {
00226
00227 float *pfLast = (float*)( pucFrom + kElement.m_uiOffset );
00228 float *pfNext = (float*)( pucTo + kElement.m_uiOffset );
00229 float *pfDest = (float*)( pucDest + kElement.m_uiOffset );
00230
00231
00232 for( unsigned int uiFloat = 0; uiFloat < ( kElement.m_uiType + 1 ); ++uiFloat, ++pfLast, ++pfNext, ++pfDest )
00233 *pfDest = *pfLast + ( *pfNext - *pfLast ) * fFactor;
00234
00235
00236 if( kElement.m_uiUsage == VertexElement::NORMAL )
00237 ((Vector3d*)( pucDest + kElement.m_uiOffset ))->Normalize();
00238 }
00239 else
00240 {
00241
00242 unsigned int uiSrcColorOne = *((unsigned int*)( pucFrom + kElement.m_uiOffset ) );
00243 unsigned int uiSrcColorTwo = *((unsigned int*)( pucTo + kElement.m_uiOffset ) );
00244
00245
00246 float fCol[4][2] = { { float( uiSrcColorOne & 0xFF ), float( uiSrcColorTwo & 0xFF ) },
00247 { float( ( uiSrcColorOne >> 8 ) & 0xFF ), float( ( uiSrcColorTwo >> 8 ) & 0xFF ) },
00248 { float( ( uiSrcColorOne >> 16 ) & 0xFF ), float( ( uiSrcColorTwo >> 16 ) & 0xFF ) },
00249 { float( ( uiSrcColorOne >> 24 ) & 0xFF ), float( ( uiSrcColorTwo >> 24 ) & 0xFF ) } };
00250
00251 int iFin[4] = { int( fCol[0][0] + ( fCol[0][1] - fCol[0][0] ) * fFactor ),
00252 int( fCol[1][0] + ( fCol[1][1] - fCol[1][0] ) * fFactor ),
00253 int( fCol[2][0] + ( fCol[2][1] - fCol[2][0] ) * fFactor ),
00254 int( fCol[3][0] + ( fCol[3][1] - fCol[3][0] ) * fFactor ) };
00255
00256 *((unsigned int*)( pucDest + kElement.m_uiOffset )) = ( iFin[0] & 0xFF ) | ( ( iFin[1] << 8 ) & 0xFF00 ) | ( ( iFin[2] << 16 ) & 0xFF0000 ) | ( ( iFin[3] << 24 ) & 0xFF000000 );
00257 }
00258 }
00259 }
00260
00269 virtual void InterpolateArray( unsigned char *pucFrom, unsigned char *pucTo, unsigned char *pucDest, float fFactor, unsigned int uiNumVertices ) const;
00270 };
00271
00272
00273 };
00274
00275
00276 #endif // __NEVERTEXDECL_H
00277