5 static __inline__ int IS_INF_OR_NAN(float x)
9 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
13 FRAG_ATTRIB_WPOS = 0, FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 =
14 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 =
15 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 =
16 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 =
17 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 =
18 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16)
21 TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX,
22 TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX,
23 TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS
25 struct gl_texture_image {
28 unsigned int WidthLog2;
34 struct gl_texture_object {
36 struct gl_texture_image *Image[MAX_FACES][15];
38 struct gl_texture_unit {
39 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
41 struct gl_texture_attrib {
42 struct gl_texture_unit Unit[(16 + 16)];
44 struct gl_renderbuffer {
45 void (*PutRowRGB) (struct gl_context * ctx, struct gl_renderbuffer * rb,
46 unsigned int count, int x, int y,
49 struct gl_framebuffer {
50 struct gl_renderbuffer *_ColorDrawBuffers[8];
53 struct gl_framebuffer *DrawBuffer;
54 struct gl_texture_attrib Texture;
57 float attrib[FRAG_ATTRIB_MAX][4];
59 typedef struct sw_span {
62 float attrStepX[FRAG_ATTRIB_MAX][4];
63 int intTex[2], intTexStep[2];
65 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
66 const SWvertex *, const SWvertex *);
68 swrast_tri_func Triangle;
70 static void simple_textured_triangle(struct gl_context *ctx,
71 const SWvertex * v0, const SWvertex * v1,
88 const int snapMask = ~(((1 << 11) / (1 << 4)) - 1);
98 ((((v0->attrib[FRAG_ATTRIB_WPOS][1] -
99 0.5F) * ((float)(1 << 11))) >=
100 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
101 ((float)(1 << 11))) +
102 0.5F) : (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
103 ((float)(1 << 11))) - 0.5F)))) & snapMask;
106 ((((v1->attrib[FRAG_ATTRIB_WPOS][1] -
107 0.5F) * ((float)(1 << 11))) >=
108 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
109 ((float)(1 << 11))) +
110 0.5F) : (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
111 ((float)(1 << 11))) - 0.5F)))) & snapMask;
114 ((((v2->attrib[FRAG_ATTRIB_WPOS][1] -
115 0.5F) * ((float)(1 << 11))) >=
116 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
117 ((float)(1 << 11))) +
118 0.5F) : (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
119 ((float)(1 << 11))) - 0.5F)))) & snapMask;
129 ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
130 0.5F) * ((float)(1 << 11))) >=
131 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
132 ((float)(1 << 11))) +
133 0.5F) : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
134 ((float)(1 << 11))) - 0.5F)))) & snapMask;
137 ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
138 0.5F) * ((float)(1 << 11))) >=
139 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
140 ((float)(1 << 11))) +
141 0.5F) : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
142 ((float)(1 << 11))) - 0.5F)))) & snapMask;
143 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11))));
144 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
145 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11))));
146 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
147 const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
148 if (IS_INF_OR_NAN(area) || area == 0.0F)
150 oneOverArea = 1.0F / area;
151 if (eBot.lines > 0) {
154 int scan_from_left_to_right;
155 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
156 const struct gl_texture_object *obj =
157 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
158 const struct gl_texture_image *texImg = obj->Image[0][obj->BaseLevel];
159 const float twidth = (float)texImg->Width;
160 const int twidth_log2 = texImg->WidthLog2;
161 const unsigned char *texture = (const unsigned char *)texImg->Data;
162 const int smask = texImg->Width - 1;
163 const int tmask = texImg->Height - 1;
164 if (!rb || !texture) {
168 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
169 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
171 (vMid->attrib[FRAG_ATTRIB_TEX0][0] -
172 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
173 span.attrStepX[FRAG_ATTRIB_TEX0][0] =
174 oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds);
177 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) * ((float)(1 << 11))) >=
178 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
179 ((float)(1 << 11))) +
180 0.5F) : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
181 ((float)(1 << 11))) - 0.5F))));
186 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
189 if (subTriangle == 0) {
190 if (scan_from_left_to_right) {
192 lines = eRight->lines;
197 if (scan_from_left_to_right) {
200 fxRightEdge = eRight->fsx - 1;
203 const int right = fxRightEdge >> 11;
204 span.x = fxLeftEdge >> 11;
208 span.end = right - span.x;
209 span.intTex[0] = sLeft;
210 if (span.end > 0 && span.y >= 0) {
212 unsigned char rgb[16384][3];
213 for (i = 0; i < span.end; i++) {
215 ((span.intTex[0]) >> 11) & smask;
217 ((span.intTex[1]) >> 11) & tmask;
218 int pos = (t << twidth_log2) + s;
219 rgb[i][0] = texture[pos + 2];
220 span.intTex[0] += span.intTexStep[0];
222 rb->PutRowRGB(ctx, rb, span.end, span.x, span.y,
229 void _swrast_choose_triangle(struct gl_context *ctx)
231 SWcontext *swrast = SWRAST_CONTEXT(ctx);
232 swrast->Triangle = simple_textured_triangle;