aboutsummaryrefslogtreecommitdiff
path: root/source/Game/VertexIndex.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-03 23:26:44 -0700
committerrtk0c <[email protected]>2022-06-03 23:26:44 -0700
commit60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (patch)
tree02ec83cc8387abfd08bd5ee7ea4e8115f1bfb8d0 /source/Game/VertexIndex.hpp
parentc2ef7737536bf1f8c81fcfae95c0183b21c9753f (diff)
Changeset: 63 [WIP] Rename directories
Diffstat (limited to 'source/Game/VertexIndex.hpp')
-rw-r--r--source/Game/VertexIndex.hpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/source/Game/VertexIndex.hpp b/source/Game/VertexIndex.hpp
new file mode 100644
index 0000000..2d65617
--- /dev/null
+++ b/source/Game/VertexIndex.hpp
@@ -0,0 +1,67 @@
+#pragma once
+
+#include "GraphicsTags.hpp"
+#include "RcPtr.hpp"
+#include "SmallVector.hpp"
+
+#include <glad/glad.h>
+#include <cstddef>
+#include <cstdint>
+#include <vector>
+
+struct GpuVertexBuffer : public RefCounted {
+ GLuint handle;
+ int sizeInBytes;
+
+ GpuVertexBuffer();
+ ~GpuVertexBuffer();
+
+ void Upload(const std::byte* data, size_t sizeInBytes);
+};
+
+struct GpuIndexBuffer : public RefCounted {
+ GLuint handle;
+ Tags::IndexType indexType;
+ int count;
+
+ GpuIndexBuffer();
+ ~GpuIndexBuffer();
+
+ Tags::IndexType GetIndexType() const { return indexType; }
+ GLenum GetIndexTypeGL() const { return Tags::FindGLType(indexType); }
+
+ void Upload(const std::byte* data, Tags::IndexType type, size_t count);
+};
+
+struct BufferBindings {
+ SmallVector<RcPtr<GpuVertexBuffer>, 4> bindings;
+
+ int GetMaxBindingIndex() const;
+
+ /// Safe. Returns nullptr if the index is not bound to any buffers.
+ GpuVertexBuffer* GetBinding(int index) const;
+ /// Adds or updates a buffer binding. Setting a binding to nullptr effectively removes the binding.
+ void SetBinding(int index, GpuVertexBuffer* buffer);
+ void Clear();
+};
+
+struct VertexElementFormat {
+ /// NOTE:
+ /// "Automatic" means it will be set inside VertexFormat::AddElement()
+ /// "Parameter" means it must be set by the user
+ /* Automatic */ int offset;
+ /* Parameter */ int bindingIndex;
+ /* Parameter */ Tags::VertexElementType type;
+ /* Parameter */ Tags::VertexElementSemantic semantic;
+
+ int GetStride() const;
+};
+
+struct VertexFormat : public RefCounted {
+ SmallVector<VertexElementFormat, 4> elements;
+ int vertexSize = 0;
+
+ const decltype(elements)& GetElements() const { return elements; }
+ void AddElement(VertexElementFormat element);
+ void RemoveElement(int index);
+};