📄 s_aaline.c
字号:
/* * Mesa 3-D graphics library * Version: 6.1 * * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#include "glheader.h"#include "imports.h"#include "macros.h"#include "swrast/s_aaline.h"#include "swrast/s_context.h"#include "swrast/s_span.h"#include "swrast/swrast.h"#include "mtypes.h"#define SUB_PIXEL 4/* * Info about the AA line we're rendering */struct LineInfo{ GLfloat x0, y0; /* start */ GLfloat x1, y1; /* end */ GLfloat dx, dy; /* direction vector */ GLfloat len; /* length */ GLfloat halfWidth; /* half of line width */ GLfloat xAdj, yAdj; /* X and Y adjustment for quad corners around line */ /* for coverage computation */ GLfloat qx0, qy0; /* quad vertices */ GLfloat qx1, qy1; GLfloat qx2, qy2; GLfloat qx3, qy3; GLfloat ex0, ey0; /* quad edge vectors */ GLfloat ex1, ey1; GLfloat ex2, ey2; GLfloat ex3, ey3; /* DO_Z */ GLfloat zPlane[4]; /* DO_FOG */ GLfloat fPlane[4]; /* DO_RGBA */ GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4]; /* DO_INDEX */ GLfloat iPlane[4]; /* DO_SPEC */ GLfloat srPlane[4], sgPlane[4], sbPlane[4]; /* DO_TEX or DO_MULTITEX */ GLfloat sPlane[MAX_TEXTURE_COORD_UNITS][4]; GLfloat tPlane[MAX_TEXTURE_COORD_UNITS][4]; GLfloat uPlane[MAX_TEXTURE_COORD_UNITS][4]; GLfloat vPlane[MAX_TEXTURE_COORD_UNITS][4]; GLfloat lambda[MAX_TEXTURE_COORD_UNITS]; GLfloat texWidth[MAX_TEXTURE_COORD_UNITS]; GLfloat texHeight[MAX_TEXTURE_COORD_UNITS]; struct sw_span span;};/* * Compute the equation of a plane used to interpolate line fragment data * such as color, Z, texture coords, etc. * Input: (x0, y0) and (x1,y1) are the endpoints of the line. * z0, and z1 are the end point values to interpolate. * Output: plane - the plane equation. * * Note: we don't really have enough parameters to specify a plane. * We take the endpoints of the line and compute a plane such that * the cross product of the line vector and the plane normal is * parallel to the projection plane. */static voidcompute_plane(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z0, GLfloat z1, GLfloat plane[4]){#if 0 /* original */ const GLfloat px = x1 - x0; const GLfloat py = y1 - y0; const GLfloat pz = z1 - z0; const GLfloat qx = -py; const GLfloat qy = px; const GLfloat qz = 0; const GLfloat a = py * qz - pz * qy; const GLfloat b = pz * qx - px * qz; const GLfloat c = px * qy - py * qx; const GLfloat d = -(a * x0 + b * y0 + c * z0); plane[0] = a; plane[1] = b; plane[2] = c; plane[3] = d;#else /* simplified */ const GLfloat px = x1 - x0; const GLfloat py = y1 - y0; const GLfloat pz = z0 - z1; const GLfloat a = pz * px; const GLfloat b = pz * py; const GLfloat c = px * px + py * py; const GLfloat d = -(a * x0 + b * y0 + c * z0); if (a == 0.0 && b == 0.0 && c == 0.0 && d == 0.0) { plane[0] = 0.0; plane[1] = 0.0; plane[2] = 1.0; plane[3] = 0.0; } else { plane[0] = a; plane[1] = b; plane[2] = c; plane[3] = d; }#endif}static INLINE voidconstant_plane(GLfloat value, GLfloat plane[4]){ plane[0] = 0.0; plane[1] = 0.0; plane[2] = -1.0; plane[3] = value;}static INLINE GLfloatsolve_plane(GLfloat x, GLfloat y, const GLfloat plane[4]){ const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2]; return z;}#define SOLVE_PLANE(X, Y, PLANE) \ ((PLANE[3] + PLANE[0] * (X) + PLANE[1] * (Y)) / -PLANE[2])/* * Return 1 / solve_plane(). */static INLINE GLfloatsolve_plane_recip(GLfloat x, GLfloat y, const GLfloat plane[4]){ const GLfloat denom = plane[3] + plane[0] * x + plane[1] * y; if (denom == 0.0) return 0.0; else return -plane[2] / denom;}/* * Solve plane and return clamped GLchan value. */static INLINE GLchansolve_plane_chan(GLfloat x, GLfloat y, const GLfloat plane[4]){ const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];#if CHAN_TYPE == GL_FLOAT return CLAMP(z, 0.0F, CHAN_MAXF);#else if (z < 0) return 0; else if (z > CHAN_MAX) return CHAN_MAX; return (GLchan) IROUND_POS(z);#endif}/* * Compute mipmap level of detail. */static INLINE GLfloatcompute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4], GLfloat invQ, GLfloat width, GLfloat height){ GLfloat dudx = sPlane[0] / sPlane[2] * invQ * width; GLfloat dudy = sPlane[1] / sPlane[2] * invQ * width; GLfloat dvdx = tPlane[0] / tPlane[2] * invQ * height; GLfloat dvdy = tPlane[1] / tPlane[2] * invQ * height; GLfloat r1 = dudx * dudx + dudy * dudy; GLfloat r2 = dvdx * dvdx + dvdy * dvdy; GLfloat rho2 = r1 + r2; /* return log base 2 of rho */ if (rho2 == 0.0F) return 0.0; else return (GLfloat) (LOGF(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */}/* * Fill in the samples[] array with the (x,y) subpixel positions of * xSamples * ySamples sample positions. * Note that the four corner samples are put into the first four * positions of the array. This allows us to optimize for the common * case of all samples being inside the polygon. */static voidmake_sample_table(GLint xSamples, GLint ySamples, GLfloat samples[][2]){ const GLfloat dx = 1.0F / (GLfloat) xSamples; const GLfloat dy = 1.0F / (GLfloat) ySamples; GLint x, y; GLint i; i = 4; for (x = 0; x < xSamples; x++) { for (y = 0; y < ySamples; y++) { GLint j; if (x == 0 && y == 0) { /* lower left */ j = 0; } else if (x == xSamples - 1 && y == 0) { /* lower right */ j = 1; } else if (x == 0 && y == ySamples - 1) { /* upper left */ j = 2; } else if (x == xSamples - 1 && y == ySamples - 1) { /* upper right */ j = 3; } else { j = i++; } samples[j][0] = x * dx + 0.5F * dx; samples[j][1] = y * dy + 0.5F * dy; } }}/* * Compute how much of the given pixel's area is inside the rectangle * defined by vertices v0, v1, v2, v3. * Vertices MUST be specified in counter-clockwise order. * Return: coverage in [0, 1]. */static GLfloatcompute_coveragef(const struct LineInfo *info, GLint winx, GLint winy){ static GLfloat samples[SUB_PIXEL * SUB_PIXEL][2]; static GLboolean haveSamples = GL_FALSE; const GLfloat x = (GLfloat) winx; const GLfloat y = (GLfloat) winy;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -