From f54370de7e4214cb7813d26b1a39a8f6e42b7b56 Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Mon, 25 Apr 2022 20:22:07 -0700 Subject: Initial work on rendering sprites to screen --- source/Mesh.hpp | 98 ++++++++++++++++++--------------------------------------- 1 file changed, 30 insertions(+), 68 deletions(-) (limited to 'source/Mesh.hpp') diff --git a/source/Mesh.hpp b/source/Mesh.hpp index bc755a3..f86fd55 100644 --- a/source/Mesh.hpp +++ b/source/Mesh.hpp @@ -1,83 +1,45 @@ #pragma once -#include "GraphicsTags.hpp" +#include "Color.hpp" +#include "VertexIndex.hpp" +#include "PodVector.hpp" #include "RcPtr.hpp" -#include "SmallVector.hpp" -#include #include #include -#include +#include +#include -struct GpuVertexBuffer : public RefCounted { - GLuint handle; - int sizeInBytes; - - GpuVertexBuffer(); - ~GpuVertexBuffer(); - - void Upload(const std::byte* data, size_t sizeInBytes); +struct StandardVertexExtra { + float u, v; + uint8_t r, g, b, a; }; -struct GpuIndexBuffer : public RefCounted { - GLuint handle; - Tags::IndexType indexType; - int sizeInBytes; - - GpuIndexBuffer(); - ~GpuIndexBuffer(); - - void Upload(const std::byte* data, size_t count); - void Upload(const std::byte* data, Tags::IndexType type, size_t count); -}; - -struct BufferBindings { - SmallVector, 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 { - std::vector elements; - int vertexSize = 0; - - const std::vector& GetElements() { return elements; } - void AddElement(VertexElementFormat element); - void RemoveElement(int index); +class StandardCpuMeshData { +public: + PodVector vertPositions; + PodVector vertExtra; + PodVector index; + size_t vertexCount; + size_t triangleCount; }; -// Initialized in main() -inline RcPtr gVformatStandard{}; -inline RcPtr gVformatStandardPacked{}; +class StandardCpuMesh { +// private: +// StandardCpuMeshData* mData = nullptr; +// RcPtr mGpuMesh; -// TODO handle immutability -class GpuMesh : public RefCounted { -public: - RcPtr vertFormat; - BufferBindings vertBufBindings; - RcPtr indexBuf; +// public: +// StandardCpuMesh(); +// ~StandardCpuMesh(); -public: - GpuMesh(); - ~GpuMesh(); +// GpuVertexBuffer* GetPosBuffer() const; +// GpuVertexBuffer* GetExtraBuffer() const; +// GpuMesh* GetGpuMesh() const { return mGpuMesh.Get(); } - bool IsEmpty() const; +// void CreateCpuData(); +// bool UpdatePositions(glm::vec3* pos, size_t count, size_t startVertIndex); +// bool UpdateColors(RgbaColor* color, size_t count, size_t starVertIndex); +// bool UpdateNormals(glm::vec2* normals, size_t count, size_t startVertIndex); +// bool UpdateIndices(uint32_t* indices, size_t count, size_t startVertIndex); }; -- cgit v1.2.3-70-g09d2