Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygens_pointtemp.h
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 6.5.3 00004 * 00005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 /* 00026 * Regarding GL_NV_point_sprite: 00027 * 00028 * Portions of this software may use or implement intellectual 00029 * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims 00030 * any and all warranties with respect to such intellectual property, 00031 * including any use thereof or modifications thereto. 00032 */ 00033 00034 00035 /* 00036 * Point rendering template code. 00037 * 00038 * Set FLAGS = bitwise-OR of the following tokens: 00039 * 00040 * RGBA = do rgba instead of color index 00041 * SMOOTH = do antialiasing 00042 * ATTRIBS = general attributes (texcoords, etc) 00043 * SPECULAR = do separate specular color 00044 * LARGE = do points with diameter > 1 pixel 00045 * ATTENUATE = compute point size attenuation 00046 * SPRITE = GL_ARB_point_sprite / GL_NV_point_sprite 00047 * 00048 * Notes: LARGE and ATTENUATE are exclusive of each other. 00049 * ATTRIBS requires RGBA 00050 */ 00051 00052 00053 /* 00054 * NOTES on antialiased point rasterization: 00055 * 00056 * Let d = distance of fragment center from vertex. 00057 * if d < rmin2 then 00058 * fragment has 100% coverage 00059 * else if d > rmax2 then 00060 * fragment has 0% coverage 00061 * else 00062 * fragment has % coverage = (d - rmin2) / (rmax2 - rmin2) 00063 */ 00064 00065 00066 static void 00067 NAME ( GLcontext *ctx, const SWvertex *vert ) 00068 { 00069 #if FLAGS & (ATTENUATE | LARGE | SMOOTH | SPRITE) 00070 GLfloat size; 00071 #endif 00072 #if FLAGS & RGBA 00073 #if (FLAGS & ATTENUATE) && (FLAGS & SMOOTH) 00074 GLfloat alphaAtten; 00075 #endif 00076 const GLchan red = vert->color[0]; 00077 const GLchan green = vert->color[1]; 00078 const GLchan blue = vert->color[2]; 00079 const GLchan alpha = vert->color[3]; 00080 #endif 00081 #if FLAGS & SPECULAR 00082 const GLchan specRed = vert->specular[0]; 00083 const GLchan specGreen = vert->specular[1]; 00084 const GLchan specBlue = vert->specular[2]; 00085 #endif 00086 #if FLAGS & INDEX 00087 const GLuint colorIndex = (GLuint) vert->index; /* XXX round? */ 00088 #endif 00089 #if FLAGS & ATTRIBS 00090 GLfloat attrib[FRAG_ATTRIB_MAX][4]; /* texture & varying */ 00091 #endif 00092 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00093 SWspan *span = &(swrast->PointSpan); 00094 00095 /* Cull primitives with malformed coordinates. 00096 */ 00097 { 00098 float tmp = vert->win[0] + vert->win[1]; 00099 if (IS_INF_OR_NAN(tmp)) 00100 return; 00101 } 00102 00103 /* 00104 * Span init 00105 */ 00106 span->interpMask = SPAN_FOG; 00107 span->arrayMask = SPAN_XY | SPAN_Z; 00108 span->attrStart[FRAG_ATTRIB_FOGC][0] = vert->attrib[FRAG_ATTRIB_FOGC][0]; 00109 span->attrStepX[FRAG_ATTRIB_FOGC][0] = 0.0; 00110 span->attrStepY[FRAG_ATTRIB_FOGC][0] = 0.0; 00111 #if FLAGS & RGBA 00112 span->arrayMask |= SPAN_RGBA; 00113 #endif 00114 #if FLAGS & SPECULAR 00115 span->arrayMask |= SPAN_SPEC; 00116 #endif 00117 #if FLAGS & INDEX 00118 span->arrayMask |= SPAN_INDEX; 00119 #endif 00120 #if FLAGS & ATTRIBS 00121 span->arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA); 00122 if (ctx->FragmentProgram._Active) { 00123 /* Don't divide texture s,t,r by q (use TXP to do that) */ 00124 ATTRIB_LOOP_BEGIN 00125 COPY_4V(attrib[attr], vert->attrib[attr]); 00126 ATTRIB_LOOP_END 00127 } 00128 else { 00129 /* Divide texture s,t,r by q here */ 00130 ATTRIB_LOOP_BEGIN 00131 const GLfloat q = vert->attrib[attr][3]; 00132 const GLfloat invQ = (q == 0.0F || q == 1.0F) ? 1.0F : (1.0F / q); 00133 attrib[attr][0] = vert->attrib[attr][0] * invQ; 00134 attrib[attr][1] = vert->attrib[attr][1] * invQ; 00135 attrib[attr][2] = vert->attrib[attr][2] * invQ; 00136 attrib[attr][3] = q; 00137 ATTRIB_LOOP_END 00138 } 00139 /* need these for fragment programs */ 00140 span->attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F; 00141 span->attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F; 00142 span->attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F; 00143 #endif 00144 #if FLAGS & SMOOTH 00145 span->arrayMask |= SPAN_COVERAGE; 00146 #endif 00147 #if FLAGS & SPRITE 00148 span->arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA); 00149 #endif 00150 00151 /* Compute point size if not known to be one */ 00152 #if FLAGS & ATTENUATE 00153 /* first, clamp attenuated size to the user-specifed range */ 00154 size = CLAMP(vert->pointSize, ctx->Point.MinSize, ctx->Point.MaxSize); 00155 #if (FLAGS & RGBA) && (FLAGS & SMOOTH) 00156 /* only if multisampling, compute the fade factor */ 00157 if (ctx->Multisample.Enabled) { 00158 if (vert->pointSize >= ctx->Point.Threshold) { 00159 alphaAtten = 1.0F; 00160 } 00161 else { 00162 GLfloat dsize = vert->pointSize / ctx->Point.Threshold; 00163 alphaAtten = dsize * dsize; 00164 } 00165 } 00166 else { 00167 alphaAtten = 1.0; 00168 } 00169 #endif 00170 #elif FLAGS & (LARGE | SMOOTH | SPRITE) 00171 /* constant, non-attenuated size */ 00172 size = ctx->Point._Size; /* this is already clamped */ 00173 #endif 00174 00175 00176 #if FLAGS & (ATTENUATE | LARGE | SMOOTH | SPRITE) 00177 /*** 00178 *** Multi-pixel points 00179 ***/ 00180 00181 /* do final clamping now */ 00182 if (ctx->Point.SmoothFlag) { 00183 size = CLAMP(size, ctx->Const.MinPointSizeAA, ctx->Const.MaxPointSizeAA); 00184 } 00185 else { 00186 size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize); 00187 } 00188 00189 {{ 00190 GLint x, y; 00191 const GLfloat radius = 0.5F * size; 00192 const GLuint z = (GLuint) (vert->win[2] + 0.5F); 00193 GLuint count; 00194 #if FLAGS & SMOOTH 00195 const GLfloat rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */ 00196 const GLfloat rmax = radius + 0.7071F; 00197 const GLfloat rmin2 = MAX2(0.0F, rmin * rmin); 00198 const GLfloat rmax2 = rmax * rmax; 00199 const GLfloat cscale = 1.0F / (rmax2 - rmin2); 00200 const GLint xmin = (GLint) (vert->win[0] - radius); 00201 const GLint xmax = (GLint) (vert->win[0] + radius); 00202 const GLint ymin = (GLint) (vert->win[1] - radius); 00203 const GLint ymax = (GLint) (vert->win[1] + radius); 00204 #else 00205 /* non-smooth */ 00206 GLint xmin, xmax, ymin, ymax; 00207 GLint iSize = (GLint) (size + 0.5F); 00208 GLint iRadius; 00209 iSize = MAX2(1, iSize); 00210 iRadius = iSize / 2; 00211 if (iSize & 1) { 00212 /* odd size */ 00213 xmin = (GLint) (vert->win[0] - iRadius); 00214 xmax = (GLint) (vert->win[0] + iRadius); 00215 ymin = (GLint) (vert->win[1] - iRadius); 00216 ymax = (GLint) (vert->win[1] + iRadius); 00217 } 00218 else { 00219 /* even size */ 00220 xmin = (GLint) vert->win[0] - iRadius; 00221 xmax = xmin + iSize - 1; 00222 ymin = (GLint) vert->win[1] - iRadius; 00223 ymax = ymin + iSize - 1; 00224 } 00225 #endif /*SMOOTH*/ 00226 00227 /* check if we need to flush */ 00228 if (span->end + (xmax-xmin+1) * (ymax-ymin+1) >= MAX_WIDTH || 00229 (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT))) { 00230 if (span->end > 0) { 00231 #if FLAGS & RGBA 00232 _swrast_write_rgba_span(ctx, span); 00233 #else 00234 _swrast_write_index_span(ctx, span); 00235 #endif 00236 span->end = 0; 00237 } 00238 } 00239 00240 /* 00241 * OK, generate fragments 00242 */ 00243 count = span->end; 00244 (void) radius; 00245 for (y = ymin; y <= ymax; y++) { 00246 /* check if we need to flush */ 00247 if (count + (xmax-xmin+1) >= MAX_WIDTH) { 00248 span->end = count; 00249 #if FLAGS & RGBA 00250 _swrast_write_rgba_span(ctx, span); 00251 #else 00252 _swrast_write_index_span(ctx, span); 00253 #endif 00254 count = span->end = 0; 00255 } 00256 for (x = xmin; x <= xmax; x++) { 00257 #if FLAGS & SPRITE 00258 GLuint u; 00259 #endif 00260 00261 #if FLAGS & RGBA 00262 span->array->rgba[count][RCOMP] = red; 00263 span->array->rgba[count][GCOMP] = green; 00264 span->array->rgba[count][BCOMP] = blue; 00265 span->array->rgba[count][ACOMP] = alpha; 00266 #endif 00267 #if FLAGS & SPECULAR 00268 span->array->spec[count][RCOMP] = specRed; 00269 span->array->spec[count][GCOMP] = specGreen; 00270 span->array->spec[count][BCOMP] = specBlue; 00271 #endif 00272 #if FLAGS & INDEX 00273 span->array->index[count] = colorIndex; 00274 #endif 00275 #if FLAGS & ATTRIBS 00276 ATTRIB_LOOP_BEGIN 00277 COPY_4V(span->array->attribs[attr][count], attrib[attr]); 00278 if (attr < FRAG_ATTRIB_VAR0 && attr >= FRAG_ATTRIB_TEX0) { 00279 const GLuint u = attr - FRAG_ATTRIB_TEX0; 00280 span->array->lambda[u][count] = 0.0; 00281 } 00282 ATTRIB_LOOP_END 00283 #endif 00284 00285 #if FLAGS & SMOOTH 00286 /* compute coverage */ 00287 { 00288 const GLfloat dx = x - vert->win[0] + 0.5F; 00289 const GLfloat dy = y - vert->win[1] + 0.5F; 00290 const GLfloat dist2 = dx * dx + dy * dy; 00291 if (dist2 < rmax2) { 00292 if (dist2 >= rmin2) { 00293 /* compute partial coverage */ 00294 span->array->coverage[count] = 1.0F - (dist2 - rmin2) * cscale; 00295 #if FLAGS & INDEX 00296 /* coverage in [0,15] */ 00297 span->array->coverage[count] *= 15.0; 00298 #endif 00299 } 00300 else { 00301 /* full coverage */ 00302 span->array->coverage[count] = 1.0F; 00303 } 00304 00305 span->array->x[count] = x; 00306 span->array->y[count] = y; 00307 span->array->z[count] = z; 00308 00309 #if (FLAGS & ATTENUATE) && (FLAGS & RGBA) 00310 span->array->rgba[count][ACOMP] = (GLchan) (alpha * alphaAtten); 00311 #elif FLAGS & RGBA 00312 span->array->rgba[count][ACOMP] = alpha; 00313 #endif /*ATTENUATE*/ 00314 count++; 00315 } /*if*/ 00316 } 00317 00318 #else /*SMOOTH*/ 00319 00320 /* not smooth (square points) */ 00321 span->array->x[count] = x; 00322 span->array->y[count] = y; 00323 span->array->z[count] = z; 00324 00325 #if FLAGS & SPRITE 00326 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { 00327 GLuint attr = FRAG_ATTRIB_TEX0 + u; 00328 if (ctx->Texture.Unit[u]._ReallyEnabled) { 00329 if (ctx->Point.CoordReplace[u]) { 00330 GLfloat s = 0.5F + (x + 0.5F - vert->win[0]) / size; 00331 GLfloat t, r; 00332 if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) 00333 t = 0.5F + (y + 0.5F - vert->win[1]) / size; 00334 else /* GL_UPPER_LEFT */ 00335 t = 0.5F - (y + 0.5F - vert->win[1]) / size; 00336 if (ctx->Point.SpriteRMode == GL_ZERO) 00337 r = 0.0F; 00338 else if (ctx->Point.SpriteRMode == GL_S) 00339 r = vert->attrib[attr][0]; 00340 else /* GL_R */ 00341 r = vert->attrib[attr][2]; 00342 span->array->attribs[attr][count][0] = s; 00343 span->array->attribs[attr][count][1] = t; 00344 span->array->attribs[attr][count][2] = r; 00345 span->array->attribs[attr][count][3] = 1.0F; 00346 span->array->lambda[u][count] = 0.0; /* XXX fix? */ 00347 } 00348 else { 00349 COPY_4V(span->array->attribs[attr][count], 00350 vert->attrib[attr]); 00351 } 00352 } 00353 } 00354 #endif /*SPRITE*/ 00355 00356 count++; /* square point */ 00357 00358 #endif /*SMOOTH*/ 00359 00360 } /*for x*/ 00361 } /*for y*/ 00362 span->end = count; 00363 }} 00364 00365 #else /* LARGE | ATTENUATE | SMOOTH | SPRITE */ 00366 00367 /*** 00368 *** Single-pixel points 00369 ***/ 00370 {{ 00371 GLuint count; 00372 00373 /* check if we need to flush */ 00374 if (span->end >= MAX_WIDTH || 00375 (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT))) { 00376 #if FLAGS & RGBA 00377 _swrast_write_rgba_span(ctx, span); 00378 #else 00379 _swrast_write_index_span(ctx, span); 00380 #endif 00381 span->end = 0; 00382 } 00383 00384 count = span->end; 00385 00386 #if FLAGS & RGBA 00387 span->array->rgba[count][RCOMP] = red; 00388 span->array->rgba[count][GCOMP] = green; 00389 span->array->rgba[count][BCOMP] = blue; 00390 span->array->rgba[count][ACOMP] = alpha; 00391 #endif 00392 #if FLAGS & SPECULAR 00393 span->array->spec[count][RCOMP] = specRed; 00394 span->array->spec[count][GCOMP] = specGreen; 00395 span->array->spec[count][BCOMP] = specBlue; 00396 #endif 00397 #if FLAGS & INDEX 00398 span->array->index[count] = colorIndex; 00399 #endif 00400 #if FLAGS & ATTRIBS 00401 ATTRIB_LOOP_BEGIN 00402 COPY_4V(span->array->attribs[attr][count], attribs[attr]); 00403 ATTRIB_LOOP_END 00404 #endif 00405 00406 span->array->x[count] = (GLint) vert->win[0]; 00407 span->array->y[count] = (GLint) vert->win[1]; 00408 span->array->z[count] = (GLint) (vert->win[2] + 0.5F); 00409 span->end = count + 1; 00410 }} 00411 00412 #endif /* LARGE || ATTENUATE || SMOOTH */ 00413 00414 ASSERT(span->end <= MAX_WIDTH); 00415 } 00416 00417 00418 #undef FLAGS 00419 #undef NAME Generated on Fri May 25 2012 04:18:52 for ReactOS by
1.7.6.1
|