⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r200_state.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
/**************************************************************************Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.The Weather Channel (TM) funded Tungsten Graphics to develop theinitial release of the Radeon 8500 driver under the XFree86 license.This notice must be preserved.Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantialportions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * Authors: *   Keith Whitwell <keith@tungstengraphics.com> */#include "glheader.h"#include "imports.h"#include "api_arrayelt.h"#include "enums.h"#include "colormac.h"#include "light.h"#include "framebuffer.h"#include "swrast/swrast.h"#include "vbo/vbo.h"#include "tnl/tnl.h"#include "tnl/t_pipeline.h"#include "swrast_setup/swrast_setup.h"#include "r200_context.h"#include "r200_ioctl.h"#include "r200_state.h"#include "r200_tcl.h"#include "r200_tex.h"#include "r200_swtcl.h"#include "r200_vertprog.h"#include "drirenderbuffer.h"/* ============================================================= * Alpha blending */static void r200AlphaFunc( GLcontext *ctx, GLenum func, GLfloat ref ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   int pp_misc = rmesa->hw.ctx.cmd[CTX_PP_MISC];   GLubyte refByte;   CLAMPED_FLOAT_TO_UBYTE(refByte, ref);   R200_STATECHANGE( rmesa, ctx );   pp_misc &= ~(R200_ALPHA_TEST_OP_MASK | R200_REF_ALPHA_MASK);   pp_misc |= (refByte & R200_REF_ALPHA_MASK);   switch ( func ) {   case GL_NEVER:      pp_misc |= R200_ALPHA_TEST_FAIL;       break;   case GL_LESS:      pp_misc |= R200_ALPHA_TEST_LESS;      break;   case GL_EQUAL:      pp_misc |= R200_ALPHA_TEST_EQUAL;      break;   case GL_LEQUAL:      pp_misc |= R200_ALPHA_TEST_LEQUAL;      break;   case GL_GREATER:      pp_misc |= R200_ALPHA_TEST_GREATER;      break;   case GL_NOTEQUAL:      pp_misc |= R200_ALPHA_TEST_NEQUAL;      break;   case GL_GEQUAL:      pp_misc |= R200_ALPHA_TEST_GEQUAL;      break;   case GL_ALWAYS:      pp_misc |= R200_ALPHA_TEST_PASS;      break;   }   rmesa->hw.ctx.cmd[CTX_PP_MISC] = pp_misc;}static void r200BlendColor( GLcontext *ctx, const GLfloat cf[4] ){   GLubyte color[4];   r200ContextPtr rmesa = R200_CONTEXT(ctx);   R200_STATECHANGE( rmesa, ctx );   CLAMPED_FLOAT_TO_UBYTE(color[0], cf[0]);   CLAMPED_FLOAT_TO_UBYTE(color[1], cf[1]);   CLAMPED_FLOAT_TO_UBYTE(color[2], cf[2]);   CLAMPED_FLOAT_TO_UBYTE(color[3], cf[3]);   if (rmesa->r200Screen->drmSupportsBlendColor)      rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCOLOR] = r200PackColor( 4, color[0], color[1], color[2], color[3] );}/** * Calculate the hardware blend factor setting.  This same function is used * for source and destination of both alpha and RGB. * * \returns * The hardware register value for the specified blend factor.  This value * will need to be shifted into the correct position for either source or * destination factor. * * \todo * Since the two cases where source and destination are handled differently * are essentially error cases, they should never happen.  Determine if these * cases can be removed. */static int blend_factor( GLenum factor, GLboolean is_src ){   int func;   switch ( factor ) {   case GL_ZERO:      func = R200_BLEND_GL_ZERO;      break;   case GL_ONE:      func = R200_BLEND_GL_ONE;      break;   case GL_DST_COLOR:      func = R200_BLEND_GL_DST_COLOR;      break;   case GL_ONE_MINUS_DST_COLOR:      func = R200_BLEND_GL_ONE_MINUS_DST_COLOR;      break;   case GL_SRC_COLOR:      func = R200_BLEND_GL_SRC_COLOR;      break;   case GL_ONE_MINUS_SRC_COLOR:      func = R200_BLEND_GL_ONE_MINUS_SRC_COLOR;      break;   case GL_SRC_ALPHA:      func = R200_BLEND_GL_SRC_ALPHA;      break;   case GL_ONE_MINUS_SRC_ALPHA:      func = R200_BLEND_GL_ONE_MINUS_SRC_ALPHA;      break;   case GL_DST_ALPHA:      func = R200_BLEND_GL_DST_ALPHA;      break;   case GL_ONE_MINUS_DST_ALPHA:      func = R200_BLEND_GL_ONE_MINUS_DST_ALPHA;      break;   case GL_SRC_ALPHA_SATURATE:      func = (is_src) ? R200_BLEND_GL_SRC_ALPHA_SATURATE : R200_BLEND_GL_ZERO;      break;   case GL_CONSTANT_COLOR:      func = R200_BLEND_GL_CONST_COLOR;      break;   case GL_ONE_MINUS_CONSTANT_COLOR:      func = R200_BLEND_GL_ONE_MINUS_CONST_COLOR;      break;   case GL_CONSTANT_ALPHA:      func = R200_BLEND_GL_CONST_ALPHA;      break;   case GL_ONE_MINUS_CONSTANT_ALPHA:      func = R200_BLEND_GL_ONE_MINUS_CONST_ALPHA;      break;   default:      func = (is_src) ? R200_BLEND_GL_ONE : R200_BLEND_GL_ZERO;   }   return func;}/** * Sets both the blend equation and the blend function. * This is done in a single * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX) * change the interpretation of the blend function. * Also, make sure that blend function and blend equation are set to their default * value if color blending is not enabled, since at least blend equations GL_MIN * and GL_FUNC_REVERSE_SUBTRACT will cause wrong results otherwise for * unknown reasons. */static void r200_set_blend_state( GLcontext * ctx ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   GLuint cntl = rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] &      ~(R200_ROP_ENABLE | R200_ALPHA_BLEND_ENABLE | R200_SEPARATE_ALPHA_ENABLE);   int func = (R200_BLEND_GL_ONE << R200_SRC_BLEND_SHIFT) |      (R200_BLEND_GL_ZERO << R200_DST_BLEND_SHIFT);   int eqn = R200_COMB_FCN_ADD_CLAMP;   int funcA = (R200_BLEND_GL_ONE << R200_SRC_BLEND_SHIFT) |      (R200_BLEND_GL_ZERO << R200_DST_BLEND_SHIFT);   int eqnA = R200_COMB_FCN_ADD_CLAMP;   R200_STATECHANGE( rmesa, ctx );   if (rmesa->r200Screen->drmSupportsBlendColor) {      if (ctx->Color.ColorLogicOpEnabled) {         rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] =  cntl | R200_ROP_ENABLE;         rmesa->hw.ctx.cmd[CTX_RB3D_ABLENDCNTL] = eqn | func;         rmesa->hw.ctx.cmd[CTX_RB3D_CBLENDCNTL] = eqn | func;         return;      } else if (ctx->Color.BlendEnabled) {         rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] =  cntl | R200_ALPHA_BLEND_ENABLE | R200_SEPARATE_ALPHA_ENABLE;      }      else {         rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] = cntl;         rmesa->hw.ctx.cmd[CTX_RB3D_ABLENDCNTL] = eqn | func;         rmesa->hw.ctx.cmd[CTX_RB3D_CBLENDCNTL] = eqn | func;         return;      }   }   else {      if (ctx->Color.ColorLogicOpEnabled) {         rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] =  cntl | R200_ROP_ENABLE;         rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = eqn | func;         return;      } else if (ctx->Color.BlendEnabled) {         rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] =  cntl | R200_ALPHA_BLEND_ENABLE;      }      else {         rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] = cntl;         rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = eqn | func;         return;      }   }   func = (blend_factor( ctx->Color.BlendSrcRGB, GL_TRUE ) << R200_SRC_BLEND_SHIFT) |      (blend_factor( ctx->Color.BlendDstRGB, GL_FALSE ) << R200_DST_BLEND_SHIFT);   switch(ctx->Color.BlendEquationRGB) {   case GL_FUNC_ADD:      eqn = R200_COMB_FCN_ADD_CLAMP;      break;   case GL_FUNC_SUBTRACT:      eqn = R200_COMB_FCN_SUB_CLAMP;      break;   case GL_FUNC_REVERSE_SUBTRACT:      eqn = R200_COMB_FCN_RSUB_CLAMP;      break;   case GL_MIN:      eqn = R200_COMB_FCN_MIN;      func = (R200_BLEND_GL_ONE << R200_SRC_BLEND_SHIFT) |         (R200_BLEND_GL_ONE << R200_DST_BLEND_SHIFT);      break;   case GL_MAX:      eqn = R200_COMB_FCN_MAX;      func = (R200_BLEND_GL_ONE << R200_SRC_BLEND_SHIFT) |         (R200_BLEND_GL_ONE << R200_DST_BLEND_SHIFT);      break;   default:      fprintf( stderr, "[%s:%u] Invalid RGB blend equation (0x%04x).\n",         __FUNCTION__, __LINE__, ctx->Color.BlendEquationRGB );      return;   }   if (!rmesa->r200Screen->drmSupportsBlendColor) {      rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = eqn | func;      return;   }   funcA = (blend_factor( ctx->Color.BlendSrcA, GL_TRUE ) << R200_SRC_BLEND_SHIFT) |      (blend_factor( ctx->Color.BlendDstA, GL_FALSE ) << R200_DST_BLEND_SHIFT);   switch(ctx->Color.BlendEquationA) {   case GL_FUNC_ADD:      eqnA = R200_COMB_FCN_ADD_CLAMP;      break;   case GL_FUNC_SUBTRACT:      eqnA = R200_COMB_FCN_SUB_CLAMP;      break;   case GL_FUNC_REVERSE_SUBTRACT:      eqnA = R200_COMB_FCN_RSUB_CLAMP;      break;   case GL_MIN:      eqnA = R200_COMB_FCN_MIN;      funcA = (R200_BLEND_GL_ONE << R200_SRC_BLEND_SHIFT) |         (R200_BLEND_GL_ONE << R200_DST_BLEND_SHIFT);      break;   case GL_MAX:      eqnA = R200_COMB_FCN_MAX;      funcA = (R200_BLEND_GL_ONE << R200_SRC_BLEND_SHIFT) |         (R200_BLEND_GL_ONE << R200_DST_BLEND_SHIFT);      break;   default:      fprintf( stderr, "[%s:%u] Invalid A blend equation (0x%04x).\n",         __FUNCTION__, __LINE__, ctx->Color.BlendEquationA );      return;   }   rmesa->hw.ctx.cmd[CTX_RB3D_ABLENDCNTL] = eqnA | funcA;   rmesa->hw.ctx.cmd[CTX_RB3D_CBLENDCNTL] = eqn | func;}static void r200BlendEquationSeparate( GLcontext *ctx,				       GLenum modeRGB, GLenum modeA ){      r200_set_blend_state( ctx );}static void r200BlendFuncSeparate( GLcontext *ctx,				     GLenum sfactorRGB, GLenum dfactorRGB,				     GLenum sfactorA, GLenum dfactorA ){      r200_set_blend_state( ctx );}/* ============================================================= * Depth testing */static void r200DepthFunc( GLcontext *ctx, GLenum func ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   R200_STATECHANGE( rmesa, ctx );   rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] &= ~R200_Z_TEST_MASK;   switch ( ctx->Depth.Func ) {   case GL_NEVER:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_NEVER;      break;   case GL_LESS:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_LESS;      break;   case GL_EQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_EQUAL;      break;   case GL_LEQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_LEQUAL;      break;   case GL_GREATER:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_GREATER;      break;   case GL_NOTEQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_NEQUAL;      break;   case GL_GEQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_GEQUAL;      break;   case GL_ALWAYS:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= R200_Z_TEST_ALWAYS;      break;   }}static void r200ClearDepth( GLcontext *ctx, GLclampd d ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   GLuint format = (rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] &		    R200_DEPTH_FORMAT_MASK);   switch ( format ) {   case R200_DEPTH_FORMAT_16BIT_INT_Z:      rmesa->state.depth.clear = d * 0x0000ffff;      break;   case R200_DEPTH_FORMAT_24BIT_INT_Z:      rmesa->state.depth.clear = d * 0x00ffffff;      break;   }}static void r200DepthMask( GLcontext *ctx, GLboolean flag ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   R200_STATECHANGE( rmesa, ctx );   if ( ctx->Depth.Mask ) {      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |=  R200_Z_WRITE_ENABLE;   } else {      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] &= ~R200_Z_WRITE_ENABLE;   }}/* ============================================================= * Fog */static void r200Fogfv( GLcontext *ctx, GLenum pname, const GLfloat *param ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   union { int i; float f; } c, d;   GLchan col[4];   GLuint i;   c.i = rmesa->hw.fog.cmd[FOG_C];   d.i = rmesa->hw.fog.cmd[FOG_D];   switch (pname) {   case GL_FOG_MODE:      if (!ctx->Fog.Enabled)	 return;      R200_STATECHANGE(rmesa, tcl);      rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] &= ~R200_TCL_FOG_MASK;      switch (ctx->Fog.Mode) {      case GL_LINEAR:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -