VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
vertexBuffer.h
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 13.09.2025.
5//
6#pragma once
7
8#include <memory>
9#include <vector>
10
11#include "constants.h"
12#include "vertexFormat.h"
13
14namespace visutwin::canvas
15{
16 class GraphicsDevice;
17
19 {
21
22 std::vector<uint8_t> data;
23 };
24
25 struct DeviceVRAM;
26
31 {
32 public:
33 VertexBuffer(GraphicsDevice* graphicsDevice, std::shared_ptr<VertexFormat> format, int numVertices,
34 const VertexBufferOptions& options = VertexBufferOptions{});
35
36 virtual ~VertexBuffer();
37
38 std::shared_ptr<VertexFormat> format() const { return _format; }
39
40 // Copies data into vertex buffer's memor
41 bool setData(const std::vector<uint8_t>& data);
42
43 // Notifies the graphics engine that the client side copy of the vertex buffer's memory can be
44 // returned to the control of the graphics driver.
45 virtual void unlock() = 0;
46
47 int numVertices() const { return _numVertices; }
48
49 virtual void* nativeBuffer() const { return nullptr; }
50
52 const std::vector<uint8_t>& storage() const { return _storage; }
53
54 protected:
58 VertexBuffer(GraphicsDevice* device, std::shared_ptr<VertexFormat> format,
59 int numVertices, int numBytes);
60
62
63 std::vector<uint8_t> _storage;
64
65 private:
66 void adjustVramSizeTracking(DeviceVRAM& vram, int size);
67
68 static int _nextId;
69
70 std::shared_ptr<VertexFormat> _format;
71 int _numVertices;
72 int _numBytes;
73 BufferUsage _usage;
74 int _id;
75 };
76}
Abstract GPU interface for resource creation, state management, and draw submission.
bool setData(const std::vector< uint8_t > &data)
virtual void * nativeBuffer() const
std::shared_ptr< VertexFormat > format() const
const std::vector< uint8_t > & storage() const
std::vector< uint8_t > _storage
VertexBuffer(GraphicsDevice *graphicsDevice, std::shared_ptr< VertexFormat > format, int numVertices, const VertexBufferOptions &options=VertexBufferOptions{})