s_aaline.c
来自「mesa-6.5-minigui源码」· C语言 代码 · 共 555 行 · 第 1/2 页
C
555 行
GLint stop = 4, i; GLfloat insideCount = SUB_PIXEL * SUB_PIXEL; if (!haveSamples) { make_sample_table(SUB_PIXEL, SUB_PIXEL, samples); haveSamples = GL_TRUE; }#if 0 /*DEBUG*/ { const GLfloat area = dx0 * dy1 - dx1 * dy0; assert(area >= 0.0); }#endif for (i = 0; i < stop; i++) { const GLfloat sx = x + samples[i][0]; const GLfloat sy = y + samples[i][1]; const GLfloat fx0 = sx - info->qx0; const GLfloat fy0 = sy - info->qy0; const GLfloat fx1 = sx - info->qx1; const GLfloat fy1 = sy - info->qy1; const GLfloat fx2 = sx - info->qx2; const GLfloat fy2 = sy - info->qy2; const GLfloat fx3 = sx - info->qx3; const GLfloat fy3 = sy - info->qy3; /* cross product determines if sample is inside or outside each edge */ GLfloat cross0 = (info->ex0 * fy0 - info->ey0 * fx0); GLfloat cross1 = (info->ex1 * fy1 - info->ey1 * fx1); GLfloat cross2 = (info->ex2 * fy2 - info->ey2 * fx2); GLfloat cross3 = (info->ex3 * fy3 - info->ey3 * fx3); /* Check if the sample is exactly on an edge. If so, let cross be a * positive or negative value depending on the direction of the edge. */ if (cross0 == 0.0F) cross0 = info->ex0 + info->ey0; if (cross1 == 0.0F) cross1 = info->ex1 + info->ey1; if (cross2 == 0.0F) cross2 = info->ex2 + info->ey2; if (cross3 == 0.0F) cross3 = info->ex3 + info->ey3; if (cross0 < 0.0F || cross1 < 0.0F || cross2 < 0.0F || cross3 < 0.0F) { /* point is outside quadrilateral */ insideCount -= 1.0F; stop = SUB_PIXEL * SUB_PIXEL; } } if (stop == 4) return 1.0F; else return insideCount * (1.0F / (SUB_PIXEL * SUB_PIXEL));}/** * Compute coverage value for color index mode. * XXX this may not be quite correct. * \return coverage in [0,15]. */static GLfloatcompute_coveragei(const struct LineInfo *info, GLint winx, GLint winy){ return compute_coveragef(info, winx, winy) * 15.0F;}typedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line, int ix, int iy); /* * Draw an AA line segment (called many times per line when stippling) */static voidsegment(GLcontext *ctx, struct LineInfo *line, plot_func plot, GLfloat t0, GLfloat t1){ const GLfloat absDx = (line->dx < 0.0F) ? -line->dx : line->dx; const GLfloat absDy = (line->dy < 0.0F) ? -line->dy : line->dy; /* compute the actual segment's endpoints */ const GLfloat x0 = line->x0 + t0 * line->dx; const GLfloat y0 = line->y0 + t0 * line->dy; const GLfloat x1 = line->x0 + t1 * line->dx; const GLfloat y1 = line->y0 + t1 * line->dy; /* compute vertices of the line-aligned quadrilateral */ line->qx0 = x0 - line->yAdj; line->qy0 = y0 + line->xAdj; line->qx1 = x0 + line->yAdj; line->qy1 = y0 - line->xAdj; line->qx2 = x1 + line->yAdj; line->qy2 = y1 - line->xAdj; line->qx3 = x1 - line->yAdj; line->qy3 = y1 + line->xAdj; /* compute the quad's edge vectors (for coverage calc) */ line->ex0 = line->qx1 - line->qx0; line->ey0 = line->qy1 - line->qy0; line->ex1 = line->qx2 - line->qx1; line->ey1 = line->qy2 - line->qy1; line->ex2 = line->qx3 - line->qx2; line->ey2 = line->qy3 - line->qy2; line->ex3 = line->qx0 - line->qx3; line->ey3 = line->qy0 - line->qy3; if (absDx > absDy) { /* X-major line */ GLfloat dydx = line->dy / line->dx; GLfloat xLeft, xRight, yBot, yTop; GLint ix, ixRight; if (x0 < x1) { xLeft = x0 - line->halfWidth; xRight = x1 + line->halfWidth; if (line->dy >= 0.0) { yBot = y0 - 3.0F * line->halfWidth; yTop = y0 + line->halfWidth; } else { yBot = y0 - line->halfWidth; yTop = y0 + 3.0F * line->halfWidth; } } else { xLeft = x1 - line->halfWidth; xRight = x0 + line->halfWidth; if (line->dy <= 0.0) { yBot = y1 - 3.0F * line->halfWidth; yTop = y1 + line->halfWidth; } else { yBot = y1 - line->halfWidth; yTop = y1 + 3.0F * line->halfWidth; } } /* scan along the line, left-to-right */ ixRight = (GLint) (xRight + 1.0F); /*printf("avg span height: %g\n", yTop - yBot);*/ for (ix = (GLint) xLeft; ix < ixRight; ix++) { const GLint iyBot = (GLint) yBot; const GLint iyTop = (GLint) (yTop + 1.0F); GLint iy; /* scan across the line, bottom-to-top */ for (iy = iyBot; iy < iyTop; iy++) { (*plot)(ctx, line, ix, iy); } yBot += dydx; yTop += dydx; } } else { /* Y-major line */ GLfloat dxdy = line->dx / line->dy; GLfloat yBot, yTop, xLeft, xRight; GLint iy, iyTop; if (y0 < y1) { yBot = y0 - line->halfWidth; yTop = y1 + line->halfWidth; if (line->dx >= 0.0) { xLeft = x0 - 3.0F * line->halfWidth; xRight = x0 + line->halfWidth; } else { xLeft = x0 - line->halfWidth; xRight = x0 + 3.0F * line->halfWidth; } } else { yBot = y1 - line->halfWidth; yTop = y0 + line->halfWidth; if (line->dx <= 0.0) { xLeft = x1 - 3.0F * line->halfWidth; xRight = x1 + line->halfWidth; } else { xLeft = x1 - line->halfWidth; xRight = x1 + 3.0F * line->halfWidth; } } /* scan along the line, bottom-to-top */ iyTop = (GLint) (yTop + 1.0F); /*printf("avg span width: %g\n", xRight - xLeft);*/ for (iy = (GLint) yBot; iy < iyTop; iy++) { const GLint ixLeft = (GLint) xLeft; const GLint ixRight = (GLint) (xRight + 1.0F); GLint ix; /* scan across the line, left-to-right */ for (ix = ixLeft; ix < ixRight; ix++) { (*plot)(ctx, line, ix, iy); } xLeft += dxdy; xRight += dxdy; } }}#define NAME(x) aa_ci_##x#define DO_Z#define DO_FOG#define DO_INDEX#include "s_aalinetemp.h"#define NAME(x) aa_rgba_##x#define DO_Z#define DO_FOG#define DO_RGBA#include "s_aalinetemp.h"#define NAME(x) aa_tex_rgba_##x#define DO_Z#define DO_FOG#define DO_RGBA#define DO_TEX#include "s_aalinetemp.h"#define NAME(x) aa_multitex_rgba_##x#define DO_Z#define DO_FOG#define DO_RGBA#define DO_MULTITEX#include "s_aalinetemp.h"#define NAME(x) aa_multitex_spec_##x#define DO_Z#define DO_FOG#define DO_RGBA#define DO_MULTITEX#define DO_SPEC#include "s_aalinetemp.h"void_swrast_choose_aa_line_function(GLcontext *ctx){ SWcontext *swrast = SWRAST_CONTEXT(ctx); ASSERT(ctx->Line.SmoothFlag); if (ctx->Visual.rgbMode) { /* RGBA */ if (ctx->Texture._EnabledCoordUnits != 0) { if (ctx->Texture._EnabledCoordUnits > 1) { /* Multitextured! */ if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR || ctx->Fog.ColorSumEnabled) swrast->Line = aa_multitex_spec_line; else swrast->Line = aa_multitex_rgba_line; } else { swrast->Line = aa_tex_rgba_line; } } else { swrast->Line = aa_rgba_line; } } else { /* Color Index */ swrast->Line = aa_ci_line; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?