-/* $Id: points.c,v 1.10 2000/06/28 23:11:10 brianp Exp $ */
+/* $Id: points.c,v 1.11 2000/07/15 03:13:43 brianp Exp $ */
/*
* Mesa 3-D graphics library
}
+/*
+ * NOTES on aa point rasterization:
+ *
+ * Let d = distance of fragment center from vertex.
+ * if d < rmin2 then
+ * fragment has 100% coverage
+ * else if d > rmax2 then
+ * fragment has 0% coverage
+ * else
+ * fragement has % coverage = (d - rmin2) / (rmax2 - rmin2)
+ */
/*
const GLfloat radius = ctx->Point.Size * 0.5F;
const GLfloat rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */
const GLfloat rmax = radius + 0.7071F;
- const GLfloat rmin2 = rmin * rmin;
+ const GLfloat rmin2 = MAX2(0.0, rmin * rmin);
const GLfloat rmax2 = rmax * rmax;
const GLfloat cscale = 256.0F / (rmax2 - rmin2);
GLuint i;
GLint red, green, blue, alpha;
GLfloat s, t, u;
GLfloat s1, t1, u1;
+ GLfloat vx = VB->Win.data[i][0];
+ GLfloat vy = VB->Win.data[i][1];
- GLint xmin = (GLint) (VB->Win.data[i][0] - radius);
- GLint xmax = (GLint) (VB->Win.data[i][0] + radius);
- GLint ymin = (GLint) (VB->Win.data[i][1] - radius);
- GLint ymax = (GLint) (VB->Win.data[i][1] + radius);
+ GLint xmin = (GLint) (vx - radius);
+ GLint xmax = (GLint) (vx + radius);
+ GLint ymin = (GLint) (vy - radius);
+ GLint ymax = (GLint) (vy + radius);
GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
red = VB->ColorPtr->data[i][0];
}
}
- for (y=ymin;y<=ymax;y++) {
- for (x=xmin;x<=xmax;x++) {
- GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0];
- GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1];
- GLfloat dist2 = dx*dx + dy*dy;
- if (dist2<rmax2) {
+ /* translate by a half pixel to simplify math below */
+ vx -= 0.5F;
+ vx -= 0.5F;
+
+ for (y = ymin; y <= ymax; y++) {
+ for (x = xmin; x <= xmax; x++) {
+ const GLfloat dx = x - vx;
+ const GLfloat dy = y - vy;
+ const GLfloat dist2 = dx*dx + dy*dy;
+ if (dist2 < rmax2) {
alpha = VB->ColorPtr->data[i][3];
- if (dist2>=rmin2) {
- GLint coverage = (GLint) (256.0F-(dist2-rmin2)*cscale);
+ if (dist2 >= rmin2) {
+ GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
/* coverage is in [0,256] */
alpha = (alpha * coverage) >> 8;
}
GLint x, y, z;
GLint red, green, blue, alpha;
- xmin = (GLint) (VB->Win.data[i][0] - radius);
- xmax = (GLint) (VB->Win.data[i][0] + radius);
- ymin = (GLint) (VB->Win.data[i][1] - radius);
- ymax = (GLint) (VB->Win.data[i][1] + radius);
+ xmin = (GLint) (VB->Win.data[i][0] - 0.0 - radius);
+ xmax = (GLint) (VB->Win.data[i][0] - 0.0 + radius);
+ ymin = (GLint) (VB->Win.data[i][1] - 0.0 - radius);
+ ymax = (GLint) (VB->Win.data[i][1] - 0.0 + radius);
z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
red = VB->ColorPtr->data[i][0];
green = VB->ColorPtr->data[i][1];
blue = VB->ColorPtr->data[i][2];
- for (y=ymin;y<=ymax;y++) {
- for (x=xmin;x<=xmax;x++) {
- GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0];
- GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1];
- GLfloat dist2 = dx*dx + dy*dy;
- if (dist2<rmax2) {
+ /*
+ printf("point %g, %g\n", VB->Win.data[i][0], VB->Win.data[i][1]);
+ printf("%d..%d X %d..%d\n", xmin, xmax, ymin, ymax);
+ */
+ for (y = ymin; y <= ymax; y++) {
+ for (x = xmin; x <= xmax; x++) {
+ const GLfloat dx = x + 0.5F - VB->Win.data[i][0];
+ const GLfloat dy = y + 0.5F - VB->Win.data[i][1];
+ const GLfloat dist2 = dx*dx + dy*dy;
+ if (dist2 < rmax2) {
alpha = VB->ColorPtr->data[i][3];
- if (dist2>=rmin2) {
- GLint coverage = (GLint) (256.0F-(dist2-rmin2)*cscale);
+ if (dist2 >= rmin2) {
+ GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
/* coverage is in [0,256] */
alpha = (alpha * coverage) >> 8;
}
}
rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */
rmax = radius + 0.7071F;
- rmin2 = rmin*rmin;
- rmax2 = rmax*rmax;
- cscale = 256.0F / (rmax2-rmin2);
+ rmin2 = MAX2(0.0, rmin * rmin);
+ rmax2 = rmax * rmax;
+ cscale = 256.0F / (rmax2 - rmin2);
xmin = (GLint) (VB->Win.data[i][0] - radius);
xmax = (GLint) (VB->Win.data[i][0] + radius);
for (y = ymin; y <= ymax; y++) {
for (x = xmin; x <= xmax; x++) {
- GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0];
- GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1];
- GLfloat dist2 = dx*dx + dy*dy;
+ const GLfloat dx = x + 0.5F - VB->Win.data[i][0];
+ const GLfloat dy = y + 0.5F - VB->Win.data[i][1];
+ const GLfloat dist2 = dx*dx + dy*dy;
if (dist2 < rmax2) {
alpha = VB->ColorPtr->data[i][3];
if (dist2 >= rmin2) {
}
rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */
rmax = radius + 0.7071F;
- rmin2 = rmin * rmin;
+ rmin2 = MAX2(0.0, rmin * rmin);
rmax2 = rmax * rmax;
cscale = 256.0F / (rmax2 - rmin2);
for (y = ymin; y <= ymax; y++) {
for (x = xmin; x <= xmax; x++) {
- GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0];
- GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1];
- GLfloat dist2 = dx * dx + dy * dy;
+ const GLfloat dx = x + 0.5F - VB->Win.data[i][0];
+ const GLfloat dy = y + 0.5F - VB->Win.data[i][1];
+ const GLfloat dist2 = dx * dx + dy * dy;
if (dist2 < rmax2) {
alpha = VB->ColorPtr->data[i][3];
if (dist2 >= rmin2) {