diff options
Diffstat (limited to 'source/Mesh.hpp')
-rw-r--r-- | source/Mesh.hpp | 98 |
1 files changed, 30 insertions, 68 deletions
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 <glad/glad.h> #include <cstddef> #include <cstdint> -#include <vector> +#include <glm/glm.hpp> +#include <memory> -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<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 { - std::vector<VertexElementFormat> elements; - int vertexSize = 0; - - const std::vector<VertexElementFormat>& GetElements() { return elements; } - void AddElement(VertexElementFormat element); - void RemoveElement(int index); +class StandardCpuMeshData { +public: + PodVector<glm::vec3> vertPositions; + PodVector<StandardVertexExtra> vertExtra; + PodVector<uint32_t> index; + size_t vertexCount; + size_t triangleCount; }; -// Initialized in main() -inline RcPtr<VertexFormat> gVformatStandard{}; -inline RcPtr<VertexFormat> gVformatStandardPacked{}; +class StandardCpuMesh { +// private: +// StandardCpuMeshData* mData = nullptr; +// RcPtr<GpuMesh> mGpuMesh; -// TODO handle immutability -class GpuMesh : public RefCounted { -public: - RcPtr<VertexFormat> vertFormat; - BufferBindings vertBufBindings; - RcPtr<GpuIndexBuffer> 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); }; |