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

📄 radeon_state.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_state.c,v 1.8 2002/12/16 16:18:58 dawes Exp $ *//**************************************************************************Copyright 2000, 2001 VA Linux Systems Inc., Fremont, California.All Rights Reserved.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: *   Gareth Hughes <gareth@valinux.com> *   Keith Whitwell <keith@tungstengraphics.com> */#include "glheader.h"#include "imports.h"#include "api_arrayelt.h"#include "enums.h"#include "light.h"#include "state.h"#include "context.h"#include "framebuffer.h"#include "vbo/vbo.h"#include "tnl/tnl.h"#include "tnl/t_pipeline.h"#include "swrast_setup/swrast_setup.h"#include "radeon_context.h"#include "radeon_ioctl.h"#include "radeon_state.h"#include "radeon_tcl.h"#include "radeon_tex.h"#include "radeon_swtcl.h"#include "drirenderbuffer.h"static void radeonUpdateSpecular( GLcontext *ctx );/* ============================================================= * Alpha blending */static void radeonAlphaFunc( GLcontext *ctx, GLenum func, GLfloat ref ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   int pp_misc = rmesa->hw.ctx.cmd[CTX_PP_MISC];   GLubyte refByte;   CLAMPED_FLOAT_TO_UBYTE(refByte, ref);   RADEON_STATECHANGE( rmesa, ctx );   pp_misc &= ~(RADEON_ALPHA_TEST_OP_MASK | RADEON_REF_ALPHA_MASK);   pp_misc |= (refByte & RADEON_REF_ALPHA_MASK);   switch ( func ) {   case GL_NEVER:      pp_misc |= RADEON_ALPHA_TEST_FAIL;      break;   case GL_LESS:      pp_misc |= RADEON_ALPHA_TEST_LESS;      break;   case GL_EQUAL:      pp_misc |= RADEON_ALPHA_TEST_EQUAL;      break;   case GL_LEQUAL:      pp_misc |= RADEON_ALPHA_TEST_LEQUAL;      break;   case GL_GREATER:      pp_misc |= RADEON_ALPHA_TEST_GREATER;      break;   case GL_NOTEQUAL:      pp_misc |= RADEON_ALPHA_TEST_NEQUAL;      break;   case GL_GEQUAL:      pp_misc |= RADEON_ALPHA_TEST_GEQUAL;      break;   case GL_ALWAYS:      pp_misc |= RADEON_ALPHA_TEST_PASS;      break;   }   rmesa->hw.ctx.cmd[CTX_PP_MISC] = pp_misc;}static void radeonBlendEquationSeparate( GLcontext *ctx,					 GLenum modeRGB, GLenum modeA ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   GLuint b = rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] & ~RADEON_COMB_FCN_MASK;   GLboolean fallback = GL_FALSE;   assert( modeRGB == modeA );   switch ( modeRGB ) {   case GL_FUNC_ADD:   case GL_LOGIC_OP:      b |= RADEON_COMB_FCN_ADD_CLAMP;      break;   case GL_FUNC_SUBTRACT:      b |= RADEON_COMB_FCN_SUB_CLAMP;      break;   default:      if (ctx->Color.BlendEnabled)	 fallback = GL_TRUE;      else	 b |= RADEON_COMB_FCN_ADD_CLAMP;      break;   }   FALLBACK( rmesa, RADEON_FALLBACK_BLEND_EQ, fallback );   if ( !fallback ) {      RADEON_STATECHANGE( rmesa, ctx );      rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = b;      if ( (ctx->Color.ColorLogicOpEnabled || (ctx->Color.BlendEnabled	    && ctx->Color.BlendEquationRGB == GL_LOGIC_OP)) ) {	 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |=  RADEON_ROP_ENABLE;      } else {	 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] &= ~RADEON_ROP_ENABLE;      }   }}static void radeonBlendFuncSeparate( GLcontext *ctx,				     GLenum sfactorRGB, GLenum dfactorRGB,				     GLenum sfactorA, GLenum dfactorA ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   GLuint b = rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] &       ~(RADEON_SRC_BLEND_MASK | RADEON_DST_BLEND_MASK);   GLboolean fallback = GL_FALSE;   switch ( ctx->Color.BlendSrcRGB ) {   case GL_ZERO:      b |= RADEON_SRC_BLEND_GL_ZERO;      break;   case GL_ONE:      b |= RADEON_SRC_BLEND_GL_ONE;      break;   case GL_DST_COLOR:      b |= RADEON_SRC_BLEND_GL_DST_COLOR;      break;   case GL_ONE_MINUS_DST_COLOR:      b |= RADEON_SRC_BLEND_GL_ONE_MINUS_DST_COLOR;      break;   case GL_SRC_COLOR:      b |= RADEON_SRC_BLEND_GL_SRC_COLOR;      break;   case GL_ONE_MINUS_SRC_COLOR:      b |= RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_COLOR;      break;   case GL_SRC_ALPHA:      b |= RADEON_SRC_BLEND_GL_SRC_ALPHA;      break;   case GL_ONE_MINUS_SRC_ALPHA:      b |= RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_ALPHA;      break;   case GL_DST_ALPHA:      b |= RADEON_SRC_BLEND_GL_DST_ALPHA;      break;   case GL_ONE_MINUS_DST_ALPHA:      b |= RADEON_SRC_BLEND_GL_ONE_MINUS_DST_ALPHA;      break;   case GL_SRC_ALPHA_SATURATE:      b |= RADEON_SRC_BLEND_GL_SRC_ALPHA_SATURATE;      break;   case GL_CONSTANT_COLOR:   case GL_ONE_MINUS_CONSTANT_COLOR:   case GL_CONSTANT_ALPHA:   case GL_ONE_MINUS_CONSTANT_ALPHA:      if (ctx->Color.BlendEnabled)	 fallback = GL_TRUE;      else	 b |= RADEON_SRC_BLEND_GL_ONE;      break;   default:      break;   }   switch ( ctx->Color.BlendDstRGB ) {   case GL_ZERO:      b |= RADEON_DST_BLEND_GL_ZERO;      break;   case GL_ONE:      b |= RADEON_DST_BLEND_GL_ONE;      break;   case GL_SRC_COLOR:      b |= RADEON_DST_BLEND_GL_SRC_COLOR;      break;   case GL_ONE_MINUS_SRC_COLOR:      b |= RADEON_DST_BLEND_GL_ONE_MINUS_SRC_COLOR;      break;   case GL_SRC_ALPHA:      b |= RADEON_DST_BLEND_GL_SRC_ALPHA;      break;   case GL_ONE_MINUS_SRC_ALPHA:      b |= RADEON_DST_BLEND_GL_ONE_MINUS_SRC_ALPHA;      break;   case GL_DST_COLOR:      b |= RADEON_DST_BLEND_GL_DST_COLOR;      break;   case GL_ONE_MINUS_DST_COLOR:      b |= RADEON_DST_BLEND_GL_ONE_MINUS_DST_COLOR;      break;   case GL_DST_ALPHA:      b |= RADEON_DST_BLEND_GL_DST_ALPHA;      break;   case GL_ONE_MINUS_DST_ALPHA:      b |= RADEON_DST_BLEND_GL_ONE_MINUS_DST_ALPHA;      break;   case GL_CONSTANT_COLOR:   case GL_ONE_MINUS_CONSTANT_COLOR:   case GL_CONSTANT_ALPHA:   case GL_ONE_MINUS_CONSTANT_ALPHA:      if (ctx->Color.BlendEnabled)	 fallback = GL_TRUE;      else	 b |= RADEON_DST_BLEND_GL_ZERO;      break;   default:      break;   }   FALLBACK( rmesa, RADEON_FALLBACK_BLEND_FUNC, fallback );   if ( !fallback ) {      RADEON_STATECHANGE( rmesa, ctx );      rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = b;   }}/* ============================================================= * Depth testing */static void radeonDepthFunc( GLcontext *ctx, GLenum func ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   RADEON_STATECHANGE( rmesa, ctx );   rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] &= ~RADEON_Z_TEST_MASK;   switch ( ctx->Depth.Func ) {   case GL_NEVER:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_NEVER;      break;   case GL_LESS:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_LESS;      break;   case GL_EQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_EQUAL;      break;   case GL_LEQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_LEQUAL;      break;   case GL_GREATER:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_GREATER;      break;   case GL_NOTEQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_NEQUAL;      break;   case GL_GEQUAL:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_GEQUAL;      break;   case GL_ALWAYS:      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_TEST_ALWAYS;      break;   }}static void radeonDepthMask( GLcontext *ctx, GLboolean flag ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   RADEON_STATECHANGE( rmesa, ctx );   if ( ctx->Depth.Mask ) {      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |=  RADEON_Z_WRITE_ENABLE;   } else {      rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] &= ~RADEON_Z_WRITE_ENABLE;   }}static void radeonClearDepth( GLcontext *ctx, GLclampd d ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   GLuint format = (rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] &		    RADEON_DEPTH_FORMAT_MASK);   switch ( format ) {   case RADEON_DEPTH_FORMAT_16BIT_INT_Z:      rmesa->state.depth.clear = d * 0x0000ffff;      break;   case RADEON_DEPTH_FORMAT_24BIT_INT_Z:      rmesa->state.depth.clear = d * 0x00ffffff;      break;   }}/* ============================================================= * Fog */static void radeonFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param ){   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);   union { int i; float f; } c, d;   GLchan col[4];   switch (pname) {   case GL_FOG_MODE:      if (!ctx->Fog.Enabled)	 return;      RADEON_STATECHANGE(rmesa, tcl);      rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] &= ~RADEON_TCL_FOG_MASK;      switch (ctx->Fog.Mode) {      case GL_LINEAR:	 rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_TCL_FOG_LINEAR;	 break;      case GL_EXP:	 rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_TCL_FOG_EXP;	 break;      case GL_EXP2:	 rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_TCL_FOG_EXP2;	 break;      default:	 return;      }   /* fallthrough */   case GL_FOG_DENSITY:   case GL_FOG_START:   case GL_FOG_END:      if (!ctx->Fog.Enabled)	 return;      c.i = rmesa->hw.fog.cmd[FOG_C];      d.i = rmesa->hw.fog.cmd[FOG_D];      switch (ctx->Fog.Mode) {      case GL_EXP:	 c.f = 0.0;	 /* While this is the opposite sign from the DDK, it makes the fog test	  * pass, and matches r200.	  */	 d.f = -ctx->Fog.Density;	 break;      case GL_EXP2:	 c.f = 0.0;	 d.f = -(ctx->Fog.Density * ctx->Fog.Density);	 break;      case GL_LINEAR:	 if (ctx->Fog.Start == ctx->Fog.End) {	    c.f = 1.0F;	    d.f = 1.0F;	 } else {	    c.f = ctx->Fog.End/(ctx->Fog.End-ctx->Fog.Start);	    /* While this is the opposite sign from the DDK, it makes the fog	     * test pass, and matches r200.	     */	    d.f = -1.0/(ctx->Fog.End-ctx->Fog.Start);	 }	 break;      default:	 break;      }      if (c.i != rmesa->hw.fog.cmd[FOG_C] || d.i != rmesa->hw.fog.cmd[FOG_D]) {	 RADEON_STATECHANGE( rmesa, fog );	 rmesa->hw.fog.cmd[FOG_C] = c.i;	 rmesa->hw.fog.cmd[FOG_D] = d.i;      }      break;   case GL_FOG_COLOR:       RADEON_STATECHANGE( rmesa, ctx );      UNCLAMPED_FLOAT_TO_RGB_CHAN( col, ctx->Fog.Color );      rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] &= ~RADEON_FOG_COLOR_MASK;      rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] |=	 radeonPackColor( 4, col[0], col[1], col[2], 0 );      break;   case GL_FOG_COORD_SRC:      radeonUpdateSpecular( ctx );      break;   default:      return;   }}/* ============================================================= * Scissoring */static GLboolean intersect_rect( drm_clip_rect_t *out,				 drm_clip_rect_t *a,				 drm_clip_rect_t *b ){   *out = *a;   if ( b->x1 > out->x1 ) out->x1 = b->x1;   if ( b->y1 > out->y1 ) out->y1 = b->y1;   if ( b->x2 < out->x2 ) out->x2 = b->x2;   if ( b->y2 < out->y2 ) out->y2 = b->y2;   if ( out->x1 >= out->x2 ) return GL_FALSE;   if ( out->y1 >= out->y2 ) return GL_FALSE;   return GL_TRUE;}void radeonRecalcScissorRects( radeonContextPtr rmesa ){   drm_clip_rect_t *out;   int i;   /* Grow cliprect store?    */   if (rmesa->state.scissor.numAllocedClipRects < rmesa->numClipRects) {      while (rmesa->state.scissor.numAllocedClipRects < rmesa->numClipRects) {	 rmesa->state.scissor.numAllocedClipRects += 1;	/* zero case */	 rmesa->state.scissor.numAllocedClipRects *= 2;

⌨️ 快捷键说明

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