| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 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 |
* Authors: |
| 25 |
* Keith Whitwell <[email protected]> |
| 26 |
* Brian Paul |
| 27 |
*/ |
| 28 |
|
| 29 |
#include "imports.h" |
| 30 |
#include "bufferobj.h" |
| 31 |
#include "context.h" |
| 32 |
#include "colormac.h" |
| 33 |
#include "mtypes.h" |
| 34 |
#include "program.h" |
| 35 |
#include "texobj.h" |
| 36 |
#include "nvfragprog.h" |
| 37 |
|
| 38 |
#include "swrast.h" |
| 39 |
#include "s_blend.h" |
| 40 |
#include "s_context.h" |
| 41 |
#include "s_lines.h" |
| 42 |
#include "s_points.h" |
| 43 |
#include "s_span.h" |
| 44 |
#include "s_triangle.h" |
| 45 |
#include "s_texture.h" |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* Recompute the value of swrast->_RasterMask, etc. according to |
| 50 |
* the current context. The _RasterMask field can be easily tested by |
| 51 |
* drivers to determine certain basic GL state (does the primitive need |
| 52 |
* stenciling, logic-op, fog, etc?). |
| 53 |
*/ |
| 54 |
static void |
| 55 |
_swrast_update_rasterflags( GLcontext *ctx ) |
| 56 |
{ |
| 57 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 58 |
GLuint rasterMask = 0; |
| 59 |
|
| 60 |
if (ctx->Color.AlphaEnabled) rasterMask |= ALPHATEST_BIT; |
| 61 |
if (ctx->Color.BlendEnabled) rasterMask |= BLEND_BIT; |
| 62 |
if (ctx->Depth.Test) rasterMask |= DEPTH_BIT; |
| 63 |
if (swrast->_FogEnabled) rasterMask |= FOG_BIT; |
| 64 |
if (ctx->Scissor.Enabled) rasterMask |= CLIP_BIT; |
| 65 |
if (ctx->Stencil.Enabled) rasterMask |= STENCIL_BIT; |
| 66 |
if (ctx->Visual.rgbMode) { |
| 67 |
const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); |
| 68 |
if (colorMask != 0xffffffff) rasterMask |= MASKING_BIT; |
| 69 |
if (ctx->Color._LogicOpEnabled) rasterMask |= LOGIC_OP_BIT; |
| 70 |
if (ctx->Texture._EnabledUnits) rasterMask |= TEXTURE_BIT; |
| 71 |
} |
| 72 |
else { |
| 73 |
if (ctx->Color.IndexMask != 0xffffffff) rasterMask |= MASKING_BIT; |
| 74 |
if (ctx->Color.IndexLogicOpEnabled) rasterMask |= LOGIC_OP_BIT; |
| 75 |
} |
| 76 |
|
| 77 |
if ( ctx->Viewport.X < 0 |
| 78 |
|| ctx->Viewport.X + ctx->Viewport.Width > (GLint) ctx->DrawBuffer->Width |
| 79 |
|| ctx->Viewport.Y < 0 |
| 80 |
|| ctx->Viewport.Y + ctx->Viewport.Height > (GLint) ctx->DrawBuffer->Height) { |
| 81 |
rasterMask |= CLIP_BIT; |
| 82 |
} |
| 83 |
|
| 84 |
if (ctx->Depth.OcclusionTest || ctx->Occlusion.Active) |
| 85 |
rasterMask |= OCCLUSION_BIT; |
| 86 |
|
| 87 |
|
| 88 |
/* If we're not drawing to exactly one color buffer set the |
| 89 |
* MULTI_DRAW_BIT flag. Also set it if we're drawing to no |
| 90 |
* buffers or the RGBA or CI mask disables all writes. |
| 91 |
*/ |
| 92 |
if (ctx->DrawBuffer->_NumColorDrawBuffers[0] != 1) { |
| 93 |
/* more than one color buffer designated for writing (or zero buffers) */ |
| 94 |
rasterMask |= MULTI_DRAW_BIT; |
| 95 |
} |
| 96 |
else if (ctx->Visual.rgbMode && *((GLuint *) ctx->Color.ColorMask) == 0) { |
| 97 |
rasterMask |= MULTI_DRAW_BIT; /* all RGBA channels disabled */ |
| 98 |
} |
| 99 |
else if (!ctx->Visual.rgbMode && ctx->Color.IndexMask==0) { |
| 100 |
rasterMask |= MULTI_DRAW_BIT; /* all color index bits disabled */ |
| 101 |
} |
| 102 |
|
| 103 |
if (ctx->FragmentProgram._Active) { |
| 104 |
rasterMask |= FRAGPROG_BIT; |
| 105 |
} |
| 106 |
|
| 107 |
if (ctx->ATIFragmentShader._Enabled) { |
| 108 |
rasterMask |= ATIFRAGSHADER_BIT; |
| 109 |
} |
| 110 |
|
| 111 |
#if CHAN_TYPE == GL_FLOAT |
| 112 |
if (ctx->Color.ClampFragmentColor == GL_TRUE) { |
| 113 |
rasterMask |= CLAMPING_BIT; |
| 114 |
} |
| 115 |
#endif |
| 116 |
|
| 117 |
SWRAST_CONTEXT(ctx)->_RasterMask = rasterMask; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
/** |
| 122 |
* Examine polycon culls tate to compute the _BackfaceSign field. |
| 123 |
* _BackfaceSign will be 0 if no culling, -1 if culling back-faces, |
| 124 |
* and 1 if culling front-faces. The Polygon FrontFace state also |
| 125 |
* factors in. |
| 126 |
*/ |
| 127 |
static void |
| 128 |
_swrast_update_polygon( GLcontext *ctx ) |
| 129 |
{ |
| 130 |
GLfloat backface_sign = 1; |
| 131 |
|
| 132 |
if (ctx->Polygon.CullFlag) { |
| 133 |
backface_sign = 1; |
| 134 |
switch(ctx->Polygon.CullFaceMode) { |
| 135 |
case GL_BACK: |
| 136 |
if(ctx->Polygon.FrontFace==GL_CCW) |
| 137 |
backface_sign = -1; |
| 138 |
break; |
| 139 |
case GL_FRONT: |
| 140 |
if(ctx->Polygon.FrontFace!=GL_CCW) |
| 141 |
backface_sign = -1; |
| 142 |
break; |
| 143 |
default: |
| 144 |
case GL_FRONT_AND_BACK: |
| 145 |
backface_sign = 0; |
| 146 |
break; |
| 147 |
} |
| 148 |
} |
| 149 |
else { |
| 150 |
backface_sign = 0; |
| 151 |
} |
| 152 |
|
| 153 |
SWRAST_CONTEXT(ctx)->_BackfaceSign = backface_sign; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
/** |
| 158 |
* Update the _PreferPixelFog field to indicate if we need to compute |
| 159 |
* fog factors per-fragment. |
| 160 |
*/ |
| 161 |
static void |
| 162 |
_swrast_update_fog_hint( GLcontext *ctx ) |
| 163 |
{ |
| 164 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 165 |
swrast->_PreferPixelFog = (!swrast->AllowVertexFog || |
| 166 |
ctx->FragmentProgram._Enabled || /* not _Active! */ |
| 167 |
(ctx->Hint.Fog == GL_NICEST && |
| 168 |
swrast->AllowPixelFog)); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
/** |
| 174 |
* Update the swrast->_AnyTextureCombine flag. |
| 175 |
*/ |
| 176 |
static void |
| 177 |
_swrast_update_texture_env( GLcontext *ctx ) |
| 178 |
{ |
| 179 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 180 |
GLuint i; |
| 181 |
swrast->_AnyTextureCombine = GL_FALSE; |
| 182 |
for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { |
| 183 |
if (ctx->Texture.Unit[i].EnvMode == GL_COMBINE_EXT || |
| 184 |
ctx->Texture.Unit[i].EnvMode == GL_COMBINE4_NV) { |
| 185 |
swrast->_AnyTextureCombine = GL_TRUE; |
| 186 |
return; |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
/** |
| 193 |
* Update swrast->_FogColor and swrast->_FogEnable values. |
| 194 |
*/ |
| 195 |
static void |
| 196 |
_swrast_update_fog_state( GLcontext *ctx ) |
| 197 |
{ |
| 198 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 199 |
|
| 200 |
/* convert fog color to GLchan values */ |
| 201 |
CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[RCOMP], ctx->Fog.Color[RCOMP]); |
| 202 |
CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[GCOMP], ctx->Fog.Color[GCOMP]); |
| 203 |
CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[BCOMP], ctx->Fog.Color[BCOMP]); |
| 204 |
|
| 205 |
/* determine if fog is needed, and if so, which fog mode */ |
| 206 |
swrast->_FogEnabled = GL_FALSE; |
| 207 |
if (ctx->FragmentProgram._Active) { |
| 208 |
if (ctx->FragmentProgram._Current->Base.Target==GL_FRAGMENT_PROGRAM_ARB) { |
| 209 |
const struct fragment_program *p |
| 210 |
= (struct fragment_program *) ctx->FragmentProgram._Current; |
| 211 |
if (p->FogOption != GL_NONE) { |
| 212 |
swrast->_FogEnabled = GL_TRUE; |
| 213 |
swrast->_FogMode = p->FogOption; |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
else if (ctx->Fog.Enabled) { |
| 218 |
swrast->_FogEnabled = GL_TRUE; |
| 219 |
swrast->_FogMode = ctx->Fog.Mode; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
/** |
| 225 |
* Update state for running fragment programs. Basically, load the |
| 226 |
* program parameters with current state values. |
| 227 |
*/ |
| 228 |
static void |
| 229 |
_swrast_update_fragment_program( GLcontext *ctx ) |
| 230 |
{ |
| 231 |
if (ctx->FragmentProgram._Active) { |
| 232 |
struct fragment_program *program = ctx->FragmentProgram._Current; |
| 233 |
_mesa_load_state_parameters(ctx, program->Parameters); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
#define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \ |
| 240 |
_NEW_TEXTURE | \ |
| 241 |
_NEW_HINT | \ |
| 242 |
_NEW_POLYGON ) |
| 243 |
|
| 244 |
/* State referenced by _swrast_choose_triangle, _swrast_choose_line. |
| 245 |
*/ |
| 246 |
#define _SWRAST_NEW_TRIANGLE (_SWRAST_NEW_DERIVED | \ |
| 247 |
_NEW_RENDERMODE| \ |
| 248 |
_NEW_POLYGON| \ |
| 249 |
_NEW_DEPTH| \ |
| 250 |
_NEW_STENCIL| \ |
| 251 |
_NEW_COLOR| \ |
| 252 |
_NEW_TEXTURE| \ |
| 253 |
_SWRAST_NEW_RASTERMASK| \ |
| 254 |
_NEW_LIGHT| \ |
| 255 |
_NEW_FOG | \ |
| 256 |
_DD_NEW_SEPARATE_SPECULAR) |
| 257 |
|
| 258 |
#define _SWRAST_NEW_LINE (_SWRAST_NEW_DERIVED | \ |
| 259 |
_NEW_RENDERMODE| \ |
| 260 |
_NEW_LINE| \ |
| 261 |
_NEW_TEXTURE| \ |
| 262 |
_NEW_LIGHT| \ |
| 263 |
_NEW_FOG| \ |
| 264 |
_NEW_DEPTH | \ |
| 265 |
_DD_NEW_SEPARATE_SPECULAR) |
| 266 |
|
| 267 |
#define _SWRAST_NEW_POINT (_SWRAST_NEW_DERIVED | \ |
| 268 |
_NEW_RENDERMODE | \ |
| 269 |
_NEW_POINT | \ |
| 270 |
_NEW_TEXTURE | \ |
| 271 |
_NEW_LIGHT | \ |
| 272 |
_NEW_FOG | \ |
| 273 |
_DD_NEW_SEPARATE_SPECULAR) |
| 274 |
|
| 275 |
#define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE |
| 276 |
|
| 277 |
#define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE |
| 278 |
|
| 279 |
#define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
/** |
| 284 |
* Stub for swrast->Triangle to select a true triangle function |
| 285 |
* after a state change. |
| 286 |
*/ |
| 287 |
static void |
| 288 |
_swrast_validate_triangle( GLcontext *ctx, |
| 289 |
const SWvertex *v0, |
| 290 |
const SWvertex *v1, |
| 291 |
const SWvertex *v2 ) |
| 292 |
{ |
| 293 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 294 |
|
| 295 |
_swrast_validate_derived( ctx ); |
| 296 |
swrast->choose_triangle( ctx ); |
| 297 |
|
| 298 |
if (ctx->Texture._EnabledUnits == 0 |
| 299 |
&& NEED_SECONDARY_COLOR(ctx) |
| 300 |
&& !ctx->FragmentProgram._Active) { |
| 301 |
/* separate specular color, but no texture */ |
| 302 |
swrast->SpecTriangle = swrast->Triangle; |
| 303 |
swrast->Triangle = _swrast_add_spec_terms_triangle; |
| 304 |
} |
| 305 |
|
| 306 |
swrast->Triangle( ctx, v0, v1, v2 ); |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* Called via swrast->Line. Examine current GL state and choose a software |
| 311 |
* line routine. Then call it. |
| 312 |
*/ |
| 313 |
static void |
| 314 |
_swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) |
| 315 |
{ |
| 316 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 317 |
|
| 318 |
_swrast_validate_derived( ctx ); |
| 319 |
swrast->choose_line( ctx ); |
| 320 |
|
| 321 |
if (ctx->Texture._EnabledUnits == 0 |
| 322 |
&& NEED_SECONDARY_COLOR(ctx) |
| 323 |
&& !ctx->FragmentProgram._Active) { |
| 324 |
swrast->SpecLine = swrast->Line; |
| 325 |
swrast->Line = _swrast_add_spec_terms_line; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
swrast->Line( ctx, v0, v1 ); |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Called via swrast->Point. Examine current GL state and choose a software |
| 334 |
* point routine. Then call it. |
| 335 |
*/ |
| 336 |
static void |
| 337 |
_swrast_validate_point( GLcontext *ctx, const SWvertex *v0 ) |
| 338 |
{ |
| 339 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 340 |
|
| 341 |
_swrast_validate_derived( ctx ); |
| 342 |
swrast->choose_point( ctx ); |
| 343 |
|
| 344 |
if (ctx->Texture._EnabledUnits == 0 |
| 345 |
&& NEED_SECONDARY_COLOR(ctx) |
| 346 |
&& !ctx->FragmentProgram._Active) { |
| 347 |
swrast->SpecPoint = swrast->Point; |
| 348 |
swrast->Point = _swrast_add_spec_terms_point; |
| 349 |
} |
| 350 |
|
| 351 |
swrast->Point( ctx, v0 ); |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
/** |
| 356 |
* Called via swrast->BlendFunc. Examine GL state to choose a blending |
| 357 |
* function, then call it. |
| 358 |
*/ |
| 359 |
static void _ASMAPI |
| 360 |
_swrast_validate_blend_func( GLcontext *ctx, GLuint n, |
| 361 |
const GLubyte mask[], |
| 362 |
GLchan src[][4], |
| 363 |
CONST GLchan dst[][4] ) |
| 364 |
{ |
| 365 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 366 |
|
| 367 |
_swrast_validate_derived( ctx ); |
| 368 |
_swrast_choose_blend_func( ctx ); |
| 369 |
|
| 370 |
swrast->BlendFunc( ctx, n, mask, src, dst ); |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
/** |
| 375 |
* Called via the swrast->TextureSample[i] function pointer. |
| 376 |
* Basically, given a texture object, an array of texture coords |
| 377 |
* and an array of level-of-detail values, return an array of colors. |
| 378 |
* In this case, determine the correct texture sampling routine |
| 379 |
* (depending on filter mode, texture dimensions, etc) then call the |
| 380 |
* sampler routine. |
| 381 |
*/ |
| 382 |
static void |
| 383 |
_swrast_validate_texture_sample( GLcontext *ctx, GLuint texUnit, |
| 384 |
const struct gl_texture_object *tObj, |
| 385 |
GLuint n, const GLfloat texcoords[][4], |
| 386 |
const GLfloat lambda[], GLchan rgba[][4] ) |
| 387 |
{ |
| 388 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 389 |
|
| 390 |
_swrast_validate_derived( ctx ); |
| 391 |
|
| 392 |
/* Compute min/mag filter threshold */ |
| 393 |
if (tObj && tObj->MinFilter != tObj->MagFilter) { |
| 394 |
if (tObj->MagFilter == GL_LINEAR |
| 395 |
&& (tObj->MinFilter == GL_NEAREST_MIPMAP_NEAREST || |
| 396 |
tObj->MinFilter == GL_NEAREST_MIPMAP_LINEAR)) { |
| 397 |
swrast->_MinMagThresh[texUnit] = 0.5F; |
| 398 |
} |
| 399 |
else { |
| 400 |
swrast->_MinMagThresh[texUnit] = 0.0F; |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
swrast->TextureSample[texUnit] = |
| 405 |
_swrast_choose_texture_sample_func( ctx, tObj ); |
| 406 |
|
| 407 |
swrast->TextureSample[texUnit]( ctx, texUnit, tObj, n, texcoords, |
| 408 |
lambda, rgba ); |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
static void |
| 413 |
_swrast_sleep( GLcontext *ctx, GLuint new_state ) |
| 414 |
{ |
| 415 |
(void) ctx; (void) new_state; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
static void |
| 420 |
_swrast_invalidate_state( GLcontext *ctx, GLuint new_state ) |
| 421 |
{ |
| 422 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 423 |
GLuint i; |
| 424 |
|
| 425 |
swrast->NewState |= new_state; |
| 426 |
|
| 427 |
/* After 10 statechanges without any swrast functions being called, |
| 428 |
* put the module to sleep. |
| 429 |
*/ |
| 430 |
if (++swrast->StateChanges > 10) { |
| 431 |
swrast->InvalidateState = _swrast_sleep; |
| 432 |
swrast->NewState = ~0; |
| 433 |
new_state = ~0; |
| 434 |
} |
| 435 |
|
| 436 |
if (new_state & swrast->invalidate_triangle) |
| 437 |
swrast->Triangle = _swrast_validate_triangle; |
| 438 |
|
| 439 |
if (new_state & swrast->invalidate_line) |
| 440 |
swrast->Line = _swrast_validate_line; |
| 441 |
|
| 442 |
if (new_state & swrast->invalidate_point) |
| 443 |
swrast->Point = _swrast_validate_point; |
| 444 |
|
| 445 |
if (new_state & _SWRAST_NEW_BLEND_FUNC) |
| 446 |
swrast->BlendFunc = _swrast_validate_blend_func; |
| 447 |
|
| 448 |
if (new_state & _SWRAST_NEW_TEXTURE_SAMPLE_FUNC) |
| 449 |
for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) |
| 450 |
swrast->TextureSample[i] = _swrast_validate_texture_sample; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
void |
| 455 |
_swrast_validate_derived( GLcontext *ctx ) |
| 456 |
{ |
| 457 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 458 |
|
| 459 |
if (swrast->NewState) { |
| 460 |
if (swrast->NewState & _SWRAST_NEW_RASTERMASK) |
| 461 |
_swrast_update_rasterflags( ctx ); |
| 462 |
|
| 463 |
if (swrast->NewState & _NEW_POLYGON) |
| 464 |
_swrast_update_polygon( ctx ); |
| 465 |
|
| 466 |
if (swrast->NewState & (_NEW_HINT | _NEW_PROGRAM)) |
| 467 |
_swrast_update_fog_hint( ctx ); |
| 468 |
|
| 469 |
if (swrast->NewState & _SWRAST_NEW_TEXTURE_ENV_MODE) |
| 470 |
_swrast_update_texture_env( ctx ); |
| 471 |
|
| 472 |
if (swrast->NewState & (_NEW_FOG | _NEW_PROGRAM)) |
| 473 |
_swrast_update_fog_state( ctx ); |
| 474 |
|
| 475 |
if (swrast->NewState & _NEW_PROGRAM) |
| 476 |
_swrast_update_fragment_program( ctx ); |
| 477 |
|
| 478 |
swrast->NewState = 0; |
| 479 |
swrast->StateChanges = 0; |
| 480 |
swrast->InvalidateState = _swrast_invalidate_state; |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
#define SWRAST_DEBUG 0 |
| 485 |
|
| 486 |
/* Public entrypoints: See also s_accum.c, s_bitmap.c, etc. |
| 487 |
*/ |
| 488 |
void |
| 489 |
_swrast_Quad( GLcontext *ctx, |
| 490 |
const SWvertex *v0, const SWvertex *v1, |
| 491 |
const SWvertex *v2, const SWvertex *v3 ) |
| 492 |
{ |
| 493 |
if (SWRAST_DEBUG) { |
| 494 |
_mesa_debug(ctx, "_swrast_Quad\n"); |
| 495 |
_swrast_print_vertex( ctx, v0 ); |
| 496 |
_swrast_print_vertex( ctx, v1 ); |
| 497 |
_swrast_print_vertex( ctx, v2 ); |
| 498 |
_swrast_print_vertex( ctx, v3 ); |
| 499 |
} |
| 500 |
SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v3 ); |
| 501 |
SWRAST_CONTEXT(ctx)->Triangle( ctx, v1, v2, v3 ); |
| 502 |
} |
| 503 |
|
| 504 |
void |
| 505 |
_swrast_Triangle( GLcontext *ctx, const SWvertex *v0, |
| 506 |
const SWvertex *v1, const SWvertex *v2 ) |
| 507 |
{ |
| 508 |
if (SWRAST_DEBUG) { |
| 509 |
_mesa_debug(ctx, "_swrast_Triangle\n"); |
| 510 |
_swrast_print_vertex( ctx, v0 ); |
| 511 |
_swrast_print_vertex( ctx, v1 ); |
| 512 |
_swrast_print_vertex( ctx, v2 ); |
| 513 |
} |
| 514 |
SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 ); |
| 515 |
} |
| 516 |
|
| 517 |
void |
| 518 |
_swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) |
| 519 |
{ |
| 520 |
if (SWRAST_DEBUG) { |
| 521 |
_mesa_debug(ctx, "_swrast_Line\n"); |
| 522 |
_swrast_print_vertex( ctx, v0 ); |
| 523 |
_swrast_print_vertex( ctx, v1 ); |
| 524 |
} |
| 525 |
SWRAST_CONTEXT(ctx)->Line( ctx, v0, v1 ); |
| 526 |
} |
| 527 |
|
| 528 |
void |
| 529 |
_swrast_Point( GLcontext *ctx, const SWvertex *v0 ) |
| 530 |
{ |
| 531 |
if (SWRAST_DEBUG) { |
| 532 |
_mesa_debug(ctx, "_swrast_Point\n"); |
| 533 |
_swrast_print_vertex( ctx, v0 ); |
| 534 |
} |
| 535 |
SWRAST_CONTEXT(ctx)->Point( ctx, v0 ); |
| 536 |
} |
| 537 |
|
| 538 |
void |
| 539 |
_swrast_InvalidateState( GLcontext *ctx, GLuint new_state ) |
| 540 |
{ |
| 541 |
if (SWRAST_DEBUG) { |
| 542 |
_mesa_debug(ctx, "_swrast_InvalidateState\n"); |
| 543 |
} |
| 544 |
SWRAST_CONTEXT(ctx)->InvalidateState( ctx, new_state ); |
| 545 |
} |
| 546 |
|
| 547 |
void |
| 548 |
_swrast_ResetLineStipple( GLcontext *ctx ) |
| 549 |
{ |
| 550 |
if (SWRAST_DEBUG) { |
| 551 |
_mesa_debug(ctx, "_swrast_ResetLineStipple\n"); |
| 552 |
} |
| 553 |
SWRAST_CONTEXT(ctx)->StippleCounter = 0; |
| 554 |
} |
| 555 |
|
| 556 |
void |
| 557 |
_swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ) |
| 558 |
{ |
| 559 |
if (SWRAST_DEBUG) { |
| 560 |
_mesa_debug(ctx, "_swrast_allow_vertex_fog %d\n", value); |
| 561 |
} |
| 562 |
SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT ); |
| 563 |
SWRAST_CONTEXT(ctx)->AllowVertexFog = value; |
| 564 |
} |
| 565 |
|
| 566 |
void |
| 567 |
_swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value ) |
| 568 |
{ |
| 569 |
if (SWRAST_DEBUG) { |
| 570 |
_mesa_debug(ctx, "_swrast_allow_pixel_fog %d\n", value); |
| 571 |
} |
| 572 |
SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT ); |
| 573 |
SWRAST_CONTEXT(ctx)->AllowPixelFog = value; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
GLboolean |
| 578 |
_swrast_CreateContext( GLcontext *ctx ) |
| 579 |
{ |
| 580 |
GLuint i; |
| 581 |
SWcontext *swrast = (SWcontext *)CALLOC(sizeof(SWcontext)); |
| 582 |
|
| 583 |
if (SWRAST_DEBUG) { |
| 584 |
_mesa_debug(ctx, "_swrast_CreateContext\n"); |
| 585 |
} |
| 586 |
|
| 587 |
if (!swrast) |
| 588 |
return GL_FALSE; |
| 589 |
|
| 590 |
swrast->NewState = ~0; |
| 591 |
|
| 592 |
swrast->choose_point = _swrast_choose_point; |
| 593 |
swrast->choose_line = _swrast_choose_line; |
| 594 |
swrast->choose_triangle = _swrast_choose_triangle; |
| 595 |
|
| 596 |
swrast->invalidate_point = _SWRAST_NEW_POINT; |
| 597 |
swrast->invalidate_line = _SWRAST_NEW_LINE; |
| 598 |
swrast->invalidate_triangle = _SWRAST_NEW_TRIANGLE; |
| 599 |
|
| 600 |
swrast->Point = _swrast_validate_point; |
| 601 |
swrast->Line = _swrast_validate_line; |
| 602 |
swrast->Triangle = _swrast_validate_triangle; |
| 603 |
swrast->InvalidateState = _swrast_sleep; |
| 604 |
swrast->BlendFunc = _swrast_validate_blend_func; |
| 605 |
|
| 606 |
swrast->AllowVertexFog = GL_TRUE; |
| 607 |
swrast->AllowPixelFog = GL_TRUE; |
| 608 |
|
| 609 |
if (ctx->Visual.doubleBufferMode) |
| 610 |
swrast->CurrentBufferBit = BUFFER_BIT_BACK_LEFT; |
| 611 |
else |
| 612 |
swrast->CurrentBufferBit = BUFFER_FRONT_LEFT; |
| 613 |
|
| 614 |
/* Optimized Accum buffer */ |
| 615 |
swrast->_IntegerAccumMode = GL_FALSE; |
| 616 |
swrast->_IntegerAccumScaler = 0.0; |
| 617 |
|
| 618 |
for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) |
| 619 |
swrast->TextureSample[i] = _swrast_validate_texture_sample; |
| 620 |
|
| 621 |
swrast->SpanArrays = MALLOC_STRUCT(span_arrays); |
| 622 |
if (!swrast->SpanArrays) { |
| 623 |
FREE(swrast); |
| 624 |
return GL_FALSE; |
| 625 |
} |
| 626 |
|
| 627 |
/* init point span buffer */ |
| 628 |
swrast->PointSpan.primitive = GL_POINT; |
| 629 |
swrast->PointSpan.start = 0; |
| 630 |
swrast->PointSpan.end = 0; |
| 631 |
swrast->PointSpan.facing = 0; |
| 632 |
swrast->PointSpan.array = swrast->SpanArrays; |
| 633 |
|
| 634 |
assert(ctx->Const.MaxTextureUnits > 0); |
| 635 |
assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_UNITS); |
| 636 |
|
| 637 |
swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureUnits * |
| 638 |
MAX_WIDTH * 4 * sizeof(GLchan)); |
| 639 |
if (!swrast->TexelBuffer) { |
| 640 |
FREE(swrast->SpanArrays); |
| 641 |
FREE(swrast); |
| 642 |
return GL_FALSE; |
| 643 |
} |
| 644 |
|
| 645 |
ctx->swrast_context = swrast; |
| 646 |
|
| 647 |
return GL_TRUE; |
| 648 |
} |
| 649 |
|
| 650 |
void |
| 651 |
_swrast_DestroyContext( GLcontext *ctx ) |
| 652 |
{ |
| 653 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 654 |
|
| 655 |
if (SWRAST_DEBUG) { |
| 656 |
_mesa_debug(ctx, "_swrast_DestroyContext\n"); |
| 657 |
} |
| 658 |
|
| 659 |
FREE( swrast->SpanArrays ); |
| 660 |
FREE( swrast->TexelBuffer ); |
| 661 |
FREE( swrast ); |
| 662 |
|
| 663 |
ctx->swrast_context = 0; |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
struct swrast_device_driver * |
| 668 |
_swrast_GetDeviceDriverReference( GLcontext *ctx ) |
| 669 |
{ |
| 670 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 671 |
return &swrast->Driver; |
| 672 |
} |
| 673 |
|
| 674 |
void |
| 675 |
_swrast_flush( GLcontext *ctx ) |
| 676 |
{ |
| 677 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 678 |
/* flush any pending fragments from rendering points */ |
| 679 |
if (swrast->PointSpan.end > 0) { |
| 680 |
if (ctx->Visual.rgbMode) { |
| 681 |
_swrast_write_rgba_span(ctx, &(swrast->PointSpan)); |
| 682 |
} |
| 683 |
else { |
| 684 |
_swrast_write_index_span(ctx, &(swrast->PointSpan)); |
| 685 |
} |
| 686 |
swrast->PointSpan.end = 0; |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
void |
| 691 |
_swrast_render_primitive( GLcontext *ctx, GLenum prim ) |
| 692 |
{ |
| 693 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 694 |
if (swrast->Primitive == GL_POINTS && prim != GL_POINTS) { |
| 695 |
_swrast_flush(ctx); |
| 696 |
} |
| 697 |
swrast->Primitive = prim; |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
void |
| 702 |
_swrast_render_start( GLcontext *ctx ) |
| 703 |
{ |
| 704 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 705 |
if (swrast->Driver.SpanRenderStart) |
| 706 |
swrast->Driver.SpanRenderStart( ctx ); |
| 707 |
swrast->PointSpan.end = 0; |
| 708 |
} |
| 709 |
|
| 710 |
void |
| 711 |
_swrast_render_finish( GLcontext *ctx ) |
| 712 |
{ |
| 713 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 714 |
if (swrast->Driver.SpanRenderFinish) |
| 715 |
swrast->Driver.SpanRenderFinish( ctx ); |
| 716 |
|
| 717 |
_swrast_flush(ctx); |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
#define SWRAST_DEBUG_VERTICES 0 |
| 722 |
|
| 723 |
void |
| 724 |
_swrast_print_vertex( GLcontext *ctx, const SWvertex *v ) |
| 725 |
{ |
| 726 |
GLuint i; |
| 727 |
|
| 728 |
if (SWRAST_DEBUG_VERTICES) { |
| 729 |
_mesa_debug(ctx, "win %f %f %f %f\n", |
| 730 |
v->win[0], v->win[1], v->win[2], v->win[3]); |
| 731 |
|
| 732 |
for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) |
| 733 |
if (ctx->Texture.Unit[i]._ReallyEnabled) |
| 734 |
_mesa_debug(ctx, "texcoord[%d] %f %f %f %f\n", i, |
| 735 |
v->texcoord[i][0], v->texcoord[i][1], |
| 736 |
v->texcoord[i][2], v->texcoord[i][3]); |
| 737 |
|
| 738 |
#if CHAN_TYPE == GL_FLOAT |
| 739 |
_mesa_debug(ctx, "color %f %f %f %f\n", |
| 740 |
v->color[0], v->color[1], v->color[2], v->color[3]); |
| 741 |
_mesa_debug(ctx, "spec %f %f %f %f\n", |
| 742 |
v->specular[0], v->specular[1], |
| 743 |
v->specular[2], v->specular[3]); |
| 744 |
#else |
| 745 |
_mesa_debug(ctx, "color %d %d %d %d\n", |
| 746 |
v->color[0], v->color[1], v->color[2], v->color[3]); |
| 747 |
_mesa_debug(ctx, "spec %d %d %d %d\n", |
| 748 |
v->specular[0], v->specular[1], |
| 749 |
v->specular[2], v->specular[3]); |
| 750 |
#endif |
| 751 |
_mesa_debug(ctx, "fog %f\n", v->fog); |
| 752 |
_mesa_debug(ctx, "index %d\n", v->index); |
| 753 |
_mesa_debug(ctx, "pointsize %f\n", v->pointSize); |
| 754 |
_mesa_debug(ctx, "\n"); |
| 755 |
} |
| 756 |
} |