3
$\begingroup$

How do you migrate Flexible Vertex Format Constants (or FVF codes) from DirectX 9 to Direct3D 11?

Old code:

#include <d3dx9.h>

struct Vertex {

public:
    Vertex() : p(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), n(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}
    Vertex(D3DXVECTOR3 p, D3DXVECTOR3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}

    // Position of the vertex (in world space)
    D3DXVECTOR3 p;
    // Normal of this vertex
    D3DXVECTOR3 n;
    // Texture UV coordinates
    float tu, tv;
};

// D3DFVF_XYZ: Vertex format includes the position of an untransformed vertex.
// D3DFVF_NORMAL: Vertex format includes a vertex normal vector.
// D3DFVF_TEX1: Number of texture coordinate sets for this vertex.
#define VERTEX_FVF ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
#define VERTEX_FVF_SIZE D3DXGetFVFVertexSize( VERTEX_FVF )

New code without D3DX:

#include <DirectXMath.h>
using namespace DirectX;

struct Vertex {

public:
    Vertex() : p(XMFLOAT3(0.0f, 0.0f, 0.0f)), n(XMFLOAT3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}
    Vertex(XMFLOAT3 p, XMFLOAT3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}

    // Position of the vertex (in world space)
    XMFLOAT3 p;
    // Normal of this vertex
    XMFLOAT3 n;
    // Texture UV coordinates
    float tu, tv;
};

// ??

P.S.: Can someone with enough reputation points create and add a directx9 tag.

$\endgroup$

1 Answer 1

2
$\begingroup$

Vertex formats are specified in D3D11 using the input layout. An example input layout description for your vertex might look like:

D3D11_INPUT_ELEMENT_DESC aInputDescs[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, p)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, n)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, UINT(offsetof(Vertex, tu)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
$\endgroup$
2
  • $\begingroup$ Is there a tangible D3D11 book you advice (like the red, blue, orange books for OpenGL)? Or is it just better to stick to Microsoft's webpages? $\endgroup$
    – Matthias
    Commented Oct 15, 2016 at 11:15
  • 1
    $\begingroup$ @Matthias I learned from the online API docs and other online resources. Maybe someone else can recommend a good book; I'm sure there are some out there. $\endgroup$ Commented Oct 15, 2016 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.