rev |
line source |
nuclear@0
|
1 /*
|
nuclear@0
|
2 256-color 3D graphics hack for real-mode DOS.
|
nuclear@0
|
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
|
nuclear@0
|
4
|
nuclear@0
|
5 This program is free software: you can redistribute it and/or modify
|
nuclear@0
|
6 it under the terms of the GNU General Public License as published by
|
nuclear@0
|
7 the Free Software Foundation, either version 3 of the License, or
|
nuclear@0
|
8 (at your option) any later version.
|
nuclear@0
|
9
|
nuclear@0
|
10 This program is distributed in the hope that it will be useful,
|
nuclear@0
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nuclear@0
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nuclear@0
|
13 GNU General Public License for more details.
|
nuclear@0
|
14
|
nuclear@0
|
15 You should have received a copy of the GNU General Public License
|
nuclear@0
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
nuclear@0
|
17 */
|
nuclear@0
|
18 static void SCAN_EDGE(struct vertex *v0, struct vertex *v1)
|
nuclear@0
|
19 {
|
nuclear@0
|
20 int i, start, end;
|
nuclear@0
|
21 float dx, dy, dfdx;
|
nuclear@0
|
22 #ifdef INTERP_DEPTH
|
nuclear@0
|
23 float z, dz, dfdz;
|
nuclear@0
|
24 #endif
|
nuclear@0
|
25 #ifdef INTERP_ENERGY
|
nuclear@0
|
26 float e, de, dfde;
|
nuclear@0
|
27 #endif
|
nuclear@0
|
28 float x, y;
|
nuclear@0
|
29 struct vertex *edge;
|
nuclear@0
|
30
|
nuclear@0
|
31 dy = v1->pos.y - v0->pos.y;
|
nuclear@0
|
32 if(dy < 1e-6 && dy > -1e-6) {
|
nuclear@0
|
33 return;
|
nuclear@0
|
34 }
|
nuclear@0
|
35
|
nuclear@0
|
36 dx = v1->pos.x - v0->pos.x;
|
nuclear@0
|
37 dfdx = dx / dy;
|
nuclear@0
|
38
|
nuclear@0
|
39 #ifdef INTERP_DEPTH
|
nuclear@0
|
40 assert(fb->zbuf);
|
nuclear@0
|
41 dz = v1->pos.z - v0->pos.z;
|
nuclear@0
|
42 dfdz = dz / dy;
|
nuclear@0
|
43 #endif
|
nuclear@0
|
44 #ifdef INTERP_ENERGY
|
nuclear@0
|
45 de = v1->energy - v0->energy;
|
nuclear@0
|
46 dfde = de / dy;
|
nuclear@0
|
47 #endif
|
nuclear@0
|
48
|
nuclear@0
|
49 if(dy < 0.0) {
|
nuclear@0
|
50 struct vertex *tmp = v0;
|
nuclear@0
|
51 v0 = v1;
|
nuclear@0
|
52 v1 = tmp;
|
nuclear@0
|
53 edge = (st->ord == MGL_CCW) ? vright : vleft;
|
nuclear@0
|
54 } else {
|
nuclear@0
|
55 edge = (st->ord == MGL_CCW) ? vleft : vright;
|
nuclear@0
|
56 }
|
nuclear@0
|
57
|
nuclear@0
|
58 start = (int)ROUND(v0->pos.y);
|
nuclear@0
|
59 end = (int)ROUND(v1->pos.y);
|
nuclear@0
|
60
|
nuclear@0
|
61 x = v0->pos.x;
|
nuclear@0
|
62 #ifdef INTERP_DEPTH
|
nuclear@0
|
63 z = v0->pos.z;
|
nuclear@0
|
64 #endif
|
nuclear@0
|
65 #ifdef INTERP_ENERGY
|
nuclear@0
|
66 e = v0->energy;
|
nuclear@0
|
67 #endif
|
nuclear@0
|
68 for(i=start; i<end; i++) {
|
nuclear@0
|
69 edge[i].pos.x = x;
|
nuclear@0
|
70 x += dfdx;
|
nuclear@0
|
71
|
nuclear@0
|
72 edge[i].cidx = v0->cidx;
|
nuclear@0
|
73 #ifdef INTERP_DEPTH
|
nuclear@0
|
74 edge[i].pos.z = z;
|
nuclear@0
|
75 z += dfdz;
|
nuclear@0
|
76 #endif
|
nuclear@0
|
77
|
nuclear@0
|
78 #ifdef INTERP_ENERGY
|
nuclear@0
|
79 edge[i].energy = e;
|
nuclear@0
|
80 e += dfde;
|
nuclear@0
|
81 #else
|
nuclear@0
|
82 edge[i].energy = v0->energy;
|
nuclear@0
|
83 #endif
|
nuclear@0
|
84 }
|
nuclear@0
|
85 }
|
nuclear@0
|
86
|
nuclear@0
|
87 static void SCAN_LINE(int y, unsigned char *sline)
|
nuclear@0
|
88 {
|
nuclear@0
|
89 int i, x0, x1, len, tmp, cidx;
|
nuclear@0
|
90 #if defined(INTERP_DEPTH) || defined(INTERP_ENERGY)
|
nuclear@0
|
91 float x, dx;
|
nuclear@0
|
92 #endif
|
nuclear@0
|
93 #ifdef INTERP_DEPTH
|
nuclear@0
|
94 float z, dz, dfdz;
|
nuclear@0
|
95 #endif
|
nuclear@0
|
96 #ifdef INTERP_ENERGY
|
nuclear@0
|
97 float e, de, dfde;
|
nuclear@0
|
98 #endif
|
nuclear@0
|
99 struct vertex *left, *right;
|
nuclear@0
|
100
|
nuclear@0
|
101 x0 = (int)ROUND(vleft[y].pos.x);
|
nuclear@0
|
102 x1 = (int)ROUND(vright[y].pos.x);
|
nuclear@0
|
103 len = x1 - x0;
|
nuclear@0
|
104
|
nuclear@0
|
105 if(x1 < x0) {
|
nuclear@0
|
106 if(st->flags & MGL_CULL_FACE) {
|
nuclear@0
|
107 return;
|
nuclear@0
|
108 }
|
nuclear@0
|
109 tmp = x0;
|
nuclear@0
|
110 x0 = x1;
|
nuclear@0
|
111 x1 = tmp;
|
nuclear@0
|
112 len = -len;
|
nuclear@0
|
113
|
nuclear@0
|
114 left = vright;
|
nuclear@0
|
115 right = vleft;
|
nuclear@0
|
116 } else {
|
nuclear@0
|
117 left = vleft;
|
nuclear@0
|
118 right = vright;
|
nuclear@0
|
119 }
|
nuclear@0
|
120
|
nuclear@0
|
121 if(x0 < 0) x0 = 0;
|
nuclear@0
|
122 if(x1 >= fb->width) x1 = fb->width - 1;
|
nuclear@0
|
123
|
nuclear@0
|
124 assert(len >= 0);
|
nuclear@0
|
125
|
nuclear@0
|
126 cidx = left[y].cidx;
|
nuclear@0
|
127 #if !defined(INTERP_DEPTH) && !defined(INTERP_ENERGY)
|
nuclear@0
|
128 /* no interpolation at all, just memset the whole scanline */
|
nuclear@0
|
129 memset(sline + x0, cidx + left[y].energy * st->col_range, len);
|
nuclear@0
|
130 #else
|
nuclear@0
|
131 /* otherwise do a loop and interpolate whatever needs interpolating */
|
nuclear@0
|
132 x = left[y].pos.x;
|
nuclear@0
|
133 dx = right[y].pos.x - x;
|
nuclear@0
|
134
|
nuclear@0
|
135 if(dx < 0.5 && dx > -0.5) {
|
nuclear@0
|
136 return;
|
nuclear@0
|
137 }
|
nuclear@0
|
138
|
nuclear@0
|
139 #ifdef INTERP_DEPTH
|
nuclear@0
|
140 z = left[y].pos.z;
|
nuclear@0
|
141 dz = right[y].pos.z - z;
|
nuclear@0
|
142 dfdz = dz / dx;
|
nuclear@0
|
143 #endif
|
nuclear@0
|
144 #ifdef INTERP_ENERGY
|
nuclear@0
|
145 e = left[y].energy;
|
nuclear@0
|
146 de = right[y].energy - e;
|
nuclear@0
|
147 dfde = de / dx;
|
nuclear@0
|
148 #endif
|
nuclear@0
|
149
|
nuclear@0
|
150 for(i=0; i<len; i++) {
|
nuclear@0
|
151 #ifdef INTERP_ENERGY
|
nuclear@0
|
152 cidx = left[y].cidx + e * st->col_range;
|
nuclear@0
|
153 e += dfde;
|
nuclear@0
|
154 #endif
|
nuclear@0
|
155 sline[x0 + i] = cidx;
|
nuclear@0
|
156 }
|
nuclear@0
|
157 #endif /* flat */
|
nuclear@0
|
158 }
|