Brenta Engine 1.0
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 TexCoords;
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 hasMipmap;
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::ShaderName shader_name);
238
239 private:
240 // render data
241 Types::VAO vao;
242 Types::Buffer vbo;
243 Types::Buffer ebo;
244 void setupMesh();
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 hasMipmap = 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_hasMipmap(GLboolean hasMipmap);
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
GLint wrapping
Type of texture wrapping.
Definition mesh.hpp:118
GLint filtering_min
Minifying texture filtering.
Definition mesh.hpp:128
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
GLboolean hasMipmap
Should the texture have a mipmap?
Definition mesh.hpp:142
void Draw(Types::ShaderName shader_name)
Draw the mesh.
Definition mesh.cpp:58
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:36
std::vector< Types::Texture > textures
textures of the mesh
Definition mesh.hpp:102
GLint filtering_mag
Magnifying texture filtering.
Definition mesh.hpp:138
GLint mipmap_mag
Type of mipmap magnifying texture filtering.
Definition mesh.hpp:206
std::vector< unsigned int > indices
indices of the mesh
Definition mesh.hpp:98
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