forked from LibreCAD/LibreCAD_3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.h
executable file
·186 lines (108 loc) · 3.66 KB
/
renderer.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef RENDERER_H
#define RENDERER_H
#include <GL/glew.h>
#include <GL/gl.h>
#include <signal.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <stack>
#include <vector>
#include "gl_entity.h"
#include "shape_entity.h"
#include "gradient_entity.h"
#include "shader.h"
#include "gl_pack.h"
#include "cacher.h"
namespace lc
{
namespace viewer
{
namespace opengl
{
//---------------Error handling(if needed)----------------------
#define ASSERT(x) if (!(x)) raise(SIGINT);
#define GLCall(x) GLClearError();\
x;\
ASSERT(GLLogCall(#x,__FILE__,__LINE__))
void GLClearError();
bool GLLogCall(const char* function,const char* file,int line);
//--------------------------------------------------------------
struct context_att
{
glm::mat4 ctm; //CTM
};
//--------------------------------------------------------------
#define PI 3.14159265
class Renderer
{
private:
std::vector< glm::vec4 > vertex_data; // for vertex data
std::vector<int> jumps;
std::vector< glm::vec4 > current_vertices; // for current shape(continous)
float path_distance; //distance(scalar) from start point to current
bool closed=false;
float line_width;
double *dashes; int dashes_size;
bool fill=false;
Shaders_book shaders;
glm::mat4 proj; //projection matrix
glm::mat4 projB;
glm::mat4 view; //view matrix for pan
glm::mat4 ctm;
std::stack < context_att > context_stack;
GL_Entity* current_gl_entity = NULL;
Cacher* CH_Ptr;
public:
Renderer();
~Renderer();
void CreateShaderProgram();
void Set_Cacher_Ref(Cacher* ch);
//---------------------------For Matrix/ Vectors/ Coordinate-----------
void Update_projection(float l,float r,float b,float t);
void Update_view();
//-----------
void Update_scale(float scale);
void Update_translate(float x,float y);
void Update_rotate(float angle);
void Reset_Transformations();
double Get_Scale();
double Get_Translate_X();
double Get_Translate_Y();
//----------
void Device_To_User(double* x, double* y);
void User_To_Device(double* x, double* y);
void Device_To_User_Distance(double* x, double* y);
void User_To_Device_Distance(double* x, double* y);
//------------context handling-------------------------------------
void Save();
void Restore();
//---------------Functions manipulating vertex data(raw)----------------------
void Add_Vertex(float x,float y,float z=0.0f);
void Append_Vertex_Data();
void Jump();
void Clear_Data();
void Close_Loop();
//---------------Functions manipulating entities---------------------------------------------------------
bool Find_GL_Entity(unsigned int id);
void Use_GL_Entity(unsigned int id);
void Add_New_Shape_Entity();
void Add_New_Gradient_Entity();
void Add_Data_To_GL_Entity();
void Select_Fill();
void Select_Color(float R,float G,float B,float A);
void Select_Line_Width(float width);
void Select_Dashes(const double* dashes, const int num_dashes, double offset, bool scaled);
//--------------------------for gradient entity----------------------------
void Add_Linear_Gradient(float x0,float y0,float x1,float y1);
void Add_Gradient_Color_Point(float R,float G,float B,float A);
//----------------------------render direct entity------------------
void Render();
//-----------------------------rendering cached entities---------------
void Render_Cached_Entity(GL_Entity* entity);
void Render_Cached_Pack(GL_Pack* pack);
};
}
}
}
#endif // RENDERER_H