]> git.lizzy.rs Git - dragonblocks3d.git/blob - src/dragonblocks/mesh.hpp
Multithreading
[dragonblocks3d.git] / src / dragonblocks / mesh.hpp
1 #pragma once
2
3 #include <vector>
4 #include "gl.hpp"
5 #include "texture.hpp"
6
7 namespace dragonblocks
8 {
9         class Scene;
10         class ShaderProgram;
11         
12         class Mesh
13         {
14                 public:
15                 class Effect
16                 {
17                         public:
18                         static double grow_time;        // s
19                         static double flyin_time;       // s
20                         static double flyin_offset;     // m
21                         static double rotate_speed;     // turns/s
22                         
23                         enum Type
24                         {
25                                 NONE,
26                                 FLYIN,
27                                 GROW,
28                                 ROTATE
29                         };
30                         
31                         glm::mat4 getModelMatrix(double, glm::vec3, glm::vec3, glm::vec3, float);
32                         
33                         Effect() = default;
34                         Effect(Type, void (*)(void *) = nullptr, void * = nullptr);
35                         Effect(const Effect &) = default;
36                         
37                         private:
38                         Type type = Type::NONE;
39                         double time_left;
40                         void (*on_finish)(void *);
41                         void *extra_data;
42                         bool expires;
43                 };
44                 
45                 int vertices_per_texture;
46                 glm::vec3 pos, size, rotation_axis;
47                 float rotation_angle;
48                 std::vector<Texture> textures;  
49                 Effect effect;
50                 
51                 void reset();
52                 void vertexConfig(const GLvoid *v, GLsizei s);
53                 void render(double dtime, ShaderProgram *);
54                 void addToScene();
55                 void removeFromScene();
56                 void runVertexConfig();
57                 
58                 Mesh(Scene *);
59
60                 private:
61                 GLuint VAO = 0, VBO = 0;
62                 Scene *scene;
63                 GLvoid *vertices = NULL;
64                 GLsizeiptr vertices_size;
65                 bool configured;
66                 bool vertices_changed;
67                 
68         };
69 }