| 34 | |
| 35 | template<typename IndexType> |
| 36 | void Init(uint32 vertices, uint32 triangles, const Float3* positions, const IndexType* indices, uint32 positionsStride = sizeof(Float3), PixelFormat positionsFormat = PixelFormat::R32G32B32_Float) |
| 37 | { |
| 38 | Triangles.Clear(); |
| 39 | Triangles.EnsureCapacity(triangles, false); |
| 40 | const IndexType* it = indices; |
| 41 | #define LOOP_BEGIN() \ |
| 42 | for (uint32 i = 0; i < triangles; i++) \ |
| 43 | { \ |
| 44 | const IndexType i0 = *(it++); \ |
| 45 | const IndexType i1 = *(it++); \ |
| 46 | const IndexType i2 = *(it++); \ |
| 47 | if (i0 < vertices && i1 < vertices && i2 < vertices) \ |
| 48 | { |
| 49 | #define LOOP_END() } } |
| 50 | if (positionsFormat == PixelFormat::R32G32B32_Float) |
| 51 | { |
| 52 | LOOP_BEGIN() |
| 53 | #define GET_POS(idx) *(const Float3*)((const byte*)positions + positionsStride * idx) |
| 54 | Triangles.Add({ GET_POS(i0), GET_POS(i1), GET_POS(i2) }); |
| 55 | #undef GET_POS |
| 56 | LOOP_END() |
| 57 | } |
| 58 | else if (positionsFormat == PixelFormat::R16G16B16A16_Float) |
| 59 | { |
| 60 | LOOP_BEGIN() |
| 61 | #define GET_POS(idx) ((const Half4*)((const byte*)positions + positionsStride * idx))->ToFloat3() |
| 62 | Triangles.Add({ GET_POS(i0), GET_POS(i1), GET_POS(i2) }); |
| 63 | #undef GET_POS |
| 64 | LOOP_END() |
| 65 | } |
| 66 | #undef LOOP_BEGIN |
| 67 | #undef LOOP_END |
| 68 | } |
| 69 | |
| 70 | void Clear() |
| 71 | { |
no test coverage detected