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);
27 FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 =
28 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 =
29 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 =
30 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 =
31 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 =
32 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16)
37 struct gl_lightmodel {
40 struct gl_depthbuffer_attrib {
44 struct gl_hint_attrib {
45 GLenum PerspectiveCorrection;
47 struct gl_light_attrib {
48 struct gl_lightmodel Model;
50 struct gl_polygon_attrib {
51 GLboolean StippleFlag;
54 TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX,
55 TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX,
56 TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS
58 struct gl_texture_image {
63 GLboolean _IsPowerOfTwo;
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,
148 EdgeT eTop; EdgeT eBot;
150 const SWvertex *vMin;const SWvertex *vMid;const SWvertex *vMax;
151 const GLint snapMask = ~(((1 << 11) / (1 << 4)) - 1);
152 GLfixed vMin_fx;GLfixed vMin_fy;GLfixed vMid_fx;GLfixed vMid_fy;GLfixed vMax_fx;GLfixed vMax_fy;
157 ((((v0->attrib[FRAG_ATTRIB_WPOS][1] -
158 0.5F) * ((float)(1 << 11))) >=
159 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
160 ((float)(1 << 11))) +
162 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
163 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
166 ((((v1->attrib[FRAG_ATTRIB_WPOS][1] -
167 0.5F) * ((float)(1 << 11))) >=
168 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
169 ((float)(1 << 11))) +
171 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
172 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
175 ((((v2->attrib[FRAG_ATTRIB_WPOS][1] -
176 0.5F) * ((float)(1 << 11))) >=
177 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
178 ((float)(1 << 11))) +
180 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
181 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
191 ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
192 0.5F) * ((float)(1 << 11))) >=
193 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
194 ((float)(1 << 11))) +
196 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
197 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
200 ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
201 0.5F) * ((float)(1 << 11))) >=
202 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
203 ((float)(1 << 11))) +
205 : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
206 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
208 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11))));
209 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
210 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11))));
211 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
213 const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
214 if (IS_INF_OR_NAN(area) || area == 0.0F)
216 oneOverArea = 1.0F / area;
217 if (eBot.lines > 0) {
220 GLint scan_from_left_to_right;
221 struct gl_renderbuffer *rb =
222 ctx->DrawBuffer->_ColorDrawBuffers[0];
223 const struct gl_texture_object *obj =
224 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
225 const struct gl_texture_image *texImg =
226 obj->Image[0][obj->BaseLevel];
227 const GLfloat twidth = (GLfloat) texImg->Width;
228 const GLint twidth_log2 = texImg->WidthLog2;
229 const GLubyte *texture = (const GLubyte *)texImg->Data;
230 const GLint smask = texImg->Width - 1;
231 const GLint tmask = texImg->Height - 1;
232 if (!rb || !texture) {
237 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
238 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
240 (vMid->attrib[FRAG_ATTRIB_TEX0][0] -
241 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
242 span.attrStepX[FRAG_ATTRIB_TEX0][0] =
243 oneOverArea * (eMaj_ds * eBot.dy -
247 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
248 ((float)(1 << 11))) >=
249 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
250 * ((float)(1 << 11))) +
252 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
253 ((float)(1 << 11))) - 0.5F))));
255 GLfixed fxLeftEdge = 0; GLfixed fxRightEdge = 0;
256 GLfixed sLeft = 0; GLfixed dsOuter = 0; GLfixed dsInner;
257 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
258 EdgeT *eLeft; EdgeT *eRight;
260 if (subTriangle == 0) {
261 if (scan_from_left_to_right) {
263 lines = eRight->lines;
268 if (scan_from_left_to_right) {
271 fxRightEdge = eRight->fsx - 1;
275 ((fxRightEdge) >> 11);
276 span.x = ((fxLeftEdge) >> 11);
280 span.end = right - span.x;
281 span.intTex[0] = sLeft;
282 if (span.end > 0 && span.y >= 0) {
285 GLubyte rgb[16384][3];
313 rb->PutRowRGB(ctx, rb,
328 void _swrast_choose_triangle(struct gl_context *ctx)
330 SWcontext *swrast = SWRAST_CONTEXT(ctx);
331 if (ctx->RenderMode == 0x1C00) {
332 if (ctx->Texture._EnabledCoordUnits
333 || ctx->FragmentProgram._Current
334 || ctx->ATIFragmentShader._Enabled
335 || _mesa_need_secondary_color(ctx) || swrast->_FogEnabled) {
336 const struct gl_texture_object *texObj2D;
337 const struct gl_texture_image *texImg;
338 GLenum minFilter; GLenum magFilter; GLenum envMode;
340 if (ctx->Texture._EnabledCoordUnits == 0x1
341 && !ctx->FragmentProgram._Current
342 && !ctx->ATIFragmentShader._Enabled
343 && ctx->Texture._EnabledUnits == 0x1
344 && ctx->Texture.Unit[0]._ReallyEnabled ==
345 (1 << TEXTURE_2D_INDEX)
346 && texObj2D->Sampler.WrapS == 0x2901
347 && texObj2D->Sampler.WrapT == 0x2901
348 && texObj2D->_Swizzle ==
349 (((0) << 0) | ((1) << 3) | ((2) << 6) | ((3) << 9))
350 && texImg->_IsPowerOfTwo && texImg->Border == 0
351 && texImg->Width == texImg->RowStride
352 && (format == MESA_FORMAT_RGB888
353 || format == MESA_FORMAT_RGBA8888)
354 && minFilter == magFilter
355 && ctx->Light.Model.ColorControl == 0x81F9
356 && !swrast->_FogEnabled
357 && ctx->Texture.Unit[0].EnvMode != 0x8570
358 && ctx->Texture.Unit[0].EnvMode != 0x8503) {
359 if (ctx->Hint.PerspectiveCorrection == 0x1101) {
360 if (minFilter == 0x2600
361 && format == MESA_FORMAT_RGB888
362 && (envMode == 0x1E01
363 || envMode == 0x2101)
365 ((swrast->_RasterMask ==
367 && ctx->Depth.Func == 0x0201
368 && ctx->Depth.Mask == 0x1)
369 || swrast->_RasterMask == 0x1000)
370 && ctx->Polygon.StippleFlag == 0x0
371 && ctx->DrawBuffer->Visual.
373 if (swrast->_RasterMask ==
376 simple_textured_triangle;