-
Notifications
You must be signed in to change notification settings - Fork 0
/
GL.cpp
113 lines (88 loc) · 3.16 KB
/
GL.cpp
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
#include "GLInternal.hpp"
#include "Rasterizer.hpp"
GLState *gCurrentState = nullptr;
// ############################################################################################
GLAPI void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
gCurrentState->clearColor.setFloat4(red, green, blue, alpha);
}
GLAPI void glClearDepth(GLclampd depth) {
gCurrentState->clearDepth = static_cast<float>(depth);
}
GLAPI void glClear(GLbitfield mask) {
if (mask & GL_COLOR_BUFFER_BIT) {
rsClearColor(gCurrentState->clearColor);
}
if (mask & GL_DEPTH_BUFFER_BIT) {
rsClearDepth(gCurrentState->clearDepth);
}
}
// ############################################################################################
GLAPI void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
gCurrentState->viewport.set(x, y, width, height);
}
GLAPI void glEnable(GLenum cap) {
gCurrentState->caps |= cap;
}
GLAPI void glDisable(GLenum cap) {
gCurrentState->caps &= ~cap;
}
GLAPI void glDepthFunc(GLenum func) {
gCurrentState->depthFunc = func;
}
// ############################################################################################
GLAPI void glMatrixMode(GLenum mode) {
gCurrentState->matrixMode = mode;
}
GLAPI void glLoadIdentity(void) {
gCurrentState->currentMat().setIdentity();
}
GLAPI void glLoadMatrixf(const GLfloat *m) {
gCurrentState->currentMat().set(m);
}
GLAPI void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
gCurrentState->currentMat().rotate(angle, x, y, z);
}
GLAPI void glScalef(GLfloat x, GLfloat y, GLfloat z) {
gCurrentState->currentMat().scale(x, y, z);
}
GLAPI void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
gCurrentState->currentMat().translate(x, y, z);
}
// ############################################################################################
GLAPI void glBegin(GLenum mode) {
gCurrentState->primType = mode;
}
GLAPI void glColor3f(GLfloat red, GLfloat green, GLfloat blue) {
gCurrentState->imColor.setFloat4(red, green, blue, 1.0f);
}
GLAPI void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
gCurrentState->imColor.setFloat4(red, green, blue, alpha);
}
GLAPI void glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
glVertex4f(x, y, z, 1.0f);
}
GLAPI void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
Vertex v;
v.pos.set(x, y, z, 1.0f);
v.color = gCurrentState->imColor;
vpAddVertex(std::move(v));
if (gCurrentState->primType == GL_QUADS) {
gCurrentState->imQuadVertsCounter++;
if (gCurrentState->imQuadVertsCounter == 3) {
size_t vert4Idx = vpGetVertices().size() - 3;
size_t vert5Idx = vpGetVertices().size() - 1;
vpAddVertex(Vertex(vpGetVertices()[vert4Idx]));
vpAddVertex(Vertex(vpGetVertices()[vert5Idx]));
}
else if (gCurrentState->imQuadVertsCounter == 4) {
gCurrentState->imQuadVertsCounter = 0;
}
}
}
GLAPI void glEnd(void) {
if (gCurrentState->primType == GL_QUADS) {
gCurrentState->primType = GL_TRIANGLES;
}
vpProcess();
gCurrentState->primType = 0;
}