brutal/Brutal.MeshOptimizer/Generated/MeshOptimizer.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

1524 lines
81 KiB
C#

using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
public static partial class MeshOptimizer
{
/// <summary>
/// Generates a vertex remap table from the vertex buffer and an optional index buffer and returns number of unique vertices
/// As a result, all vertices that are binary equivalent map to the same (new) location, with no gaps in the resulting sequence.
/// Resulting remap table maps old vertices to new vertices and can be used in meshopt_remapVertexBuffer/meshopt_remapIndexBuffer.
/// Note that binary equivalence considers all vertex_size bytes, including padding which should be zero-initialized.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting remap table (vertex_count elements)
/// indices can be NULL if the input is unindexed
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateVertexRemap")]
public static partial ByteSize64 GenerateVertexRemap(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize
);
/// <summary>
/// Generates a vertex remap table from multiple vertex streams and an optional index buffer and returns number of unique vertices
/// As a result, all vertices that are binary equivalent map to the same (new) location, with no gaps in the resulting sequence.
/// Resulting remap table maps old vertices to new vertices and can be used in meshopt_remapVertexBuffer/meshopt_remapIndexBuffer.
/// To remap vertex buffers, you will need to call meshopt_remapVertexBuffer for each vertex stream.
/// Note that binary equivalence considers all size bytes in each stream, including padding which should be zero-initialized.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting remap table (vertex_count elements)
/// indices can be NULL if the input is unindexed
/// stream_count must be &lt;= 16
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateVertexRemapMulti")]
public static partial ByteSize64 GenerateVertexRemapMulti(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount,
Ptr<MeshOptStream> streams,
long streamCount
);
/// <summary>
/// Generates a vertex remap table from the vertex buffer and an optional index buffer and returns number of unique vertices
/// As a result, all vertices that are equivalent map to the same (new) location, with no gaps in the resulting sequence.
/// Equivalence is checked in two steps: vertex positions are compared for equality, and then the user-specified equality function is called (if provided).
/// Resulting remap table maps old vertices to new vertices and can be used in meshopt_remapVertexBuffer/meshopt_remapIndexBuffer.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting remap table (vertex_count elements)
/// indices can be NULL if the input is unindexed
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// callback can be NULL if no additional equality check is needed; otherwise, it should return 1 if vertices with specified indices are equivalent and 0 if they are not
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateVertexRemapCustom")]
public static unsafe partial ByteSize64 GenerateVertexRemapCustom(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
delegate* unmanaged[Cdecl]<Ptr, int, int, int> callback,
Ptr context
);
/// <summary>
/// Generates vertex buffer from the source vertex buffer and remap table generated by meshopt_generateVertexRemap
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting vertex buffer (unique_vertex_count elements, returned by meshopt_generateVertexRemap)
/// vertex_count should be the initial vertex count and not the value returned by meshopt_generateVertexRemap
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_remapVertexBuffer")]
public static partial void RemapVertexBuffer(
Ptr destination,
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize,
Ptr<int> remap
);
/// <summary>
/// Generate index buffer from the source index buffer and remap table generated by meshopt_generateVertexRemap
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// indices can be NULL if the input is unindexed
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_remapIndexBuffer")]
public static partial void RemapIndexBuffer(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<int> remap
);
/// <summary>
/// Generate index buffer that can be used for more efficient rendering when only a subset of the vertex attributes is necessary
/// All vertices that are binary equivalent (wrt first vertex_size bytes) map to the first vertex in the original vertex buffer.
/// This makes it possible to use the index buffer for Z pre-pass or shadowmap rendering, while using the original index buffer for regular rendering.
/// Note that binary equivalence considers all vertex_size bytes, including padding which should be zero-initialized.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateShadowIndexBuffer")]
public static partial void GenerateShadowIndexBuffer(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize,
ByteSize64 vertexStride
);
/// <summary>
/// Generate index buffer that can be used for more efficient rendering when only a subset of the vertex attributes is necessary
/// All vertices that are binary equivalent (wrt specified streams) map to the first vertex in the original vertex buffer.
/// This makes it possible to use the index buffer for Z pre-pass or shadowmap rendering, while using the original index buffer for regular rendering.
/// Note that binary equivalence considers all size bytes in each stream, including padding which should be zero-initialized.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// stream_count must be &lt;= 16
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateShadowIndexBufferMulti")]
public static partial void GenerateShadowIndexBufferMulti(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount,
Ptr<MeshOptStream> streams,
long streamCount
);
/// <summary>
/// Generates a remap table that maps all vertices with the same position to the same (existing) index.
/// Similarly to meshopt_generateShadowIndexBuffer, this can be helpful to pre-process meshes for position-only rendering.
/// This can also be used to implement algorithms that require positional-only connectivity, such as hierarchical simplification.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting remap table (vertex_count elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generatePositionRemap")]
public static partial void GeneratePositionRemap(
Ptr<int> destination,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Generate index buffer that can be used as a geometry shader input with triangle adjacency topology
/// Each triangle is converted into a 6-vertex patch with the following layout:
/// - 0, 2, 4: original triangle vertices
/// - 1, 3, 5: vertices adjacent to edges 02, 24 and 40
/// The resulting patch can be rendered with geometry shaders using e.g. VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY.
/// This can be used to implement algorithms like silhouette detection/expansion and other forms of GS-driven rendering.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count*2 elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateAdjacencyIndexBuffer")]
public static partial void GenerateAdjacencyIndexBuffer(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Generate index buffer that can be used for PN-AEN tessellation with crack-free displacement
/// Each triangle is converted into a 12-vertex patch with the following layout:
/// - 0, 1, 2: original triangle vertices
/// - 3, 4: opposing edge for edge 0, 1
/// - 5, 6: opposing edge for edge 1, 2
/// - 7, 8: opposing edge for edge 2, 0
/// - 9, 10, 11: dominant vertices for corners 0, 1, 2
/// The resulting patch can be rendered with hardware tessellation using PN-AEN and displacement mapping.
/// See "Tessellation on Any Budget" (John McDonald, GDC 2011) for implementation details.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count*4 elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateTessellationIndexBuffer")]
public static partial void GenerateTessellationIndexBuffer(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Generate index buffer that can be used for visibility buffer rendering and returns the size of the reorder table
/// Each triangle's provoking vertex index is equal to primitive id; this allows passing it to the fragment shader using flat/nointerpolation attribute.
/// This is important for performance on hardware where primitive id can't be accessed efficiently in fragment shader.
/// The reorder table stores the original vertex id for each vertex in the new index buffer, and should be used in the vertex shader to load vertex data.
/// The provoking vertex is assumed to be the first vertex in the triangle; if this is not the case (OpenGL), rotate each triangle (abc -&gt; bca) before rendering.
/// For maximum efficiency the input index buffer should be optimized for vertex cache first.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// reorder must contain enough space for the worst case reorder table (vertex_count + index_count/3 elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateProvokingIndexBuffer")]
public static partial ByteSize64 GenerateProvokingIndexBuffer(
Ptr<int> destination,
Ptr<int> reorder,
Ptr<int> indices,
long indexCount,
long vertexCount
);
/// <summary>
/// Vertex transform cache optimizer
/// Reorders indices to reduce the number of GPU vertex shader invocations
/// If index buffer contains multiple ranges for multiple draw calls, this function needs to be called on each range individually.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeVertexCache")]
public static partial void OptimizeVertexCache(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount
);
/// <summary>
/// Vertex transform cache optimizer for strip-like caches
/// Produces inferior results to meshopt_optimizeVertexCache from the GPU vertex cache perspective
/// However, the resulting index order is more optimal if the goal is to reduce the triangle strip length or improve compression efficiency
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeVertexCacheStrip")]
public static partial void OptimizeVertexCacheStrip(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount
);
/// <summary>
/// Vertex transform cache optimizer for FIFO caches
/// Reorders indices to reduce the number of GPU vertex shader invocations
/// Generally takes ~3x less time to optimize meshes but produces inferior results compared to meshopt_optimizeVertexCache
/// If index buffer contains multiple ranges for multiple draw calls, this function needs to be called on each range individually.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// cache_size should be less than the actual GPU cache size to avoid cache thrashing
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeVertexCacheFifo")]
public static partial void OptimizeVertexCacheFifo(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount,
int cacheSize
);
/// <summary>
/// Overdraw optimizer
/// Reorders indices to reduce the number of GPU vertex shader invocations and the pixel overdraw
/// If index buffer contains multiple ranges for multiple draw calls, this function needs to be called on each range individually.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// indices must contain index data that is the result of meshopt_optimizeVertexCache (<em>not</em> the original mesh indices!)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// threshold indicates how much the overdraw optimizer can degrade vertex cache efficiency (1.05 = up to 5%) to reduce overdraw more efficiently
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeOverdraw")]
public static partial void OptimizeOverdraw(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
float threshold
);
/// <summary>
/// Vertex fetch cache optimizer
/// Reorders vertices and changes indices to reduce the amount of GPU memory fetches during vertex processing
/// Returns the number of unique vertices, which is the same as input vertex count unless some vertices are unused
/// This function works for a single vertex stream; for multiple vertex streams, use meshopt_optimizeVertexFetchRemap + meshopt_remapVertexBuffer for each stream.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting vertex buffer (vertex_count elements)
/// indices is used both as an input and as an output index buffer
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeVertexFetch")]
public static partial ByteSize64 OptimizeVertexFetch(
Ptr destination,
Ptr<int> indices,
long indexCount,
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize
);
/// <summary>
/// Vertex fetch cache optimizer
/// Generates vertex remap to reduce the amount of GPU memory fetches during vertex processing
/// Returns the number of unique vertices, which is the same as input vertex count unless some vertices are unused
/// The resulting remap table should be used to reorder vertex/index buffers using meshopt_remapVertexBuffer/meshopt_remapIndexBuffer
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting remap table (vertex_count elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeVertexFetchRemap")]
public static partial ByteSize64 OptimizeVertexFetchRemap(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount
);
/// <summary>
/// Index buffer encoder
/// Encodes index data into an array of bytes that is generally much smaller (&lt;1.5 bytes/triangle) and compresses better (&lt;1 bytes/triangle) compared to original.
/// Input index buffer must represent a triangle list.
/// Returns encoded data size on success, 0 on error; the only error condition is if buffer doesn't have enough space
/// For maximum efficiency the index buffer being encoded has to be optimized for vertex cache and vertex fetch first.
/// </summary>
/// <remarks>
/// <para>
/// buffer must contain enough space for the encoded index buffer (use meshopt_encodeIndexBufferBound to compute worst case size)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeIndexBuffer")]
public static partial ByteSize64 EncodeIndexBuffer(
Ptr<byte> buffer,
ByteSize64 bufferSize,
Ptr<int> indices,
long indexCount
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeIndexBufferBound")]
public static partial ByteSize64 EncodeIndexBufferBound(long indexCount, long vertexCount);
/// <summary>
/// Set index encoder format version (defaults to 1)
/// </summary>
/// <remarks>
/// <para>
/// version must specify the data format version to encode; valid values are 0 (decodable by all library versions) and 1 (decodable by 0.14+)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeIndexVersion")]
public static partial void EncodeIndexVersion(int version);
/// <summary>
/// Index buffer decoder
/// Decodes index data from an array of bytes generated by meshopt_encodeIndexBuffer
/// Returns 0 if decoding was successful, and an error code otherwise
/// The decoder is safe to use for untrusted input, but it may produce garbage data (e.g. out of range indices).
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeIndexBuffer")]
public static partial int DecodeIndexBuffer(
Ptr destination,
long indexCount,
ByteSize64 indexSize,
Ptr<byte> buffer,
ByteSize64 bufferSize
);
/// <summary>
/// Get encoded index format version
/// Returns format version of the encoded index buffer/sequence, or -1 if the buffer header is invalid
/// Note that a non-negative value doesn't guarantee that the buffer will be decoded correctly if the input is malformed.
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeIndexVersion")]
public static partial int DecodeIndexVersion(Ptr<byte> buffer, ByteSize64 bufferSize);
/// <summary>
/// Index sequence encoder
/// Encodes index sequence into an array of bytes that is generally smaller and compresses better compared to original.
/// Input index sequence can represent arbitrary topology; for triangle lists meshopt_encodeIndexBuffer is likely to be better.
/// Returns encoded data size on success, 0 on error; the only error condition is if buffer doesn't have enough space
/// </summary>
/// <remarks>
/// <para>
/// buffer must contain enough space for the encoded index sequence (use meshopt_encodeIndexSequenceBound to compute worst case size)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeIndexSequence")]
public static partial ByteSize64 EncodeIndexSequence(
Ptr<byte> buffer,
ByteSize64 bufferSize,
Ptr<int> indices,
long indexCount
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeIndexSequenceBound")]
public static partial ByteSize64 EncodeIndexSequenceBound(long indexCount, long vertexCount);
/// <summary>
/// Index sequence decoder
/// Decodes index data from an array of bytes generated by meshopt_encodeIndexSequence
/// Returns 0 if decoding was successful, and an error code otherwise
/// The decoder is safe to use for untrusted input, but it may produce garbage data (e.g. out of range indices).
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index sequence (index_count elements)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeIndexSequence")]
public static partial int DecodeIndexSequence(
Ptr destination,
long indexCount,
ByteSize64 indexSize,
Ptr<byte> buffer,
ByteSize64 bufferSize
);
/// <summary>
/// Experimental: Meshlet encoder
/// Encodes meshlet data into an array of bytes that is generally smaller and compresses better compared to original.
/// Returns encoded data size on success, 0 on error; the only error condition is if buffer doesn't have enough space
/// This function encodes a single meshlet; when encoding multiple meshlets, additional headers may be necessary to store vertex/triangle count and encoded size.
/// For maximum efficiency the meshlet being encoded should be optimized using meshopt_optimizeMeshletLevel with level 1+ (3 recommended); additionally, vertex reference data should be optimized for locality (fetch).
/// </summary>
/// <remarks>
/// <para>
/// buffer must contain enough space for the encoded meshlet (use meshopt_encodeMeshletBound to compute worst case size)
/// vertices may be NULL, in which case vertex_count must be 0 and only triangle data is encoded
/// vertex_count and triangle_count must be &lt;= 256.
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeMeshlet")]
public static partial ByteSize64 EncodeMeshlet(
Ptr<byte> buffer,
ByteSize64 bufferSize,
Ptr<int> vertices,
long vertexCount,
Ptr<byte> triangles,
long triangleCount
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeMeshletBound")]
public static partial ByteSize64 EncodeMeshletBound(ByteSize64 maxVertices, ByteSize64 maxTriangles);
/// <summary>
/// Experimental: Meshlet decoder
/// Decodes meshlet data from an array of bytes generated by meshopt_encodeMeshlet
/// Returns 0 if decoding was successful, and an error code otherwise
/// The decoder is safe to use for untrusted input, but it may produce garbage data.
/// </summary>
/// <remarks>
/// <para>
/// vertices must contain enough space for the resulting vertex data, aligned to 4 bytes (align(vertex_count * vertex_size, 4) bytes)
/// vertex_size must be 2 (16-bit vertex references) or 4 (32-bit vertex references)
/// triangles must contain enough space for the resulting triangle data, aligned to 4 bytes (align(triangle_count * triangle_size, 4) bytes)
/// triangle_size must be 3 (8-bit triangle indices) or 4 (32-bit packed triangles, stored as (a) | (b &lt;&lt; 8) | (c &lt;&lt; 16))
/// vertex_count, triangle_count match those used during encoding exactly; buffer_size must be equal to the encoded size returned by meshopt_encodeMeshlet.
/// vertices may be NULL, in which case vertex_count must be 0 and the meshlet must contain just triangle data
/// </para>
/// <para>
/// When using "raw" decoding (meshopt_decodeMeshletRaw), both vertices and triangles should have available space further aligned to 16 bytes for efficient SIMD decoding.
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeMeshlet")]
public static partial int DecodeMeshlet(
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize,
Ptr triangles,
long triangleCount,
ByteSize64 triangleSize,
Ptr<byte> buffer,
ByteSize64 bufferSize
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeMeshletRaw")]
public static partial int DecodeMeshletRaw(
Ptr<int> vertices,
long vertexCount,
Ptr<int> triangles,
long triangleCount,
Ptr<byte> buffer,
ByteSize64 bufferSize
);
/// <summary>
/// Vertex buffer encoder
/// Encodes vertex data into an array of bytes that is generally smaller and compresses better compared to original.
/// Returns encoded data size on success, 0 on error; the only error condition is if buffer doesn't have enough space
/// This function works for a single vertex stream; for multiple vertex streams, call meshopt_encodeVertexBuffer for each stream.
/// Note that all vertex_size bytes of each vertex are encoded verbatim, including padding which should be zero-initialized.
/// For maximum efficiency the vertex buffer being encoded has to be quantized and optimized for locality of reference (cache/fetch) first.
/// </summary>
/// <remarks>
/// <para>
/// buffer must contain enough space for the encoded vertex buffer (use meshopt_encodeVertexBufferBound to compute worst case size)
/// vertex_size must be a multiple of 4 (and &lt;= 256)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeVertexBuffer")]
public static partial ByteSize64 EncodeVertexBuffer(
Ptr<byte> buffer,
ByteSize64 bufferSize,
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeVertexBufferBound")]
public static partial ByteSize64 EncodeVertexBufferBound(long vertexCount, ByteSize64 vertexSize);
/// <summary>
/// Vertex buffer encoder
/// Encodes vertex data just like meshopt_encodeVertexBuffer, but allows to override compression level.
/// For compression level to take effect, the vertex encoding version must be set to 1.
/// The default compression level implied by meshopt_encodeVertexBuffer is 2.
/// </summary>
/// <remarks>
/// <para>
/// buffer must contain enough space for the encoded vertex buffer (use meshopt_encodeVertexBufferBound to compute worst case size)
/// vertex_size must be a multiple of 4 (and &lt;= 256)
/// level should be in the range [0, 3] with 0 being the fastest and 3 being the slowest and producing the best compression ratio.
/// version should be -1 to use the default version (specified via meshopt_encodeVertexVersion), or 0/1 to override the version; per above, level won't take effect if version is 0.
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeVertexBufferLevel")]
public static partial ByteSize64 EncodeVertexBufferLevel(
Ptr<byte> buffer,
ByteSize64 bufferSize,
Ptr vertices,
long vertexCount,
ByteSize64 vertexSize,
int level,
int version
);
/// <summary>
/// Set vertex encoder format version (defaults to 1)
/// </summary>
/// <remarks>
/// <para>
/// version must specify the data format version to encode; valid values are 0 (decodable by all library versions) and 1 (decodable by 0.23+)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeVertexVersion")]
public static partial void EncodeVertexVersion(int version);
/// <summary>
/// Vertex buffer decoder
/// Decodes vertex data from an array of bytes generated by meshopt_encodeVertexBuffer
/// Returns 0 if decoding was successful, and an error code otherwise
/// The decoder is safe to use for untrusted input, but it may produce garbage data.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting vertex buffer (vertex_count * vertex_size bytes)
/// vertex_size must be a multiple of 4 (and &lt;= 256)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeVertexBuffer")]
public static partial int DecodeVertexBuffer(
Ptr destination,
long vertexCount,
ByteSize64 vertexSize,
Ptr<byte> buffer,
ByteSize64 bufferSize
);
/// <summary>
/// Get encoded vertex format version
/// Returns format version of the encoded vertex buffer, or -1 if the buffer header is invalid
/// Note that a non-negative value doesn't guarantee that the buffer will be decoded correctly if the input is malformed.
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeVertexVersion")]
public static partial int DecodeVertexVersion(Ptr<byte> buffer, ByteSize64 bufferSize);
/// <summary>
/// Vertex buffer filters
/// These functions can be used to filter output of meshopt_decodeVertexBuffer in-place.
/// </summary>
/// <remarks>
/// <para>
/// meshopt_decodeFilterOct decodes octahedral encoding of a unit vector with K-bit signed X/Y as an input; Z must store 1.0f.
/// Each component is stored as an 8-bit or 16-bit normalized integer; stride must be equal to 4 or 8. W is preserved as is.
/// </para>
/// <para>
/// meshopt_decodeFilterQuat decodes 3-component quaternion encoding with K-bit component encoding and a 2-bit component index indicating which component to reconstruct.
/// Each component is stored as an 16-bit integer; stride must be equal to 8.
/// </para>
/// <para>
/// meshopt_decodeFilterExp decodes exponential encoding of floating-point data with 8-bit exponent and 24-bit integer mantissa as 2^E*M.
/// Each 32-bit component is decoded in isolation; stride must be divisible by 4.
/// </para>
/// <para>
/// meshopt_decodeFilterColor decodes RGBA colors from YCoCg (+A) color encoding where RGB is converted to YCoCg space with K-bit component encoding, and A is stored using K-1 bits.
/// Each component is stored as an 8-bit or 16-bit normalized integer; stride must be equal to 4 or 8.
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeFilterOct")]
public static partial void DecodeFilterOct(Ptr buffer, long count, ByteSize64 stride);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeFilterQuat")]
public static partial void DecodeFilterQuat(Ptr buffer, long count, ByteSize64 stride);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeFilterExp")]
public static partial void DecodeFilterExp(Ptr buffer, long count, ByteSize64 stride);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_decodeFilterColor")]
public static partial void DecodeFilterColor(Ptr buffer, long count, ByteSize64 stride);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeFilterOct")]
public static partial void EncodeFilterOct(
Ptr destination,
long count,
ByteSize64 stride,
int bits,
Ptr<float> data
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeFilterQuat")]
public static partial void EncodeFilterQuat(
Ptr destination,
long count,
ByteSize64 stride,
int bits,
Ptr<float> data
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeFilterExp")]
public static partial void EncodeFilterExp(
Ptr destination,
long count,
ByteSize64 stride,
int bits,
Ptr<float> data,
MeshOptEncodeExpMode mode
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_encodeFilterColor")]
public static partial void EncodeFilterColor(
Ptr destination,
long count,
ByteSize64 stride,
int bits,
Ptr<float> data
);
/// <summary>
/// Mesh simplifier
/// Reduces the number of triangles in the mesh, attempting to preserve mesh appearance as much as possible
/// The algorithm tries to preserve mesh topology and can stop short of the target goal based on topology constraints or target error.
/// If not all attributes from the input mesh are needed, it's recommended to reindex the mesh without them prior to simplification.
/// Returns the number of indices after simplification, with destination containing new index data
/// </summary>
/// <remarks>
/// <para>
/// The resulting index buffer references vertices from the original vertex buffer.
/// If the original vertex data isn't needed, creating a compact vertex buffer using meshopt_optimizeVertexFetch is recommended.
/// </para>
/// <para>
/// destination must contain enough space for the target index buffer, worst case is index_count elements (<em>not</em> target_index_count)!
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// target_error represents the error relative to mesh extents that can be tolerated, e.g. 0.01 = 1% deformation; value range [0..1]
/// options must be a bitmask composed of meshopt_SimplifyX options; 0 is a safe default
/// result_error can be NULL; when it's not NULL, it will contain the resulting (relative) error after simplification
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplify")]
public static partial ByteSize64 Simplify(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
long targetIndexCount,
float targetError,
int options,
Ptr<float> resultError
);
/// <summary>
/// Mesh simplifier with attribute metric
/// Reduces the number of triangles in the mesh, attempting to preserve mesh appearance as much as possible.
/// Similar to meshopt_simplify, but incorporates attribute values into the error metric used to prioritize simplification order.
/// The algorithm tries to preserve mesh topology and can stop short of the target goal based on topology constraints or target error.
/// If not all attributes from the input mesh are needed, it's recommended to reindex the mesh without them prior to simplification.
/// Returns the number of indices after simplification, with destination containing new index data
/// </summary>
/// <remarks>
/// <para>
/// The resulting index buffer references vertices from the original vertex buffer.
/// If the original vertex data isn't needed, creating a compact vertex buffer using meshopt_optimizeVertexFetch is recommended.
/// Note that the number of attributes with non-zero weights affects memory requirements and running time.
/// </para>
/// <para>
/// destination must contain enough space for the target index buffer, worst case is index_count elements (<em>not</em> target_index_count)!
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// vertex_attributes should have attribute_count floats for each vertex
/// attribute_weights should have attribute_count floats in total; the weights determine relative priority of attributes between each other and wrt position
/// attribute_count must be &lt;= 32
/// vertex_lock can be NULL; when it's not NULL, it should have a value for each vertex composed of meshopt_SimplifyVertex_* flags
/// target_error represents the error relative to mesh extents that can be tolerated, e.g. 0.01 = 1% deformation; value range [0..1]
/// options must be a bitmask composed of meshopt_SimplifyX options; 0 is a safe default
/// result_error can be NULL; when it's not NULL, it will contain the resulting (relative) error after simplification
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplifyWithAttributes")]
public static partial ByteSize64 SimplifyWithAttributes(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
Ptr<float> vertexAttributes,
ByteSize64 vertexAttributesStride,
Ptr<float> attributeWeights,
long attributeCount,
Ptr<byte> vertexLock,
long targetIndexCount,
float targetError,
int options,
Ptr<float> resultError
);
/// <summary>
/// Mesh simplifier with position/attribute update
/// Reduces the number of triangles in the mesh, attempting to preserve mesh appearance as much as possible.
/// Similar to meshopt_simplifyWithAttributes, but destructively updates positions and attribute values for optimal appearance.
/// The algorithm tries to preserve mesh topology and can stop short of the target goal based on topology constraints or target error.
/// If not all attributes from the input mesh are needed, it's recommended to reindex the mesh without them prior to simplification.
/// Returns the number of indices after simplification, indices are destructively updated with new index data
/// </summary>
/// <remarks>
/// <para>
/// The updated index buffer references vertices from the original vertex buffer, however the vertex positions and attributes are updated in-place.
/// Creating a compact vertex buffer using meshopt_optimizeVertexFetch is recommended; if the original vertex data is needed, it should be copied before simplification.
/// Note that the number of attributes with non-zero weights affects memory requirements and running time. Attributes with zero weights are not updated.
/// </para>
/// <para>
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// vertex_attributes should have attribute_count floats for each vertex
/// attribute_weights should have attribute_count floats in total; the weights determine relative priority of attributes between each other and wrt position
/// attribute_count must be &lt;= 32
/// vertex_lock can be NULL; when it's not NULL, it should have a value for each vertex composed of meshopt_SimplifyVertex_* flags
/// target_error represents the error relative to mesh extents that can be tolerated, e.g. 0.01 = 1% deformation; value range [0..1]
/// options must be a bitmask composed of meshopt_SimplifyX options; 0 is a safe default
/// result_error can be NULL; when it's not NULL, it will contain the resulting (relative) error after simplification
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplifyWithUpdate")]
public static partial ByteSize64 SimplifyWithUpdate(
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
Ptr<float> vertexAttributes,
ByteSize64 vertexAttributesStride,
Ptr<float> attributeWeights,
long attributeCount,
Ptr<byte> vertexLock,
long targetIndexCount,
float targetError,
int options,
Ptr<float> resultError
);
/// <summary>
/// Mesh simplifier (sloppy)
/// Reduces the number of triangles in the mesh, sacrificing mesh appearance for simplification performance
/// The algorithm doesn't preserve mesh topology but can stop short of the target goal based on target error.
/// Returns the number of indices after simplification, with destination containing new index data
/// The resulting index buffer references vertices from the original vertex buffer.
/// If the original vertex data isn't needed, creating a compact vertex buffer using meshopt_optimizeVertexFetch is recommended.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the target index buffer, worst case is index_count elements (<em>not</em> target_index_count)!
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// vertex_lock can be NULL; when it's not NULL, it should have a value for each vertex; vertices that can't be moved should set 1 consistently for all indices with the same position
/// target_error represents the error relative to mesh extents that can be tolerated, e.g. 0.01 = 1% deformation; value range [0..1]
/// result_error can be NULL; when it's not NULL, it will contain the resulting (relative) error after simplification
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplifySloppy")]
public static partial ByteSize64 SimplifySloppy(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
Ptr<byte> vertexLock,
long targetIndexCount,
float targetError,
Ptr<float> resultError
);
/// <summary>
/// Mesh simplifier (pruner)
/// Reduces the number of triangles in the mesh by removing small isolated parts of the mesh
/// Returns the number of indices after simplification, with destination containing new index data
/// The resulting index buffer references vertices from the original vertex buffer.
/// If the original vertex data isn't needed, creating a compact vertex buffer using meshopt_optimizeVertexFetch is recommended.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the target index buffer, worst case is index_count elements
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// target_error represents the error relative to mesh extents that can be tolerated, e.g. 0.01 = 1% deformation; value range [0..1]
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplifyPrune")]
public static partial ByteSize64 SimplifyPrune(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
float targetError
);
/// <summary>
/// Point cloud simplifier
/// Reduces the number of points in the cloud to reach the given target
/// Returns the number of points after simplification, with destination containing new index data
/// The resulting index buffer references vertices from the original vertex buffer.
/// If the original vertex data isn't needed, creating a compact vertex buffer using meshopt_optimizeVertexFetch is recommended.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the target index buffer (target_vertex_count elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// vertex_colors can be NULL; when it's not NULL, it should have float3 color in the first 12 bytes of each vertex
/// color_weight determines relative priority of color wrt position; 1.0 is a safe default
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplifyPoints")]
public static partial ByteSize64 SimplifyPoints(
Ptr<int> destination,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
Ptr<float> vertexColors,
ByteSize64 vertexColorsStride,
float colorWeight,
long targetVertexCount
);
/// <summary>
/// Returns the error scaling factor used by the simplifier to convert between absolute and relative extents
/// </summary>
/// <remarks>
/// <para>
/// Absolute error must be <em>divided</em> by the scaling factor before passing it to meshopt_simplify as target_error
/// Relative error returned by meshopt_simplify via result_error must be <em>multiplied</em> by the scaling factor to get absolute error.
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_simplifyScale")]
public static partial float SimplifyScale(
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Mesh stripifier
/// Converts a previously vertex cache optimized triangle list to triangle strip, stitching strips using restart index or degenerate triangles
/// Returns the number of indices in the resulting strip, with destination containing new index data
/// For maximum efficiency the index buffer being converted has to be optimized for vertex cache first.
/// Using restart indices can result in ~10% smaller index buffers, but on some GPUs restart indices may result in decreased performance.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the target index buffer, worst case can be computed with meshopt_stripifyBound
/// restart_index should be 0xffff or 0xffffffff depending on index size, or 0 to use degenerate triangles
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_stripify")]
public static partial ByteSize64 Stripify(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
long vertexCount,
int restartIndex
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_stripifyBound")]
public static partial ByteSize64 StripifyBound(long indexCount);
/// <summary>
/// Mesh unstripifier
/// Converts a triangle strip to a triangle list
/// Returns the number of indices in the resulting list, with destination containing new index data
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the target index buffer, worst case can be computed with meshopt_unstripifyBound
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_unstripify")]
public static partial ByteSize64 Unstripify(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
int restartIndex
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_unstripifyBound")]
public static partial ByteSize64 UnstripifyBound(long indexCount);
/// <summary>
/// Vertex transform cache analyzer
/// Returns cache hit statistics using a simplified FIFO model
/// Results may not match actual GPU performance
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_analyzeVertexCache")]
public static partial MeshOptVertexCacheStatistics AnalyzeVertexCache(
Ptr<int> indices,
long indexCount,
long vertexCount,
int cacheSize,
int warpSize,
int primgroupSize
);
/// <summary>
/// Vertex fetch cache analyzer
/// Returns cache hit statistics using a simplified direct mapped model
/// Results may not match actual GPU performance
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_analyzeVertexFetch")]
public static partial MeshOptVertexFetchStatistics AnalyzeVertexFetch(
Ptr<int> indices,
long indexCount,
long vertexCount,
ByteSize64 vertexSize
);
/// <summary>
/// Overdraw analyzer
/// Returns overdraw statistics using a software rasterizer
/// Results may not match actual GPU performance
/// </summary>
/// <remarks>
/// <para>
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_analyzeOverdraw")]
public static partial MeshOptOverdrawStatistics AnalyzeOverdraw(
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Coverage analyzer
/// Returns coverage statistics (ratio of viewport pixels covered from each axis) using a software rasterizer
/// </summary>
/// <remarks>
/// <para>
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_analyzeCoverage")]
public static partial MeshOptCoverageStatistics AnalyzeCoverage(
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Meshlet builder
/// Splits the mesh into a set of meshlets where each meshlet has a micro index buffer indexing into meshlet vertices that refer to the original vertex buffer
/// The resulting data can be used to render meshes using NVidia programmable mesh shading pipeline, or in other cluster-based renderers.
/// When targeting mesh shading hardware, for maximum efficiency meshlets should be further optimized using meshopt_optimizeMeshlet.
/// When using buildMeshlets, vertex positions need to be provided to minimize the size of the resulting clusters.
/// When using buildMeshletsScan, for maximum efficiency the index buffer being converted has to be optimized for vertex cache first.
/// </summary>
/// <remarks>
/// <para>
/// meshlets must contain enough space for all meshlets, worst case size can be computed with meshopt_buildMeshletsBound
/// meshlet_vertices must contain enough space for all meshlets, worst case is index_count elements (<em>not</em> vertex_count!)
/// meshlet_triangles must contain enough space for all meshlets, worst case is index_count elements
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// max_vertices and max_triangles must not exceed implementation limits (max_vertices &lt;= 256, max_triangles &lt;= 512)
/// cone_weight should be set to 0 when cone culling is not used, and a value between 0 and 1 otherwise to balance between cluster size and cone culling efficiency
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_buildMeshlets")]
public static partial ByteSize64 BuildMeshlets(
Ptr<MeshOptMeshlet> meshlets,
Ptr<int> meshletVertices,
Ptr<byte> meshletTriangles,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
ByteSize64 maxVertices,
ByteSize64 maxTriangles,
float coneWeight
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_buildMeshletsScan")]
public static partial ByteSize64 BuildMeshletsScan(
Ptr<MeshOptMeshlet> meshlets,
Ptr<int> meshletVertices,
Ptr<byte> meshletTriangles,
Ptr<int> indices,
long indexCount,
long vertexCount,
ByteSize64 maxVertices,
ByteSize64 maxTriangles
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_buildMeshletsBound")]
public static partial ByteSize64 BuildMeshletsBound(
long indexCount,
ByteSize64 maxVertices,
ByteSize64 maxTriangles
);
/// <summary>
/// Meshlet builder with flexible cluster sizes
/// Splits the mesh into a set of meshlets, similarly to meshopt_buildMeshlets, but allows to specify minimum and maximum number of triangles per meshlet.
/// Clusters between min and max triangle counts are split when the cluster size would have exceeded the expected cluster size by more than split_factor.
/// </summary>
/// <remarks>
/// <para>
/// meshlets must contain enough space for all meshlets, worst case size can be computed with meshopt_buildMeshletsBound using min_triangles (<em>not</em> max!)
/// meshlet_vertices must contain enough space for all meshlets, worst case is index_count elements (<em>not</em> vertex_count!)
/// meshlet_triangles must contain enough space for all meshlets, worst case is index_count elements
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// max_vertices, min_triangles and max_triangles must not exceed implementation limits (max_vertices &lt;= 256, max_triangles &lt;= 512; min_triangles &lt;= max_triangles)
/// cone_weight should be set to 0 when cone culling is not used, and a value between 0 and 1 otherwise to balance between cluster size and cone culling efficiency
/// split_factor should be set to a non-negative value; when greater than 0, clusters that have large bounds may be split unless they are under the min_triangles threshold
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_buildMeshletsFlex")]
public static partial ByteSize64 BuildMeshletsFlex(
Ptr<MeshOptMeshlet> meshlets,
Ptr<int> meshletVertices,
Ptr<byte> meshletTriangles,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
ByteSize64 maxVertices,
ByteSize64 minTriangles,
ByteSize64 maxTriangles,
float coneWeight,
float splitFactor
);
/// <summary>
/// Meshlet builder that produces clusters optimized for raytracing
/// Splits the mesh into a set of meshlets, similarly to meshopt_buildMeshlets, but optimizes cluster subdivision for raytracing and allows to specify minimum and maximum number of triangles per meshlet.
/// </summary>
/// <remarks>
/// <para>
/// meshlets must contain enough space for all meshlets, worst case size can be computed with meshopt_buildMeshletsBound using min_triangles (<em>not</em> max!)
/// meshlet_vertices must contain enough space for all meshlets, worst case is index_count elements (<em>not</em> vertex_count!)
/// meshlet_triangles must contain enough space for all meshlets, worst case is index_count elements
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// max_vertices, min_triangles and max_triangles must not exceed implementation limits (max_vertices &lt;= 256, max_triangles &lt;= 512; min_triangles &lt;= max_triangles)
/// fill_weight allows to prioritize clusters that are closer to maximum size at some cost to SAH quality; 0.5 is a safe default
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_buildMeshletsSpatial")]
public static partial ByteSize64 BuildMeshletsSpatial(
Ptr<MeshOptMeshlet> meshlets,
Ptr<int> meshletVertices,
Ptr<byte> meshletTriangles,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
ByteSize64 maxVertices,
ByteSize64 minTriangles,
ByteSize64 maxTriangles,
float fillWeight
);
/// <summary>
/// Meshlet optimizer
/// Reorders meshlet vertices and triangles to maximize locality which can improve rasterizer throughput or ray tracing performance when using fast-build modes.
/// </summary>
/// <remarks>
/// <para>
/// meshlet_triangles and meshlet_vertices must refer to meshlet data; when buildMeshlets* is used, these need to be computed from meshlet's vertex_offset and triangle_offset
/// triangle_count and vertex_count must not exceed implementation limits (vertex_count &lt;= 256, triangle_count &lt;= 512)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeMeshlet")]
public static partial void OptimizeMeshlet(
Ptr<int> meshletVertices,
Ptr<byte> meshletTriangles,
long triangleCount,
long vertexCount
);
/// <summary>
/// Experimental: Meshlet optimizer
/// Reorders meshlet vertices and triangles to maximize locality, with higher levels resulting in smaller compressed size at the cost of optimization time.
/// At level 0 the result is equivalent to meshopt_optimizeMeshlet; levels &gt;= 1 may rotate triangle corners to improve compression (which can change provoking vertex and affect OMM data).
/// </summary>
/// <remarks>
/// <para>
/// level should be in the range [0, 9] with 0 equivalent to meshopt_optimizeMeshlet and 9 being the slowest; the sweet spot for compression ratio is around 3
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_optimizeMeshletLevel")]
public static partial void OptimizeMeshletLevel(
Ptr<int> meshletVertices,
long vertexCount,
Ptr<byte> meshletTriangles,
long triangleCount,
int level
);
/// <summary>
/// Cluster bounds generator
/// Creates bounding volumes that can be used for frustum, backface and occlusion culling.
/// </summary>
/// <remarks>
/// <para>
/// For backface culling with orthographic projection, use the following formula to reject backfacing clusters:
/// dot(view, cone_axis) &gt;= cone_cutoff
/// </para>
/// <para>
/// For perspective projection, you can use the formula that needs cone apex in addition to axis &amp; cutoff:
/// dot(normalize(cone_apex - camera_position), cone_axis) &gt;= cone_cutoff
/// </para>
/// <para>
/// Alternatively, you can use the formula that doesn't need cone apex and uses bounding sphere instead:
/// dot(normalize(center - camera_position), cone_axis) &gt;= cone_cutoff + radius / length(center - camera_position)
/// or an equivalent formula that doesn't have a singularity at center = camera_position:
/// dot(center - camera_position, cone_axis) &gt;= cone_cutoff * length(center - camera_position) + radius
/// </para>
/// <para>
/// The formula that uses the apex is slightly more accurate but needs the apex; if you are already using bounding sphere
/// to do frustum/occlusion culling, the formula that doesn't use the apex may be preferable (for derivation see
/// Real-Time Rendering 4th Edition, section 19.3).
/// </para>
/// <para>
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// vertex_count should specify the number of vertices in the entire mesh, not cluster or meshlet
/// indices should have at most 256 unique vertex indices
/// index_count/3 and triangle_count must not exceed implementation limits (&lt;= 512)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_computeClusterBounds")]
public static partial MeshOptBounds ComputeClusterBounds(
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_computeMeshletBounds")]
public static partial MeshOptBounds ComputeMeshletBounds(
Ptr<int> meshletVertices,
Ptr<byte> meshletTriangles,
long triangleCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Sphere bounds generator
/// Creates bounding sphere around a set of points or a set of spheres; returns the center and radius of the sphere, with other fields of the result set to 0.
/// </summary>
/// <remarks>
/// <para>
/// positions should have float3 position in the first 12 bytes of each element
/// radii can be NULL; when it's not NULL, it should have a non-negative float radius in the first 4 bytes of each element
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_computeSphereBounds")]
public static partial MeshOptBounds ComputeSphereBounds(
Ptr<float> positions,
long count,
ByteSize64 positionsStride,
Ptr<float> radii,
ByteSize64 radiiStride
);
/// <summary>
/// Experimental: Extract meshlet-local vertex and triangle indices from absolute cluster indices.
/// Fills triangles[] and vertices[] such that vertices[triangles[i]] == indices[i], and returns the number of unique vertices.
/// </summary>
/// <remarks>
/// <para>
/// indices should have at most 256 unique vertex indices
/// index_count/3 must not exceed implementation limits (&lt;= 512)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_extractMeshletIndices")]
public static partial ByteSize64 ExtractMeshletIndices(
Ptr<int> vertices,
Ptr<byte> triangles,
Ptr<int> indices,
long indexCount
);
/// <summary>
/// Cluster partitioner
/// Partitions clusters into groups of similar size, prioritizing grouping clusters that share vertices or are close to each other.
/// When vertex positions are not provided, only clusters that share vertices will be grouped together, which may result in small partitions for some inputs.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting partition data (cluster_count elements)
/// destination[i] will contain the partition id for cluster i, with the total number of partitions returned by the function
/// cluster_indices should have the vertex indices referenced by each cluster, stored sequentially
/// cluster_index_counts should have the number of indices in each cluster; sum of all cluster_index_counts must be equal to total_index_count
/// vertex_positions can be NULL; when it's not NULL, it should have float3 position in the first 12 bytes of each vertex
/// target_partition_size is a target size for each partition, in clusters; the resulting partitions may be smaller or larger (up to target + target/3)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_partitionClusters")]
public static partial ByteSize64 PartitionClusters(
Ptr<int> destination,
Ptr<int> clusterIndices,
long totalIndexCount,
Ptr<int> clusterIndexCounts,
long clusterCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
ByteSize64 targetPartitionSize
);
/// <summary>
/// Spatial sorter
/// Generates a remap table that can be used to reorder points for spatial locality.
/// Resulting remap table maps old vertices to new vertices and can be used in meshopt_remapVertexBuffer.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting remap table (vertex_count elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_spatialSortRemap")]
public static partial void SpatialSortRemap(
Ptr<int> destination,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Spatial sorter
/// Reorders triangles for spatial locality, and generates a new index buffer. The resulting index buffer can be used with other functions like optimizeVertexCache.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (index_count elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_spatialSortTriangles")]
public static partial void SpatialSortTriangles(
Ptr<int> destination,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride
);
/// <summary>
/// Spatial clusterizer
/// Reorders points into clusters optimized for spatial locality, and generates a new index buffer.
/// Ensures the output can be split into cluster_size chunks where each chunk has good positional locality. Only the last chunk will be smaller than cluster_size.
/// </summary>
/// <remarks>
/// <para>
/// destination must contain enough space for the resulting index buffer (vertex_count elements)
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_spatialClusterPoints")]
public static partial void SpatialClusterPoints(
Ptr<int> destination,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
ByteSize64 clusterSize
);
/// <summary>
/// Experimental: Opacity micromap generator (measure)
/// Computes a subdivision level for each input triangle, as well as deduplicating the triangles that reference the same UVs to reduce rasterization requests.
/// Returns the number of OMM entries.
/// </summary>
/// <remarks>
/// <para>
/// levels and sources must contain enough space for the worst case output (index_count/3 elements, one per resulting OMM entry)
/// levels[i] will contain the subdivision level for entry i, with the total number of entries returned by the function; each entry should be rasterized from triangle index sources[i]
/// omm_indices must contain enough space for the resulting OMM indices (index_count/3 elements, one per triangle)
/// vertex_uvs should have float2 texture coordinate in the first 8 bytes of each vertex
/// max_level specifies the maximum subdivision level (0..12)
/// target_edge can be 0; when &gt;0, triangle subdivision is adaptive and targets target_edge^2 texel area
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_opacityMapMeasure")]
public static partial ByteSize64 OpacityMapMeasure(
Ptr<byte> levels,
Ptr<int> sources,
Ptr<int> ommIndices,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexUvs,
long vertexCount,
ByteSize64 vertexUvsStride,
int textureWidth,
int textureHeight,
int maxLevel,
float targetEdge
);
/// <summary>
/// Experimental: Opacity micromap generator (rasterize)
/// Rasterizes opacity state for a single triangle entry by sampling the alpha texture, using bilinear filtering and 0.5 alpha cutoff.
/// </summary>
/// <remarks>
/// <para>
/// result should contain enough space for the output opacity data (which can be computed using meshopt_opacityMapEntrySize)
/// level specifies the subdivision level (0..12)
/// states should be 2 for 2-state format (opaque/transparent) and 4 for 4-state format (opaque/transparent/unknown)
/// uv0/uv1/uv2 should refer to a float2 texture coordinate for each triangle corner; note that micromap data is sensitive to the corner order
/// texture_data should point to the alpha channel of the first pixel, encoded as UNORM8
/// texture_stride specifies the distance in bytes between consecutive pixels, e.g. 4 for RGBA input
/// texture_pitch specifies the distance in bytes between consecutive rows, e.g. 4*texture_width for tightly packed RGBA input
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_opacityMapRasterize")]
public static partial void OpacityMapRasterize(
Ptr<byte> result,
int level,
int states,
Ptr<float> uv0,
Ptr<float> uv1,
Ptr<float> uv2,
Ptr<byte> textureData,
ByteSize64 textureStride,
ByteSize64 texturePitch,
int textureWidth,
int textureHeight
);
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_opacityMapEntrySize")]
public static partial ByteSize64 OpacityMapEntrySize(int level, int states);
/// <summary>
/// Experimental: Opacity micromap generator (compact)
/// Compacts and deduplicates opacity data, merging identical micromap entries and replacing micromap states with special indices (-4..-1) when possible.
/// Returns the number of OMM entries after compaction; the data array should be trimmed using the last offset/size.
/// </summary>
/// <remarks>
/// <para>
/// data should contain opacity data for all input/output entries
/// levels should contain subdivision levels for all input/output entries
/// offsets should contain offset into data[] for each entry
/// levels[i] and offsets[i] will be updated with post-compaction level/offset for entry i, with the total number of entries returned by the function
/// omm_indices should contain indices into the original OMM data, and will be updated with a new index or a special index (-4..-1) when possible
/// states should be 2 for 2-state format (opaque/transparent) and 4 for 4-state format (opaque/transparent/unknown)
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_opacityMapCompact")]
public static partial ByteSize64 OpacityMapCompact(
Ptr<byte> data,
ByteSize64 dataSize,
Ptr<byte> levels,
Ptr<int> offsets,
long ommCount,
Ptr<int> ommIndices,
long triangleCount,
int states
);
/// <summary>
/// Experimental: Tangent space generator
/// Computes per-corner tangent vectors; for each corner, computes normalized tangent vector (xyz) and orientation (w, +/-1).
/// Bitangent can be reconstructed via cross(normal, tangent.xyz) * tangent.w.
/// To apply tangents to the mesh, either deindex and reindex it with the tangent stream, or copy tangents to existing vertex data while duplicating
/// vertices with different tangent vectors (e.g. on UV mirror seams).
/// Input can be indexed or unindexed (indices=NULL); this does not affect the resulting tangents, but indexed inputs are ~30% faster to process.
/// </summary>
/// <remarks>
/// <para>
/// result must contain enough space for the output tangent data (index_count*4 elements)
/// indices can be NULL if the input is unindexed
/// vertex_positions should have float3 position in the first 12 bytes of each vertex
/// vertex_normals should have unit float3 normal in the first 12 bytes of each vertex
/// vertex_uvs should have float2 texture coordinate in the first 8 bytes of each vertex
/// </para>
/// </remarks>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_generateTangents")]
public static partial void GenerateTangents(
Ptr<float> result,
Ptr<int> indices,
long indexCount,
Ptr<float> vertexPositions,
long vertexCount,
ByteSize64 vertexPositionsStride,
Ptr<float> vertexNormals,
ByteSize64 vertexNormalsStride,
Ptr<float> vertexUvs,
ByteSize64 vertexUvsStride,
int options
);
/// <summary>
/// Quantize a float into half-precision (as defined by IEEE-754 fp16) floating point value
/// Generates +-inf for overflow, preserves NaN, flushes denormals to zero, rounds to nearest
/// Representable magnitude range: [6e-5; 65504]
/// Maximum relative reconstruction error: 5e-4
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_quantizeHalf")]
public static partial ushort QuantizeHalf(float v);
/// <summary>
/// Quantize a float into a floating point value with a limited number of significant mantissa bits, preserving the IEEE-754 fp32 binary representation
/// Preserves infinities/NaN, flushes denormals to zero, rounds to nearest
/// Assumes N is in a valid mantissa precision range, which is 1..23
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_quantizeFloat")]
public static partial float QuantizeFloat(float v, int n);
/// <summary>
/// Reverse quantization of a half-precision (as defined by IEEE-754 fp16) floating point value
/// Preserves Inf/NaN, flushes denormals to zero
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_dequantizeHalf")]
public static partial float DequantizeHalf(ushort h);
/// <summary>
/// Set allocation callbacks
/// These callbacks will be used instead of the default operator new/operator delete for all temporary allocations in the library.
/// Note that all algorithms only allocate memory for temporary use.
/// allocate/deallocate are always called in a stack-like order - last pointer to be allocated is deallocated first.
/// </summary>
[LibraryImport("meshoptimizer", EntryPoint = "meshopt_setAllocator")]
public static unsafe partial void SetAllocator(
delegate* unmanaged[Cdecl]<ByteSize64, Ptr> allocate,
delegate* unmanaged[Cdecl]<Ptr, void> deallocate
);
}
}