VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
metalVertexBuffer.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 on 25.10.2025.
5//
6#include "metalVertexBuffer.h"
7
8namespace visutwin::canvas
9{
10 MetalVertexBuffer::MetalVertexBuffer(GraphicsDevice* graphicsDevice, const std::shared_ptr<VertexFormat>& format,
11 int numVertices, const VertexBufferOptions& options)
12 : VertexBuffer(graphicsDevice, format, numVertices, options), MetalBuffer(gpu::BufferUsage::VERTEX)
13 {
14 if (!_storage.empty()) {
15 unlock();
16 }
17 }
18
19 MetalVertexBuffer::MetalVertexBuffer(GraphicsDevice* device, const std::shared_ptr<VertexFormat>& format,
20 int numVertices, MTL::Buffer* externalBuffer)
22 static_cast<int>(format->size()) * numVertices),
24 {
25 adoptBuffer(externalBuffer); // Takes ownership via retain
26 }
27
29 {
30 MetalBuffer::unlock(static_cast<MetalGraphicsDevice*>(_device), _storage);
31 }
32}
Abstract GPU interface for resource creation, state management, and draw submission.
MetalVertexBuffer(GraphicsDevice *graphicsDevice, const std::shared_ptr< VertexFormat > &format, int numVertices, const VertexBufferOptions &options=VertexBufferOptions{})
std::shared_ptr< VertexFormat > format() const
std::vector< uint8_t > _storage
VertexBuffer(GraphicsDevice *graphicsDevice, std::shared_ptr< VertexFormat > format, int numVertices, const VertexBufferOptions &options=VertexBufferOptions{})
MetalBuffer(const BufferUsage usageFlags)
Definition metalBuffer.h:34
void adoptBuffer(MTL::Buffer *buffer)