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

📄 s_blend.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
         if (mask[i]) {            rgba[i][RCOMP] = MIN2( rgba[i][RCOMP], dest[i][RCOMP] );            rgba[i][GCOMP] = MIN2( rgba[i][GCOMP], dest[i][GCOMP] );            rgba[i][BCOMP] = MIN2( rgba[i][BCOMP], dest[i][BCOMP] );            rgba[i][ACOMP] = MIN2( rgba[i][ACOMP], dest[i][ACOMP] );         }      }   }   else {      GLfloat (*rgba)[4] = (GLfloat (*)[4]) src;      const GLfloat (*dest)[4] = (const GLfloat (*)[4]) dst;      ASSERT(chanType == GL_FLOAT);      for (i=0;i<n;i++) {         if (mask[i]) {            rgba[i][RCOMP] = MIN2( rgba[i][RCOMP], dest[i][RCOMP] );            rgba[i][GCOMP] = MIN2( rgba[i][GCOMP], dest[i][GCOMP] );            rgba[i][BCOMP] = MIN2( rgba[i][BCOMP], dest[i][BCOMP] );            rgba[i][ACOMP] = MIN2( rgba[i][ACOMP], dest[i][ACOMP] );         }      }   }}/** * Blend max function. * Any chanType ok. */static void _BLENDAPIblend_max(GLcontext *ctx, GLuint n, const GLubyte mask[],          GLvoid *src, const GLvoid *dst, GLenum chanType){   GLuint i;   ASSERT(ctx->Color.BlendEquationRGB == GL_MAX);   ASSERT(ctx->Color.BlendEquationA == GL_MAX);   (void) ctx;   if (chanType == GL_UNSIGNED_BYTE) {      GLubyte (*rgba)[4] = (GLubyte (*)[4]) src;      const GLubyte (*dest)[4] = (const GLubyte (*)[4]) dst;      for (i=0;i<n;i++) {         if (mask[i]) {            rgba[i][RCOMP] = MAX2( rgba[i][RCOMP], dest[i][RCOMP] );            rgba[i][GCOMP] = MAX2( rgba[i][GCOMP], dest[i][GCOMP] );            rgba[i][BCOMP] = MAX2( rgba[i][BCOMP], dest[i][BCOMP] );            rgba[i][ACOMP] = MAX2( rgba[i][ACOMP], dest[i][ACOMP] );         }      }   }   else if (chanType == GL_UNSIGNED_SHORT) {      GLushort (*rgba)[4] = (GLushort (*)[4]) src;      const GLushort (*dest)[4] = (const GLushort (*)[4]) dst;      for (i=0;i<n;i++) {         if (mask[i]) {            rgba[i][RCOMP] = MAX2( rgba[i][RCOMP], dest[i][RCOMP] );            rgba[i][GCOMP] = MAX2( rgba[i][GCOMP], dest[i][GCOMP] );            rgba[i][BCOMP] = MAX2( rgba[i][BCOMP], dest[i][BCOMP] );            rgba[i][ACOMP] = MAX2( rgba[i][ACOMP], dest[i][ACOMP] );         }      }   }   else {      GLfloat (*rgba)[4] = (GLfloat (*)[4]) src;      const GLfloat (*dest)[4] = (const GLfloat (*)[4]) dst;      ASSERT(chanType == GL_FLOAT);      for (i=0;i<n;i++) {         if (mask[i]) {            rgba[i][RCOMP] = MAX2( rgba[i][RCOMP], dest[i][RCOMP] );            rgba[i][GCOMP] = MAX2( rgba[i][GCOMP], dest[i][GCOMP] );            rgba[i][BCOMP] = MAX2( rgba[i][BCOMP], dest[i][BCOMP] );            rgba[i][ACOMP] = MAX2( rgba[i][ACOMP], dest[i][ACOMP] );         }      }   }}/** * Modulate:  result = src * dest * Any chanType ok. */static void _BLENDAPIblend_modulate(GLcontext *ctx, GLuint n, const GLubyte mask[],               GLvoid *src, const GLvoid *dst, GLenum chanType){   GLuint i;   (void) ctx;   if (chanType == GL_UNSIGNED_BYTE) {      GLubyte (*rgba)[4] = (GLubyte (*)[4]) src;      const GLubyte (*dest)[4] = (const GLubyte (*)[4]) dst;      for (i=0;i<n;i++) {         if (mask[i]) {	    GLint divtemp;            rgba[i][RCOMP] = DIV255(rgba[i][RCOMP] * dest[i][RCOMP]);            rgba[i][GCOMP] = DIV255(rgba[i][GCOMP] * dest[i][GCOMP]);            rgba[i][BCOMP] = DIV255(rgba[i][BCOMP] * dest[i][BCOMP]);            rgba[i][ACOMP] = DIV255(rgba[i][ACOMP] * dest[i][ACOMP]);         }      }   }   else if (chanType == GL_UNSIGNED_SHORT) {      GLushort (*rgba)[4] = (GLushort (*)[4]) src;      const GLushort (*dest)[4] = (const GLushort (*)[4]) dst;      for (i=0;i<n;i++) {         if (mask[i]) {            rgba[i][RCOMP] = (rgba[i][RCOMP] * dest[i][RCOMP] + 65535) >> 16;            rgba[i][GCOMP] = (rgba[i][GCOMP] * dest[i][GCOMP] + 65535) >> 16;            rgba[i][BCOMP] = (rgba[i][BCOMP] * dest[i][BCOMP] + 65535) >> 16;            rgba[i][ACOMP] = (rgba[i][ACOMP] * dest[i][ACOMP] + 65535) >> 16;         }      }   }   else {      GLfloat (*rgba)[4] = (GLfloat (*)[4]) src;      const GLfloat (*dest)[4] = (const GLfloat (*)[4]) dst;      ASSERT(chanType == GL_FLOAT);      for (i=0;i<n;i++) {         if (mask[i]) {            rgba[i][RCOMP] = rgba[i][RCOMP] * dest[i][RCOMP];            rgba[i][GCOMP] = rgba[i][GCOMP] * dest[i][GCOMP];            rgba[i][BCOMP] = rgba[i][BCOMP] * dest[i][BCOMP];            rgba[i][ACOMP] = rgba[i][ACOMP] * dest[i][ACOMP];         }      }   }}/** * Do any blending operation, using floating point. * \param n  number of pixels * \param mask  fragment writemask array * \param rgba  array of incoming (and modified) pixels * \param dest  array of pixels from the dest color buffer */static voidblend_general_float(GLcontext *ctx, GLuint n, const GLubyte mask[],                    GLfloat rgba[][4], GLfloat dest[][4],                    GLenum chanType){   GLuint i;   for (i = 0; i < n; i++) {      if (mask[i]) {         /* Incoming/source Color */         const GLfloat Rs = rgba[i][RCOMP];         const GLfloat Gs = rgba[i][GCOMP];         const GLfloat Bs = rgba[i][BCOMP];         const GLfloat As = rgba[i][ACOMP];         /* Frame buffer/dest color */         const GLfloat Rd = dest[i][RCOMP];         const GLfloat Gd = dest[i][GCOMP];         const GLfloat Bd = dest[i][BCOMP];         const GLfloat Ad = dest[i][ACOMP];         GLfloat sR, sG, sB, sA;  /* Source factor */         GLfloat dR, dG, dB, dA;  /* Dest factor */         GLfloat r, g, b, a;      /* result color */         /* XXX for the case of constant blend terms we could init          * the sX and dX variables just once before the loop.          */         /* Source RGB factor */         switch (ctx->Color.BlendSrcRGB) {            case GL_ZERO:               sR = sG = sB = 0.0F;               break;            case GL_ONE:               sR = sG = sB = 1.0F;               break;            case GL_DST_COLOR:               sR = Rd;               sG = Gd;               sB = Bd;               break;            case GL_ONE_MINUS_DST_COLOR:               sR = 1.0F - Rd;               sG = 1.0F - Gd;               sB = 1.0F - Bd;               break;            case GL_SRC_ALPHA:               sR = sG = sB = As;               break;            case GL_ONE_MINUS_SRC_ALPHA:               sR = sG = sB = 1.0F - As;               break;            case GL_DST_ALPHA:               sR = sG = sB = Ad;               break;            case GL_ONE_MINUS_DST_ALPHA:               sR = sG = sB = 1.0F - Ad;               break;            case GL_SRC_ALPHA_SATURATE:               if (As < 1.0F - Ad) {                  sR = sG = sB = As;               }               else {                  sR = sG = sB = 1.0F - Ad;               }               break;            case GL_CONSTANT_COLOR:               sR = ctx->Color.BlendColor[0];               sG = ctx->Color.BlendColor[1];               sB = ctx->Color.BlendColor[2];               break;            case GL_ONE_MINUS_CONSTANT_COLOR:               sR = 1.0F - ctx->Color.BlendColor[0];               sG = 1.0F - ctx->Color.BlendColor[1];               sB = 1.0F - ctx->Color.BlendColor[2];               break;            case GL_CONSTANT_ALPHA:               sR = sG = sB = ctx->Color.BlendColor[3];               break;            case GL_ONE_MINUS_CONSTANT_ALPHA:               sR = sG = sB = 1.0F - ctx->Color.BlendColor[3];               break;            case GL_SRC_COLOR:               sR = Rs;               sG = Gs;               sB = Bs;               break;            case GL_ONE_MINUS_SRC_COLOR:               sR = 1.0F - Rs;               sG = 1.0F - Gs;               sB = 1.0F - Bs;               break;            default:               /* this should never happen */               _mesa_problem(ctx, "Bad blend source RGB factor in blend_general_float");               return;         }         /* Source Alpha factor */         switch (ctx->Color.BlendSrcA) {            case GL_ZERO:               sA = 0.0F;               break;            case GL_ONE:               sA = 1.0F;               break;            case GL_DST_COLOR:               sA = Ad;               break;            case GL_ONE_MINUS_DST_COLOR:               sA = 1.0F - Ad;               break;            case GL_SRC_ALPHA:               sA = As;               break;            case GL_ONE_MINUS_SRC_ALPHA:               sA = 1.0F - As;               break;            case GL_DST_ALPHA:               sA = Ad;               break;            case GL_ONE_MINUS_DST_ALPHA:               sA = 1.0F - Ad;               break;            case GL_SRC_ALPHA_SATURATE:               sA = 1.0;               break;            case GL_CONSTANT_COLOR:               sA = ctx->Color.BlendColor[3];               break;            case GL_ONE_MINUS_CONSTANT_COLOR:               sA = 1.0F - ctx->Color.BlendColor[3];               break;            case GL_CONSTANT_ALPHA:               sA = ctx->Color.BlendColor[3];               break;            case GL_ONE_MINUS_CONSTANT_ALPHA:               sA = 1.0F - ctx->Color.BlendColor[3];               break;            case GL_SRC_COLOR:               sA = As;               break;            case GL_ONE_MINUS_SRC_COLOR:               sA = 1.0F - As;               break;            default:               /* this should never happen */               sA = 0.0F;               _mesa_problem(ctx, "Bad blend source A factor in blend_general_float");               return;         }         /* Dest RGB factor */         switch (ctx->Color.BlendDstRGB) {            case GL_ZERO:               dR = dG = dB = 0.0F;               break;            case GL_ONE:               dR = dG = dB = 1.0F;               break;            case GL_SRC_COLOR:               dR = Rs;               dG = Gs;               dB = Bs;               break;            case GL_ONE_MINUS_SRC_COLOR:               dR = 1.0F - Rs;               dG = 1.0F - Gs;               dB = 1.0F - Bs;               break;            case GL_SRC_ALPHA:               dR = dG = dB = As;               break;            case GL_ONE_MINUS_SRC_ALPHA:               dR = dG = dB = 1.0F - As;               break;            case GL_DST_ALPHA:               dR = dG = dB = Ad;               break;            case GL_ONE_MINUS_DST_ALPHA:               dR = dG = dB = 1.0F - Ad;               break;            case GL_CONSTANT_COLOR:               dR = ctx->Color.BlendColor[0];               dG = ctx->Color.BlendColor[1];               dB = ctx->Color.BlendColor[2];               break;            case GL_ONE_MINUS_CONSTANT_COLOR:               dR = 1.0F - ctx->Color.BlendColor[0];               dG = 1.0F - ctx->Color.BlendColor[1];               dB = 1.0F - ctx->Color.BlendColor[2];               break;            case GL_CONSTANT_ALPHA:               dR = dG = dB = ctx->Color.BlendColor[3];               break;            case GL_ONE_MINUS_CONSTANT_ALPHA:               dR = dG = dB = 1.0F - ctx->Color.BlendColor[3];

⌨️ 快捷键说明

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