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

📄 sis_state.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.Copyright 2003 Eric AnholtAll Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationon the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whomthe Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice (including the nextparagraph) shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALLERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THEUSE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ *//* * Authors: *    Sung-Ching Lin <sclin@sis.com.tw> *    Eric Anholt <anholt@FreeBSD.org> */#include "sis_context.h"#include "sis_state.h"#include "sis_tris.h"#include "sis_lock.h"#include "sis_tex.h"#include "context.h"#include "enums.h"#include "colormac.h"#include "swrast/swrast.h"#include "vbo/vbo.h"#include "tnl/tnl.h"#include "swrast_setup/swrast_setup.h"#include "tnl/t_pipeline.h"/* ============================================================= * Alpha blending */static voidsisDDAlphaFunc( GLcontext * ctx, GLenum func, GLfloat ref ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   GLubyte refbyte;   __GLSiSHardware *prev = &smesa->prev;   __GLSiSHardware *current = &smesa->current;   CLAMPED_FLOAT_TO_UBYTE(refbyte, ref);   current->hwAlpha = refbyte << 16;   /* Alpha Test function */   switch (func)   {   case GL_NEVER:      current->hwAlpha |= SiS_ALPHA_NEVER;      break;   case GL_LESS:      current->hwAlpha |= SiS_ALPHA_LESS;      break;   case GL_EQUAL:      current->hwAlpha |= SiS_ALPHA_EQUAL;      break;   case GL_LEQUAL:      current->hwAlpha |= SiS_ALPHA_LEQUAL;      break;   case GL_GREATER:      current->hwAlpha |= SiS_ALPHA_GREATER;      break;   case GL_NOTEQUAL:      current->hwAlpha |= SiS_ALPHA_NOTEQUAL;      break;   case GL_GEQUAL:      current->hwAlpha |= SiS_ALPHA_GEQUAL;      break;   case GL_ALWAYS:      current->hwAlpha |= SiS_ALPHA_ALWAYS;      break;   }   prev->hwAlpha = current->hwAlpha;   smesa->GlobalFlag |= GFLAG_ALPHASETTING;}static voidsisDDBlendFuncSeparate( GLcontext *ctx, 			GLenum sfactorRGB, GLenum dfactorRGB,			GLenum sfactorA,   GLenum dfactorA ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   __GLSiSHardware *prev = &smesa->prev;   __GLSiSHardware *current = &smesa->current;   current->hwDstSrcBlend = 0;   switch (dfactorRGB)   {   case GL_ZERO:      current->hwDstSrcBlend |= SiS_D_ZERO;      break;   case GL_ONE:      current->hwDstSrcBlend |= SiS_D_ONE;      break;   case GL_SRC_COLOR:      current->hwDstSrcBlend |= SiS_D_SRC_COLOR;      break;   case GL_ONE_MINUS_SRC_COLOR:      current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_COLOR;      break;   case GL_SRC_ALPHA:      current->hwDstSrcBlend |= SiS_D_SRC_ALPHA;      break;   case GL_ONE_MINUS_SRC_ALPHA:      current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_ALPHA;      break;   case GL_DST_COLOR:      current->hwDstSrcBlend |= SiS_D_DST_COLOR;      break;   case GL_ONE_MINUS_DST_COLOR:      current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_COLOR;      break;   case GL_DST_ALPHA:      current->hwDstSrcBlend |= SiS_D_DST_ALPHA;      break;   case GL_ONE_MINUS_DST_ALPHA:      current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_ALPHA;      break;   default:      fprintf(stderr, "Unknown dst blend function 0x%x\n", dfactorRGB);      break;   }   switch (sfactorRGB)   {   case GL_ZERO:      current->hwDstSrcBlend |= SiS_S_ZERO;      break;   case GL_ONE:      current->hwDstSrcBlend |= SiS_S_ONE;      break;   case GL_SRC_COLOR:      current->hwDstSrcBlend |= SiS_S_SRC_COLOR;      break;   case GL_ONE_MINUS_SRC_COLOR:      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_COLOR;      break;   case GL_SRC_ALPHA:      current->hwDstSrcBlend |= SiS_S_SRC_ALPHA;      break;   case GL_ONE_MINUS_SRC_ALPHA:      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_ALPHA;      break;   case GL_DST_COLOR:      current->hwDstSrcBlend |= SiS_S_DST_COLOR;      break;   case GL_ONE_MINUS_DST_COLOR:      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_COLOR;      break;   case GL_DST_ALPHA:      current->hwDstSrcBlend |= SiS_S_DST_ALPHA;      break;   case GL_ONE_MINUS_DST_ALPHA:      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_ALPHA;      break;   case GL_SRC_ALPHA_SATURATE:      current->hwDstSrcBlend |= SiS_S_SRC_ALPHA_SATURATE;      break;   default:      fprintf(stderr, "Unknown src blend function 0x%x\n", sfactorRGB);      break;   }   if (current->hwDstSrcBlend != prev->hwDstSrcBlend) {      prev->hwDstSrcBlend = current->hwDstSrcBlend;      smesa->GlobalFlag |= GFLAG_DSTBLEND;   }}/* ============================================================= * Depth testing */static voidsisDDDepthFunc( GLcontext * ctx, GLenum func ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   __GLSiSHardware *prev = &smesa->prev;   __GLSiSHardware *current = &smesa->current;   current->hwZ &= ~MASK_ZTestMode;   switch (func)   {   case GL_LESS:      current->hwZ |= SiS_Z_COMP_S_LT_B;      break;   case GL_GEQUAL:      current->hwZ |= SiS_Z_COMP_S_GE_B;      break;   case GL_LEQUAL:      current->hwZ |= SiS_Z_COMP_S_LE_B;      break;   case GL_GREATER:      current->hwZ |= SiS_Z_COMP_S_GT_B;      break;   case GL_NOTEQUAL:      current->hwZ |= SiS_Z_COMP_S_NE_B;      break;   case GL_EQUAL:      current->hwZ |= SiS_Z_COMP_S_EQ_B;      break;   case GL_ALWAYS:      current->hwZ |= SiS_Z_COMP_ALWAYS;      break;   case GL_NEVER:      current->hwZ |= SiS_Z_COMP_NEVER;      break;   }   if (current->hwZ != prev->hwZ) {      prev->hwZ = current->hwZ;      smesa->GlobalFlag |= GFLAG_ZSETTING;   }}voidsisDDDepthMask( GLcontext * ctx, GLboolean flag ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   __GLSiSHardware *prev = &smesa->prev;   __GLSiSHardware *current = &smesa->current;   if (!ctx->Depth.Test)      flag = GL_FALSE;   if (ctx->Visual.stencilBits) {      if (flag || (ctx->Stencil.WriteMask[0] != 0)) {         current->hwCapEnable |= MASK_ZWriteEnable;         if (flag && ((ctx->Stencil.WriteMask[0] & 0xff) == 0xff)) {	      current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable;         } else {            current->hwCapEnable2 |= MASK_ZMaskWriteEnable;            current->hwZMask = (ctx->Stencil.WriteMask[0] << 24) |               ((flag) ? 0x00ffffff : 0);            if (current->hwZMask ^ prev->hwZMask) {               prev->hwZMask = current->hwZMask;               smesa->GlobalFlag |= GFLAG_ZSETTING;            }         }      } else {         current->hwCapEnable &= ~MASK_ZWriteEnable;      }   } else {      if (flag) {         current->hwCapEnable |= MASK_ZWriteEnable;         current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable;      } else {         current->hwCapEnable &= ~MASK_ZWriteEnable;      }   }}/* ============================================================= * Clipping */voidsisUpdateClipping( GLcontext *ctx ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   __GLSiSHardware *prev = &smesa->prev;   __GLSiSHardware *current = &smesa->current;   GLint x1, y1, x2, y2;   if (smesa->is6326) {      /* XXX: 6326 has its own clipping for now. Should be fixed */      sis6326UpdateClipping(ctx);      return;   }   x1 = 0;   y1 = 0;   x2 = smesa->width - 1;   y2 = smesa->height - 1;   if (ctx->Scissor.Enabled) {      if (ctx->Scissor.X > x1)         x1 = ctx->Scissor.X;      if (ctx->Scissor.Y > y1)         y1 = ctx->Scissor.Y;      if (ctx->Scissor.X + ctx->Scissor.Width - 1 < x2)         x2 = ctx->Scissor.X + ctx->Scissor.Width - 1;      if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < y2)         y2 = ctx->Scissor.Y + ctx->Scissor.Height - 1;   }   y1 = Y_FLIP(y1);   y2 = Y_FLIP(y2);   current->clipTopBottom = (y2 << 13) | y1;   current->clipLeftRight = (x1 << 13) | x2;   if ((current->clipTopBottom ^ prev->clipTopBottom) ||       (current->clipLeftRight ^ prev->clipLeftRight))   {      prev->clipTopBottom = current->clipTopBottom;      prev->clipLeftRight = current->clipLeftRight;      smesa->GlobalFlag |= GFLAG_CLIPPING;   }}static voidsisDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ){   if (ctx->Scissor.Enabled)      sisUpdateClipping( ctx );}/* ============================================================= * Culling */static voidsisUpdateCull( GLcontext *ctx ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   GLint cullflag, frontface;   cullflag = ctx->Polygon.CullFaceMode;   frontface = ctx->Polygon.FrontFace;   smesa->AGPParseSet &= ~(MASK_PsCullDirection_CCW);   smesa->dwPrimitiveSet &= ~(MASK_CullDirection);   if((cullflag == GL_FRONT && frontface == GL_CCW) ||      (cullflag == GL_BACK && frontface == GL_CW))   {      smesa->AGPParseSet |= MASK_PsCullDirection_CCW;      smesa->dwPrimitiveSet |= OP_3D_CullDirection_CCW;   }}static voidsisDDCullFace( GLcontext *ctx, GLenum mode ){   sisUpdateCull( ctx );}static voidsisDDFrontFace( GLcontext *ctx, GLenum mode ){   sisUpdateCull( ctx );}/* ============================================================= * Masks */static void sisDDColorMask( GLcontext *ctx,			    GLboolean r, GLboolean g,			    GLboolean b, GLboolean a ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   __GLSiSHardware *prev = &smesa->prev;   __GLSiSHardware *current = &smesa->current;   if (r && g && b && ((ctx->Visual.alphaBits == 0) || a)) {      current->hwCapEnable2 &= ~(MASK_AlphaMaskWriteEnable |				 MASK_ColorMaskWriteEnable);   } else {      current->hwCapEnable2 |= (MASK_AlphaMaskWriteEnable |                             MASK_ColorMaskWriteEnable);      current->hwDstMask = (r) ? smesa->redMask : 0 |			   (g) ? smesa->greenMask : 0 |			   (b) ? smesa->blueMask : 0 |			   (a) ? smesa->alphaMask : 0;   }      if (current->hwDstMask != prev->hwDstMask) {      prev->hwDstMask = current->hwDstMask;      smesa->GlobalFlag |= GFLAG_DESTSETTING;   }}/* ============================================================= * Rendering attributes */static void sisUpdateSpecular(GLcontext *ctx){   sisContextPtr smesa = SIS_CONTEXT(ctx);   __GLSiSHardware *current = &smesa->current;   if (NEED_SECONDARY_COLOR(ctx))      current->hwCapEnable |= MASK_SpecularEnable;   else      current->hwCapEnable &= ~MASK_SpecularEnable;}static void sisDDLightModelfv(GLcontext *ctx, GLenum pname,			      const GLfloat *param){   if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {      sisUpdateSpecular(ctx);   }}static void sisDDShadeModel( GLcontext *ctx, GLenum mode ){   sisContextPtr smesa = SIS_CONTEXT(ctx);   /* Signal to sisRasterPrimitive to recalculate dwPrimitiveSet */   smesa->hw_primitive = -1;}

⌨️ 快捷键说明

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