Removed bgfx::weldVertices. (#3659)

This commit is contained in:
Branimir Karadžić
2026-04-12 18:30:57 -07:00
committed by GitHub
parent 2e49e0e38a
commit f3ad0e91af
18 changed files with 168 additions and 337 deletions

View File

@@ -2883,20 +2883,6 @@ public static class bgfx
[LinkName("bgfx_vertex_convert")]
public static extern void vertex_convert(VertexLayout* _dstLayout, void* _dstData, VertexLayout* _srcLayout, void* _srcData, uint32 _num);
/// <summary>
/// Weld vertices. Returns number of unique vertices after welding.
/// </summary>
///
/// <param name="_output">Welded vertices remapping table. The size of buffer must be the same as number of vertices.</param>
/// <param name="_layout">Vertex stream layout.</param>
/// <param name="_data">Vertex stream.</param>
/// <param name="_num">Number of vertices in vertex stream.</param>
/// <param name="_index32">Set to `true` if input indices are 32-bit.</param>
/// <param name="_epsilon">Error tolerance for vertex position comparison.</param>
///
[LinkName("bgfx_weld_vertices")]
public static extern uint32 weld_vertices(void* _output, VertexLayout* _layout, void* _data, uint32 _num, bool _index32, float _epsilon);
/// <summary>
/// Convert index buffer for use with different primitive topologies.
/// </summary>

View File

@@ -2122,15 +2122,6 @@ extern fn void vertex_unpack(float _output, Attrib _attr, VertexLayout* _layout,
// _num : `Number of vertices to convert from source to destination.`
extern fn void vertex_convert(VertexLayout* _dstLayout, void* _dstData, VertexLayout* _srcLayout, void* _srcData, uint _num) @extern("bgfx_vertex_convert");
// Weld vertices. Returns number of unique vertices after welding.
// _output : `Welded vertices remapping table. The size of buffer must be the same as number of vertices.`
// _layout : `Vertex stream layout.`
// _data : `Vertex stream.`
// _num : `Number of vertices in vertex stream.`
// _index32 : `Set to `true` if input indices are 32-bit.`
// _epsilon : `Error tolerance for vertex position comparison.`
extern fn uint weld_vertices(void* _output, VertexLayout* _layout, void* _data, uint _num, bool _index32, float _epsilon) @extern("bgfx_weld_vertices");
// Convert index buffer for use with different primitive topologies.
// _conversion : `Conversion type, see `TopologyConvert::Enum`.`
// _dst : `Destination index buffer. If this argument is NULL function will return number of indices after conversion.`

View File

@@ -2832,20 +2832,6 @@ public static partial class bgfx
[DllImport(DllName, EntryPoint="bgfx_vertex_convert", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void vertex_convert(VertexLayout* _dstLayout, void* _dstData, VertexLayout* _srcLayout, void* _srcData, uint _num);
/// <summary>
/// Weld vertices. Returns number of unique vertices after welding.
/// </summary>
///
/// <param name="_output">Welded vertices remapping table. The size of buffer must be the same as number of vertices.</param>
/// <param name="_layout">Vertex stream layout.</param>
/// <param name="_data">Vertex stream.</param>
/// <param name="_num">Number of vertices in vertex stream.</param>
/// <param name="_index32">Set to `true` if input indices are 32-bit.</param>
/// <param name="_epsilon">Error tolerance for vertex position comparison.</param>
///
[DllImport(DllName, EntryPoint="bgfx_weld_vertices", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe uint weld_vertices(void* _output, VertexLayout* _layout, void* _data, uint _num, bool _index32, float _epsilon);
/// <summary>
/// Convert index buffer for use with different primitive topologies.
/// </summary>

View File

@@ -9,7 +9,7 @@ import bindbc.common.types: c_int64, c_uint64, va_list;
import bindbc.bgfx.config;
static import bgfx.impl;
enum uint apiVersion = 142;
enum uint apiVersion = 143;
alias ViewID = ushort;
@@ -2019,19 +2019,6 @@ mixin(joinFnBinds((){
*/
{q{void}, q{vertexConvert}, q{ref const VertexLayout dstLayout, void* dstData, ref const VertexLayout srcLayout, const(void)* srcData, uint num=1}, ext: `C++, "bgfx"`},
/**
* Weld vertices. Returns number of unique vertices after welding.
Params:
output = Welded vertices remapping table. The size of buffer
must be the same as number of vertices.
layout = Vertex stream layout.
data = Vertex stream.
num = Number of vertices in vertex stream.
index32 = Set to `true` if input indices are 32-bit.
epsilon = Error tolerance for vertex position comparison.
*/
{q{uint}, q{weldVertices}, q{void* output, ref const VertexLayout layout, const(void)* data, uint num, bool index32, float epsilon=0.001f}, ext: `C++, "bgfx"`},
/**
* Convert index buffer for use with different primitive topologies.
Params:

View File

@@ -2238,18 +2238,6 @@ pub inline fn vertexConvert(_dstLayout: [*c]const VertexLayout, _dstData: ?*anyo
}
extern fn bgfx_vertex_convert(_dstLayout: [*c]const VertexLayout, _dstData: ?*anyopaque, _srcLayout: [*c]const VertexLayout, _srcData: ?*const anyopaque, _num: u32) void;
/// Weld vertices. Returns number of unique vertices after welding.
/// <param name="_output">Welded vertices remapping table. The size of buffer must be the same as number of vertices.</param>
/// <param name="_layout">Vertex stream layout.</param>
/// <param name="_data">Vertex stream.</param>
/// <param name="_num">Number of vertices in vertex stream.</param>
/// <param name="_index32">Set to `true` if input indices are 32-bit.</param>
/// <param name="_epsilon">Error tolerance for vertex position comparison.</param>
pub inline fn weldVertices(_output: ?*anyopaque, _layout: [*c]const VertexLayout, _data: ?*const anyopaque, _num: u32, _index32: bool, _epsilon: f32) u32 {
return bgfx_weld_vertices(_output, _layout, _data, _num, _index32, _epsilon);
}
extern fn bgfx_weld_vertices(_output: ?*anyopaque, _layout: [*c]const VertexLayout, _data: ?*const anyopaque, _num: u32, _index32: bool, _epsilon: f32) u32;
/// Convert index buffer for use with different primitive topologies.
/// <param name="_conversion">Conversion type, see `TopologyConvert::Enum`.</param>
/// <param name="_dst">Destination index buffer. If this argument is NULL function will return number of indices after conversion.</param>

View File

@@ -216,7 +216,6 @@ Miscellaneous
.. doxygenfunction:: bgfx::vertexPack
.. doxygenfunction:: bgfx::vertexUnpack
.. doxygenfunction:: bgfx::vertexConvert
.. doxygenfunction:: bgfx::weldVertices
.. doxygenfunction:: bgfx::topologyConvert
.. doxygenfunction:: bgfx::topologySortTriList
.. doxygenfunction:: bgfx::setPaletteColor(uint8_t _index, const float _rgba[4])

View File

@@ -682,67 +682,6 @@ struct HalfEdges
HalfEdge* m_endPtr;
};
struct WeldedVertex
{
uint16_t m_v;
bool m_welded;
};
inline float sqLength(const float _a[3], const float _b[3])
{
const float xx = _a[0] - _b[0];
const float yy = _a[1] - _b[1];
const float zz = _a[2] - _b[2];
return xx*xx + yy*yy + zz*zz;
}
uint16_t weldVertices(WeldedVertex* _output, const bgfx::VertexLayout& _layout, const void* _data, uint16_t _num, float _epsilon)
{
const uint32_t hashSize = bx::uint32_nextpow2(_num);
const uint32_t hashMask = hashSize-1;
const float epsilonSq = _epsilon*_epsilon;
uint16_t numVertices = 0;
const uint32_t size = sizeof(uint16_t)*(hashSize + _num);
uint16_t* hashTable = (uint16_t*)BX_STACK_ALLOC(size);
bx::memSet(hashTable, 0xff, size);
uint16_t* next = hashTable + hashSize;
for (uint16_t ii = 0; ii < _num; ++ii)
{
float pos[4];
vertexUnpack(pos, bgfx::Attrib::Position, _layout, _data, ii);
uint32_t hashValue = bx::hash<bx::HashMurmur2A>(pos, 3*sizeof(float) ) & hashMask;
uint16_t offset = hashTable[hashValue];
for (; UINT16_MAX != offset; offset = next[offset])
{
float test[4];
vertexUnpack(test, bgfx::Attrib::Position, _layout, _data, _output[offset].m_v);
if (sqLength(test, pos) < epsilonSq)
{
_output[ii].m_v = _output[offset].m_v;
_output[ii].m_welded = true;
break;
}
}
if (UINT16_MAX == offset)
{
_output[ii].m_v = ii;
_output[ii].m_welded = false;
next[ii] = hashTable[hashValue];
hashTable[hashValue] = ii;
numVertices++;
}
}
return numVertices;
}
struct Group
{
Group()
@@ -804,20 +743,12 @@ struct Group
EdgeMap edgeMap;
//Get unique indices.
WeldedVertex* uniqueVertices = (WeldedVertex*)malloc(m_numVertices*sizeof(WeldedVertex) );
::weldVertices(uniqueVertices, _layout, m_vertices, m_numVertices, 0.0001f);
uint16_t* uniqueVertices = (uint16_t*)malloc(m_numVertices * sizeof(uint16_t) );
weldVertices(uniqueVertices, _layout, m_vertices, m_numVertices, false);
uint16_t* uniqueIndices = (uint16_t*)malloc(m_numIndices*sizeof(uint16_t) );
for (uint32_t ii = 0; ii < m_numIndices; ++ii)
{
uint16_t index = m_indices[ii];
if (uniqueVertices[index].m_welded)
{
uniqueIndices[ii] = uniqueVertices[index].m_v;
}
else
{
uniqueIndices[ii] = index;
}
uniqueIndices[ii] = uniqueVertices[m_indices[ii] ];
}
free(uniqueVertices);

View File

@@ -65,24 +65,6 @@ public:
}
}
static void remapIndices(uint32_t* _indices, uint32_t _num)
{
uint32_t target = 0;
for (uint32_t i = 0; i < _num; i++)
{
uint32_t map = _indices[i];
if (i != map)
{
_indices[i] = _indices[map];
}
else
{
_indices[i] = target;
++target;
}
}
}
static const bgfx::Memory* mergeVertices(const uint8_t* _vb, uint16_t _stride, const uint32_t* _indices, uint32_t _num, uint32_t _numMerged)
{
const bgfx::Memory* mem = bgfx::alloc(_stride * _numMerged);
@@ -154,8 +136,23 @@ public:
bx::free(entry::getAllocator(), m_cacheWeld);
m_cacheWeld = (uint32_t*)bx::alloc(entry::getAllocator(), numVertices * sizeof(uint32_t) );
m_totalVertices = bgfx::weldVertices(m_cacheWeld, _mesh->m_layout, vbData, numVertices, true, 0.00001f);
remapIndices(m_cacheWeld, numVertices);
m_totalVertices = weldVertices(m_cacheWeld, _mesh->m_layout, vbData, numVertices, true);
// Compact remap to sequential indices.
uint32_t target = 0;
for (uint32_t ii = 0; ii < numVertices; ++ii)
{
uint32_t map = m_cacheWeld[ii];
if (ii != map)
{
m_cacheWeld[ii] = m_cacheWeld[map];
}
else
{
m_cacheWeld[ii] = target++;
}
}
m_totalVertices = target;
}
const bgfx::Memory* vb = mergeVertices(

View File

@@ -357,6 +357,45 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexLayout _la
delete [] tangents;
}
uint32_t weldVertices(void* _output, const bgfx::VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32)
{
const uint16_t stride = _layout.getStride();
const uint16_t posOffset = _layout.getOffset(bgfx::Attrib::Position);
unsigned int* remap = (unsigned int*)malloc(_num * sizeof(unsigned int) );
meshopt_generatePositionRemap(remap, (const float*)( (const uint8_t*)_data + posOffset), _num, stride);
uint32_t numVertices = 0;
for (uint32_t ii = 0; ii < _num; ++ii)
{
if (remap[ii] == ii)
{
numVertices++;
}
}
if (_index32)
{
uint32_t* output = (uint32_t*)_output;
for (uint32_t ii = 0; ii < _num; ++ii)
{
output[ii] = remap[ii];
}
}
else
{
uint16_t* output = (uint16_t*)_output;
for (uint32_t ii = 0; ii < _num; ++ii)
{
output[ii] = (uint16_t)remap[ii];
}
}
free(remap);
return numVertices;
}
Group::Group()
{
reset();

View File

@@ -18,27 +18,83 @@ namespace stl = tinystl;
#include "args.h"
/// Load file contents into memory.
///
/// @param[in] _filePath File path to load.
/// @param[out] _size If non-NULL, will be set to the size of the loaded data.
///
/// @returns Pointer to loaded data. Must be freed with `unload`.
///
void* load(const bx::FilePath& _filePath, uint32_t* _size = NULL);
/// Free memory allocated by `load`.
///
/// @param[in] _ptr Pointer to data returned by `load`.
///
void unload(void* _ptr);
/// Load shader from file.
///
/// @param[in] _name Shader name.
///
/// @returns Shader handle.
///
bgfx::ShaderHandle loadShader(const bx::StringView& _name);
/// Load shader program from vertex and fragment shader files.
///
/// @param[in] _vsName Vertex shader name.
/// @param[in] _fsName Fragment shader name.
///
/// @returns Program handle.
///
bgfx::ProgramHandle loadProgram(const bx::StringView& _vsName, const bx::StringView& _fsName);
/// Load texture from file.
///
/// @param[in] _filePath File path to texture.
/// @param[in] _flags Texture creation flags.
/// @param[in] _skip Number of top-level mip levels to skip.
/// @param[out] _info If non-NULL, will be filled with texture info.
/// @param[out] _orientation If non-NULL, will be filled with image orientation.
///
/// @returns Texture handle.
///
bgfx::TextureHandle loadTexture(const bx::FilePath& _filePath, uint64_t _flags = BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL, bimg::Orientation::Enum* _orientation = NULL);
/// Load image container from file.
///
/// @param[in] _filePath File path to image.
/// @param[in] _dstFormat Destination texture format.
///
/// @returns Pointer to image container.
///
bimg::ImageContainer* imageLoad(const bx::FilePath& _filePath, bgfx::TextureFormat::Enum _dstFormat);
/// Calculate tangent vectors for a vertex/index buffer pair.
///
/// @param[in,out] _vertices Vertex stream (tangent attribute will be written).
/// @param[in] _numVertices Number of vertices.
/// @param[in] _layout Vertex stream layout.
/// @param[in] _indices Index buffer.
/// @param[in] _numIndices Number of indices.
///
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexLayout _layout, const uint16_t* _indices, uint32_t _numIndices);
/// Weld vertices by position. Generates a remap table that maps each vertex
/// to the first vertex with the same position. Returns number of unique vertices.
///
/// @param[out] _output Welded vertices remapping table. The size of buffer
/// must be the same as number of vertices.
/// @param[in] _layout Vertex stream layout.
/// @param[in] _data Vertex stream.
/// @param[in] _num Number of vertices in vertex stream.
/// @param[in] _index32 Set to `true` if input indices are 32-bit.
///
/// @returns Number of unique vertices after vertex welding.
///
uint32_t weldVertices(void* _output, const bgfx::VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32);
/// Returns true if both internal transient index and vertex buffer have
/// enough space.
///
@@ -53,6 +109,14 @@ inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::Vertex
;
}
/// Encode normal vector as RGBA8 color value.
///
/// @param[in] _x X component of the normal.
/// @param[in] _y Y component of the normal.
/// @param[in] _z Z component of the normal.
/// @param[in] _w W component.
///
/// @returns Packed RGBA8 value.
///
inline uint32_t encodeNormalRgba8(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f)
{
@@ -68,7 +132,7 @@ inline uint32_t encodeNormalRgba8(float _x, float _y = 0.0f, float _z = 0.0f, fl
return dst;
}
///
/// Rendering state for a mesh pass.
struct MeshState
{
struct Texture
@@ -129,28 +193,67 @@ struct Mesh
GroupArray m_groups;
};
/// Load mesh from file.
///
/// @param[in] _filePath File path to mesh.
/// @param[in] _ramcopy If `true`, keep a RAM copy of vertex/index data.
///
/// @returns Pointer to loaded mesh.
///
Mesh* meshLoad(const bx::FilePath& _filePath, bool _ramcopy = false);
/// Unload mesh and free resources.
///
/// @param[in] _mesh Pointer to mesh to unload.
///
void meshUnload(Mesh* _mesh);
/// Create mesh state for multi-pass rendering.
///
/// @returns Pointer to new mesh state.
///
MeshState* meshStateCreate();
/// Destroy mesh state.
///
/// @param[in] _meshState Pointer to mesh state to destroy.
///
void meshStateDestroy(MeshState* _meshState);
/// Submit mesh for rendering with a single program.
///
/// @param[in] _mesh Pointer to mesh.
/// @param[in] _id View ID.
/// @param[in] _program Program handle.
/// @param[in] _mtx Model transform matrix.
/// @param[in] _state Render state flags.
///
void meshSubmit(const Mesh* _mesh, bgfx::ViewId _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state = BGFX_STATE_MASK);
/// Submit mesh for multi-pass rendering.
///
/// @param[in] _mesh Pointer to mesh.
/// @param[in] _state Array of mesh state pointers, one per pass.
/// @param[in] _numPasses Number of rendering passes.
/// @param[in] _mtx Model transform matrix.
/// @param[in] _numMatrices Number of matrices.
///
void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices = 1);
/// bgfx::RendererType::Enum to name.
/// Get renderer type name.
///
/// @param[in] _type Renderer type enum.
///
/// @returns Renderer name string.
///
bx::StringView getName(bgfx::RendererType::Enum _type);
/// Name to bgfx::RendererType::Enum.
/// Get renderer type from name.
///
/// @param[in] _name Renderer type name.
///
/// @returns Renderer type enum.
///
bgfx::RendererType::Enum getType(const bx::StringView& _name);
#endif // BGFX_UTILS_H_HEADER_GUARD

View File

@@ -1980,29 +1980,6 @@ namespace bgfx
, uint32_t _num = 1
);
/// Weld vertices. Returns number of unique vertices after welding.
///
/// @param[in] _output Welded vertices remapping table. The size of buffer
/// must be the same as number of vertices.
/// @param[in] _layout Vertex stream layout.
/// @param[in] _data Vertex stream.
/// @param[in] _num Number of vertices in vertex stream.
/// @param[in] _index32 Set to `true` if input indices are 32-bit.
/// @param[in] _epsilon Error tolerance for vertex position comparison.
///
/// @returns Number of unique vertices after vertex welding.
///
/// @attention C99's equivalent binding is `bgfx_weld_vertices`.
///
uint32_t weldVertices(
void* _output
, const VertexLayout& _layout
, const void* _data
, uint32_t _num
, bool _index32
, float _epsilon = 0.001f
);
/// Convert index buffer for use with different primitive topologies.
///
/// @param[in] _conversion Conversion type, see `TopologyConvert::Enum`.

View File

@@ -1130,22 +1130,6 @@ BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const
*/
BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_layout_t * _dstLayout, void* _dstData, const bgfx_vertex_layout_t * _srcLayout, const void* _srcData, uint32_t _num);
/**
* Weld vertices. Returns number of unique vertices after welding.
*
* @param[in] _output Welded vertices remapping table. The size of buffer
* must be the same as number of vertices.
* @param[in] _layout Vertex stream layout.
* @param[in] _data Vertex stream.
* @param[in] _num Number of vertices in vertex stream.
* @param[in] _index32 Set to `true` if input indices are 32-bit.
* @param[in] _epsilon Error tolerance for vertex position comparison.
*
* @returns Number of unique vertices after vertex welding.
*
*/
BGFX_C_API uint32_t bgfx_weld_vertices(void* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon);
/**
* Convert index buffer for use with different primitive topologies.
*
@@ -3780,7 +3764,6 @@ typedef enum bgfx_function_id
BGFX_FUNCTION_ID_VERTEX_PACK,
BGFX_FUNCTION_ID_VERTEX_UNPACK,
BGFX_FUNCTION_ID_VERTEX_CONVERT,
BGFX_FUNCTION_ID_WELD_VERTICES,
BGFX_FUNCTION_ID_TOPOLOGY_CONVERT,
BGFX_FUNCTION_ID_TOPOLOGY_SORT_TRI_LIST,
BGFX_FUNCTION_ID_GET_SUPPORTED_RENDERERS,
@@ -3990,7 +3973,6 @@ struct bgfx_interface_vtbl
void (*vertex_pack)(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, void* _data, uint32_t _index);
void (*vertex_unpack)(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _index);
void (*vertex_convert)(const bgfx_vertex_layout_t * _dstLayout, void* _dstData, const bgfx_vertex_layout_t * _srcLayout, const void* _srcData, uint32_t _num);
uint32_t (*weld_vertices)(void* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon);
uint32_t (*topology_convert)(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32);
void (*topology_sort_tri_list)(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32);
uint8_t (*get_supported_renderers)(uint8_t _max, bgfx_renderer_type_t* _enum);

View File

@@ -15,7 +15,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(142)
#define BGFX_API_VERSION UINT32_C(143)
/**
* Color RGB/alpha/depth write. When it's not specified write will be disabled.

View File

@@ -1,7 +1,7 @@
-- vim: syntax=lua
-- bgfx interface
version(142)
version(143)
typedef "bool"
typedef "char"
@@ -1153,18 +1153,6 @@ func.vertexConvert { section = "Miscellaneous" }
.num "uint32_t" --- Number of vertices to convert from source to destination.
{ default = 1 }
--- Weld vertices. Returns number of unique vertices after welding.
func.weldVertices { section = "Miscellaneous" }
"uint32_t" --- Number of unique vertices after vertex welding.
.output "void*" --- Welded vertices remapping table. The size of buffer
--- must be the same as number of vertices.
.layout "const VertexLayout &" --- Vertex stream layout.
.data "const void*" --- Vertex stream.
.num "uint32_t" --- Number of vertices in vertex stream.
.index32 "bool" --- Set to `true` if input indices are 32-bit.
.epsilon "float" --- Error tolerance for vertex position comparison.
{ default = "0.001f" }
--- Convert index buffer for use with different primitive topologies.
func.topologyConvert { section = "Miscellaneous" }
"uint32_t" --- Number of output indices after conversion.

View File

@@ -3606,11 +3606,6 @@ namespace bgfx
flushTextureUpdateBatch(_cmdbuf);
}
uint32_t weldVertices(void* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon)
{
return weldVertices(_output, _layout, _data, _num, _index32, _epsilon, g_allocator);
}
uint32_t topologyConvert(TopologyConvert::Enum _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32)
{
return topologyConvert(_conversion, _dst, _dstSize, _indices, _numIndices, _index32, g_allocator);

View File

@@ -132,12 +132,6 @@ BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_layout_t * _dstLayout, voi
bgfx::vertexConvert(dstLayout, _dstData, srcLayout, _srcData, _num);
}
BGFX_C_API uint32_t bgfx_weld_vertices(void* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon)
{
const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout;
return bgfx::weldVertices(_output, layout, _data, _num, _index32, _epsilon);
}
BGFX_C_API uint32_t bgfx_topology_convert(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32)
{
return bgfx::topologyConvert((bgfx::TopologyConvert::Enum)_conversion, _dst, _dstSize, _indices, _numIndices, _index32);
@@ -1333,7 +1327,6 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
bgfx_vertex_pack,
bgfx_vertex_unpack,
bgfx_vertex_convert,
bgfx_weld_vertices,
bgfx_topology_convert,
bgfx_topology_sort_tri_list,
bgfx_get_supported_renderers,

View File

@@ -715,112 +715,4 @@ namespace bgfx
}
}
inline float sqLength(const float _a[3], const float _b[3])
{
const float xx = _a[0] - _b[0];
const float yy = _a[1] - _b[1];
const float zz = _a[2] - _b[2];
return xx*xx + yy*yy + zz*zz;
}
template<typename IndexT>
static IndexT weldVerticesRef(IndexT* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, float _epsilon)
{
// Brute force slow vertex welding...
const float epsilonSq = _epsilon*_epsilon;
uint32_t numVertices = 0;
bx::memSet(_output, 0xff, _num*sizeof(IndexT) );
for (uint32_t ii = 0; ii < _num; ++ii)
{
if (IndexT(-1) != _output[ii])
{
continue;
}
_output[ii] = (IndexT)ii;
++numVertices;
float pos[4];
vertexUnpack(pos, Attrib::Position, _layout, _data, ii);
for (uint32_t jj = 0; jj < _num; ++jj)
{
if (IndexT(-1) != _output[jj])
{
continue;
}
float test[4];
vertexUnpack(test, Attrib::Position, _layout, _data, jj);
if (sqLength(test, pos) < epsilonSq)
{
_output[jj] = IndexT(ii);
}
}
}
return IndexT(numVertices);
}
template<typename IndexT>
static IndexT weldVertices(IndexT* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, float _epsilon, bx::AllocatorI* _allocator)
{
const uint32_t hashSize = bx::uint32_nextpow2(_num);
const uint32_t hashMask = hashSize-1;
const float epsilonSq = _epsilon*_epsilon;
uint32_t numVertices = 0;
const uint32_t size = sizeof(IndexT)*(hashSize + _num);
IndexT* hashTable = (IndexT*)bx::alloc(_allocator, size);
bx::memSet(hashTable, 0xff, size);
IndexT* next = hashTable + hashSize;
for (uint32_t ii = 0; ii < _num; ++ii)
{
float pos[4];
vertexUnpack(pos, Attrib::Position, _layout, _data, ii);
uint32_t hashValue = bx::hash<bx::HashMurmur2A>(pos, 3*sizeof(float) ) & hashMask;
IndexT offset = hashTable[hashValue];
for (; IndexT(-1) != offset; offset = next[offset])
{
float test[4];
vertexUnpack(test, Attrib::Position, _layout, _data, _output[offset]);
if (sqLength(test, pos) < epsilonSq)
{
_output[ii] = _output[offset];
break;
}
}
if (IndexT(-1) == offset)
{
_output[ii] = IndexT(ii);
next[ii] = hashTable[hashValue];
hashTable[hashValue] = IndexT(ii);
numVertices++;
}
}
bx::free(_allocator, hashTable);
return IndexT(numVertices);
}
uint32_t weldVertices(void* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon, bx::AllocatorI* _allocator)
{
if (_index32)
{
return weldVertices( (uint32_t*)_output, _layout, _data, _num, _epsilon, _allocator);
}
return weldVertices( (uint16_t*)_output, _layout, _data, _num, _epsilon, _allocator);
}
} // namespace bgfx

View File

@@ -38,9 +38,6 @@ namespace bgfx
///
int32_t read(bx::ReaderI* _reader, bgfx::VertexLayout& _layout, bx::Error* _err = NULL);
///
uint32_t weldVertices(void* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon, bx::AllocatorI* _allocator);
} // namespace bgfx
#endif // BGFX_VERTEXDECL_H_HEADER_GUARD