-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.h
More file actions
90 lines (70 loc) · 2.85 KB
/
Model.h
File metadata and controls
90 lines (70 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef MODEL_H_
#define MODEL_H_
#include <vector>
#include "ModelInstance.h"
#include "ModelType.h"
#include "GPUBuffer.h"
#include "Material.h"
#include "stdio.h"
#include "config.h"
#include <limits>
/*
* This is a 3D model.
* It stores vertex data.
* It must have a model-type, that defines
* a) the drawing primitive
* b) the shader
* c) the vertex attributes
* for this model.
* The vertex attribute "position" is available per default.
* The position must have 3+ components.
* The model can also have instances (and is an instance itself).
* Instances use the same vertex data.
* Each instance uses a different matrix.
* All matrices are stored subsequently.
*/
class Model : public ModelInstance {
ModelType* modeltype_;
GLint num_vertices_;
// Vertices with their attributes in contiguous storage locations (as they will be in gpu memory)
std::vector<GLfloat> vertices_;
// Instances of this model, including this object itself at index 0 (array index equals instance_id)
std::vector<ModelInstance*> instances_;
// Model matrices (array index equals instance_id)
std::vector<glm::mat4> matrices_;
// Counts how often this model has been use()d since last draw
int num_new_instances_;
public:
Model(int id, ModelType* modeltype);
Model(int id, ModelType* modeltype, std::initializer_list<std::initializer_list<std::initializer_list<GLfloat>>> v);
Model(int id, ModelType* modeltype, std::vector<std::vector<std::vector<GLfloat>>> v);
~Model();
// Returns instance of this model, which can be seperately transformed (hardware instancing)
ModelInstance* use();
//TODO
//ModelInstance* use(glm::vec3 pos); // directly translate instance after use
void draw(GLint offset, GLuint instance_attribs_offset);
GLsizeiptr bytes() { return vertices_.size() * sizeof(GLfloat); }
const GLvoid* pointer() { return vertices_.data(); }
GLsizeiptr bytes_matrices() { return matrices_.size() * sizeof(matrices_[0]); }
const GLvoid* pointer_matrices() { return matrices_.data(); }
GLsizeiptr bytes_instance_attribs();
void update_instance_attribs(GPUBuffer* b, GLint offset);
const GLvoid* pointer_instance_attr(unsigned int instance_index, unsigned int attr_index);
// GETTER
ModelType* modeltype() { return modeltype_; }
GLint num_vertices() { return num_vertices_; }
GLsizei num_instances() { return instances_.size(); }
GLsizei num_matrices() { return matrices_.size(); }
ModelInstance* instance(int instance_id) { return instances_[instance_id]; }
bool num_new_instances() { return num_new_instances_; }
glm::mat4* matrix_at(int index) { return &matrices_[index]; }
// SETTER
void vertices(std::vector<std::vector<std::vector<GLfloat>>> vertices);
void instances_added();
//TODO
// Draw this model independently from a world (own vao and vbo required)
// void draw_free();
friend class ModelInstance; // allows model instances to see private members
};
#endif