I need to write a file format that writes out data to a file and can read it back.
It should be able to read the data back fairly fast, which should involve blitting a large block of data into a std::vector (since their storage is always implemented contiguously).
However, when writing the file, I have no idea how to enforce constraints on alignment and size of ints and other types.
How should this be done? I'm using gcc on buntu linux on Q6600 (x86).
Just as an example:
struct Vertex
{
float point [3];
float normal [3];
float texcoord [2];
}
Later on, the data is stored in a std::vector<Vertex>
. I have thought about using __attribute__
and packing / aligning it so that it will be more portable across different platforms.
edit: I've already made a specification, and I intend to use it. The largest bits of data are the Vertex and Indices, so those will be read as big blocks, and for example (one part of a larger spec): A VertexGroup is a group of vertices who share a characteristic. They can only hold one material at a time, so there should be many of them contained in a mesh.
<uint> thisid # Of this VertexGroup
<string> name
<uint> materialId # A material
<uint> vertexCount
for (vetexCount):
<3xfloat> point
<3xfloat> normal
<2xfloat> texcoord
<uint> triangleCount
for (triangleCount):
<3xuint> indices