aboutsummaryrefslogtreecommitdiff
path: root/source/CpuMesh.hpp
blob: 9fcb00c95b79197d680e0b5f82c9cdc5c51332b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include "Color.hpp"
#include "Mesh.hpp"
#include "PodVector.hpp"
#include "RcPtr.hpp"

#include <cstddef>
#include <cstdint>
#include <glm/glm.hpp>
#include <memory>

struct StandardVertex {
	float x, y, z;
	float u, v;
	uint8_t r, g, b, a;
};

struct StandardVertexExtra {
	float u, v;
	uint8_t r, g, b, a;
};

class StandardCpuMeshData {
public:
	PodVector<glm::vec3> vertPositions;
	PodVector<StandardVertexExtra> vertExtra;
	PodVector<uint32_t> index;
	size_t vertexCount;
	size_t triangleCount;
};

class StandardCpuMesh {
private:
	StandardCpuMeshData* mData = nullptr;
	RcPtr<GpuMesh> mGpuMesh;

public:
	StandardCpuMesh();
	~StandardCpuMesh();

	GpuVertexBuffer* GetPosBuffer() const;
	GpuVertexBuffer* GetExtraBuffer() const;
	GpuMesh* GetGpuMesh() const { return mGpuMesh.Get(); }

	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);
};