]> git.wh0rd.org - ICEs.git/blob - 394889/s_triangle.i.4
more
[ICEs.git] / 394889 / s_triangle.i.4
1 typedef unsigned int GLenum;
2 typedef unsigned char GLboolean;
3 typedef unsigned int GLbitfield;
4 typedef void GLvoid;
5 typedef int GLint;
6 typedef unsigned char GLubyte;
7 typedef unsigned int GLuint;
8 typedef float GLfloat;
9 typedef int GLfixed;
10 typedef union {
11 GLfloat f;
12 GLint i;
13 } fi_type;
14 static __inline__ int IS_INF_OR_NAN(float x)
15 {
16 fi_type tmp;
17 tmp.f = x;
18 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
19 }
20
21 typedef enum {
22 MESA_FORMAT_RGBA8888,
23 MESA_FORMAT_RGB888,
24 } gl_format;
25 typedef enum {
26 FRAG_ATTRIB_WPOS = 0,
27 FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 =
28 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 =
29 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 =
30 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 =
31 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 =
32 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16)
33 } gl_frag_result;
34 struct gl_config {
35 GLint depthBits;
36 };
37 struct gl_lightmodel {
38 GLenum ColorControl;
39 };
40 struct gl_depthbuffer_attrib {
41 GLenum Func;
42 GLboolean Mask;
43 };
44 struct gl_hint_attrib {
45 GLenum PerspectiveCorrection;
46 };
47 struct gl_light_attrib {
48 struct gl_lightmodel Model;
49 };
50 struct gl_polygon_attrib {
51 GLboolean StippleFlag;
52 };
53 typedef enum {
54 TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX,
55 TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX,
56 TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS
57 } gl_texture_index;
58 struct gl_texture_image {
59 GLuint Border;
60 GLuint Width;
61 GLuint Height;
62 GLuint WidthLog2;
63 GLboolean _IsPowerOfTwo;
64 GLuint RowStride;
65 GLvoid *Data;
66 };
67 typedef enum {
68 MAX_FACES = 6
69 } gl_face_index;
70 struct gl_sampler_object {
71 GLenum WrapS;
72 GLenum WrapT;
73 };
74 struct gl_texture_object {
75 struct gl_sampler_object Sampler;
76 GLint BaseLevel;
77 GLuint _Swizzle;
78 struct gl_texture_image *Image[MAX_FACES][15];
79 };
80 struct gl_texture_unit {
81 GLbitfield _ReallyEnabled;
82 GLenum EnvMode;
83 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
84 };
85 struct gl_texture_attrib {
86 struct gl_texture_unit Unit[(16 + 16)];
87 GLbitfield _EnabledUnits;
88 GLbitfield _EnabledCoordUnits;
89 };
90 struct gl_fragment_program_state {
91 struct gl_fragment_program *_Current;
92 };
93 struct gl_ati_fragment_shader_state {
94 GLboolean _Enabled;
95 };
96 struct gl_renderbuffer {
97 void (*PutRowRGB) (struct gl_context * ctx, struct gl_renderbuffer * rb,
98 GLuint count, GLint x, GLint y, const void *values,
99 const GLubyte * mask);
100 };
101 struct gl_framebuffer {
102 struct gl_config Visual;
103 struct gl_renderbuffer *_ColorDrawBuffers[8];
104 };
105 struct gl_context {
106 struct gl_framebuffer *DrawBuffer;
107 struct gl_depthbuffer_attrib Depth;
108 struct gl_hint_attrib Hint;
109 struct gl_light_attrib Light;
110 struct gl_polygon_attrib Polygon;
111 struct gl_texture_attrib Texture;
112 struct gl_fragment_program_state FragmentProgram;
113 struct gl_ati_fragment_shader_state ATIFragmentShader;
114 GLenum RenderMode;
115 };
116 typedef struct {
117 GLfloat attrib[FRAG_ATTRIB_MAX][4];
118 } SWvertex;
119 typedef struct sw_span {
120 GLint x, y;
121 GLuint end;
122 GLfloat attrStepX[FRAG_ATTRIB_MAX][4];
123 GLfixed intTex[2], intTexStep[2];
124 } SWspan;
125 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
126 const SWvertex *, const SWvertex *);
127 typedef struct {
128 GLbitfield _RasterMask;
129 GLboolean _FogEnabled;
130 swrast_tri_func Triangle;
131 } SWcontext;
132 static __inline__ SWcontext *SWRAST_CONTEXT(struct gl_context *ctx)
133 {
134 }
135
136 static void simple_textured_triangle(struct gl_context *ctx,
137 const SWvertex * v0, const SWvertex * v1,
138 const SWvertex * v2)
139 {
140 typedef struct {
141 GLfloat dx;
142 GLfloat dy;
143 GLfixed fsx;
144 GLfixed fx0;
145 GLint lines;
146 } EdgeT;
147 EdgeT eMaj;
148 EdgeT eTop; EdgeT eBot;
149 GLfloat oneOverArea;
150 const SWvertex *vMin;const SWvertex *vMid;const SWvertex *vMax;
151 const GLint snapMask = ~(((1 << 11) / (1 << 4)) - 1);
152 GLfixed vMin_fx;GLfixed vMin_fy;GLfixed vMid_fx;GLfixed vMid_fy;GLfixed vMax_fx;GLfixed vMax_fy;
153 SWspan span;
154 {
155 const GLfixed fy0 =
156 (((int)
157 ((((v0->attrib[FRAG_ATTRIB_WPOS][1] -
158 0.5F) * ((float)(1 << 11))) >=
159 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
160 ((float)(1 << 11))) +
161 0.5F)
162 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
163 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
164 const GLfixed fy1 =
165 (((int)
166 ((((v1->attrib[FRAG_ATTRIB_WPOS][1] -
167 0.5F) * ((float)(1 << 11))) >=
168 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
169 ((float)(1 << 11))) +
170 0.5F)
171 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
172 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
173 const GLfixed fy2 =
174 (((int)
175 ((((v2->attrib[FRAG_ATTRIB_WPOS][1] -
176 0.5F) * ((float)(1 << 11))) >=
177 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
178 ((float)(1 << 11))) +
179 0.5F)
180 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
181 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
182 if (fy0 <= fy1) {
183 if (fy1 <= fy2) {
184 vMin = v0;
185 vMax = v1;
186 vMin_fy = fy0;
187 }
188 }
189 vMin_fx =
190 (((int)
191 ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
192 0.5F) * ((float)(1 << 11))) >=
193 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
194 ((float)(1 << 11))) +
195 0.5F)
196 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
197 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
198 vMid_fx =
199 (((int)
200 ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
201 0.5F) * ((float)(1 << 11))) >=
202 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
203 ((float)(1 << 11))) +
204 0.5F)
205 : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
206 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
207 }
208 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11))));
209 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
210 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11))));
211 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
212 {
213 const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
214 if (IS_INF_OR_NAN(area) || area == 0.0F)
215 return;
216 oneOverArea = 1.0F / area;
217 if (eBot.lines > 0) {
218 eBot.fx0 = vMin_fx;
219 }
220 GLint scan_from_left_to_right;
221 struct gl_renderbuffer *rb =
222 ctx->DrawBuffer->_ColorDrawBuffers[0];
223 const struct gl_texture_object *obj =
224 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
225 const struct gl_texture_image *texImg =
226 obj->Image[0][obj->BaseLevel];
227 const GLfloat twidth = (GLfloat) texImg->Width;
228 const GLint twidth_log2 = texImg->WidthLog2;
229 const GLubyte *texture = (const GLubyte *)texImg->Data;
230 const GLint smask = texImg->Width - 1;
231 const GLint tmask = texImg->Height - 1;
232 if (!rb || !texture) {
233 return;
234 }
235 {
236 GLfloat eMaj_ds =
237 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
238 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
239 GLfloat eBot_ds =
240 (vMid->attrib[FRAG_ATTRIB_TEX0][0] -
241 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
242 span.attrStepX[FRAG_ATTRIB_TEX0][0] =
243 oneOverArea * (eMaj_ds * eBot.dy -
244 eMaj.dy * eBot_ds);
245 span.intTexStep[0] =
246 (((int)
247 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
248 ((float)(1 << 11))) >=
249 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
250 * ((float)(1 << 11))) +
251 0.5F)
252 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
253 ((float)(1 << 11))) - 0.5F))));
254 GLint subTriangle;
255 GLfixed fxLeftEdge = 0; GLfixed fxRightEdge = 0;
256 GLfixed sLeft = 0; GLfixed dsOuter = 0; GLfixed dsInner;
257 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
258 EdgeT *eLeft; EdgeT *eRight;
259 int lines;
260 if (subTriangle == 0) {
261 if (scan_from_left_to_right) {
262 eRight = &eBot;
263 lines = eRight->lines;
264 } else {
265 eRight = &eMaj;
266 }
267 } else {
268 if (scan_from_left_to_right) {
269 eRight = &eTop;
270 }
271 fxRightEdge = eRight->fsx - 1;
272 }
273 while (lines > 0) {
274 const GLint right =
275 ((fxRightEdge) >> 11);
276 span.x = ((fxLeftEdge) >> 11);
277 if (right <= span.x)
278 span.end = 0;
279 else
280 span.end = right - span.x;
281 span.intTex[0] = sLeft;
282 if (span.end > 0 && span.y >= 0) {
283 {
284 GLuint i;
285 GLubyte rgb[16384][3];
286 for (i = 0;
287 i < span.end;
288 i++) {
289 GLint s =
290 ((span.
291 intTex[0])
292 >> 11) &
293 smask;
294 GLint t =
295 ((span.
296 intTex[1])
297 >> 11) &
298 tmask;
299 GLint pos =
300 (t <<
301 twidth_log2)
302 + s;
303 rgb[i][0] =
304 texture[pos
305 +
306 2];
307 span.
308 intTex[0] +=
309 span.
310 intTexStep
311 [0];
312 }
313 rb->PutRowRGB(ctx, rb,
314 span.end,
315 span.x,
316 span.y,
317 rgb,
318 ((void *)
319 0));
320 }
321 }
322 }
323 }
324 }
325 }
326 }
327
328 void _swrast_choose_triangle(struct gl_context *ctx)
329 {
330 SWcontext *swrast = SWRAST_CONTEXT(ctx);
331 if (ctx->RenderMode == 0x1C00) {
332 if (ctx->Texture._EnabledCoordUnits
333 || ctx->FragmentProgram._Current
334 || ctx->ATIFragmentShader._Enabled
335 || _mesa_need_secondary_color(ctx) || swrast->_FogEnabled) {
336 const struct gl_texture_object *texObj2D;
337 const struct gl_texture_image *texImg;
338 GLenum minFilter; GLenum magFilter; GLenum envMode;
339 gl_format format;
340 if (ctx->Texture._EnabledCoordUnits == 0x1
341 && !ctx->FragmentProgram._Current
342 && !ctx->ATIFragmentShader._Enabled
343 && ctx->Texture._EnabledUnits == 0x1
344 && ctx->Texture.Unit[0]._ReallyEnabled ==
345 (1 << TEXTURE_2D_INDEX)
346 && texObj2D->Sampler.WrapS == 0x2901
347 && texObj2D->Sampler.WrapT == 0x2901
348 && texObj2D->_Swizzle ==
349 (((0) << 0) | ((1) << 3) | ((2) << 6) | ((3) << 9))
350 && texImg->_IsPowerOfTwo && texImg->Border == 0
351 && texImg->Width == texImg->RowStride
352 && (format == MESA_FORMAT_RGB888
353 || format == MESA_FORMAT_RGBA8888)
354 && minFilter == magFilter
355 && ctx->Light.Model.ColorControl == 0x81F9
356 && !swrast->_FogEnabled
357 && ctx->Texture.Unit[0].EnvMode != 0x8570
358 && ctx->Texture.Unit[0].EnvMode != 0x8503) {
359 if (ctx->Hint.PerspectiveCorrection == 0x1101) {
360 if (minFilter == 0x2600
361 && format == MESA_FORMAT_RGB888
362 && (envMode == 0x1E01
363 || envMode == 0x2101)
364 &&
365 ((swrast->_RasterMask ==
366 (0x004 | 0x1000)
367 && ctx->Depth.Func == 0x0201
368 && ctx->Depth.Mask == 0x1)
369 || swrast->_RasterMask == 0x1000)
370 && ctx->Polygon.StippleFlag == 0x0
371 && ctx->DrawBuffer->Visual.
372 depthBits <= 16) {
373 if (swrast->_RasterMask ==
374 (0x004 | 0x1000)) {
375 swrast->Triangle =
376 simple_textured_triangle;
377 }
378 }
379 }
380 }
381 }
382 }
383 }