73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#pragma clang diagnostic ignored "-Wint-to-pointer-cast"
|
|
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
|
|
|
#include <NBGraphics/Mesh.hpp>
|
|
|
|
namespace nb{
|
|
|
|
// class Mesh
|
|
Mesh::Mesh(
|
|
VertexDataPointerList vertexdata_,
|
|
unsigned int count_,
|
|
GLenum primitive_
|
|
) :
|
|
_primitive(primitive_),
|
|
_count(count_),
|
|
_vao(std::make_shared<VAO>(vertexdata_))
|
|
{}
|
|
|
|
Mesh::Mesh(
|
|
GLenum primitive_,
|
|
const std::shared_ptr<VAO>& vao_,
|
|
unsigned int count_
|
|
) :
|
|
_primitive(primitive_),
|
|
_count(count_),
|
|
_vao(vao_)
|
|
{}
|
|
|
|
Mesh::Mesh(
|
|
GLenum primitive_,
|
|
const VertexData& vertex_data_,
|
|
unsigned int count_
|
|
) : Mesh(primitive_, std::make_shared<VAO>(), count_) {
|
|
_vao->attributes({vertex_data_});
|
|
}
|
|
|
|
Mesh::Mesh(
|
|
GLenum primitive_,
|
|
const ByteVector& data_,
|
|
unsigned int count_,
|
|
const std::vector<VertexAttribute>& attributes_
|
|
) : Mesh(
|
|
primitive_,
|
|
VertexData(data_, attributes_),
|
|
count_
|
|
) {}
|
|
|
|
void Mesh::draw(unsigned int offset, unsigned int count) const {
|
|
_vao->bind();
|
|
OPENGL_CALL(
|
|
glDrawArrays(_primitive, offset, count);
|
|
);
|
|
}
|
|
|
|
// class InstancedMesh
|
|
|
|
void InstancedMesh::draw(unsigned int offset, unsigned instancecount) const {
|
|
_vao->bind();
|
|
OPENGL_CALL(
|
|
glDrawArraysInstanced(_primitive, 0, _count, instancecount);
|
|
);
|
|
}
|
|
|
|
// class IndexMeshes
|
|
|
|
void IndexedMesh::draw(unsigned int offset, unsigned numindices) const {
|
|
_vao->bind();
|
|
OPENGL_CALL(
|
|
glDrawElements(Mesh::_primitive, _count, _ebo->datatype(), (void*)offset)
|
|
);
|
|
}
|
|
|
|
} // namespace nb
|