Number5
Visualisierung 2 Project - Florian Schober (0828151, f.schober@live.com), Andreas Walch (0926780, walch.andreas89@gmail.com)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleMesh.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Scene.hpp"
4 
5 class SimpleMesh;
6 
12 {
15  map<string,function<void(Shader*)>> m_uniforms;
17  public:
23 
24  public:
31  SimpleMeshInstance(Application* app, SimpleMesh* mesh, bool pickable = true);
35  virtual ~SimpleMeshInstance();
36 
42  void prepareDraw(DrawArgs& args, Shader* shader);
43 
49  virtual bool update(double time, double timeDelta);
50 
51 
57  template<typename t>
58  void uniform(string const & name, t value)
59  {
60  m_uniforms[name] = [value, name]
61  (Shader* shader)
62  {
63  shader->uniform(name,value);
64  };
65  }
66 };
67 
68 
75 {
78  string m_name;
80  vector<vec3> m_positions;
81  vector<vec2> m_uvs;
82  vector<vec3> m_normals;
83  vector<uint> m_indices;
86  GLuint m_uvBuffer;
87  GLuint m_normalsBuffer;
88  GLuint m_indicesBuffer;
89  GLuint m_vao;
91  set<SimpleMeshInstance*> m_instances;
93  public:
100  template<typename t_fnc>
101  SimpleMesh(Application* app, string const & name, t_fnc fnc)
102  : m_name(name)
103  , m_app(app)
104  {
105  fnc(&m_positions, &m_normals, &m_uvs, &m_indices);
106  create();
107  }
108 
112  ~SimpleMesh();
113 
119  void drawAllInstances(DrawArgs& args, Shader* shader);
120 
126  SimpleMeshInstance* createInstance(bool pickable = true);
127 
134 
135  private:
136 
140  void create();
141 };
142 
148 {
149  typedef map<string,unique_ptr<SimpleMesh>> mesh_map;
150 
155  public:
161 
168  template<typename t_fnc>
169  SimpleMesh* create(string const & name, t_fnc fnc)
170  {
171  auto mesh = new SimpleMesh(m_app, name, fnc);
172  m_meshes[name].reset(mesh);
173  return mesh;
174  }
175 
181  SimpleMesh* get(string const & name);
182 
187  void drawAll(DrawArgs& args);
188 };
map< string, unique_ptr< SimpleMesh > > mesh_map
Definition: SimpleMesh.hpp:149
Transformation m_transformation
Definition: SimpleMesh.hpp:14
vector< vec3 > m_positions
Definition: SimpleMesh.hpp:80
SimpleMeshes(Application *app)
Definition: SimpleMesh.cpp:157
GLuint m_positionsBuffer
Definition: SimpleMesh.hpp:85
GLuint m_uvBuffer
Definition: SimpleMesh.hpp:86
void create()
Definition: SimpleMesh.cpp:37
SimpleMesh * m_mesh
Definition: SimpleMesh.hpp:13
Definition: Shader.hpp:8
SimpleMeshInstance * createInstance(bool pickable=true)
Definition: SimpleMesh.cpp:105
set< SimpleMeshInstance * > m_instances
Definition: SimpleMesh.hpp:91
void prepareDraw(DrawArgs &args, Shader *shader)
Definition: SimpleMesh.cpp:17
Shader * m_shader
Definition: SimpleMesh.hpp:153
SimpleMesh(Application *app, string const &name, t_fnc fnc)
Definition: SimpleMesh.hpp:101
GLuint m_indicesBuffer
Definition: SimpleMesh.hpp:88
map< string, function< void(Shader *)> > m_uniforms
Definition: SimpleMesh.hpp:15
vector< vec3 > m_normals
Definition: SimpleMesh.hpp:82
vector< uint > m_indices
Definition: SimpleMesh.hpp:83
void uniform(string const &name, t value)
Definition: SimpleMesh.hpp:58
GLuint m_normalsBuffer
Definition: SimpleMesh.hpp:87
void drawAllInstances(DrawArgs &args, Shader *shader)
Definition: SimpleMesh.cpp:92
Transformation & getTransform()
Definition: SimpleMesh.hpp:22
vector< vec2 > m_uvs
Definition: SimpleMesh.hpp:81
string m_name
Definition: SimpleMesh.hpp:78
Application * m_app
Definition: SimpleMesh.hpp:152
mesh_map m_meshes
Definition: SimpleMesh.hpp:151
SimpleMesh * create(string const &name, t_fnc fnc)
Definition: SimpleMesh.hpp:169
void unregisterInstance(SimpleMeshInstance *obj)
Definition: SimpleMesh.cpp:114
void drawAll(DrawArgs &args)
Definition: SimpleMesh.cpp:186
virtual ~SimpleMeshInstance()
Definition: SimpleMesh.cpp:11
virtual bool update(double time, double timeDelta)
Definition: SimpleMesh.cpp:30
GLuint m_vao
Definition: SimpleMesh.hpp:89
Application * m_app
Definition: SimpleMesh.hpp:76
SimpleMeshInstance(Application *app, SimpleMesh *mesh, bool pickable=true)
Definition: SimpleMesh.cpp:6