1 typedef unsigned int GLenum;
2 typedef unsigned char GLubyte;
3 typedef unsigned int GLuint;
8 static __inline__ int IS_INF_OR_NAN(float x)
12 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
16 MESA_FORMAT_RGBA8888, MESA_FORMAT_RGB888,
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)
29 struct gl_lightmodel {
32 struct gl_depthbuffer_attrib {
36 struct gl_hint_attrib {
37 GLenum PerspectiveCorrection;
39 struct gl_light_attrib {
40 struct gl_lightmodel Model;
42 struct gl_polygon_attrib {
43 unsigned char StippleFlag;
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
50 struct gl_texture_image {
55 unsigned char _IsPowerOfTwo;
62 struct gl_sampler_object {
66 struct gl_texture_object {
67 struct gl_sampler_object Sampler;
70 struct gl_texture_image *Image[MAX_FACES][15];
72 struct gl_texture_unit {
73 unsigned int _ReallyEnabled;
75 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
77 struct gl_texture_attrib {
78 struct gl_texture_unit Unit[(16 + 16)];
79 unsigned int _EnabledUnits;
80 unsigned int _EnabledCoordUnits;
82 struct gl_fragment_program_state {
83 struct gl_fragment_program *_Current;
85 struct gl_ati_fragment_shader_state {
86 unsigned char _Enabled;
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);
92 struct gl_framebuffer {
93 struct gl_config Visual;
94 struct gl_renderbuffer *_ColorDrawBuffers[8];
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;
108 float attrib[FRAG_ATTRIB_MAX][4];
110 typedef struct sw_span {
113 float attrStepX[FRAG_ATTRIB_MAX][4];
114 int intTex[2], intTexStep[2];
116 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
117 const SWvertex *, const SWvertex *);
119 unsigned int _RasterMask;
120 unsigned char _FogEnabled;
121 swrast_tri_func Triangle;
123 static void simple_textured_triangle(struct gl_context *ctx,
124 const SWvertex * v0, const SWvertex * v1,
138 const SWvertex *vMin;
139 const SWvertex *vMid;
140 const SWvertex *vMax;
141 const int snapMask = ~(((1 << 11) / (1 << 4)) - 1);
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))) +
156 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
157 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
165 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
166 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
174 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
175 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
190 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
191 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
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))) +
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)
208 oneOverArea = 1.0F / area;
209 if (eBot.lines > 0) {
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) {
228 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
229 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
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 -
238 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
239 ((float)(1 << 11))) >=
240 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
241 * ((float)(1 << 11))) +
243 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
244 ((float)(1 << 11))) - 0.5F))));
249 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
252 if (subTriangle == 0) {
253 if (scan_from_left_to_right) {
255 lines = eRight->lines;
260 if (scan_from_left_to_right) {
263 fxRightEdge = eRight->fsx - 1;
266 const int right= fxRightEdge >> 11;
267 span.x = fxLeftEdge >> 11;
271 span.end = right - span.x;
272 span.intTex[0] = sLeft;
273 if (span.end > 0 && span.y >= 0) {
275 GLubyte rgb[16384][3];
303 rb->PutRowRGB(ctx, rb,
313 void _swrast_choose_triangle(struct gl_context *ctx)
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;
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)
352 ((swrast->_RasterMask ==
354 && ctx->Depth.Func == 0x0201
355 && ctx->Depth.Mask == 0x1)
356 || swrast->_RasterMask == 0x1000)
357 && ctx->Polygon.StippleFlag == 0x0
358 && ctx->DrawBuffer->Visual.
360 if (swrast->_RasterMask ==
363 simple_textured_triangle;