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