1 typedef unsigned int GLenum;
2 typedef unsigned char GLboolean;
3 typedef unsigned int GLbitfield;
6 typedef unsigned char GLubyte;
7 typedef unsigned int GLuint;
14 static __inline__ int IS_INF_OR_NAN(float x)
18 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
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)
36 struct gl_lightmodel {
39 struct gl_depthbuffer_attrib {
43 struct gl_hint_attrib {
44 GLenum PerspectiveCorrection;
46 struct gl_light_attrib {
47 struct gl_lightmodel Model;
49 struct gl_polygon_attrib {
50 GLboolean StippleFlag;
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
57 struct gl_texture_image {
62 GLboolean _IsPowerOfTwo;
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
70 struct gl_sampler_object {
74 struct gl_texture_object {
75 struct gl_sampler_object Sampler;
78 struct gl_texture_image *Image[MAX_FACES][15];
80 struct gl_texture_unit {
81 GLbitfield _ReallyEnabled;
83 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
85 struct gl_texture_attrib {
86 struct gl_texture_unit Unit[(16 + 16)];
87 GLbitfield _EnabledUnits;
88 GLbitfield _EnabledCoordUnits;
90 struct gl_fragment_program_state {
91 struct gl_fragment_program *_Current;
93 struct gl_ati_fragment_shader_state {
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);
101 struct gl_framebuffer {
102 struct gl_config Visual;
103 struct gl_renderbuffer *_ColorDrawBuffers[8];
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;
117 GLfloat attrib[FRAG_ATTRIB_MAX][4];
119 typedef struct sw_span {
122 GLfloat attrStepX[FRAG_ATTRIB_MAX][4];
123 GLfixed intTex[2], intTexStep[2];
125 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
126 const SWvertex *, const SWvertex *);
128 GLbitfield _RasterMask;
129 GLboolean _FogEnabled;
130 swrast_tri_func Triangle;
132 static __inline__ SWcontext *SWRAST_CONTEXT(struct gl_context *ctx)
136 static void simple_textured_triangle(struct gl_context *ctx,
137 const SWvertex * v0, const SWvertex * v1,
147 EdgeT eMaj, eTop, eBot;
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;
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))) +
161 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
162 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
170 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
171 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
179 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
180 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
195 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
196 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
204 : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
205 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))));
212 const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
213 if (IS_INF_OR_NAN(area) || area == 0.0F)
215 oneOverArea = 1.0F / area;
216 if (eBot.lines > 0) {
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) {
236 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
237 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
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 -
246 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
247 ((float)(1 << 11))) >=
248 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
249 * ((float)(1 << 11))) +
251 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
252 ((float)(1 << 11))) - 0.5F))));
254 GLfixed fxLeftEdge = 0, fxRightEdge = 0;
255 GLfixed sLeft = 0, dsOuter = 0, dsInner;
256 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
257 EdgeT *eLeft, *eRight;
259 if (subTriangle == 0) {
260 if (scan_from_left_to_right) {
262 lines = eRight->lines;
267 if (scan_from_left_to_right) {
270 fxRightEdge = eRight->fsx - 1;
274 ((fxRightEdge) >> 11);
275 span.x = ((fxLeftEdge) >> 11);
279 span.end = right - span.x;
280 span.intTex[0] = sLeft;
281 if (span.end > 0 && span.y >= 0) {
284 GLubyte rgb[16384][3];
312 rb->PutRowRGB(ctx, rb,
327 void _swrast_choose_triangle(struct gl_context *ctx)
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;
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)
364 ((swrast->_RasterMask ==
366 && ctx->Depth.Func == 0x0201
367 && ctx->Depth.Mask == 0x1)
368 || swrast->_RasterMask == 0x1000)
369 && ctx->Polygon.StippleFlag == 0x0
370 && ctx->DrawBuffer->Visual.
372 if (swrast->_RasterMask ==
375 simple_textured_triangle;