engine/include/resource_mesh.h

46 lines
1.0 KiB
C
Raw Permalink Normal View History

2024-03-31 10:11:22 +00:00
#pragma once
2022-12-20 23:51:04 +00:00
2024-06-01 22:03:39 +00:00
#include <vector>
2022-12-20 23:51:04 +00:00
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
2023-11-05 01:04:05 +00:00
#include <glm/vec4.hpp>
2022-12-20 23:51:04 +00:00
2023-05-01 13:13:35 +00:00
#include "gfx.h"
#include "gfx_device.h"
2023-05-01 12:55:49 +00:00
2022-12-20 23:51:04 +00:00
namespace engine {
2023-05-01 12:55:49 +00:00
struct Vertex {
glm::vec3 pos;
glm::vec3 norm;
glm::vec4 tangent; // w component flips binormal if -1. w should be 1 or -1
glm::vec2 uv;
2022-12-20 23:51:04 +00:00
2024-06-01 22:03:39 +00:00
static constexpr int floatsPerVertex() { return static_cast<int>(sizeof(Vertex) / sizeof(float)); }
};
2022-12-20 23:51:04 +00:00
class Mesh {
2024-06-01 22:03:39 +00:00
GFXDevice* const m_gfx;
const gfx::Buffer* m_vb;
const gfx::Buffer* m_ib;
uint32_t m_count;
public:
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
Mesh(const Mesh&) = delete;
2024-06-01 22:03:39 +00:00
~Mesh();
2024-06-01 22:03:39 +00:00
Mesh& operator=(const Mesh&) = delete;
2024-06-01 22:03:39 +00:00
const gfx::Buffer* getVB();
const gfx::Buffer* getIB();
uint32_t getCount();
2024-06-01 22:03:39 +00:00
private:
void initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
2022-12-20 23:51:04 +00:00
};
2024-03-31 10:11:22 +00:00
} // namespace engine