From faa00a1639608002f0988757ab886db7e7e04945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 14 Aug 2026 23:11:26 +0000 Subject: [PATCH] Fixed topologyConvert strip conversion. Fixed Uint10 vertex packing. (#3889) --- src/topology.cpp | 5 +++-- src/vertexlayout.cpp | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/topology.cpp b/src/topology.cpp index ab6f2d17b..2b76f4b4a 100644 --- a/src/topology.cpp +++ b/src/topology.cpp @@ -46,7 +46,7 @@ namespace bgfx { const uint32_t numIndices = isEven(_numIndices) ? _numIndices + 1 : _numIndices; - if (NULL != _dst) + if (NULL == _dst) { return numIndices; } @@ -54,7 +54,8 @@ namespace bgfx IndexT* dst = (IndexT*)_dst; IndexT* end = &dst[_dstSize/sizeof(IndexT)]; - if (isEven(_numIndices) ) + if (isEven(_numIndices) + && dst < end) { *dst++ = _indices[_numIndices-1]; } diff --git a/src/vertexlayout.cpp b/src/vertexlayout.cpp index 9fb664868..9671d2ccc 100644 --- a/src/vertexlayout.cpp +++ b/src/vertexlayout.cpp @@ -445,9 +445,9 @@ namespace bgfx switch (num) { default: [[fallthrough]]; - case 3: packed |= uint32_t(*_input++ * 511.0f + 512.0f); [[fallthrough]]; - case 2: packed <<= 10; packed |= uint32_t(*_input++ * 511.0f + 512.0f); [[fallthrough]]; - case 1: packed <<= 10; packed |= uint32_t(*_input++ * 511.0f + 512.0f); + case 3: packed |= (uint32_t(_input[2] * 511.0f + 512.0f) & 0x3ff)<<20; [[fallthrough]]; + case 2: packed |= (uint32_t(_input[1] * 511.0f + 512.0f) & 0x3ff)<<10; [[fallthrough]]; + case 1: packed |= (uint32_t(_input[0] * 511.0f + 512.0f) & 0x3ff); } } else @@ -455,9 +455,9 @@ namespace bgfx switch (num) { default: [[fallthrough]]; - case 3: packed |= uint32_t(*_input++ * 1023.0f); [[fallthrough]]; - case 2: packed <<= 10; packed |= uint32_t(*_input++ * 1023.0f); [[fallthrough]]; - case 1: packed <<= 10; packed |= uint32_t(*_input++ * 1023.0f); + case 3: packed |= (uint32_t(_input[2] * 1023.0f) & 0x3ff)<<20; [[fallthrough]]; + case 2: packed |= (uint32_t(_input[1] * 1023.0f) & 0x3ff)<<10; [[fallthrough]]; + case 1: packed |= (uint32_t(_input[0] * 1023.0f) & 0x3ff); } } } @@ -466,9 +466,9 @@ namespace bgfx switch (num) { default: [[fallthrough]]; - case 3: packed |= uint32_t(*_input++); [[fallthrough]]; - case 2: packed <<= 10; packed |= uint32_t(*_input++); [[fallthrough]]; - case 1: packed <<= 10; packed |= uint32_t(*_input++); + case 3: packed |= (uint32_t(_input[2]) & 0x3ff)<<20; [[fallthrough]]; + case 2: packed |= (uint32_t(_input[1]) & 0x3ff)<<10; [[fallthrough]]; + case 1: packed |= (uint32_t(_input[0]) & 0x3ff); } } *(uint32_t*)data = packed;