6#include <brenta/logger.hpp>
7#include <brenta/mesh.hpp>
10using namespace brenta;
20 GL_LINEAR_MIPMAP_LINEAR,
24mesh::mesh(config&& conf)
26 this->vertices = conf.vertices;
28 this->textures = std::move(conf.textures);
37 DEBUG(
"mesh: created");
42 DEBUG(
"mesh: deleted");
49 this->vbo.init(GL_ARRAY_BUFFER);
50 this->ebo.init(GL_ELEMENT_ARRAY_BUFFER);
52 &this->vertices[0], GL_STATIC_DRAW);
54 &this->indices[0], GL_STATIC_DRAW);
64 gl::bind_vertex_array(0);
67void mesh::draw(shader::name_t shader_name)
const
69 if (this->vao.get_id() == 0)
71 ERROR(
"mesh::draw: not initialized");
75 unsigned int diffuseNr = 1;
76 unsigned int specularNr = 1;
77 for (
unsigned int i = 0; i < this->textures.size(); i++)
82 std::string name = textures[i]->type;
83 if (name ==
"texture_diffuse")
84 number = std::to_string(diffuseNr++);
85 else if (name ==
"texture_specular")
86 number = std::to_string(specularNr++);
89 textures[i]->bind(GL_TEXTURE_2D, this->
wrapping,
108mesh::builder &mesh::builder::vertices(std::vector<types::vertex> vertices)
110 this->conf.vertices = vertices;
120mesh::builder &mesh::builder::textures(std::vector<std::shared_ptr<texture>> textures)
122 this->conf.textures = std::move(textures);
156mesh mesh::builder::build()
158 return mesh(std::move(this->conf));
static void draw_elements(GLenum mode, int count, GLenum type, const void *indices)
Draw Elements.
The Builder class is used to build a Mesh object.
The Mesh class represents a 3D model.
GLint filtering_min
Minifying texture filtering.
GLint mipmap_mag
Type of mipmap magnifying texture filtering.
GLint wrapping
Type of texture wrapping.
GLboolean has_mipmap
Should the texture have a mipmap?
std::vector< unsigned int > indices
indices of the mesh
GLint mipmap_min
Type of mipmap minifying texture filtering.
GLint filtering_mag
Magnifying texture filtering.
static bool set_int(shader::name_t shader_name, const GLchar *name, int value)
Set an integer in the shader.
static void active_texture(GLenum texture)
Activate a texture unit.
void copy_indices(GLsizeiptr size, const void *data, GLenum usage)
Copy data to the buffer object.
void copy_vertices(GLsizeiptr size, const void *data, GLenum usage)
Copy data to the buffer object.
void set_vertex_data(buffer &buffer, unsigned int index, GLint size, GLenum type, GLboolean is_normalized, GLsizei stride, const void *pointer)
Set the vertex data.
The Vertex struct represents a vertex of a 3D model.