#include "dxstdafx.h" #include ".\flexvertex.h" FlexFormat* FlexVertex::format = NULL; void FlexVertex::setFormat(FlexFormat* format) { FlexVertex::format = format; } FlexFormat::FlexFormat() : posByteOffset(0), normalByteOffset(12), diffuseByteOffset(24), specularByteOffset(28), nTex(2) { unsigned int ii[16] = {24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144}; for(int iu=0; iu<16; iu++) texByteOffset[iu] = ii[iu]; } void FlexVertexArray::setFormat(D3DVERTEXELEMENT9* decl) { int i=0; format.nTex = 0; while(decl[i].Type != D3DDECLTYPE_UNUSED) { if(decl[i].Usage == D3DDECLUSAGE_POSITION) format.posByteOffset = decl[i].Offset; if(decl[i].Usage == D3DDECLUSAGE_NORMAL) format.normalByteOffset = decl[i].Offset; if(decl[i].Usage == D3DDECLUSAGE_COLOR) { if(decl[i].UsageIndex == 0) format.diffuseByteOffset = decl[i].Offset; if(decl[i].UsageIndex == 1) format.specularByteOffset = decl[i].Offset; } if(decl[i].Usage == D3DDECLUSAGE_TEXCOORD) { format.texByteOffset[decl[i].UsageIndex] = decl[i].Offset; if(decl[i].UsageIndex >= format.nTex) format.nTex = decl[i].UsageIndex+1; } i++; } FlexVertex::setFormat(&format); }