VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
metalIndexBuffer.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 22.11.2025.
5//
6#include "metalIndexBuffer.h"
7
9
10namespace visutwin::canvas
11{
12 namespace
13 {
14 size_t indexElementSize(const IndexFormat format)
15 {
16 switch (format) {
18 return 1;
20 return 2;
22 return 4;
23 default:
24 return 2;
25 }
26 }
27 }
28
30 : IndexBuffer(graphicsDevice, format, numIndices), MetalBuffer(gpu::BufferUsage::INDEX)
31 {
32 }
33
34 bool MetalIndexBuffer::setData(const std::vector<uint8_t>& data)
35 {
36 const auto expectedSize = static_cast<size_t>(numIndices()) * indexElementSize(format());
37 if (data.size() != expectedSize) {
38 return false;
39 }
40
41 _storage = data;
42 MetalBuffer::unlock(static_cast<MetalGraphicsDevice*>(_device), _storage);
43 return true;
44 }
45}
Abstract GPU interface for resource creation, state management, and draw submission.
IndexFormat format() const
Definition indexBuffer.h:33
IndexBuffer(GraphicsDevice *graphicsDevice, IndexFormat format, int numIndices)
std::vector< uint8_t > _storage
Definition indexBuffer.h:49
MetalIndexBuffer(GraphicsDevice *graphicsDevice, IndexFormat format, int numIndices)
bool setData(const std::vector< uint8_t > &data) override
MetalBuffer(const BufferUsage usageFlags)
Definition metalBuffer.h:34