55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "GLFunctions.hpp"
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <vector>
|
|
|
|
namespace engine {
|
|
|
|
// -----------------------------------------------------------------------
|
|
// Mesh
|
|
//
|
|
// Owns a VAO/VBO/(optional)EBO describing an interleaved
|
|
// position+normal+uv vertex stream, plus static factory methods that
|
|
// procedurally build a few common primitive shapes (spheres, rings,
|
|
// circles) so a project has no dependency on external model files.
|
|
// -----------------------------------------------------------------------
|
|
struct Vertex {
|
|
glm::vec3 position;
|
|
glm::vec3 normal;
|
|
glm::vec2 uv;
|
|
};
|
|
|
|
class Mesh {
|
|
public:
|
|
Mesh() = default;
|
|
~Mesh();
|
|
|
|
Mesh(const Mesh&) = delete;
|
|
Mesh& operator=(const Mesh&) = delete;
|
|
Mesh(Mesh&& other) noexcept;
|
|
Mesh& operator=(Mesh&& other) noexcept;
|
|
|
|
void upload(const std::vector<Vertex>& vertices, const std::vector<unsigned int>& indices);
|
|
void uploadLineStrip(const std::vector<glm::vec3>& points);
|
|
void draw() const;
|
|
void drawLineStrip() const;
|
|
|
|
static Mesh createUVSphere(int stacks, int slices);
|
|
static Mesh createRing(float innerRadius, float outerRadius, int segments);
|
|
static Mesh createOrbitCircle(int segments); // unit circle in XZ
|
|
|
|
private:
|
|
void release();
|
|
|
|
GLuint vao_ = 0;
|
|
GLuint vbo_ = 0;
|
|
GLuint ebo_ = 0;
|
|
GLsizei indexCount_ = 0;
|
|
GLsizei vertexCount_ = 0;
|
|
bool isLineStrip_ = false;
|
|
};
|
|
|
|
} // namespace engine
|