You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.7 KiB
100 lines
2.7 KiB
|
|
#pragma once |
|
#include <memory> |
|
#include <glm/glm.hpp> |
|
#include "mesh.h" |
|
#include <set> |
|
#include "glutil.h" |
|
#include <GL/glu.h> |
|
#include <glm/gtc/matrix_transform.hpp> |
|
#include <glm/gtc/type_ptr.hpp> |
|
#include "entity.h" |
|
|
|
void draw_objects(Shader *shader, const std::vector<physics_model> positions, std::shared_ptr<Model> m, const glm::mat4 view, const glm::mat4 projection) ; |
|
|
|
void setup_shader(Shader *shader, const glm::mat4 view, const glm::mat4 projection, const glm::vec3 position, const glm::mat4 orientation); |
|
|
|
namespace drawing { |
|
|
|
struct instanced_renderer { |
|
GLuint vbo; |
|
Shader * shader; |
|
}; |
|
|
|
struct position { |
|
glm::vec3 position; |
|
glm::mat4 orientation; |
|
}; |
|
|
|
instanced_renderer instanced_setup(Shader* shader, const std::vector<position> &positions); |
|
void instanced_update(const instanced_renderer r, const std::vector<position> &positions); |
|
void instanced_draw(const instanced_renderer r, const glm::mat4 view, const glm::mat4 projection); |
|
void noninstanced_set_camera(Shader *shader, const glm::mat4 view, const glm::mat4 projection); |
|
void noninstanced_draw(std::vector<position> objects, Model * model, Shader *shader, const glm::mat4 view, const glm::mat4 projection); |
|
}; |
|
|
|
struct object { |
|
glm::vec3 position; |
|
glm::mat4 orientation; |
|
std::shared_ptr<Model> model; |
|
}; |
|
|
|
// handles shaders, models, meshes for drawing a collection of similar objects |
|
class drawing_object_handle { |
|
public: |
|
virtual void draw(const glm::mat4 view, const glm::mat4 projection) = 0; |
|
virtual void draw(int i, const glm::mat4 view, const glm::mat4 projection) = 0; |
|
}; |
|
|
|
|
|
class simple_object_draw_system : public drawing_object_handle { |
|
Shader *shader; |
|
|
|
|
|
|
|
public: |
|
std::vector<object> objects; |
|
std::set<int> do_not_draw; |
|
simple_object_draw_system(Shader *shader); |
|
|
|
int add(std::shared_ptr<Model> model, glm::vec3 position, glm::mat4 orientation); |
|
|
|
|
|
void remove(int i); |
|
|
|
void return_to_draw_list(int i); |
|
|
|
void draw(int i, const glm::mat4 view, const glm::mat4 projection) override; |
|
|
|
|
|
void draw(const glm::mat4 view, const glm::mat4 projection) override; |
|
|
|
}; |
|
|
|
|
|
/* Draw a lot of the same object. */ |
|
class instanced_drawing : public drawing_object_handle { |
|
public: |
|
struct object { |
|
glm::vec3 position; |
|
glm::mat4 model; |
|
}; |
|
private: |
|
|
|
std::vector<object> models; |
|
|
|
Model *model; |
|
Shader *shader; |
|
|
|
unsigned int instance_VBO; |
|
public: |
|
instanced_drawing (Model *model, Shader *shader, std::vector<object> obj_models); |
|
instanced_drawing (Model *model, Shader *shader); |
|
|
|
int finalize (); |
|
int add(glm::vec3 position, glm::mat4 orientation); |
|
void draw(const glm::mat4 view, const glm::mat4 projection) override; |
|
}; |
|
|
|
|
|
|
|
|