Split 'decode()' function into several variants so it's not so heavily overloaded.

This commit is contained in:
David Williams 2014-07-24 16:55:11 +02:00
parent 98e722271e
commit bfa14a32df
8 changed files with 18 additions and 19 deletions

View File

@ -103,7 +103,7 @@ int main(int argc, char *argv[])
// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
// decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code.
auto decodedMesh = decode(mesh);
auto decodedMesh = decodeMesh(mesh);
//Pass the surface to the OpenGL window
openGLWidget.addMesh(decodedMesh);

View File

@ -151,7 +151,7 @@ int main(int argc, char *argv[])
// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
// decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code.
//auto decodedMesh = decode(mesh);
//auto decodedMesh = decodeMesh(mesh);
//Pass the surface to the OpenGL window
OpenGLMeshData meshData = buildOpenGLMeshData(mesh);

View File

@ -128,7 +128,7 @@ int main(int argc, char *argv[])
auto mesh = extractMarchingCubesMesh(&volData, regToExtract);
// The returned mesh needs to be decoded to be appropriate for GPU rendering.
auto decodedMesh = decode(mesh);
auto decodedMesh = decodeMesh(mesh);
// Pass the surface to the OpenGL window. Note that we are also passing an offset in this multi-mesh example. This is because
// the surface extractors return a mesh with 'local space' positions to reduce storage requirements and precision problems.

View File

@ -189,7 +189,7 @@ int main(int argc, char *argv[])
auto mesh = extractCubicMesh(&volData, reg2);
std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;
auto decodedMesh = decode(mesh);
auto decodedMesh = decodeMesh(mesh);
//Pass the surface to the OpenGL window
openGLWidget.addMesh(decodedMesh);

View File

@ -92,12 +92,12 @@ int main(int argc, char *argv[])
//Extract the surface
auto meshLowLOD = extractMarchingCubesMesh(&volDataLowLOD, volDataLowLOD.getEnclosingRegion());
// The returned mesh needs to be decoded to be appropriate for GPU rendering.
auto decodedMeshLowLOD = decode(meshLowLOD);
auto decodedMeshLowLOD = decodeMesh(meshLowLOD);
//Extract the surface
auto meshHighLOD = extractMarchingCubesMesh(&volData, PolyVox::Region(Vector3DInt32(30, 0, 0), Vector3DInt32(63, 63, 63)));
// The returned mesh needs to be decoded to be appropriate for GPU rendering.
auto decodedMeshHighLOD = decode(meshHighLOD);
auto decodedMeshHighLOD = decodeMesh(meshHighLOD);
//Pass the surface to the OpenGL window
openGLWidget.addMesh(decodedMeshHighLOD, Vector3DInt32(30, 0, 0));

View File

@ -54,7 +54,7 @@ namespace PolyVox
};
/// Decodes a position from a CubicVertex
inline Vector3DFloat decode(const Vector3DUint8& encodedPosition)
inline Vector3DFloat decodePosition(const Vector3DUint8& encodedPosition)
{
Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ());
result -= 0.5f; // Apply the required offset
@ -63,10 +63,10 @@ namespace PolyVox
/// Decodes a MarchingCubesVertex by converting it into a regular Vertex which can then be directly used for rendering.
template<typename DataType>
Vertex<DataType> decode(const CubicVertex<DataType>& cubicVertex)
Vertex<DataType> decodeVertex(const CubicVertex<DataType>& cubicVertex)
{
Vertex<DataType> result;
result.position = decode(cubicVertex.encodedPosition);
result.position = decodePosition(cubicVertex.encodedPosition);
result.normal.setElements(0.0f, 0.0f, 0.0f); // Currently not calculated
result.data = cubicVertex.data; // Data is not encoded
return result;

View File

@ -47,9 +47,8 @@ namespace PolyVox
// Each component of the position is stored using 8.8 fixed-point encoding.
Vector3DUint16 encodedPosition;
// Each component of the normal is encoded using 5 bits of this variable.
// The 16 bits are -xxxxxyyyyyzzzzz (note the left-most bit is currently
// unused). Some extra shifting and scaling is required to make it signed.
// The normal is encoded as a 16-bit unsigned integer using the 'oct16'
// encoding described here: http://jcgt.org/published/0003/02/01/
uint16_t encodedNormal;
// User data
@ -57,7 +56,7 @@ namespace PolyVox
};
/// Decodes a position from a MarchingCubesVertex
inline Vector3DFloat decode(const Vector3DUint16& encodedPosition)
inline Vector3DFloat decodePosition(const Vector3DUint16& encodedPosition)
{
Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ());
result *= (1.0f / 256.0f); // Division is compile-time constant
@ -107,7 +106,7 @@ namespace PolyVox
return (resultX << 8) | resultY;
}
inline Vector3DFloat decode(const uint16_t& encodedNormal)
inline Vector3DFloat decodeNormal(const uint16_t& encodedNormal)
{
// Extract the two bytes from the uint16_t.
uint16_t ux = (encodedNormal >> 8) & 0xFF;
@ -139,11 +138,11 @@ namespace PolyVox
/// Decodes a MarchingCubesVertex by converting it into a regular Vertex which can then be directly used for rendering.
template<typename DataType>
Vertex<DataType> decode(const MarchingCubesVertex<DataType>& marchingCubesVertex)
Vertex<DataType> decodeVertex(const MarchingCubesVertex<DataType>& marchingCubesVertex)
{
Vertex<DataType> result;
result.position = decode(marchingCubesVertex.encodedPosition);
result.normal = decode(marchingCubesVertex.encodedNormal);
result.position = decodePosition(marchingCubesVertex.encodedPosition);
result.normal = decodeNormal(marchingCubesVertex.encodedNormal);
result.data = marchingCubesVertex.data; // Data is not encoded
return result;
}

View File

@ -72,14 +72,14 @@ namespace PolyVox
};
template <typename MeshType>
Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decode(const MeshType& mesh)
Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodeMesh(const MeshType& mesh)
{
Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > result;
result.m_vecVertices.resize(mesh.m_vecVertices.size());
for(typename MeshType::IndexType ct = 0; ct < mesh.m_vecVertices.size(); ct++)
{
result.m_vecVertices[ct] = decode(mesh.m_vecVertices[ct]);
result.m_vecVertices[ct] = decodeVertex(mesh.m_vecVertices[ct]);
}
result.m_vecTriangleIndices = mesh.m_vecTriangleIndices;