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