atm i try to evaluate the requirements on a "flexible vertexformat". This will be interesting especially for shaders guy. Looking at ogl and dx8/dx9 i defined the following "system":
Code: Select all
enum VERTEX_DATA_TYPE { VERTEX_U8_4D, VERTEX_U32_1D, VERTEX_S16_2D, VERTEX_S16_4D,
VERTEX_F32_1D, VERTEX_F32_2D, VERTEX_F32_3D, VERTEX_F32_4D };
enum VERTEX_DATA_USAGE { VERTEX_POSITION, VERTEX_INT, VERTEX_NORMAL,
VERTEX_TEXTCOORD0, VERTEX_TEXTCOORD1, VERTEX_TEXTCOORD2, VERTEX_TEXTCOORD3,
VERTEX_TEXTCOORD4, VERTEX_TEXTCOORD5, VERTEX_TEXTCOORD6, VERTEX_TEXTCOORD7 };
struct VertexDeclaration
{
u32 offset;
VERTEX_DECL_TYPE data_type;
VERTEX_DATA_USAGE data_usage;
};
Second: The reason why it provides so few possibilities is simple. Just take a look at the following code and you will see it is may be the biggest "supported by all" subset.
Datatypes:
Code: Select all
typedef enum D3DDECLTYPE
{
D3DDECLTYPE_FLOAT1 = 0,
D3DDECLTYPE_FLOAT2 = 1,
D3DDECLTYPE_FLOAT3 = 2,
D3DDECLTYPE_FLOAT4 = 3,
D3DDECLTYPE_D3DCOLOR = 4,
D3DDECLTYPE_UBYTE4 = 5,
D3DDECLTYPE_SHORT2 = 6,
D3DDECLTYPE_SHORT4 = 7,
D3DDECLTYPE_UBYTE4N = 8,
D3DDECLTYPE_SHORT2N = 9,
D3DDECLTYPE_SHORT4N = 10,
D3DDECLTYPE_USHORT2N = 11,
D3DDECLTYPE_USHORT4N = 12,
D3DDECLTYPE_UDEC3 = 13,
D3DDECLTYPE_DEC3N = 14,
D3DDECLTYPE_FLOAT16_2 = 15,
D3DDECLTYPE_FLOAT16_4 = 16,
D3DDECLTYPE_UNUSED = 17,
};
/* DataType */
#define GL_BYTE 0x1400
#define GL_UNSIGNED_BYTE 0x1401
#define GL_SHORT 0x1402
#define GL_UNSIGNED_SHORT 0x1403
#define GL_INT 0x1404
#define GL_UNSIGNED_INT 0x1405
#define GL_FLOAT 0x1406
#define GL_2_BYTES 0x1407
#define GL_3_BYTES 0x1408
#define GL_4_BYTES 0x1409
#define GL_DOUBLE 0x140A
Code: Select all
typedef enum D3DDECLUSAGE
{
D3DDECLUSAGE_POSITION = 0,
D3DDECLUSAGE_BLENDWEIGHT = 1,
D3DDECLUSAGE_BLENDINDICES = 2,
D3DDECLUSAGE_NORMAL = 3,
D3DDECLUSAGE_PSIZE = 4,
D3DDECLUSAGE_TEXCOORD = 5,
D3DDECLUSAGE_TANGENT = 6,
D3DDECLUSAGE_BINORMAL = 7,
D3DDECLUSAGE_TESSFACTOR = 8,
D3DDECLUSAGE_POSITIONT = 9,
D3DDECLUSAGE_COLOR = 10,
D3DDECLUSAGE_FOG = 11,
D3DDECLUSAGE_DEPTH = 12,
D3DDECLUSAGE_SAMPLE = 13,
};
glVertexPointer <- allows GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE; count: 2-4
glNormalPointer <- allows GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE; count: 3
glColorPointer <- allows GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, GL_DOUBLE; count: 3-4
glTexCoordPointer <- allows GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE; count: 1-4