Euphoria
compiledmesh.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <map>
5 
6 #include "core/mesh.h"
7 #include "base/mat4.h"
8 #include "render/buffer.h"
9 
10 
11 namespace eu::io
12 {
13  struct DirPath;
14 }
15 
16 
17 namespace eu::render
18 {
19  struct Texture2;
20  struct MaterialShader;
21  struct Light;
22  struct MaterialOverride;
23  struct MaterialShaderCache;
24  struct TextureCache;
25 
26 
27  // one part of the mesh, single material
29  {
30  // todo(Gustav): move vertex buffer and point layout to the compile mesh instead
32 
33  // todo(Gustav): rename config to something better... like layout?
36  int tri_count;
37  unsigned int material;
38  };
39 
40 
42  {
46  float shininess;
47  std::shared_ptr<MaterialShader> shader;
48  std::map<core::EnumValue, std::shared_ptr<Texture2>> textures;
49 
50 
52 
53  void set_texture
54  (
55  const core::EnumValue& name,
56  std::shared_ptr<Texture2> texture
57  );
58 
62 
63  void apply
64  (
65  const mat4f& model_matrix,
66  const mat4f& projection_matrix,
67  const mat4f& view_matrix,
68  const vec3f& camera,
69  const Light& light
70  ) const;
71 
75  [[nodiscard]] bool validate() const;
76  };
77 
78 
81  struct CompiledMesh
82  {
83  std::vector<std::shared_ptr<CompiledMeshPart>> parts;
84  std::vector<CompiledMeshMaterial> materials;
85 
86 
87  void
88  render
89  (
90  const mat4f& model_matrix,
91  const mat4f& projection_matrix,
92  const mat4f& view_matrix,
93  const vec3f& camera,
94  const Light& light,
95  const std::shared_ptr<MaterialOverride>& overridden_materials
96  );
97  };
98 
99 
100  std::shared_ptr<CompiledMesh>
102  (
103  const core::Mesh& mesh,
104  MaterialShaderCache* shader_cache,
105  TextureCache* texture_cache,
106  const io::DirPath& texture_folder,
107  const std::string& debug_name
108  );
109 }
Definition: enum.h:8
std::shared_ptr< CompiledMesh > compile_mesh(const core::Mesh &mesh, MaterialShaderCache *shader_cache, TextureCache *texture_cache, const io::DirPath &texture_folder, const std::string &debug_name)
Definition: rgb.h:62
Definition: mat4.h:14
bool validate() const
Asks the shader if all the textures are set, and if more than necessary are set.
void apply(const mat4f &model_matrix, const mat4f &projection_matrix, const mat4f &view_matrix, const vec3f &camera, const Light &light) const
Definition: compiledmesh.cc:51
void load_default_materials_from_shader(TextureCache *cache)
Gets the default materials from the shader if they are null/not set.
Definition: compiledmesh.cc:93
std::map< core::EnumValue, std::shared_ptr< Texture2 > > textures
Definition: compiledmesh.h:48
std::shared_ptr< MaterialShader > shader
Definition: compiledmesh.h:47
void set_texture(const core::EnumValue &name, std::shared_ptr< Texture2 > texture)
Definition: compiledmesh.cc:36
A collection of parts making up a mesh.
Definition: compiledmesh.h:82
std::vector< std::shared_ptr< CompiledMeshPart > > parts
Definition: compiledmesh.h:83
std::vector< CompiledMeshMaterial > materials
Definition: compiledmesh.h:84
void render(const mat4f &model_matrix, const mat4f &projection_matrix, const mat4f &view_matrix, const vec3f &camera, const Light &light, const std::shared_ptr< MaterialOverride > &overridden_materials)
Reuses points.
Definition: buffer.h:64
Stores what the data in the vertex_buffer is and how it is laid out/used Represents a OpenGL Vertex A...
Definition: buffer.h:34
Stores vertices, uv, etc.
Definition: buffer.h:13
Definition: vec3.h:48