Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygens_context.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.1 00004 * 00005 * Copyright (C) 1999-2008 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 * Authors: 00025 * Keith Whitwell <keith@tungstengraphics.com> 00026 * Brian Paul 00027 */ 00028 00029 #include "main/imports.h" 00030 #include "main/bufferobj.h" 00031 #include "main/context.h" 00032 #include "main/colormac.h" 00033 #include "main/mtypes.h" 00034 #include "main/teximage.h" 00035 #include "shader/prog_parameter.h" 00036 #include "shader/prog_statevars.h" 00037 #include "swrast.h" 00038 #include "s_blend.h" 00039 #include "s_context.h" 00040 #include "s_lines.h" 00041 #include "s_points.h" 00042 #include "s_span.h" 00043 #include "s_triangle.h" 00044 #include "s_texfilter.h" 00045 00046 00053 static void 00054 _swrast_update_rasterflags( GLcontext *ctx ) 00055 { 00056 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00057 GLbitfield rasterMask = 0; 00058 00059 if (ctx->Color.AlphaEnabled) rasterMask |= ALPHATEST_BIT; 00060 if (ctx->Color.BlendEnabled) rasterMask |= BLEND_BIT; 00061 if (ctx->Depth.Test) rasterMask |= DEPTH_BIT; 00062 if (swrast->_FogEnabled) rasterMask |= FOG_BIT; 00063 if (ctx->Scissor.Enabled) rasterMask |= CLIP_BIT; 00064 if (ctx->Stencil.Enabled) rasterMask |= STENCIL_BIT; 00065 if (ctx->Visual.rgbMode) { 00066 const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); 00067 if (colorMask != 0xffffffff) rasterMask |= MASKING_BIT; 00068 if (ctx->Color._LogicOpEnabled) rasterMask |= LOGIC_OP_BIT; 00069 if (ctx->Texture._EnabledUnits) rasterMask |= TEXTURE_BIT; 00070 } 00071 else { 00072 if (ctx->Color.IndexMask != 0xffffffff) rasterMask |= MASKING_BIT; 00073 if (ctx->Color.IndexLogicOpEnabled) rasterMask |= LOGIC_OP_BIT; 00074 } 00075 00076 if ( ctx->Viewport.X < 0 00077 || ctx->Viewport.X + ctx->Viewport.Width > (GLint) ctx->DrawBuffer->Width 00078 || ctx->Viewport.Y < 0 00079 || ctx->Viewport.Y + ctx->Viewport.Height > (GLint) ctx->DrawBuffer->Height) { 00080 rasterMask |= CLIP_BIT; 00081 } 00082 00083 if (ctx->Query.CurrentOcclusionObject) 00084 rasterMask |= OCCLUSION_BIT; 00085 00086 00087 /* If we're not drawing to exactly one color buffer set the 00088 * MULTI_DRAW_BIT flag. Also set it if we're drawing to no 00089 * buffers or the RGBA or CI mask disables all writes. 00090 */ 00091 if (ctx->DrawBuffer->_NumColorDrawBuffers != 1) { 00092 /* more than one color buffer designated for writing (or zero buffers) */ 00093 rasterMask |= MULTI_DRAW_BIT; 00094 } 00095 else if (ctx->Visual.rgbMode && *((GLuint *) ctx->Color.ColorMask) == 0) { 00096 rasterMask |= MULTI_DRAW_BIT; /* all RGBA channels disabled */ 00097 } 00098 else if (!ctx->Visual.rgbMode && ctx->Color.IndexMask==0) { 00099 rasterMask |= MULTI_DRAW_BIT; /* all color index bits disabled */ 00100 } 00101 00102 if (ctx->FragmentProgram._Current) { 00103 rasterMask |= FRAGPROG_BIT; 00104 } 00105 00106 if (ctx->ATIFragmentShader._Enabled) { 00107 rasterMask |= ATIFRAGSHADER_BIT; 00108 } 00109 00110 #if CHAN_TYPE == GL_FLOAT 00111 if (ctx->Color.ClampFragmentColor == GL_TRUE) { 00112 rasterMask |= CLAMPING_BIT; 00113 } 00114 #endif 00115 00116 SWRAST_CONTEXT(ctx)->_RasterMask = rasterMask; 00117 } 00118 00119 00126 static void 00127 _swrast_update_polygon( GLcontext *ctx ) 00128 { 00129 GLfloat backface_sign; 00130 00131 if (ctx->Polygon.CullFlag) { 00132 switch (ctx->Polygon.CullFaceMode) { 00133 case GL_BACK: 00134 backface_sign = -1.0; 00135 break; 00136 case GL_FRONT: 00137 backface_sign = 1.0; 00138 break; 00139 case GL_FRONT_AND_BACK: 00140 /* fallthrough */ 00141 default: 00142 backface_sign = 0.0; 00143 } 00144 } 00145 else { 00146 backface_sign = 0.0; 00147 } 00148 00149 SWRAST_CONTEXT(ctx)->_BackfaceCullSign = backface_sign; 00150 00151 /* This is for front/back-face determination, but not for culling */ 00152 SWRAST_CONTEXT(ctx)->_BackfaceSign 00153 = (ctx->Polygon.FrontFace == GL_CW) ? -1.0 : 1.0; 00154 } 00155 00156 00157 00162 static void 00163 _swrast_update_fog_hint( GLcontext *ctx ) 00164 { 00165 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00166 swrast->_PreferPixelFog = (!swrast->AllowVertexFog || 00167 ctx->FragmentProgram._Current || 00168 (ctx->Hint.Fog == GL_NICEST && 00169 swrast->AllowPixelFog)); 00170 } 00171 00172 00173 00177 static void 00178 _swrast_update_texture_env( GLcontext *ctx ) 00179 { 00180 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00181 GLuint i; 00182 swrast->_AnyTextureCombine = GL_FALSE; 00183 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { 00184 if (ctx->Texture.Unit[i].EnvMode == GL_COMBINE_EXT || 00185 ctx->Texture.Unit[i].EnvMode == GL_COMBINE4_NV) { 00186 swrast->_AnyTextureCombine = GL_TRUE; 00187 return; 00188 } 00189 } 00190 } 00191 00192 00198 static void 00199 _swrast_update_deferred_texture(GLcontext *ctx) 00200 { 00201 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00202 if (ctx->Color.AlphaEnabled) { 00203 /* alpha test depends on post-texture/shader colors */ 00204 swrast->_DeferredTexture = GL_FALSE; 00205 } 00206 else { 00207 const struct gl_fragment_program *fprog 00208 = ctx->FragmentProgram._Current; 00209 if (fprog && (fprog->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR))) { 00210 /* Z comes from fragment program/shader */ 00211 swrast->_DeferredTexture = GL_FALSE; 00212 } 00213 else if (ctx->Query.CurrentOcclusionObject) { 00214 /* occlusion query depends on shader discard/kill results */ 00215 swrast->_DeferredTexture = GL_FALSE; 00216 } 00217 else { 00218 swrast->_DeferredTexture = GL_TRUE; 00219 } 00220 } 00221 } 00222 00223 00227 static void 00228 _swrast_update_fog_state( GLcontext *ctx ) 00229 { 00230 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00231 const struct gl_fragment_program *fp = ctx->FragmentProgram._Current; 00232 00233 /* determine if fog is needed, and if so, which fog mode */ 00234 swrast->_FogEnabled = GL_FALSE; 00235 if (fp && fp->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { 00236 if (fp->FogOption != GL_NONE) { 00237 swrast->_FogEnabled = GL_TRUE; 00238 swrast->_FogMode = fp->FogOption; 00239 } 00240 } 00241 else if (ctx->Fog.Enabled) { 00242 swrast->_FogEnabled = GL_TRUE; 00243 swrast->_FogMode = ctx->Fog.Mode; 00244 } 00245 } 00246 00247 00252 static void 00253 _swrast_update_fragment_program(GLcontext *ctx, GLbitfield newState) 00254 { 00255 const struct gl_fragment_program *fp = ctx->FragmentProgram._Current; 00256 if (fp) { 00257 #if 0 00258 /* XXX Need a way to trigger the initial loading of parameters 00259 * even when there's no recent state changes. 00260 */ 00261 if (fp->Base.Parameters->StateFlags & newState) 00262 #endif 00263 _mesa_load_state_parameters(ctx, fp->Base.Parameters); 00264 } 00265 } 00266 00267 00268 00269 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \ 00270 _NEW_TEXTURE | \ 00271 _NEW_HINT | \ 00272 _NEW_POLYGON ) 00273 00274 /* State referenced by _swrast_choose_triangle, _swrast_choose_line. 00275 */ 00276 #define _SWRAST_NEW_TRIANGLE (_SWRAST_NEW_DERIVED | \ 00277 _NEW_RENDERMODE| \ 00278 _NEW_POLYGON| \ 00279 _NEW_DEPTH| \ 00280 _NEW_STENCIL| \ 00281 _NEW_COLOR| \ 00282 _NEW_TEXTURE| \ 00283 _SWRAST_NEW_RASTERMASK| \ 00284 _NEW_LIGHT| \ 00285 _NEW_FOG | \ 00286 _DD_NEW_SEPARATE_SPECULAR) 00287 00288 #define _SWRAST_NEW_LINE (_SWRAST_NEW_DERIVED | \ 00289 _NEW_RENDERMODE| \ 00290 _NEW_LINE| \ 00291 _NEW_TEXTURE| \ 00292 _NEW_LIGHT| \ 00293 _NEW_FOG| \ 00294 _NEW_DEPTH | \ 00295 _DD_NEW_SEPARATE_SPECULAR) 00296 00297 #define _SWRAST_NEW_POINT (_SWRAST_NEW_DERIVED | \ 00298 _NEW_RENDERMODE | \ 00299 _NEW_POINT | \ 00300 _NEW_TEXTURE | \ 00301 _NEW_LIGHT | \ 00302 _NEW_FOG | \ 00303 _DD_NEW_SEPARATE_SPECULAR) 00304 00305 #define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE 00306 00307 #define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE 00308 00309 #define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR 00310 00311 00312 00317 static void 00318 _swrast_validate_triangle( GLcontext *ctx, 00319 const SWvertex *v0, 00320 const SWvertex *v1, 00321 const SWvertex *v2 ) 00322 { 00323 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00324 00325 _swrast_validate_derived( ctx ); 00326 swrast->choose_triangle( ctx ); 00327 ASSERT(swrast->Triangle); 00328 00329 if (ctx->Texture._EnabledUnits == 0 00330 && NEED_SECONDARY_COLOR(ctx) 00331 && !ctx->FragmentProgram._Current) { 00332 /* separate specular color, but no texture */ 00333 swrast->SpecTriangle = swrast->Triangle; 00334 swrast->Triangle = _swrast_add_spec_terms_triangle; 00335 } 00336 00337 swrast->Triangle( ctx, v0, v1, v2 ); 00338 } 00339 00344 static void 00345 _swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) 00346 { 00347 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00348 00349 _swrast_validate_derived( ctx ); 00350 swrast->choose_line( ctx ); 00351 ASSERT(swrast->Line); 00352 00353 if (ctx->Texture._EnabledUnits == 0 00354 && NEED_SECONDARY_COLOR(ctx) 00355 && !ctx->FragmentProgram._Current) { 00356 swrast->SpecLine = swrast->Line; 00357 swrast->Line = _swrast_add_spec_terms_line; 00358 } 00359 00360 swrast->Line( ctx, v0, v1 ); 00361 } 00362 00367 static void 00368 _swrast_validate_point( GLcontext *ctx, const SWvertex *v0 ) 00369 { 00370 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00371 00372 _swrast_validate_derived( ctx ); 00373 swrast->choose_point( ctx ); 00374 00375 if (ctx->Texture._EnabledUnits == 0 00376 && NEED_SECONDARY_COLOR(ctx) 00377 && !ctx->FragmentProgram._Current) { 00378 swrast->SpecPoint = swrast->Point; 00379 swrast->Point = _swrast_add_spec_terms_point; 00380 } 00381 00382 swrast->Point( ctx, v0 ); 00383 } 00384 00385 00390 static void _ASMAPI 00391 _swrast_validate_blend_func(GLcontext *ctx, GLuint n, const GLubyte mask[], 00392 GLvoid *src, const GLvoid *dst, 00393 GLenum chanType ) 00394 { 00395 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00396 00397 _swrast_validate_derived( ctx ); /* why is this needed? */ 00398 _swrast_choose_blend_func( ctx, chanType ); 00399 00400 swrast->BlendFunc( ctx, n, mask, src, dst, chanType ); 00401 } 00402 00403 00408 static void 00409 _swrast_validate_texture_images(GLcontext *ctx) 00410 { 00411 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00412 GLuint u; 00413 00414 if (!swrast->ValidateTextureImage || !ctx->Texture._EnabledUnits) { 00415 /* no textures enabled, or no way to validate images! */ 00416 return; 00417 } 00418 00419 for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++) { 00420 if (ctx->Texture.Unit[u]._ReallyEnabled) { 00421 struct gl_texture_object *texObj = ctx->Texture.Unit[u]._Current; 00422 ASSERT(texObj); 00423 if (texObj) { 00424 GLuint numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; 00425 GLuint face; 00426 for (face = 0; face < numFaces; face++) { 00427 GLint lvl; 00428 for (lvl = texObj->BaseLevel; lvl <= texObj->_MaxLevel; lvl++) { 00429 struct gl_texture_image *texImg = texObj->Image[face][lvl]; 00430 if (texImg && !texImg->Data) { 00431 swrast->ValidateTextureImage(ctx, texObj, face, lvl); 00432 ASSERT(texObj->Image[face][lvl]->Data); 00433 } 00434 } 00435 } 00436 } 00437 } 00438 } 00439 } 00440 00441 00447 void 00448 _swrast_eject_texture_images(GLcontext *ctx) 00449 { 00450 GLuint u; 00451 00452 if (!ctx->Texture._EnabledUnits) { 00453 /* no textures enabled */ 00454 return; 00455 } 00456 00457 for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++) { 00458 if (ctx->Texture.Unit[u]._ReallyEnabled) { 00459 struct gl_texture_object *texObj = ctx->Texture.Unit[u]._Current; 00460 ASSERT(texObj); 00461 if (texObj) { 00462 GLuint numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; 00463 GLuint face; 00464 for (face = 0; face < numFaces; face++) { 00465 GLint lvl; 00466 for (lvl = texObj->BaseLevel; lvl <= texObj->_MaxLevel; lvl++) { 00467 struct gl_texture_image *texImg = texObj->Image[face][lvl]; 00468 if (texImg && texImg->Data) { 00469 _mesa_free_texmemory(texImg->Data); 00470 texImg->Data = NULL; 00471 } 00472 } 00473 } 00474 } 00475 } 00476 } 00477 } 00478 00479 00480 00481 static void 00482 _swrast_sleep( GLcontext *ctx, GLbitfield new_state ) 00483 { 00484 (void) ctx; (void) new_state; 00485 } 00486 00487 00488 static void 00489 _swrast_invalidate_state( GLcontext *ctx, GLbitfield new_state ) 00490 { 00491 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00492 GLuint i; 00493 00494 swrast->NewState |= new_state; 00495 00496 /* After 10 statechanges without any swrast functions being called, 00497 * put the module to sleep. 00498 */ 00499 if (++swrast->StateChanges > 10) { 00500 swrast->InvalidateState = _swrast_sleep; 00501 swrast->NewState = ~0; 00502 new_state = ~0; 00503 } 00504 00505 { 00506 const struct gl_fragment_program *fp = ctx->FragmentProgram._Current; 00507 if (fp && (fp->Base.Parameters->StateFlags & new_state)) { 00508 _mesa_load_state_parameters(ctx, fp->Base.Parameters); 00509 } 00510 } 00511 00512 if (new_state & swrast->InvalidateTriangleMask) 00513 swrast->Triangle = _swrast_validate_triangle; 00514 00515 if (new_state & swrast->InvalidateLineMask) 00516 swrast->Line = _swrast_validate_line; 00517 00518 if (new_state & swrast->InvalidatePointMask) 00519 swrast->Point = _swrast_validate_point; 00520 00521 if (new_state & _SWRAST_NEW_BLEND_FUNC) 00522 swrast->BlendFunc = _swrast_validate_blend_func; 00523 00524 if (new_state & _SWRAST_NEW_TEXTURE_SAMPLE_FUNC) 00525 for (i = 0 ; i < ctx->Const.MaxTextureImageUnits ; i++) 00526 swrast->TextureSample[i] = NULL; 00527 } 00528 00529 00530 void 00531 _swrast_update_texture_samplers(GLcontext *ctx) 00532 { 00533 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00534 GLuint u; 00535 00536 for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++) { 00537 const struct gl_texture_object *tObj = ctx->Texture.Unit[u]._Current; 00538 /* Note: If tObj is NULL, the sample function will be a simple 00539 * function that just returns opaque black (0,0,0,1). 00540 */ 00541 swrast->TextureSample[u] = _swrast_choose_texture_sample_func(ctx, tObj); 00542 } 00543 } 00544 00545 00550 static void 00551 _swrast_update_active_attribs(GLcontext *ctx) 00552 { 00553 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00554 GLuint attribsMask; 00555 00556 /* 00557 * Compute _ActiveAttribsMask = which fragment attributes are needed. 00558 */ 00559 if (ctx->FragmentProgram._Current) { 00560 /* fragment program/shader */ 00561 attribsMask = ctx->FragmentProgram._Current->Base.InputsRead; 00562 attribsMask &= ~FRAG_BIT_WPOS; /* WPOS is always handled specially */ 00563 } 00564 else if (ctx->ATIFragmentShader._Enabled) { 00565 attribsMask = ~0; /* XXX fix me */ 00566 } 00567 else { 00568 /* fixed function */ 00569 attribsMask = 0x0; 00570 00571 #if CHAN_TYPE == GL_FLOAT 00572 attribsMask |= FRAG_BIT_COL0; 00573 #endif 00574 00575 if (ctx->Fog.ColorSumEnabled || 00576 (ctx->Light.Enabled && 00577 ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)) { 00578 attribsMask |= FRAG_BIT_COL1; 00579 } 00580 00581 if (swrast->_FogEnabled) 00582 attribsMask |= FRAG_BIT_FOGC; 00583 00584 attribsMask |= (ctx->Texture._EnabledUnits << FRAG_ATTRIB_TEX0); 00585 } 00586 00587 swrast->_ActiveAttribMask = attribsMask; 00588 00589 /* Update _ActiveAttribs[] list */ 00590 { 00591 GLuint i, num = 0; 00592 for (i = 0; i < FRAG_ATTRIB_MAX; i++) { 00593 if (attribsMask & (1 << i)) { 00594 swrast->_ActiveAttribs[num++] = i; 00595 /* how should this attribute be interpolated? */ 00596 if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1) 00597 swrast->_InterpMode[i] = ctx->Light.ShadeModel; 00598 else 00599 swrast->_InterpMode[i] = GL_SMOOTH; 00600 } 00601 } 00602 swrast->_NumActiveAttribs = num; 00603 } 00604 } 00605 00606 00607 void 00608 _swrast_validate_derived( GLcontext *ctx ) 00609 { 00610 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00611 00612 if (swrast->NewState) { 00613 if (swrast->NewState & _NEW_POLYGON) 00614 _swrast_update_polygon( ctx ); 00615 00616 if (swrast->NewState & (_NEW_HINT | _NEW_PROGRAM)) 00617 _swrast_update_fog_hint( ctx ); 00618 00619 if (swrast->NewState & _SWRAST_NEW_TEXTURE_ENV_MODE) 00620 _swrast_update_texture_env( ctx ); 00621 00622 if (swrast->NewState & (_NEW_FOG | _NEW_PROGRAM)) 00623 _swrast_update_fog_state( ctx ); 00624 00625 if (swrast->NewState & (_NEW_MODELVIEW | 00626 _NEW_PROJECTION | 00627 _NEW_TEXTURE_MATRIX | 00628 _NEW_FOG | 00629 _NEW_LIGHT | 00630 _NEW_LINE | 00631 _NEW_TEXTURE | 00632 _NEW_TRANSFORM | 00633 _NEW_POINT | 00634 _NEW_VIEWPORT | 00635 _NEW_PROGRAM)) 00636 _swrast_update_fragment_program( ctx, swrast->NewState ); 00637 00638 if (swrast->NewState & (_NEW_TEXTURE | _NEW_PROGRAM)) { 00639 _swrast_update_texture_samplers( ctx ); 00640 _swrast_validate_texture_images(ctx); 00641 } 00642 00643 if (swrast->NewState & (_NEW_COLOR | _NEW_PROGRAM)) 00644 _swrast_update_deferred_texture(ctx); 00645 00646 if (swrast->NewState & _SWRAST_NEW_RASTERMASK) 00647 _swrast_update_rasterflags( ctx ); 00648 00649 if (swrast->NewState & (_NEW_DEPTH | 00650 _NEW_FOG | 00651 _NEW_LIGHT | 00652 _NEW_PROGRAM | 00653 _NEW_TEXTURE)) 00654 _swrast_update_active_attribs(ctx); 00655 00656 swrast->NewState = 0; 00657 swrast->StateChanges = 0; 00658 swrast->InvalidateState = _swrast_invalidate_state; 00659 } 00660 } 00661 00662 #define SWRAST_DEBUG 0 00663 00664 /* Public entrypoints: See also s_accum.c, s_bitmap.c, etc. 00665 */ 00666 void 00667 _swrast_Quad( GLcontext *ctx, 00668 const SWvertex *v0, const SWvertex *v1, 00669 const SWvertex *v2, const SWvertex *v3 ) 00670 { 00671 if (SWRAST_DEBUG) { 00672 _mesa_debug(ctx, "_swrast_Quad\n"); 00673 _swrast_print_vertex( ctx, v0 ); 00674 _swrast_print_vertex( ctx, v1 ); 00675 _swrast_print_vertex( ctx, v2 ); 00676 _swrast_print_vertex( ctx, v3 ); 00677 } 00678 SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v3 ); 00679 SWRAST_CONTEXT(ctx)->Triangle( ctx, v1, v2, v3 ); 00680 } 00681 00682 void 00683 _swrast_Triangle( GLcontext *ctx, const SWvertex *v0, 00684 const SWvertex *v1, const SWvertex *v2 ) 00685 { 00686 if (SWRAST_DEBUG) { 00687 _mesa_debug(ctx, "_swrast_Triangle\n"); 00688 _swrast_print_vertex( ctx, v0 ); 00689 _swrast_print_vertex( ctx, v1 ); 00690 _swrast_print_vertex( ctx, v2 ); 00691 } 00692 SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 ); 00693 } 00694 00695 void 00696 _swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) 00697 { 00698 if (SWRAST_DEBUG) { 00699 _mesa_debug(ctx, "_swrast_Line\n"); 00700 _swrast_print_vertex( ctx, v0 ); 00701 _swrast_print_vertex( ctx, v1 ); 00702 } 00703 SWRAST_CONTEXT(ctx)->Line( ctx, v0, v1 ); 00704 } 00705 00706 void 00707 _swrast_Point( GLcontext *ctx, const SWvertex *v0 ) 00708 { 00709 if (SWRAST_DEBUG) { 00710 _mesa_debug(ctx, "_swrast_Point\n"); 00711 _swrast_print_vertex( ctx, v0 ); 00712 } 00713 SWRAST_CONTEXT(ctx)->Point( ctx, v0 ); 00714 } 00715 00716 void 00717 _swrast_InvalidateState( GLcontext *ctx, GLbitfield new_state ) 00718 { 00719 if (SWRAST_DEBUG) { 00720 _mesa_debug(ctx, "_swrast_InvalidateState\n"); 00721 } 00722 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, new_state ); 00723 } 00724 00725 void 00726 _swrast_ResetLineStipple( GLcontext *ctx ) 00727 { 00728 if (SWRAST_DEBUG) { 00729 _mesa_debug(ctx, "_swrast_ResetLineStipple\n"); 00730 } 00731 SWRAST_CONTEXT(ctx)->StippleCounter = 0; 00732 } 00733 00734 void 00735 _swrast_SetFacing(GLcontext *ctx, GLuint facing) 00736 { 00737 SWRAST_CONTEXT(ctx)->PointLineFacing = facing; 00738 } 00739 00740 void 00741 _swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ) 00742 { 00743 if (SWRAST_DEBUG) { 00744 _mesa_debug(ctx, "_swrast_allow_vertex_fog %d\n", value); 00745 } 00746 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT ); 00747 SWRAST_CONTEXT(ctx)->AllowVertexFog = value; 00748 } 00749 00750 void 00751 _swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value ) 00752 { 00753 if (SWRAST_DEBUG) { 00754 _mesa_debug(ctx, "_swrast_allow_pixel_fog %d\n", value); 00755 } 00756 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT ); 00757 SWRAST_CONTEXT(ctx)->AllowPixelFog = value; 00758 } 00759 00760 00761 GLboolean 00762 _swrast_CreateContext( GLcontext *ctx ) 00763 { 00764 GLuint i; 00765 SWcontext *swrast = (SWcontext *)CALLOC(sizeof(SWcontext)); 00766 00767 if (SWRAST_DEBUG) { 00768 _mesa_debug(ctx, "_swrast_CreateContext\n"); 00769 } 00770 00771 if (!swrast) 00772 return GL_FALSE; 00773 00774 swrast->NewState = ~0; 00775 00776 swrast->choose_point = _swrast_choose_point; 00777 swrast->choose_line = _swrast_choose_line; 00778 swrast->choose_triangle = _swrast_choose_triangle; 00779 00780 swrast->InvalidatePointMask = _SWRAST_NEW_POINT; 00781 swrast->InvalidateLineMask = _SWRAST_NEW_LINE; 00782 swrast->InvalidateTriangleMask = _SWRAST_NEW_TRIANGLE; 00783 00784 swrast->Point = _swrast_validate_point; 00785 swrast->Line = _swrast_validate_line; 00786 swrast->Triangle = _swrast_validate_triangle; 00787 swrast->InvalidateState = _swrast_sleep; 00788 swrast->BlendFunc = _swrast_validate_blend_func; 00789 00790 swrast->AllowVertexFog = GL_TRUE; 00791 swrast->AllowPixelFog = GL_TRUE; 00792 00793 /* Optimized Accum buffer */ 00794 swrast->_IntegerAccumMode = GL_FALSE; 00795 swrast->_IntegerAccumScaler = 0.0; 00796 00797 for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) 00798 swrast->TextureSample[i] = NULL; 00799 00800 swrast->SpanArrays = MALLOC_STRUCT(sw_span_arrays); 00801 if (!swrast->SpanArrays) { 00802 FREE(swrast); 00803 return GL_FALSE; 00804 } 00805 swrast->SpanArrays->ChanType = CHAN_TYPE; 00806 #if CHAN_TYPE == GL_UNSIGNED_BYTE 00807 swrast->SpanArrays->rgba = swrast->SpanArrays->rgba8; 00808 #elif CHAN_TYPE == GL_UNSIGNED_SHORT 00809 swrast->SpanArrays->rgba = swrast->SpanArrays->rgba16; 00810 #else 00811 swrast->SpanArrays->rgba = swrast->SpanArrays->attribs[FRAG_ATTRIB_COL0]; 00812 #endif 00813 00814 /* init point span buffer */ 00815 swrast->PointSpan.primitive = GL_POINT; 00816 swrast->PointSpan.end = 0; 00817 swrast->PointSpan.facing = 0; 00818 swrast->PointSpan.array = swrast->SpanArrays; 00819 00820 swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureImageUnits * 00821 MAX_WIDTH * 4 * sizeof(GLchan)); 00822 if (!swrast->TexelBuffer) { 00823 FREE(swrast->SpanArrays); 00824 FREE(swrast); 00825 return GL_FALSE; 00826 } 00827 00828 ctx->swrast_context = swrast; 00829 00830 return GL_TRUE; 00831 } 00832 00833 void 00834 _swrast_DestroyContext( GLcontext *ctx ) 00835 { 00836 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00837 00838 if (SWRAST_DEBUG) { 00839 _mesa_debug(ctx, "_swrast_DestroyContext\n"); 00840 } 00841 00842 FREE( swrast->SpanArrays ); 00843 if (swrast->ZoomedArrays) 00844 FREE( swrast->ZoomedArrays ); 00845 FREE( swrast->TexelBuffer ); 00846 FREE( swrast ); 00847 00848 ctx->swrast_context = 0; 00849 } 00850 00851 00852 struct swrast_device_driver * 00853 _swrast_GetDeviceDriverReference( GLcontext *ctx ) 00854 { 00855 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00856 return &swrast->Driver; 00857 } 00858 00859 void 00860 _swrast_flush( GLcontext *ctx ) 00861 { 00862 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00863 /* flush any pending fragments from rendering points */ 00864 if (swrast->PointSpan.end > 0) { 00865 if (ctx->Visual.rgbMode) { 00866 _swrast_write_rgba_span(ctx, &(swrast->PointSpan)); 00867 } 00868 else { 00869 _swrast_write_index_span(ctx, &(swrast->PointSpan)); 00870 } 00871 swrast->PointSpan.end = 0; 00872 } 00873 } 00874 00875 void 00876 _swrast_render_primitive( GLcontext *ctx, GLenum prim ) 00877 { 00878 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00879 if (swrast->Primitive == GL_POINTS && prim != GL_POINTS) { 00880 _swrast_flush(ctx); 00881 } 00882 swrast->Primitive = prim; 00883 } 00884 00885 00886 void 00887 _swrast_render_start( GLcontext *ctx ) 00888 { 00889 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00890 if (swrast->Driver.SpanRenderStart) 00891 swrast->Driver.SpanRenderStart( ctx ); 00892 swrast->PointSpan.end = 0; 00893 } 00894 00895 void 00896 _swrast_render_finish( GLcontext *ctx ) 00897 { 00898 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00899 if (swrast->Driver.SpanRenderFinish) 00900 swrast->Driver.SpanRenderFinish( ctx ); 00901 00902 _swrast_flush(ctx); 00903 } 00904 00905 00906 #define SWRAST_DEBUG_VERTICES 0 00907 00908 void 00909 _swrast_print_vertex( GLcontext *ctx, const SWvertex *v ) 00910 { 00911 GLuint i; 00912 00913 if (SWRAST_DEBUG_VERTICES) { 00914 _mesa_debug(ctx, "win %f %f %f %f\n", 00915 v->attrib[FRAG_ATTRIB_WPOS][0], 00916 v->attrib[FRAG_ATTRIB_WPOS][1], 00917 v->attrib[FRAG_ATTRIB_WPOS][2], 00918 v->attrib[FRAG_ATTRIB_WPOS][3]); 00919 00920 for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) 00921 if (ctx->Texture.Unit[i]._ReallyEnabled) 00922 _mesa_debug(ctx, "texcoord[%d] %f %f %f %f\n", i, 00923 v->attrib[FRAG_ATTRIB_TEX0 + i][0], 00924 v->attrib[FRAG_ATTRIB_TEX0 + i][1], 00925 v->attrib[FRAG_ATTRIB_TEX0 + i][2], 00926 v->attrib[FRAG_ATTRIB_TEX0 + i][3]); 00927 00928 #if CHAN_TYPE == GL_FLOAT 00929 _mesa_debug(ctx, "color %f %f %f %f\n", 00930 v->color[0], v->color[1], v->color[2], v->color[3]); 00931 #else 00932 _mesa_debug(ctx, "color %d %d %d %d\n", 00933 v->color[0], v->color[1], v->color[2], v->color[3]); 00934 #endif 00935 _mesa_debug(ctx, "spec %g %g %g %g\n", 00936 v->attrib[FRAG_ATTRIB_COL1][0], 00937 v->attrib[FRAG_ATTRIB_COL1][1], 00938 v->attrib[FRAG_ATTRIB_COL1][2], 00939 v->attrib[FRAG_ATTRIB_COL1][3]); 00940 _mesa_debug(ctx, "fog %f\n", v->attrib[FRAG_ATTRIB_FOGC][0]); 00941 _mesa_debug(ctx, "index %d\n", v->attrib[FRAG_ATTRIB_CI][0]); 00942 _mesa_debug(ctx, "pointsize %f\n", v->pointSize); 00943 _mesa_debug(ctx, "\n"); 00944 } 00945 } Generated on Sun May 27 2012 04:20:42 for ReactOS by
1.7.6.1
|