Brenta Engine 1.1
Loading...
Searching...
No Matches
mesh.hpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2024 Giovanni Santini
5
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 */
26
27#pragma once
28
29#include "buffer.hpp"
30#include "gl_helper.hpp"
31#include "shader.hpp"
32#include "texture.hpp"
33#include "vao.hpp"
34
35#include <glm/glm.hpp>
36#include <glm/gtc/matrix_transform.hpp>
37#include <glm/gtc/type_ptr.hpp>
38#include <string>
39#include <vector>
40
41namespace brenta
42{
43
44namespace types
45{
46
53struct vertex
54{
55 glm::vec3 position;
56 glm::vec3 normal;
57 glm::vec2 tex_coords;
58};
59
67struct texture
68{
69 unsigned int id;
70 std::string type;
71 std::string path;
72};
73
74} // namespace types
75
83class mesh
84{
85 public:
89 std::vector<types::vertex> vertices;
98 std::vector<unsigned int> indices;
102 std::vector<types::texture> textures;
118 GLint wrapping;
142 GLboolean has_mipmap;
207
221 mesh(std::vector<types::vertex> vertices, std::vector<unsigned int> indices,
222 std::vector<types::texture> textures, GLint wrapping = GL_REPEAT,
223 GLint filtering_min = GL_NEAREST, GLint filtering_mag = GL_LINEAR,
224 GLboolean hasMipmap = GL_TRUE,
225 GLint mipmap_min = GL_LINEAR_MIPMAP_LINEAR,
226 GLint mipmap_max = GL_LINEAR);
230 class builder;
231
237 void draw(types::shader_name_t shader_name);
238
239 private:
240 // render data
241 types::vao vao;
242 types::buffer vbo;
243 types::buffer ebo;
244 void setup_mesh();
245};
246
251{
252 private:
253 std::vector<types::vertex> vertices = {};
254 std::vector<unsigned int> indices = {};
255 std::vector<types::texture> textures = {};
256 GLint wrapping = GL_REPEAT;
257 GLint filtering_min = GL_NEAREST;
258 GLint filtering_mag = GL_LINEAR;
259 GLboolean has_mipmap = GL_TRUE;
260 GLint mipmap_min = GL_LINEAR_MIPMAP_LINEAR;
261 GLint mipmap_mag = GL_LINEAR;
262
263 public:
264 builder &set_vertices(std::vector<types::vertex> vertices);
265 builder &set_indices(std::vector<unsigned int> indices);
266 builder &set_textures(std::vector<types::texture> textures);
267 builder &set_wrapping(GLint wrapping);
268 builder &set_filtering_min(GLint filtering_min);
269 builder &set_filtering_mag(GLint filtering_mag);
270 builder &set_has_mipmap(GLboolean has_mipmap);
271 builder &set_mipmap_min(GLint mipmap_min);
272 builder &set_mipmap_mag(GLint mipmap_mag);
273
274 mesh build();
275};
276
277} // namespace brenta
The Builder class is used to build a Mesh object.
Definition mesh.hpp:251
The Mesh class represents a 3D model.
Definition mesh.hpp:84
std::vector< types::texture > textures
textures of the mesh
Definition mesh.hpp:102
GLint filtering_min
Minifying texture filtering.
Definition mesh.hpp:128
GLint mipmap_mag
Type of mipmap magnifying texture filtering.
Definition mesh.hpp:206
void draw(types::shader_name_t shader_name)
Draw the mesh.
Definition mesh.cpp:57
GLint wrapping
Type of texture wrapping.
Definition mesh.hpp:118
GLboolean has_mipmap
Should the texture have a mipmap?
Definition mesh.hpp:142
std::vector< unsigned int > indices
indices of the mesh
Definition mesh.hpp:98
std::vector< types::vertex > vertices
vertices of the mesh
Definition mesh.hpp:89
GLint mipmap_min
Type of mipmap minifying texture filtering.
Definition mesh.hpp:174
GLint filtering_mag
Magnifying texture filtering.
Definition mesh.hpp:138
mesh(std::vector< types::vertex > vertices, std::vector< unsigned int > indices, std::vector< types::texture > textures, GLint wrapping=GL_REPEAT, GLint filtering_min=GL_NEAREST, GLint filtering_mag=GL_LINEAR, GLboolean hasMipmap=GL_TRUE, GLint mipmap_min=GL_LINEAR_MIPMAP_LINEAR, GLint mipmap_max=GL_LINEAR)
Construct a new Mesh object.
Definition mesh.cpp:35
Buffer wrapper around OpenGL buffer objects.
Definition buffer.hpp:50
Vertex Array Object (VAO)
Definition vao.hpp:45
The Texture struct represents a texture of a 3D model.
Definition mesh.hpp:68
The Vertex struct represents a vertex of a 3D model.
Definition mesh.hpp:54