aboutsummaryrefslogtreecommitdiff
path: root/source/VertexIndex.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-25 20:22:07 -0700
committerrtk0c <[email protected]>2022-04-25 20:22:07 -0700
commit855da86feae1a5cc14dc2d486ccf115f484dbc2e (patch)
tree8284c6a6bdfb1a919eb1a22f466f4180a329c7f3 /source/VertexIndex.hpp
parentd78a55de5003dbb040f1d1c369409e63a2c806d8 (diff)
Changeset: 16 Initial work on rendering sprites to screen
Diffstat (limited to 'source/VertexIndex.hpp')
-rw-r--r--source/VertexIndex.hpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/source/VertexIndex.hpp b/source/VertexIndex.hpp
new file mode 100644
index 0000000..cc5aeca
--- /dev/null
+++ b/source/VertexIndex.hpp
@@ -0,0 +1,71 @@
+#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);
+};
+
+// Initialized in main()
+inline RcPtr<VertexFormat> gVformatStandard{};
+inline RcPtr<VertexFormat> gVformatStandardPacked{};