ReactOS  0.4.11-dev-721-g95bc44e
s_aatritemp.h
Go to the documentation of this file.
1 /*
2  * Mesa 3-D graphics library
3  * Version: 7.0.3
4  *
5  * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 
26 /*
27  * Antialiased Triangle Rasterizer Template
28  *
29  * This file is #include'd to generate custom AA triangle rasterizers.
30  * NOTE: this code hasn't been optimized yet. That'll come after it
31  * works correctly.
32  *
33  * The following macros may be defined to indicate what auxillary information
34  * must be copmuted across the triangle:
35  * DO_Z - if defined, compute Z values
36  * DO_ATTRIBS - if defined, compute texcoords, varying, etc.
37  */
38 
39 /*void triangle( struct gl_context *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv )*/
40 {
41  const SWcontext *swrast = SWRAST_CONTEXT(ctx);
42  const GLfloat *p0 = v0->attrib[FRAG_ATTRIB_WPOS];
43  const GLfloat *p1 = v1->attrib[FRAG_ATTRIB_WPOS];
44  const GLfloat *p2 = v2->attrib[FRAG_ATTRIB_WPOS];
45  const SWvertex *vMin, *vMid, *vMax;
49  GLfloat majDx, majDy; /* major (i.e. long) edge dx and dy */
50 
52 
53 #ifdef DO_Z
54  GLfloat zPlane[4];
55 #endif
56  GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4];
57 #if defined(DO_ATTRIBS)
58  GLfloat attrPlane[FRAG_ATTRIB_MAX][4][4];
59  GLfloat wPlane[4]; /* win[3] */
60 #endif
62 
63  (void) swrast;
64 
65  INIT_SPAN(span, GL_POLYGON);
67 
68  /* determine bottom to top order of vertices */
69  {
70  GLfloat y0 = v0->attrib[FRAG_ATTRIB_WPOS][1];
71  GLfloat y1 = v1->attrib[FRAG_ATTRIB_WPOS][1];
72  GLfloat y2 = v2->attrib[FRAG_ATTRIB_WPOS][1];
73  if (y0 <= y1) {
74  if (y1 <= y2) {
75  vMin = v0; vMid = v1; vMax = v2; /* y0<=y1<=y2 */
76  }
77  else if (y2 <= y0) {
78  vMin = v2; vMid = v0; vMax = v1; /* y2<=y0<=y1 */
79  }
80  else {
81  vMin = v0; vMid = v2; vMax = v1; bf = -bf; /* y0<=y2<=y1 */
82  }
83  }
84  else {
85  if (y0 <= y2) {
86  vMin = v1; vMid = v0; vMax = v2; bf = -bf; /* y1<=y0<=y2 */
87  }
88  else if (y2 <= y1) {
89  vMin = v2; vMid = v1; vMax = v0; bf = -bf; /* y2<=y1<=y0 */
90  }
91  else {
92  vMin = v1; vMid = v2; vMax = v0; /* y1<=y2<=y0 */
93  }
94  }
95  }
96 
97  majDx = vMax->attrib[FRAG_ATTRIB_WPOS][0] - vMin->attrib[FRAG_ATTRIB_WPOS][0];
98  majDy = vMax->attrib[FRAG_ATTRIB_WPOS][1] - vMin->attrib[FRAG_ATTRIB_WPOS][1];
99 
100  /* front/back-face determination and cullling */
101  {
102  const GLfloat botDx = vMid->attrib[FRAG_ATTRIB_WPOS][0] - vMin->attrib[FRAG_ATTRIB_WPOS][0];
104  const GLfloat area = majDx * botDy - botDx * majDy;
105  /* Do backface culling */
106  if (area * bf < 0 || area == 0 || IS_INF_OR_NAN(area))
107  return;
108  ltor = (GLboolean) (area < 0.0F);
109  }
110 
111  /* Plane equation setup:
112  * We evaluate plane equations at window (x,y) coordinates in order
113  * to compute color, Z, fog, texcoords, etc. This isn't terribly
114  * efficient but it's easy and reliable.
115  */
116 #ifdef DO_Z
117  compute_plane(p0, p1, p2, p0[2], p1[2], p2[2], zPlane);
118  span.arrayMask |= SPAN_Z;
119 #endif
120  if (ctx->Light.ShadeModel == GL_SMOOTH) {
121  compute_plane(p0, p1, p2, v0->color[RCOMP], v1->color[RCOMP], v2->color[RCOMP], rPlane);
122  compute_plane(p0, p1, p2, v0->color[GCOMP], v1->color[GCOMP], v2->color[GCOMP], gPlane);
123  compute_plane(p0, p1, p2, v0->color[BCOMP], v1->color[BCOMP], v2->color[BCOMP], bPlane);
124  compute_plane(p0, p1, p2, v0->color[ACOMP], v1->color[ACOMP], v2->color[ACOMP], aPlane);
125  }
126  else {
127  constant_plane(v2->color[RCOMP], rPlane);
128  constant_plane(v2->color[GCOMP], gPlane);
129  constant_plane(v2->color[BCOMP], bPlane);
130  constant_plane(v2->color[ACOMP], aPlane);
131  }
132  span.arrayMask |= SPAN_RGBA;
133 #if defined(DO_ATTRIBS)
134  {
135  const GLfloat invW0 = v0->attrib[FRAG_ATTRIB_WPOS][3];
136  const GLfloat invW1 = v1->attrib[FRAG_ATTRIB_WPOS][3];
137  const GLfloat invW2 = v2->attrib[FRAG_ATTRIB_WPOS][3];
138  compute_plane(p0, p1, p2, invW0, invW1, invW2, wPlane);
139  span.attrStepX[FRAG_ATTRIB_WPOS][3] = plane_dx(wPlane);
140  span.attrStepY[FRAG_ATTRIB_WPOS][3] = plane_dy(wPlane);
142  GLuint c;
143  if (swrast->_InterpMode[attr] == GL_FLAT) {
144  for (c = 0; c < 4; c++) {
145  constant_plane(v2->attrib[attr][c] * invW2, attrPlane[attr][c]);
146  }
147  }
148  else {
149  for (c = 0; c < 4; c++) {
150  const GLfloat a0 = v0->attrib[attr][c] * invW0;
151  const GLfloat a1 = v1->attrib[attr][c] * invW1;
152  const GLfloat a2 = v2->attrib[attr][c] * invW2;
153  compute_plane(p0, p1, p2, a0, a1, a2, attrPlane[attr][c]);
154  }
155  }
156  for (c = 0; c < 4; c++) {
157  span.attrStepX[attr][c] = plane_dx(attrPlane[attr][c]);
158  span.attrStepY[attr][c] = plane_dy(attrPlane[attr][c]);
159  }
161  }
162 #endif
163 
164  /* Begin bottom-to-top scan over the triangle.
165  * The long edge will either be on the left or right side of the
166  * triangle. We always scan from the long edge toward the shorter
167  * edges, stopping when we find that coverage = 0. If the long edge
168  * is on the left we scan left-to-right. Else, we scan right-to-left.
169  */
170  yMin = vMin->attrib[FRAG_ATTRIB_WPOS][1];
171  yMax = vMax->attrib[FRAG_ATTRIB_WPOS][1];
172  iyMin = (GLint) yMin;
173  iyMax = (GLint) yMax + 1;
174 
175  if (ltor) {
176  /* scan left to right */
177  const GLfloat *pMin = vMin->attrib[FRAG_ATTRIB_WPOS];
178  const GLfloat *pMid = vMid->attrib[FRAG_ATTRIB_WPOS];
179  const GLfloat *pMax = vMax->attrib[FRAG_ATTRIB_WPOS];
180  const GLfloat dxdy = majDx / majDy;
181  const GLfloat xAdj = dxdy < 0.0F ? -dxdy : 0.0F;
182  GLint iy;
183 #ifdef _OPENMP
184 #pragma omp parallel for schedule(dynamic) private(iy) firstprivate(span)
185 #endif
186  for (iy = iyMin; iy < iyMax; iy++) {
187  GLfloat x = pMin[0] - (yMin - iy) * dxdy;
188  GLint ix, startX = (GLint) (x - xAdj);
189  GLuint count;
190  GLfloat coverage = 0.0F;
191 
192 #ifdef _OPENMP
193  /* each thread needs to use a different (global) SpanArrays variable */
194  span.array = SWRAST_CONTEXT(ctx)->SpanArrays + omp_get_thread_num();
195 #endif
196  /* skip over fragments with zero coverage */
197  while (startX < MAX_WIDTH) {
198  coverage = compute_coveragef(pMin, pMid, pMax, startX, iy);
199  if (coverage > 0.0F)
200  break;
201  startX++;
202  }
203 
204  /* enter interior of triangle */
205  ix = startX;
206 
207 #if defined(DO_ATTRIBS)
208  /* compute attributes at left-most fragment */
209  span.attrStart[FRAG_ATTRIB_WPOS][3] = solve_plane(ix + 0.5F, iy + 0.5F, wPlane);
211  GLuint c;
212  for (c = 0; c < 4; c++) {
213  span.attrStart[attr][c] = solve_plane(ix + 0.5F, iy + 0.5F, attrPlane[attr][c]);
214  }
216 #endif
217 
218  count = 0;
219  while (coverage > 0.0F) {
220  /* (cx,cy) = center of fragment */
221  const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
222  SWspanarrays *array = span.array;
223  array->coverage[count] = coverage;
224 #ifdef DO_Z
225  array->z[count] = (GLuint) solve_plane(cx, cy, zPlane);
226 #endif
227  array->rgba[count][RCOMP] = solve_plane_chan(cx, cy, rPlane);
228  array->rgba[count][GCOMP] = solve_plane_chan(cx, cy, gPlane);
229  array->rgba[count][BCOMP] = solve_plane_chan(cx, cy, bPlane);
230  array->rgba[count][ACOMP] = solve_plane_chan(cx, cy, aPlane);
231  ix++;
232  count++;
233  coverage = compute_coveragef(pMin, pMid, pMax, ix, iy);
234  }
235 
236  if (ix > startX) {
237  span.x = startX;
238  span.y = iy;
239  span.end = (GLuint) ix - (GLuint) startX;
240  _swrast_write_rgba_span(ctx, &span);
241  }
242  }
243  }
244  else {
245  /* scan right to left */
246  const GLfloat *pMin = vMin->attrib[FRAG_ATTRIB_WPOS];
249  const GLfloat dxdy = majDx / majDy;
250  const GLfloat xAdj = dxdy > 0 ? dxdy : 0.0F;
252 #ifdef _OPENMP
253 #pragma omp parallel for schedule(dynamic) private(iy) firstprivate(span)
254 #endif
255  for (iy = iyMin; iy < iyMax; iy++) {
256  GLfloat x = pMin[0] - (yMin - iy) * dxdy;
257  GLint ix, left, startX = (GLint) (x + xAdj);
258  GLuint count, n;
259  GLfloat coverage = 0.0F;
260 
261 #ifdef _OPENMP
262  /* each thread needs to use a different (global) SpanArrays variable */
263  span.array = SWRAST_CONTEXT(ctx)->SpanArrays + omp_get_thread_num();
264 #endif
265  /* make sure we're not past the window edge */
266  if (startX >= ctx->DrawBuffer->_Xmax) {
267  startX = ctx->DrawBuffer->_Xmax - 1;
268  }
269 
270  /* skip fragments with zero coverage */
271  while (startX > 0) {
272  coverage = compute_coveragef(pMin, pMax, pMid, startX, iy);
273  if (coverage > 0.0F)
274  break;
275  startX--;
276  }
277 
278  /* enter interior of triangle */
279  ix = startX;
280  count = 0;
281  while (coverage > 0.0F) {
282  /* (cx,cy) = center of fragment */
283  const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
284  SWspanarrays *array = span.array;
285  ASSERT(ix >= 0);
286  array->coverage[ix] = coverage;
287 #ifdef DO_Z
288  array->z[ix] = (GLuint) solve_plane(cx, cy, zPlane);
289 #endif
290  array->rgba[ix][RCOMP] = solve_plane_chan(cx, cy, rPlane);
291  array->rgba[ix][GCOMP] = solve_plane_chan(cx, cy, gPlane);
292  array->rgba[ix][BCOMP] = solve_plane_chan(cx, cy, bPlane);
293  array->rgba[ix][ACOMP] = solve_plane_chan(cx, cy, aPlane);
294  ix--;
295  count++;
296  coverage = compute_coveragef(pMin, pMax, pMid, ix, iy);
297  }
298 
299 #if defined(DO_ATTRIBS)
300  /* compute attributes at left-most fragment */
301  span.attrStart[FRAG_ATTRIB_WPOS][3] = solve_plane(ix + 1.5F, iy + 0.5F, wPlane);
303  GLuint c;
304  for (c = 0; c < 4; c++) {
305  span.attrStart[attr][c] = solve_plane(ix + 1.5F, iy + 0.5F, attrPlane[attr][c]);
306  }
308 #endif
309 
310  if (startX > ix) {
311  n = (GLuint) startX - (GLuint) ix;
312 
313  left = ix + 1;
314 
315  /* shift all values to the left */
316  /* XXX this is temporary */
317  {
318  SWspanarrays *array = span.array;
319  GLint j;
320  for (j = 0; j < (GLint) n; j++) {
321  array->coverage[j] = array->coverage[j + left];
322  COPY_CHAN4(array->rgba[j], array->rgba[j + left]);
323 #ifdef DO_Z
324  array->z[j] = array->z[j + left];
325 #endif
326  }
327  }
328 
329  span.x = left;
330  span.y = iy;
331  span.end = n;
332  _swrast_write_rgba_span(ctx, &span);
333  }
334  }
335  }
336 }
337 
338 
339 #undef DO_Z
340 #undef DO_ATTRIBS
341 #undef DO_OCCLUSION_TEST
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG y1
Definition: winddi.h:3706
static GLfloat plane_dy(const GLfloat plane[4])
Definition: s_aatriangle.c:129
GLfloat rPlane[4]
Definition: s_aatritemp.h:56
static GLfloat solve_plane(GLfloat x, GLfloat y, const GLfloat plane[4])
Definition: s_aaline.c:135
GLfloat majDx
Definition: s_aatritemp.h:49
constant_plane(v2->color[GCOMP], gPlane)
#define GL_FLAT
Definition: gl.h:338
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define MAX_WIDTH
Definition: config.h:118
GLfloat bf
Definition: s_aatritemp.h:61
GLuint z[MAX_WIDTH]
Definition: s_span.h:88
GLint iy
Definition: s_aatritemp.h:251
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define ATTRIB_LOOP_BEGIN
Definition: s_context.h:429
const GLfloat * pMax
Definition: s_aatritemp.h:248
Arrays of fragment values.
Definition: s_span.h:68
GLfloat v0
Definition: glext.h:6061
const SWvertex * vMax
Definition: s_aatritemp.h:45
GLfloat attrStepY[FRAG_ATTRIB_MAX][4]
Definition: s_span.h:134
GLboolean ltor
Definition: s_aatritemp.h:48
#define GL_SMOOTH
Definition: gl.h:339
GLfloat attrStart[FRAG_ATTRIB_MAX][4]
Definition: s_span.h:132
static SWcontext * SWRAST_CONTEXT(struct gl_context *ctx)
Definition: s_context.h:310
const GLfloat * pMid
Definition: s_aatritemp.h:247
GLint iyMax
Definition: s_aatritemp.h:46
Data-structure to handle vertices in the software rasterizer.
Definition: swrast.h:72
GLfloat attrStepX[FRAG_ATTRIB_MAX][4]
Definition: s_span.h:133
const GLfloat * p2
Definition: s_aatritemp.h:44
GLuint n
Definition: s_context.h:57
SWspan span
Definition: s_aatritemp.h:51
GLfloat coverage[MAX_WIDTH]
Definition: s_span.h:91
#define BCOMP
Definition: txc_dxtn.h:35
unsigned char GLboolean
Definition: gl.h:151
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:47
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:570
GLint iyMin
Definition: s_aatritemp.h:46
#define GCOMP
Definition: txc_dxtn.h:34
const GLfloat * p0
Definition: s_aatritemp.h:42
#define RCOMP
Definition: txc_dxtn.h:33
GLbitfield arrayMask
Definition: s_span.h:153
static void compute_plane(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z0, GLfloat z1, GLfloat plane[4])
Definition: s_aaline.c:80
float GLfloat
Definition: gl.h:161
GLint x
Definition: s_span.h:111
GLfloat yMin
Definition: s_aatritemp.h:47
#define SPAN_RGBA
Definition: s_span.h:50
#define IS_INF_OR_NAN(x)
Definition: imports.h:226
void _swrast_write_rgba_span(struct gl_context *ctx, SWspan *span)
Definition: s_span.c:835
static const struct update_accum a2
Definition: msg.c:586
void swrast
Definition: s_aatritemp.h:63
const SWvertex * vMid
Definition: s_aatritemp.h:45
GLint left
Definition: glext.h:7726
GLuint GLuint GLsizei count
Definition: gl.h:1545
Definition: cookie.c:170
GLfloat gPlane[4]
Definition: s_aatritemp.h:56
const GLfloat area
Definition: s_aatritemp.h:104
SWspanarrays * SpanArrays
Definition: s_context.h:278
GLfloat bPlane[4]
Definition: s_aatritemp.h:56
static GLfloat plane_dx(const GLfloat plane[4])
Definition: s_aatriangle.c:123
__u8 attr
Definition: mkdosfs.c:359
#define ATTRIB_LOOP_END
Definition: s_context.h:435
const SWvertex * vMin
Definition: s_aatritemp.h:45
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG _In_ LONG y2
Definition: winddi.h:3706
GLchan(* rgba)[4]
Definition: s_span.h:85
GLfloat aPlane[4]
Definition: s_aatritemp.h:56
GLenum _InterpMode[FRAG_ATTRIB_MAX]
Definition: s_context.h:222
#define SPAN_COVERAGE
Definition: s_span.h:56
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
const GLfloat xAdj
Definition: s_aatritemp.h:250
GLfloat yMax
Definition: s_aatritemp.h:47
unsigned int GLuint
Definition: gl.h:159
SWspanarrays * array
Definition: s_span.h:164
GLint y
Definition: s_span.h:111
static GLchan solve_plane_chan(GLfloat x, GLfloat y, const GLfloat plane[4])
Definition: s_aaline.c:163
GLfloat _BackfaceCullSign
Definition: s_context.h:209
#define GL_POLYGON
Definition: gl.h:199
#define SPAN_Z
Definition: s_span.h:51
_Out_opt_ int * cx
Definition: commctrl.h:570
const GLfloat dxdy
Definition: s_aatritemp.h:249
#define c
Definition: ke_i.h:80
Per-context state that's private to the software rasterizer module.
Definition: s_context.h:192
static const struct update_accum a1
Definition: msg.c:578
GLfloat majDy
Definition: s_aatritemp.h:49
const GLfloat * p1
Definition: s_aatritemp.h:43
GLuint end
Definition: s_span.h:114
INIT_SPAN(span, GL_POLYGON)
GLfloat GLfloat v1
Definition: glext.h:6062
const GLfloat botDy
Definition: s_aatritemp.h:103
GLfloat attrib[FRAG_ATTRIB_MAX][4]
Definition: swrast.h:73
#define ACOMP
Definition: txc_dxtn.h:36
static GLfloat compute_coveragef(const struct LineInfo *info, GLint winx, GLint winy)
Definition: s_aaline.c:255
#define F(x, y, z)
Definition: md5.c:51
const GLint const GLsizei GLint
Definition: dispatch.h:5271
INT x
Definition: msvc.h:62