1#include "hellfire/graphics/Mesh.h"
2#include <unordered_map>
3#include "hellfire/core/Application.h"
4#include "hellfire/graphics/Vertex.h"
5#include "hellfire/graphics/material/Material.h"
11 Mesh::
Mesh(
const std::vector<Vertex> &vertices,
35 vao_ = std::make_unique<VA>();
36 vbo_ = std::make_unique<VB>();
37 ibo_ = std::make_unique<IB>();
42 vbo_->pass_data(vertices);
45 ibo_->pass_data(indices);
48 glEnableVertexAttribArray(0);
49 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex),
50 reinterpret_cast<
void *>(offsetof(Vertex, position)));
53 glEnableVertexAttribArray(1);
54 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex),
55 reinterpret_cast<
void *>(offsetof(Vertex, normal)));
58 glEnableVertexAttribArray(2);
59 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex),
60 reinterpret_cast<
void *>(offsetof(Vertex, color)));
63 glEnableVertexAttribArray(3);
64 glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE,
sizeof(Vertex),
65 reinterpret_cast<
void *>(offsetof(Vertex, texCoords)));
68 glEnableVertexAttribArray(4);
69 glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex),
70 reinterpret_cast<
void *>(offsetof(Vertex, tangent)));
73 glEnableVertexAttribArray(5);
74 glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex),
75 reinterpret_cast<
void *>(offsetof(Vertex, bitangent)));
85 glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT,
nullptr);
89 void Mesh::draw_instanced(
const size_t amount)
const {
91 glDrawElementsInstanced(GL_TRIANGLES, get_index_count(),
92 GL_UNSIGNED_INT,
nullptr, amount);
97 return indices.size();
Mesh(const std::vector< Vertex > &vertices, const std::vector< unsigned int > &indices)
int get_index_count() const
Mesh(const std::vector< Vertex > &vertices, const std::vector< unsigned int > &indices, bool defer_build)