-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLRenderer.h
84 lines (63 loc) · 1.43 KB
/
GLRenderer.h
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
#pragma once
#include <GL/glew.h>
#include <glm/glm.hpp>
#include "Game.h"
#include "Camera.h"
#include "Chunk.h"
#include <map>
#include <vector>
class Game;
class Camera;
class Chunk;
struct Mesh
{
std::vector<glm::vec3> vertices;
std::vector<glm::vec4> colors;
std::vector<glm::vec3> normals;
std::vector<unsigned int> indices;
glm::vec3 translation;
};
struct MeshBuffer
{
GLuint vertexBuffer;
GLuint colorBuffer;
GLuint normalBuffer;
GLuint indexBuffer;
int indexSize;
glm::vec3 translation;
};
class GLRenderer
{
public:
GLRenderer(Game* game, GLFWwindow* window, Camera* camera);
~GLRenderer(void);
void update();
void startMesh(int* id);
void finishMesh(int id, Chunk* chunk);
int addPointToMesh(int id, glm::vec3 &point, glm::vec4 &color, glm::vec3 &normal);
void addTriangleToMesh(int id, int point1, int point2, int point3);
void renderACube();
void renderMesh(int id);
bool chunkInFrustum(Chunk* chunk);
bool pointInFrustum(glm::vec3 &pos);
bool sphereInFrustum(glm::vec3 ¢er, double radius);
void setTranslation(glm::vec3 pos);
glm::mat4 getTranslation(glm::vec3 pos);
int getNextID();
private:
GLuint programID;
GLuint posHandle;
GLuint colorHandle;
GLuint normalHandle;
GLuint MVPHandle;
GLuint modelHandle;
GLuint viewHandle;
GLFWwindow* window;
Game* game;
Camera* camera;
int currentID;
int activeID;
int lockValue;
Mesh activeMesh;
std::map<unsigned int, MeshBuffer> meshBuffers;
};