6 int IS_INF_OR_NAN(float x)
10 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
14 MESA_FORMAT_RGBA8888, MESA_FORMAT_RGB888,
17 FRAG_ATTRIB_WPOS = 0, FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 =
18 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 =
19 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 =
20 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 =
21 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 =
22 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16)
27 struct gl_lightmodel {
28 unsigned int ColorControl;
30 struct gl_depthbuffer_attrib {
34 struct gl_hint_attrib {
35 unsigned int PerspectiveCorrection;
37 struct gl_light_attrib {
38 struct gl_lightmodel Model;
40 struct gl_polygon_attrib {
41 unsigned char StippleFlag;
44 TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX,
45 TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX,
46 TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS
48 struct gl_texture_image {
52 unsigned int WidthLog2;
53 unsigned char _IsPowerOfTwo;
54 unsigned int RowStride;
60 struct gl_sampler_object {
64 struct gl_texture_object {
65 struct gl_sampler_object Sampler;
67 unsigned int _Swizzle;
68 struct gl_texture_image *Image[MAX_FACES][15];
70 struct gl_texture_unit {
71 unsigned int _ReallyEnabled;
73 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
75 struct gl_texture_attrib {
76 struct gl_texture_unit Unit[(16 + 16)];
77 unsigned int _EnabledUnits;
78 unsigned int _EnabledCoordUnits;
80 struct gl_fragment_program_state {
81 struct gl_fragment_program *_Current;
83 struct gl_ati_fragment_shader_state {
84 unsigned char _Enabled;
86 struct gl_renderbuffer {
87 void (*PutRowRGB) (struct gl_context * ctx, struct gl_renderbuffer * rb,
88 unsigned int count, int x, int y, const void *values);
90 struct gl_framebuffer {
91 struct gl_config Visual;
92 struct gl_renderbuffer *_ColorDrawBuffers[8];
95 struct gl_framebuffer *DrawBuffer;
96 struct gl_depthbuffer_attrib Depth;
97 struct gl_hint_attrib Hint;
98 struct gl_light_attrib Light;
99 struct gl_polygon_attrib Polygon;
100 struct gl_texture_attrib Texture;
101 struct gl_fragment_program_state FragmentProgram;
102 struct gl_ati_fragment_shader_state ATIFragmentShader;
103 unsigned int RenderMode;
106 float attrib[FRAG_ATTRIB_MAX][4];
108 typedef struct sw_span {
111 float attrStepX[FRAG_ATTRIB_MAX][4];
112 int intTex[2], intTexStep[2];
114 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
115 const SWvertex *, const SWvertex *);
117 unsigned int _RasterMask;
118 unsigned char _FogEnabled;
119 swrast_tri_func Triangle;
121 static void simple_textured_triangle(struct gl_context *ctx,
122 const SWvertex * v0, const SWvertex * v1,
136 const SWvertex *vMin;
137 const SWvertex *vMid;
138 const SWvertex *vMax;
139 const int snapMask = ~(((1 << 11) / (1 << 4)) - 1);
149 ((((v0->attrib[FRAG_ATTRIB_WPOS][1] -
150 0.5F) * ((float)(1 << 11))) >=
151 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
152 ((float)(1 << 11))) +
154 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
155 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
158 ((((v1->attrib[FRAG_ATTRIB_WPOS][1] -
159 0.5F) * ((float)(1 << 11))) >=
160 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
161 ((float)(1 << 11))) +
163 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
164 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
167 ((((v2->attrib[FRAG_ATTRIB_WPOS][1] -
168 0.5F) * ((float)(1 << 11))) >=
169 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
170 ((float)(1 << 11))) +
172 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
173 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
183 ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
184 0.5F) * ((float)(1 << 11))) >=
185 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
186 ((float)(1 << 11))) +
188 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
189 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
192 ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
193 0.5F) * ((float)(1 << 11))) >=
194 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
195 ((float)(1 << 11))) +
197 : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
198 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
199 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11))));
200 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
201 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11))));
202 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
203 const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
204 if (IS_INF_OR_NAN(area) || area == 0.0F)
206 oneOverArea = 1.0F / area;
207 if (eBot.lines > 0) {
210 int scan_from_left_to_right;
211 struct gl_renderbuffer *rb =
212 ctx->DrawBuffer->_ColorDrawBuffers[0];
213 const struct gl_texture_object *obj =
214 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
215 const struct gl_texture_image *texImg =
216 obj->Image[0][obj->BaseLevel];
217 const float twidth = (float) texImg->Width;
218 const int twidth_log2 = texImg->WidthLog2;
219 const unsigned char *texture = (const unsigned char *)texImg->Data;
220 const int smask = texImg->Width - 1;
221 const int tmask = texImg->Height - 1;
222 if (!rb || !texture) {
226 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
227 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
229 (vMid->attrib[FRAG_ATTRIB_TEX0][0] -
230 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
231 span.attrStepX[FRAG_ATTRIB_TEX0][0] =
232 oneOverArea * (eMaj_ds * eBot.dy -
236 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
237 ((float)(1 << 11))) >=
238 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
239 * ((float)(1 << 11))) +
241 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
242 ((float)(1 << 11))) - 0.5F))));
247 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
250 if (subTriangle == 0) {
251 if (scan_from_left_to_right) {
253 lines = eRight->lines;
258 if (scan_from_left_to_right) {
261 fxRightEdge = eRight->fsx - 1;
264 const int right= fxRightEdge >> 11;
265 span.x = fxLeftEdge >> 11;
269 span.end = right - span.x;
270 span.intTex[0] = sLeft;
271 if (span.end > 0 && span.y >= 0) {
273 unsigned char rgb[16384][3];
301 rb->PutRowRGB(ctx, rb,
311 void _swrast_choose_triangle(struct gl_context *ctx)
313 SWcontext *swrast = SWRAST_CONTEXT(ctx);
314 if (ctx->RenderMode == 0x1C00) {
315 if (ctx->Texture._EnabledCoordUnits
316 || ctx->FragmentProgram._Current
317 || ctx->ATIFragmentShader._Enabled
318 || _mesa_need_secondary_color(ctx) || swrast->_FogEnabled) {
319 const struct gl_texture_object *texObj2D;
320 const struct gl_texture_image *texImg;
321 unsigned int minFilter;
322 unsigned int magFilter;
323 unsigned int envMode;
325 if (ctx->Texture._EnabledCoordUnits == 0x1
326 && !ctx->FragmentProgram._Current
327 && !ctx->ATIFragmentShader._Enabled
328 && ctx->Texture._EnabledUnits == 0x1
329 && ctx->Texture.Unit[0]._ReallyEnabled ==
330 (1 << TEXTURE_2D_INDEX)
331 && texObj2D->Sampler.WrapS == 0x2901
332 && texObj2D->Sampler.WrapT == 0x2901
333 && texObj2D->_Swizzle ==
334 (((0) << 0) | ((1) << 3) | ((2) << 6) | ((3) << 9))
335 && texImg->_IsPowerOfTwo && texImg->Border == 0
336 && texImg->Width == texImg->RowStride
337 && (format == MESA_FORMAT_RGB888
338 || format == MESA_FORMAT_RGBA8888)
339 && minFilter == magFilter
340 && ctx->Light.Model.ColorControl == 0x81F9
341 && !swrast->_FogEnabled
342 && ctx->Texture.Unit[0].EnvMode != 0x8570
343 && ctx->Texture.Unit[0].EnvMode != 0x8503) {
344 if (ctx->Hint.PerspectiveCorrection == 0x1101) {
345 if (minFilter == 0x2600
346 && format == MESA_FORMAT_RGB888
347 && (envMode == 0x1E01
348 || envMode == 0x2101)
350 ((swrast->_RasterMask ==
352 && ctx->Depth.Func == 0x0201
353 && ctx->Depth.Mask == 0x1)
354 || swrast->_RasterMask == 0x1000)
355 && ctx->Polygon.StippleFlag == 0x0
356 && ctx->DrawBuffer->Visual.
358 if (swrast->_RasterMask ==
361 simple_textured_triangle;