]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
1 | typedef union { |
2 | float f; | |
3 | int i; | |
4 | } fi_type; | |
5 | static __inline__ int IS_INF_OR_NAN(float x) | |
6 | { | |
7 | fi_type tmp; | |
8 | tmp.f = x; | |
9 | return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31); | |
10 | } | |
11 | ||
12 | struct gl_texture_image { | |
13 | unsigned int Width; | |
14 | unsigned int Height; | |
15 | unsigned int WidthLog2; | |
16 | void *Data; | |
17 | }; | |
18 | struct gl_texture_object { | |
19 | int BaseLevel; | |
20 | struct gl_texture_image *Image[6][15]; | |
21 | }; | |
22 | struct gl_texture_unit { | |
23 | struct gl_texture_object *CurrentTex[9]; | |
24 | }; | |
25 | struct gl_texture_attrib { | |
26 | struct gl_texture_unit Unit[(16 + 16)]; | |
27 | }; | |
28 | struct gl_renderbuffer { | |
29 | void (*PutRowRGB) (); | |
30 | }; | |
31 | struct gl_framebuffer { | |
32 | struct gl_renderbuffer *_ColorDrawBuffers[8]; | |
33 | }; | |
34 | struct gl_context { | |
35 | struct gl_framebuffer *DrawBuffer; | |
36 | struct gl_texture_attrib Texture; | |
37 | }; | |
38 | typedef struct { | |
39 | float attrib[30][4]; | |
40 | } SWvertex; | |
41 | typedef struct sw_span { | |
42 | int x, y; | |
43 | unsigned int end; | |
44 | float attrStepX[30][4]; | |
45 | int intTex[2], intTexStep[2]; | |
46 | } SWspan; | |
47 | static void simple_textured_triangle(const SWvertex * v1) | |
48 | { | |
49 | struct gl_context *ctx; | |
50 | const SWvertex * v0; | |
51 | const SWvertex * v2; | |
52 | typedef struct { | |
53 | float dx; | |
54 | float dy; | |
55 | int fsx; | |
56 | int fx0; | |
57 | int lines; | |
58 | } EdgeT; | |
59 | EdgeT eMaj; | |
60 | EdgeT eTop; | |
61 | EdgeT eBot; | |
62 | float oneOverArea; | |
63 | const SWvertex *vMin; | |
64 | const SWvertex *vMid; | |
65 | const SWvertex *vMax; | |
66 | const int snapMask = ~127; | |
67 | int vMin_fx; | |
68 | int vMin_fy; | |
69 | int vMid_fx; | |
70 | int vMid_fy; | |
71 | int vMax_fx; | |
72 | int vMax_fy; | |
73 | SWspan span; | |
74 | const int fy0 = | |
75 | (((int) | |
76 | ((((v0->attrib[0][1] - | |
77 | 0.5F) * (float)2048) >= | |
78 | 0.0F) ? (((v0->attrib[0][1] - 0.5F) * | |
79 | (float)2048) + | |
80 | 0.5F) : (((v0->attrib[0][1] - 0.5F) * | |
81 | (float)2048) - 0.5F)))) & snapMask; | |
82 | const int fy1 = | |
83 | (((int) | |
84 | ((((v1->attrib[0][1] - | |
85 | 0.5F) * (float)2048) >= | |
86 | 0.0F) ? (((v1->attrib[0][1] - 0.5F) * | |
87 | (float)2048) + | |
88 | 0.5F) : (((v1->attrib[0][1] - 0.5F) * | |
89 | (float)2048) - 0.5F)))) & snapMask; | |
90 | const int fy2 = | |
91 | (((int) | |
92 | ((((v2->attrib[0][1] - | |
93 | 0.5F) * (float)2048) >= | |
94 | 0.0F) ? (((v2->attrib[0][1] - 0.5F) * | |
95 | (float)2048) + | |
96 | 0.5F) : (((v2->attrib[0][1] - 0.5F) * | |
97 | (float)2048) - 0.5F)))) & snapMask; | |
98 | if (fy0 <= fy1) { | |
99 | if (fy1 <= fy2) { | |
100 | vMin = v0; | |
101 | vMax = v1; | |
102 | vMin_fy = fy0; | |
103 | } | |
104 | } | |
105 | vMin_fx = | |
106 | (((int) | |
107 | ((((vMin->attrib[0][0] + | |
108 | 0.5F) * (float)2048) >= | |
109 | 0.0F) ? (((vMin->attrib[0][0] + 0.5F) * | |
110 | (float)2048) + | |
111 | 0.5F) : (((vMin->attrib[0][0] + 0.5F) * | |
112 | (float)2048) - 0.5F)))) & snapMask; | |
113 | vMid_fx = | |
114 | (((int) | |
115 | ((((vMid->attrib[0][0] + | |
116 | 0.5F) * (float)2048) >= | |
117 | 0.0F) ? (((vMid->attrib[0][0] + 0.5F) * | |
118 | (float)2048) + | |
119 | 0.5F) : (((vMid->attrib[0][0] + 0.5F) * | |
120 | (float)2048) - 0.5F)))) & snapMask; | |
121 | eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / (float)2048)); | |
122 | eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / (float)2048)); | |
123 | eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / (float)2048)); | |
124 | eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / (float)2048)); | |
125 | const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; | |
126 | if (IS_INF_OR_NAN(area)) | |
127 | return; | |
128 | oneOverArea = 1.0F / area; | |
129 | eBot.fx0 = vMin_fx; | |
130 | int scan_from_left_to_right; | |
131 | struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; | |
132 | const struct gl_texture_object *obj; | |
133 | const struct gl_texture_image *texImg; | |
134 | const float twidth; | |
135 | const int twidth_log2; | |
136 | const unsigned char *texture = texImg->Data; | |
137 | const int smask = texImg->Width; | |
138 | const int tmask = texImg->Height; | |
139 | float eMaj_ds = | |
140 | (vMax->attrib[4][0] - | |
141 | vMin->attrib[4][0]) * twidth; | |
142 | float eBot_ds; | |
143 | span.attrStepX[4][0] = | |
144 | oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); | |
145 | span.intTexStep[0] = | |
146 | (((int) | |
147 | ((((span.attrStepX[4][0]) * (float)2048) >= | |
148 | 0.0F) ? (((span.attrStepX[4][0]) * | |
149 | (float)2048) + | |
150 | 0.5F) : (((span.attrStepX[4][0]) * | |
151 | (float)2048) - 0.5F)))); | |
152 | int subTriangle; | |
153 | int fxLeftEdge = 0; | |
154 | int fxRightEdge = 0; | |
155 | int sLeft = 0; | |
156 | for (subTriangle = 0; subTriangle <= 1; subTriangle++) { | |
157 | EdgeT *eRight; | |
158 | int lines; | |
159 | if (subTriangle == 0) { | |
160 | if (scan_from_left_to_right) { | |
161 | eRight = &eBot; | |
162 | lines = eRight->lines; | |
163 | } | |
164 | else { | |
165 | eRight = &eMaj; | |
166 | } | |
167 | } else { | |
168 | if (scan_from_left_to_right) | |
169 | { | |
170 | eRight = &eTop; | |
171 | } | |
172 | fxRightEdge = eRight->fsx - 1; | |
173 | } | |
174 | while (lines > 0) | |
175 | { | |
176 | const int right = fxRightEdge >> 11; | |
177 | span.x = fxLeftEdge >> 11; | |
178 | if (right <= span.x) | |
179 | span.end = 0; | |
180 | else | |
181 | span.end = right - span.x; | |
182 | span.intTex[0] = sLeft; | |
183 | if (span.end > 0 && span.y >= 0) | |
184 | { | |
185 | unsigned int i; | |
186 | unsigned char rgb[16384][3]; | |
187 | for (i = 0; i < span.end; i++) | |
188 | { | |
189 | int s = ((span.intTex[0]) >> 11) & smask; | |
190 | int t = | |
191 | ((span.intTex[1]) >> 11) & tmask; | |
192 | int pos = (t << twidth_log2) + s; | |
193 | rgb[i][0] = texture[pos + 2]; | |
194 | span.intTex[0] += span.intTexStep[0]; | |
195 | } | |
196 | rb->PutRowRGB( | |
197 | rgb | |
198 | ); | |
199 | } | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
204 | void *foo() | |
205 | { | |
206 | return simple_textured_triangle; | |
207 | } |