Supporting Various "Position" formats

Started by
0 comments, last by ProjectEW 9 years, 10 months ago

So far my engine always used 32-bit float3 to store position in a vertex. To integrate with a middleware package, my engine needs to support half position 16-bit float4. Some parts of my engine need to read the vertex data on the CPU side (say to compute a bounding box). Does someone have a clean solution for this besides if/else states like:

if(half format)

{

cast to half*

}

else

{

cast to float*

}

-----Quat
Advertisement

Depending on how exactly you are accessing and handling the vectors, you could make an overload of your vector handling function that accepts only half-vectors, casts it to a float vector, then passes it onto the overload of the function that takes a full size vector.

For example:


void calculateAABB(Vector3f v)
{
    ...
}

void calculateAABB(Vector3s v)
{
    calculateAABB((Vector3f)v);
}

Alternatively, if you are the one writing the vector classes, you could write an implicit cast in both vector classes to the other type, so the two can be used interchangeably. However, this code practice may be frowned upon, I don't use much C++.

This topic is closed to new replies.

Advertisement