3 VBO
Chuck Walbourn редактировал(а) эту страницу 2018-11-12 10:25:55 -08:00

File Format Details

The VBO object is essentially a binary dump of a VB and an IB. It does not describe the input layout, the vertex size, attributes or material information, or support 32-bit index buffers.

DWORD numVertices
DWORD numIndices
<vertex data>
<16-bit index data>

The ResourceLoading sample used a vertex layout of { XMFLOAT3 position, XMFLOAT3 normal, XMFLOAT2 textureCoordinates } which is assumed to be fixed for the format. Variants could use alternative vertex formats, but this information is not encoded in the VBO file itself.

Example Code

std::ifstream vboFile(szFileName, std::ifstream::in | std::ifstream::binary);
if ( !vboFile.is_open() )
    return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );

uint32_t numVertices = 0;
uint32_t numIndices = 0;

vboFile.read( reinterpret_cast<char*>( &numVertices ), sizeof(uint32_t ) );
if ( !numVertices )
    return E_FAIL;

vboFile.read( reinterpret_cast<char*>( &numIndices ), sizeof(uint32_t ) );
if ( !numIndices )
    return E_FAIL;

struct Vertex
{
    XMFLOAT3 position;
    XMFLOAT3 normal;
    XMFLOAT2 textureCoordinates;
};

std::vector<Vertex> vertices;
vertices.resize( numVertices );
vboFile.read( reinterpret_cast<char*>( vertices.data() ), sizeof(Vertex) * numVertices );

std::vector<uint16_t> indices;
indices.resize( numIndices );
vboFile.read( reinterpret_cast<char*>( indices.data() ), sizeof(uint16_t) * numIndices );