81 lines
2.1 KiB
C++
81 lines
2.1 KiB
C++
#pragma once
|
|
#ifndef _NB_MESH
|
|
#define _NB_MESH
|
|
|
|
#include <NBGraphics/GLLoad.hpp>
|
|
|
|
#include <NBGraphics/Buffers.hpp>
|
|
#include <NBGraphics/VertexArray.hpp>
|
|
#include <NBGraphics/VertexData.hpp>
|
|
|
|
namespace nb{
|
|
|
|
class Mesh {
|
|
protected:
|
|
const GLenum _primitive;
|
|
const unsigned int _count;
|
|
std::shared_ptr<VAO> _vao;
|
|
|
|
public:
|
|
Mesh(
|
|
VertexDataPointerList vao,
|
|
unsigned int count,
|
|
GLenum primitive=GL_TRIANGLES
|
|
);
|
|
Mesh(GLenum primitive, const std::shared_ptr<VAO>& vertex_array, unsigned int count);
|
|
Mesh(GLenum primitive, const VertexData& vertex_data, unsigned int count);
|
|
Mesh(
|
|
GLenum primitive,
|
|
const ByteVector& data,
|
|
unsigned int count,
|
|
const std::vector<VertexAttribute>& attributes
|
|
);
|
|
|
|
Mesh(Mesh&&);
|
|
Mesh(const Mesh&&) = delete;
|
|
Mesh& operator=(Mesh&&) = delete;
|
|
Mesh& operator=(const Mesh&) = delete;
|
|
|
|
inline virtual void draw() const { this->draw(_count); }
|
|
inline virtual void draw(unsigned int count) const { this->draw(0, count); }
|
|
virtual void draw(unsigned int offset, unsigned int count) const;
|
|
inline GLenum primitive() const { return _primitive; }
|
|
inline unsigned int count() const { return _count; }
|
|
inline std::shared_ptr<VAO> vao() const { return _vao; }
|
|
};
|
|
|
|
class InstancedMesh : public Mesh {
|
|
protected:
|
|
using Mesh::_primitive;
|
|
using Mesh::_count;
|
|
using Mesh::_vao;
|
|
|
|
public:
|
|
virtual void draw(unsigned int offset, unsigned int count) const;
|
|
};
|
|
|
|
class IndexedMesh : public Mesh {
|
|
protected:
|
|
std::shared_ptr<ElementBuffer> _ebo;
|
|
|
|
public:
|
|
template<typename T>
|
|
IndexedMesh(
|
|
GLenum primitive,
|
|
const ByteVector& data,
|
|
const std::vector<VertexAttribute>& attributes,
|
|
const std::vector<T>& indices
|
|
) : Mesh(primitive, data, indices.size(), attributes) {
|
|
_vao->bind();
|
|
_ebo = std::make_shared<ElementBuffer>(indices);
|
|
}
|
|
|
|
using Mesh::draw;
|
|
virtual void draw(unsigned int offset, unsigned int count) const;
|
|
};
|
|
|
|
class InstancedIndexedMesh : virtual public IndexedMesh {};
|
|
|
|
|
|
}
|
|
#endif |