-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEE.h
126 lines (102 loc) · 2.55 KB
/
LEE.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
#pragma once
#include "gz.h"
#include "disp.h"
#include "LineEq.h"
#include "TriPlanar.h"
#include "help.h"
#include "shader.h"
#include "Texture.h"
#include "AntiAliasing.h"
class LEE
{
public:
static LEE* getLEE() {
static LEE leeInstance;
return &leeInstance;
};
void setDisplay(GzDisplay *display) {
this->display = display;
this->xres = display->xres;
this->yres = display->yres;
#ifdef _DEBUG
if(drawed==NULL)
drawed = (bool *)malloc(this->xres*this->yres * sizeof(bool));
#endif
}
void setRed(float cr) {
rgb[RED] = cr;
}
void setBlue(float cb) {
rgb[BLUE] = cb;
}
void setGreen(float cg) {
rgb[GREEN] = cg;
}
void getBoundBox(int& l, int& u, int& r, int& b) {
l = this->l;
u = this->u;
r = this->r;
b = this->b;
}
Shader* getShader() {
return shader;
}
void setAA(GzDisplay* display) {
if (aa != NULL)
delete aa;
aa = new AntiAliasing(display);
}
AntiAliasing* getAA() {
return aa;
}
void setTex(GzTexture texFun) {
if (texture != NULL)
delete texture;
texture = new Texture(texFun);
}
// set vertices
// adjust shared vertices
// sort vertices
// calculate ABC for line equation
//
//
//input: triangle vertices
//output: area of the triangle
QType buildTriangle(GzCoord triVertices[]);
// judge if given pt from bounding box should be drawn
// expression evaluation & z buffer
//
// input: coordinate in screen
void draw(GzCoord triVertices[], GzCoord normal[], GzTextureIndex t[]);
void draw(GzCoord triVertices[], GzCoord normal[]);
void draw(GzCoord triVertices[]);
//find boundbox
void boundBox(GzCoord triVertices[]);
private:
bool coveredEdge(QType A, QType B);
void putPixel(int x, int y, int z, bool& drawn);
void putShaderPixel(int i, int j, int z, bool& drawn);
void putTexPixel(int i, int j, int z, bool& drawn);
void putBuffer(int i, int j, short color[]);
void drawPixel(GzCoord triVertices[], QType area, void(LEE::*pf)(int i, int j, int z, bool& drawn));
void drawFlatPixel(int z, void(LEE::*pf)(int i, int j, int z, bool& drawn));
//void drawDepth(GzCoord triVertices[]);
LEE();
~LEE();
GzCoord * _triVertices;
GzDisplay *display;
int xres, yres;//copy from disp
int l, r, u, b;//bounding box left, right, up, bottom
GzColor rgb;//color r, g, b;
short srgb[3];//color r, g, b in short;
LineEq<QType>* edges[3];
TriPlanar* triPl;//planar for z interpolation
Shader* shader;
Texture* texture;
AntiAliasing* aa;
#ifdef _DEBUG
//test duplicated rendering
bool * drawed;
#endif // DEBUG
};
typedef void(LEE::*pf)(int i, int j, int z, bool& drawn);