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