]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
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, FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 = | |
27 | 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 = | |
28 | 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 = | |
29 | 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 = | |
30 | 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 = | |
31 | 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16) | |
32 | } gl_frag_result; | |
33 | struct gl_config { | |
34 | GLint depthBits; | |
35 | }; | |
36 | struct gl_lightmodel { | |
37 | GLenum ColorControl; | |
38 | }; | |
39 | struct gl_depthbuffer_attrib { | |
40 | GLenum Func; | |
41 | GLboolean Mask; | |
42 | }; | |
43 | struct gl_hint_attrib { | |
44 | GLenum PerspectiveCorrection; | |
45 | }; | |
46 | struct gl_light_attrib { | |
47 | struct gl_lightmodel Model; | |
48 | }; | |
49 | struct gl_polygon_attrib { | |
50 | GLboolean StippleFlag; | |
51 | }; | |
52 | typedef enum { | |
53 | TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX, | |
54 | TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX, | |
55 | TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS | |
56 | } gl_texture_index; | |
57 | struct gl_texture_image { | |
58 | GLuint Border; | |
59 | GLuint Width; | |
60 | GLuint Height; | |
61 | GLuint WidthLog2; | |
62 | GLboolean _IsPowerOfTwo; | |
63 | GLuint RowStride; | |
64 | GLvoid *Data; | |
65 | }; | |
66 | typedef enum { | |
67 | FACE_POS_X = 0, FACE_NEG_X = 1, FACE_POS_Y = 2, FACE_NEG_Y = | |
68 | 3, FACE_POS_Z = 4, FACE_NEG_Z = 5, 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, eTop, eBot; | |
148 | GLfloat oneOverArea; | |
149 | const SWvertex *vMin, *vMid, *vMax; | |
150 | const GLint snapMask = ~(((1 << 11) / (1 << 4)) - 1); | |
151 | GLfixed vMin_fx, vMin_fy, vMid_fx, vMid_fy, vMax_fx, vMax_fy; | |
152 | SWspan span; | |
153 | { | |
154 | const GLfixed fy0 = | |
155 | (((int) | |
156 | ((((v0->attrib[FRAG_ATTRIB_WPOS][1] - | |
157 | 0.5F) * ((float)(1 << 11))) >= | |
158 | 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) * | |
159 | ((float)(1 << 11))) + | |
160 | 0.5F) | |
161 | : (((v0->attrib[FRAG_ATTRIB_WPOS][1] - | |
162 | 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; | |
163 | const GLfixed fy1 = | |
164 | (((int) | |
165 | ((((v1->attrib[FRAG_ATTRIB_WPOS][1] - | |
166 | 0.5F) * ((float)(1 << 11))) >= | |
167 | 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) * | |
168 | ((float)(1 << 11))) + | |
169 | 0.5F) | |
170 | : (((v1->attrib[FRAG_ATTRIB_WPOS][1] - | |
171 | 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; | |
172 | const GLfixed fy2 = | |
173 | (((int) | |
174 | ((((v2->attrib[FRAG_ATTRIB_WPOS][1] - | |
175 | 0.5F) * ((float)(1 << 11))) >= | |
176 | 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) * | |
177 | ((float)(1 << 11))) + | |
178 | 0.5F) | |
179 | : (((v2->attrib[FRAG_ATTRIB_WPOS][1] - | |
180 | 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; | |
181 | if (fy0 <= fy1) { | |
182 | if (fy1 <= fy2) { | |
183 | vMin = v0; | |
184 | vMax = v1; | |
185 | vMin_fy = fy0; | |
186 | } | |
187 | } | |
188 | vMin_fx = | |
189 | (((int) | |
190 | ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] + | |
191 | 0.5F) * ((float)(1 << 11))) >= | |
192 | 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) * | |
193 | ((float)(1 << 11))) + | |
194 | 0.5F) | |
195 | : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + | |
196 | 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; | |
197 | vMid_fx = | |
198 | (((int) | |
199 | ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] + | |
200 | 0.5F) * ((float)(1 << 11))) >= | |
201 | 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) * | |
202 | ((float)(1 << 11))) + | |
203 | 0.5F) | |
204 | : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + | |
205 | 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; | |
206 | } | |
207 | eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11)))); | |
208 | eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11)))); | |
209 | eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11)))); | |
210 | eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11)))); | |
211 | { | |
212 | const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; | |
213 | if (IS_INF_OR_NAN(area) || area == 0.0F) | |
214 | return; | |
215 | oneOverArea = 1.0F / area; | |
216 | if (eBot.lines > 0) { | |
217 | eBot.fx0 = vMin_fx; | |
218 | } | |
219 | GLint scan_from_left_to_right; | |
220 | struct gl_renderbuffer *rb = | |
221 | ctx->DrawBuffer->_ColorDrawBuffers[0]; | |
222 | const struct gl_texture_object *obj = | |
223 | ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; | |
224 | const struct gl_texture_image *texImg = | |
225 | obj->Image[0][obj->BaseLevel]; | |
226 | const GLfloat twidth = (GLfloat) texImg->Width; | |
227 | const GLint twidth_log2 = texImg->WidthLog2; | |
228 | const GLubyte *texture = (const GLubyte *)texImg->Data; | |
229 | const GLint smask = texImg->Width - 1; | |
230 | const GLint tmask = texImg->Height - 1; | |
231 | if (!rb || !texture) { | |
232 | return; | |
233 | } | |
234 | { | |
235 | GLfloat eMaj_ds = | |
236 | (vMax->attrib[FRAG_ATTRIB_TEX0][0] - | |
237 | vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth; | |
238 | GLfloat eBot_ds = | |
239 | (vMid->attrib[FRAG_ATTRIB_TEX0][0] - | |
240 | vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth; | |
241 | span.attrStepX[FRAG_ATTRIB_TEX0][0] = | |
242 | oneOverArea * (eMaj_ds * eBot.dy - | |
243 | eMaj.dy * eBot_ds); | |
244 | span.intTexStep[0] = | |
245 | (((int) | |
246 | ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) * | |
247 | ((float)(1 << 11))) >= | |
248 | 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) | |
249 | * ((float)(1 << 11))) + | |
250 | 0.5F) | |
251 | : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) * | |
252 | ((float)(1 << 11))) - 0.5F)))); | |
253 | GLint subTriangle; | |
254 | GLfixed fxLeftEdge = 0, fxRightEdge = 0; | |
255 | GLfixed sLeft = 0, dsOuter = 0, dsInner; | |
256 | for (subTriangle = 0; subTriangle <= 1; subTriangle++) { | |
257 | EdgeT *eLeft, *eRight; | |
258 | int lines; | |
259 | if (subTriangle == 0) { | |
260 | if (scan_from_left_to_right) { | |
261 | eRight = &eBot; | |
262 | lines = eRight->lines; | |
263 | } else { | |
264 | eRight = &eMaj; | |
265 | } | |
266 | } else { | |
267 | if (scan_from_left_to_right) { | |
268 | eRight = &eTop; | |
269 | } | |
270 | fxRightEdge = eRight->fsx - 1; | |
271 | } | |
272 | while (lines > 0) { | |
273 | const GLint right = | |
274 | ((fxRightEdge) >> 11); | |
275 | span.x = ((fxLeftEdge) >> 11); | |
276 | if (right <= span.x) | |
277 | span.end = 0; | |
278 | else | |
279 | span.end = right - span.x; | |
280 | span.intTex[0] = sLeft; | |
281 | if (span.end > 0 && span.y >= 0) { | |
282 | { | |
283 | GLuint i; | |
284 | GLubyte rgb[16384][3]; | |
285 | for (i = 0; | |
286 | i < span.end; | |
287 | i++) { | |
288 | GLint s = | |
289 | ((span. | |
290 | intTex[0]) | |
291 | >> 11) & | |
292 | smask; | |
293 | GLint t = | |
294 | ((span. | |
295 | intTex[1]) | |
296 | >> 11) & | |
297 | tmask; | |
298 | GLint pos = | |
299 | (t << | |
300 | twidth_log2) | |
301 | + s; | |
302 | rgb[i][0] = | |
303 | texture[pos | |
304 | + | |
305 | 2]; | |
306 | span. | |
307 | intTex[0] += | |
308 | span. | |
309 | intTexStep | |
310 | [0]; | |
311 | } | |
312 | rb->PutRowRGB(ctx, rb, | |
313 | span.end, | |
314 | span.x, | |
315 | span.y, | |
316 | rgb, | |
317 | ((void *) | |
318 | 0)); | |
319 | } | |
320 | } | |
321 | } | |
322 | } | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | void _swrast_choose_triangle(struct gl_context *ctx) | |
328 | { | |
329 | SWcontext *swrast = SWRAST_CONTEXT(ctx); | |
330 | if (ctx->RenderMode == 0x1C00) { | |
331 | if (ctx->Texture._EnabledCoordUnits | |
332 | || ctx->FragmentProgram._Current | |
333 | || ctx->ATIFragmentShader._Enabled | |
334 | || _mesa_need_secondary_color(ctx) || swrast->_FogEnabled) { | |
335 | const struct gl_texture_object *texObj2D; | |
336 | const struct gl_texture_image *texImg; | |
337 | GLenum minFilter, magFilter, envMode; | |
338 | gl_format format; | |
339 | if (ctx->Texture._EnabledCoordUnits == 0x1 | |
340 | && !ctx->FragmentProgram._Current | |
341 | && !ctx->ATIFragmentShader._Enabled | |
342 | && ctx->Texture._EnabledUnits == 0x1 | |
343 | && ctx->Texture.Unit[0]._ReallyEnabled == | |
344 | (1 << TEXTURE_2D_INDEX) | |
345 | && texObj2D->Sampler.WrapS == 0x2901 | |
346 | && texObj2D->Sampler.WrapT == 0x2901 | |
347 | && texObj2D->_Swizzle == | |
348 | (((0) << 0) | ((1) << 3) | ((2) << 6) | ((3) << 9)) | |
349 | && texImg->_IsPowerOfTwo && texImg->Border == 0 | |
350 | && texImg->Width == texImg->RowStride | |
351 | && (format == MESA_FORMAT_RGB888 | |
352 | || format == MESA_FORMAT_RGBA8888) | |
353 | && minFilter == magFilter | |
354 | && ctx->Light.Model.ColorControl == 0x81F9 | |
355 | && !swrast->_FogEnabled | |
356 | && ctx->Texture.Unit[0].EnvMode != 0x8570 | |
357 | && ctx->Texture.Unit[0].EnvMode != 0x8503) { | |
358 | if (ctx->Hint.PerspectiveCorrection == 0x1101) { | |
359 | if (minFilter == 0x2600 | |
360 | && format == MESA_FORMAT_RGB888 | |
361 | && (envMode == 0x1E01 | |
362 | || envMode == 0x2101) | |
363 | && | |
364 | ((swrast->_RasterMask == | |
365 | (0x004 | 0x1000) | |
366 | && ctx->Depth.Func == 0x0201 | |
367 | && ctx->Depth.Mask == 0x1) | |
368 | || swrast->_RasterMask == 0x1000) | |
369 | && ctx->Polygon.StippleFlag == 0x0 | |
370 | && ctx->DrawBuffer->Visual. | |
371 | depthBits <= 16) { | |
372 | if (swrast->_RasterMask == | |
373 | (0x004 | 0x1000)) { | |
374 | swrast->Triangle = | |
375 | simple_textured_triangle; | |
376 | } | |
377 | } | |
378 | } | |
379 | } | |
380 | } | |
381 | } | |
382 | } |