//--------------------------------------------------------------------------------------------------------------------- MF_API void MFBegin(uint32 vertexCount) { MFDebug_Assert(phase == 1, "not in order 1"); MFDebug_Assert(vertexCount > 0, "Invalid primitive count."); currentPrim.numVertices = vertexCount; if(gImmitateQuads) currentPrim.numVertices *= 3; // create an appropriate vertex buffer pVB = MFVertex_CreateVertexBuffer(pDecl, currentPrim.numVertices, MFVBType_Scratch); currentPrim.pMeshState = MFStateBlock_CreateTemporary(gLargeStateblock ? 256 : 64); MFStateBlock_SetRenderState(currentPrim.pMeshState, MFSCRS_VertexDeclaration, pDecl); MFStateBlock_SetRenderState(currentPrim.pMeshState, MFSCRS_VertexBuffer0, pVB); MFVertex_LockVertexBuffer(pVB, (void**)&pLocked); currentVert = 0; current.u = current.v = 0.0f; current.colour = 0xFFFFFFFF; current.normal.x = current.normal.z = 0.0f; current.normal.y = 1.0f; phase = 2; }
void BuildVertexBuffers() { struct Vertex { float pos[3]; float uv[2]; uint32 col; }; // create vertex format declaration MFVertexElement elements[] = { { 0, MFVET_Position, 0, 3 }, { 0, MFVET_TexCoord, 0, 2 }, { 0, MFVET_Colour, 0, 4 } }; pVertexDecl = MFVertex_CreateVertexDeclaration(elements, sizeof(elements)/sizeof(elements[0])); // create box vertex buffer Vertex prism[4 * 3] = // 4 triangles, 1 per face { { { 1, -1, -1 }, { 0, 0 }, 0xFFFF0000 }, { { -1, -1, -1 }, { 0, 0 }, 0xFFFF0000 }, { { 0, 1, 0 }, { 0, 0 }, 0xFFFF0000 }, { { -1, -1, -1 }, { 0, 0 }, 0xFF00FF00 }, { { -1, -1, 1 }, { 0, 0 }, 0xFF00FF00 }, { { 0, 1, 0 }, { 0, 0 }, 0xFF00FF00 }, { { -1, -1, 1 }, { 0, 0 }, 0xFF0000FF }, { { 1, -1, 1 }, { 0, 0 }, 0xFF0000FF }, { { 0, 1, 0 }, { 0, 0 }, 0xFF0000FF }, { { 1, -1, 1 }, { 0, 0 }, 0xFFFFFF00 }, { { 1, -1, -1 }, { 0, 0 }, 0xFFFFFF00 }, { { 0, 1, 0 }, { 0, 0 }, 0xFFFFFF00 } }; pPrismVertexBuffer = MFVertex_CreateVertexBuffer(pVertexDecl, 4*3, MFVBType_Static, prism); pPrismMeshStateBlock = MFStateBlock_Create(64); MFStateBlock_SetRenderState(pPrismMeshStateBlock, MFSCRS_VertexDeclaration, pVertexDecl); MFStateBlock_SetRenderState(pPrismMeshStateBlock, MFSCRS_VertexBuffer(0), pPrismVertexBuffer); // create box vertex buffer Vertex box[12 * 3] = // 12 triangles, 2 per 6 faces of a cube { { { -1, -1, -1 }, { 0, 0 }, 0xFFFFFFFF }, { { -1, 1, -1 }, { 1, 0 }, 0xFFFFFFFF }, { { 1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, -1, -1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { 1, -1, -1 }, { 0, 1 }, 0xFFFFFFFF }, { { -1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, -1, 1 }, { 1, 0 }, 0xFFFFFFFF }, { { 1, 1, 1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, 1, 1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, 1, 1 }, { 0, 1 }, 0xFFFFFFFF }, { { 1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, -1, -1 }, { 1, 0 }, 0xFFFFFFFF }, { { 1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { 1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { 1, 1, 1 }, { 0, 1 }, 0xFFFFFFFF }, { { -1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { -1, 1, 1 }, { 1, 0 }, 0xFFFFFFFF }, { { -1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { -1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, -1, -1 }, { 0, 1 }, 0xFFFFFFFF }, { { -1, 1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, 1, 1 }, { 1, 0 }, 0xFFFFFFFF }, { { 1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, 1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, 1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, 1, -1 }, { 0, 1 }, 0xFFFFFFFF }, { { -1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { -1, -1, -1 }, { 1, 0 }, 0xFFFFFFFF }, { { 1, -1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { -1, -1, 1 }, { 0, 0 }, 0xFFFFFFFF }, { { 1, -1, -1 }, { 1, 1 }, 0xFFFFFFFF }, { { 1, -1, 1 }, { 0, 1 }, 0xFFFFFFFF } }; pBoxVertexBuffer = MFVertex_CreateVertexBuffer(pVertexDecl, 12*3, MFVBType_Static, box); pBoxMeshStateBlock = MFStateBlock_Create(64); MFStateBlock_SetRenderState(pBoxMeshStateBlock, MFSCRS_VertexDeclaration, pVertexDecl); MFStateBlock_SetRenderState(pBoxMeshStateBlock, MFSCRS_VertexBuffer(0), pBoxVertexBuffer); }