mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Added weldVertices 32-bit indices support.
This commit is contained in:
@@ -2352,10 +2352,11 @@ public static partial class bgfx
|
||||
/// <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 ushort weld_vertices(ushort* _output, VertexLayout* _layout, void* _data, ushort _num, float _epsilon);
|
||||
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.
|
||||
|
||||
@@ -115,9 +115,10 @@ version(BindBgfx_Static)
|
||||
* _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.
|
||||
*/
|
||||
ushort bgfx_weld_vertices(ushort* _output, const(bgfx_vertex_layout_t)* _layout, const(void)* _data, ushort _num, float _epsilon);
|
||||
uint bgfx_weld_vertices(void* _output, const(bgfx_vertex_layout_t)* _layout, const(void)* _data, uint _num, bool _index32, float _epsilon);
|
||||
|
||||
/**
|
||||
* Convert index buffer for use with different primitive topologies.
|
||||
@@ -2198,9 +2199,10 @@ else
|
||||
* _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.
|
||||
*/
|
||||
alias da_bgfx_weld_vertices = ushort function(ushort* _output, const(bgfx_vertex_layout_t)* _layout, const(void)* _data, ushort _num, float _epsilon);
|
||||
alias da_bgfx_weld_vertices = uint function(void* _output, const(bgfx_vertex_layout_t)* _layout, const(void)* _data, uint _num, bool _index32, float _epsilon);
|
||||
da_bgfx_weld_vertices bgfx_weld_vertices;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ public import core.stdc.stdarg : va_list;
|
||||
|
||||
extern(C) @nogc nothrow:
|
||||
|
||||
enum uint BGFX_API_VERSION = 106;
|
||||
enum uint BGFX_API_VERSION = 107;
|
||||
|
||||
alias bgfx_view_id_t = ushort;
|
||||
|
||||
|
||||
@@ -1835,16 +1835,18 @@ namespace bgfx
|
||||
/// @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 equivalent is `bgfx_weld_vertices`.
|
||||
///
|
||||
uint16_t weldVertices(
|
||||
uint16_t* _output
|
||||
uint32_t weldVertices(
|
||||
void* _output
|
||||
, const VertexLayout& _layout
|
||||
, const void* _data
|
||||
, uint16_t _num
|
||||
, uint32_t _num
|
||||
, bool _index32
|
||||
, float _epsilon = 0.001f
|
||||
);
|
||||
|
||||
|
||||
@@ -1011,12 +1011,13 @@ BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_layout_t * _dstLayout, voi
|
||||
* @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 uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint16_t _num, float _epsilon);
|
||||
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.
|
||||
@@ -3469,7 +3470,7 @@ 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);
|
||||
uint16_t (*weld_vertices)(uint16_t* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint16_t _num, float _epsilon);
|
||||
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);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#ifndef BGFX_DEFINES_H_HEADER_GUARD
|
||||
#define BGFX_DEFINES_H_HEADER_GUARD
|
||||
|
||||
#define BGFX_API_VERSION UINT32_C(106)
|
||||
#define BGFX_API_VERSION UINT32_C(107)
|
||||
|
||||
/**
|
||||
* Color RGB/alpha/depth write. When it's not specified write will be disabled.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- vim: syntax=lua
|
||||
-- bgfx interface
|
||||
|
||||
version(106)
|
||||
version(107)
|
||||
|
||||
typedef "bool"
|
||||
typedef "char"
|
||||
@@ -1060,14 +1060,15 @@ func.vertexConvert
|
||||
|
||||
--- Weld vertices.
|
||||
func.weldVertices
|
||||
"uint16_t" --- Number of unique vertices after vertex welding.
|
||||
.output "uint16_t*" --- 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 "uint16_t" --- Number of vertices in vertex stream.
|
||||
.epsilon "float" --- Error tolerance for vertex position comparison.
|
||||
{ default = "0.001f" }
|
||||
"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
|
||||
|
||||
@@ -3254,6 +3254,11 @@ 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);
|
||||
|
||||
@@ -114,10 +114,10 @@ BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_layout_t * _dstLayout, voi
|
||||
bgfx::vertexConvert(dstLayout, _dstData, srcLayout, _srcData, _num);
|
||||
}
|
||||
|
||||
BGFX_C_API uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint16_t _num, float _epsilon)
|
||||
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, _epsilon);
|
||||
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)
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define BGFX_REV_NUMBER 7218
|
||||
#define BGFX_REV_SHA1 "1c063fdc67d601fc90aea7b8e9493924880a33f5"
|
||||
#define BGFX_REV_NUMBER 7224
|
||||
#define BGFX_REV_SHA1 "dfaf8168227fedde5a8ad2503ed6e33013bdf49f"
|
||||
|
||||
@@ -725,22 +725,23 @@ namespace bgfx
|
||||
return xx*xx + yy*yy + zz*zz;
|
||||
}
|
||||
|
||||
uint16_t weldVerticesRef(uint16_t* _output, const VertexLayout& _layout, const void* _data, uint16_t _num, float _epsilon)
|
||||
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(uint16_t) );
|
||||
bx::memSet(_output, 0xff, _num*sizeof(IndexT) );
|
||||
|
||||
for (uint32_t ii = 0; ii < _num; ++ii)
|
||||
{
|
||||
if (UINT16_MAX != _output[ii])
|
||||
if (IndexT(-1) != _output[ii])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_output[ii] = (uint16_t)ii;
|
||||
_output[ii] = (IndexT)ii;
|
||||
++numVertices;
|
||||
|
||||
float pos[4];
|
||||
@@ -748,7 +749,7 @@ namespace bgfx
|
||||
|
||||
for (uint32_t jj = 0; jj < _num; ++jj)
|
||||
{
|
||||
if (UINT16_MAX != _output[jj])
|
||||
if (IndexT(-1) != _output[jj])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -758,15 +759,16 @@ namespace bgfx
|
||||
|
||||
if (sqLength(test, pos) < epsilonSq)
|
||||
{
|
||||
_output[jj] = (uint16_t)ii;
|
||||
_output[jj] = IndexT(ii);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (uint16_t)numVertices;
|
||||
return IndexT(numVertices);
|
||||
}
|
||||
|
||||
uint16_t weldVertices(uint16_t* _output, const VertexLayout& _layout, const void* _data, uint16_t _num, float _epsilon)
|
||||
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;
|
||||
@@ -774,11 +776,11 @@ namespace bgfx
|
||||
|
||||
uint32_t numVertices = 0;
|
||||
|
||||
const uint32_t size = sizeof(uint16_t)*(hashSize + _num);
|
||||
uint16_t* hashTable = (uint16_t*)alloca(size);
|
||||
const uint32_t size = sizeof(IndexT)*(hashSize + _num);
|
||||
IndexT* hashTable = (IndexT*)BX_ALLOC(_allocator, size);
|
||||
bx::memSet(hashTable, 0xff, size);
|
||||
|
||||
uint16_t* next = hashTable + hashSize;
|
||||
IndexT* next = hashTable + hashSize;
|
||||
|
||||
for (uint32_t ii = 0; ii < _num; ++ii)
|
||||
{
|
||||
@@ -786,8 +788,8 @@ namespace bgfx
|
||||
vertexUnpack(pos, 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])
|
||||
IndexT offset = hashTable[hashValue];
|
||||
for (; IndexT(-1) != offset; offset = next[offset])
|
||||
{
|
||||
float test[4];
|
||||
vertexUnpack(test, Attrib::Position, _layout, _data, _output[offset]);
|
||||
@@ -799,16 +801,28 @@ namespace bgfx
|
||||
}
|
||||
}
|
||||
|
||||
if (UINT16_MAX == offset)
|
||||
if (IndexT(-1) == offset)
|
||||
{
|
||||
_output[ii] = (uint16_t)ii;
|
||||
_output[ii] = IndexT(ii);
|
||||
next[ii] = hashTable[hashValue];
|
||||
hashTable[hashValue] = (uint16_t)ii;
|
||||
hashTable[hashValue] = IndexT(ii);
|
||||
numVertices++;
|
||||
}
|
||||
}
|
||||
|
||||
return (uint16_t)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
|
||||
|
||||
@@ -35,6 +35,9 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user