| 318 | }; |
| 319 | |
| 320 | class IndexBufferData final : private VariantHandleHolder<bgfx::IndexBufferHandle, bgfx::DynamicIndexBufferHandle> |
| 321 | { |
| 322 | public: |
| 323 | IndexBufferData(const Napi::TypedArray& bytes, uint16_t flags, bool dynamic) |
| 324 | { |
| 325 | const bgfx::Memory* memory = bgfx::copy(bytes.As<Napi::Uint8Array>().Data(), static_cast<uint32_t>(bytes.ByteLength())); |
| 326 | if (!dynamic) |
| 327 | { |
| 328 | m_handle = bgfx::createIndexBuffer(memory, flags); |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | m_handle = bgfx::createDynamicIndexBuffer(memory, flags); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | ~IndexBufferData() |
| 337 | { |
| 338 | constexpr auto nonDynamic = [](auto handle) { |
| 339 | bgfx::destroy(handle); |
| 340 | }; |
| 341 | constexpr auto dynamic = [](auto handle) { |
| 342 | bgfx::destroy(handle); |
| 343 | }; |
| 344 | DoForHandleTypes(nonDynamic, dynamic); |
| 345 | } |
| 346 | |
| 347 | void Update(const Napi::TypedArray& bytes, uint32_t startingIdx) |
| 348 | { |
| 349 | const bgfx::Memory* memory = bgfx::copy(bytes.As<Napi::Uint8Array>().Data(), static_cast<uint32_t>(bytes.ByteLength())); |
| 350 | |
| 351 | constexpr auto nonDynamic = [](auto) { |
| 352 | throw std::runtime_error("Cannot update a non-dynamic index buffer."); |
| 353 | }; |
| 354 | const auto dynamic = [memory, startingIdx](auto handle) { |
| 355 | bgfx::update(handle, startingIdx, memory); |
| 356 | }; |
| 357 | DoForHandleTypes(nonDynamic, dynamic); |
| 358 | } |
| 359 | |
| 360 | void SetBgfxIndexBuffer() const |
| 361 | { |
| 362 | constexpr auto nonDynamic = [](auto handle) { |
| 363 | bgfx::setIndexBuffer(handle); |
| 364 | }; |
| 365 | constexpr auto dynamic = [](auto handle) { |
| 366 | bgfx::setIndexBuffer(handle); |
| 367 | }; |
| 368 | DoForHandleTypes(nonDynamic, dynamic); |
| 369 | } |
| 370 | }; |
| 371 | |
| 372 | class VertexBufferData final : VariantHandleHolder<bgfx::VertexBufferHandle, bgfx::DynamicVertexBufferHandle> |
| 373 | { |
nothing calls this directly
no outgoing calls
no test coverage detected