Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygens_alpha.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 6.5.2 00004 * 00005 * Copyright (C) 1999-2006 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 00030 #include "main/glheader.h" 00031 #include "main/context.h" 00032 #include "main/colormac.h" 00033 #include "main/macros.h" 00034 00035 #include "s_alpha.h" 00036 #include "s_context.h" 00037 00038 00039 #define ALPHA_TEST(ALPHA, LOOP_CODE) \ 00040 do { \ 00041 switch (ctx->Color.AlphaFunc) { \ 00042 case GL_LESS: \ 00043 for (i = 0; i < n; i++) { \ 00044 mask[i] &= (ALPHA < ref); \ 00045 LOOP_CODE; \ 00046 } \ 00047 break; \ 00048 case GL_LEQUAL: \ 00049 for (i = 0; i < n; i++) { \ 00050 mask[i] &= (ALPHA <= ref); \ 00051 LOOP_CODE; \ 00052 } \ 00053 break; \ 00054 case GL_GEQUAL: \ 00055 for (i = 0; i < n; i++) { \ 00056 mask[i] &= (ALPHA >= ref); \ 00057 LOOP_CODE; \ 00058 } \ 00059 break; \ 00060 case GL_GREATER: \ 00061 for (i = 0; i < n; i++) { \ 00062 mask[i] &= (ALPHA > ref); \ 00063 LOOP_CODE; \ 00064 } \ 00065 break; \ 00066 case GL_NOTEQUAL: \ 00067 for (i = 0; i < n; i++) { \ 00068 mask[i] &= (ALPHA != ref); \ 00069 LOOP_CODE; \ 00070 } \ 00071 break; \ 00072 case GL_EQUAL: \ 00073 for (i = 0; i < n; i++) { \ 00074 mask[i] &= (ALPHA == ref); \ 00075 LOOP_CODE; \ 00076 } \ 00077 break; \ 00078 default: \ 00079 _mesa_problem(ctx, "Invalid alpha test in _swrast_alpha_test" ); \ 00080 return 0; \ 00081 } \ 00082 } while (0) 00083 00084 00085 00092 GLint 00093 _swrast_alpha_test(const GLcontext *ctx, SWspan *span) 00094 { 00095 const GLuint n = span->end; 00096 GLubyte *mask = span->array->mask; 00097 GLuint i; 00098 00099 if (ctx->Color.AlphaFunc == GL_ALWAYS) { 00100 /* do nothing */ 00101 return 1; 00102 } 00103 else if (ctx->Color.AlphaFunc == GL_NEVER) { 00104 /* All pixels failed - caller should check for this return value and 00105 * act accordingly. 00106 */ 00107 span->writeAll = GL_FALSE; 00108 return 0; 00109 } 00110 00111 if (span->arrayMask & SPAN_RGBA) { 00112 /* Use array's alpha values */ 00113 if (span->array->ChanType == GL_UNSIGNED_BYTE) { 00114 GLubyte (*rgba)[4] = span->array->rgba8; 00115 GLubyte ref; 00116 CLAMPED_FLOAT_TO_UBYTE(ref, ctx->Color.AlphaRef); 00117 ALPHA_TEST(rgba[i][ACOMP], ;); 00118 } 00119 else if (span->array->ChanType == GL_UNSIGNED_SHORT) { 00120 GLushort (*rgba)[4] = span->array->rgba16; 00121 GLushort ref; 00122 CLAMPED_FLOAT_TO_USHORT(ref, ctx->Color.AlphaRef); 00123 ALPHA_TEST(rgba[i][ACOMP], ;); 00124 } 00125 else { 00126 GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0]; 00127 const GLfloat ref = ctx->Color.AlphaRef; 00128 ALPHA_TEST(rgba[i][ACOMP], ;); 00129 } 00130 } 00131 else { 00132 /* Interpolate alpha values */ 00133 ASSERT(span->interpMask & SPAN_RGBA); 00134 if (span->array->ChanType == GL_UNSIGNED_BYTE) { 00135 const GLfixed alphaStep = span->alphaStep; 00136 GLfixed alpha = span->alpha; 00137 GLubyte ref; 00138 CLAMPED_FLOAT_TO_UBYTE(ref, ctx->Color.AlphaRef); 00139 ALPHA_TEST(FixedToInt(alpha), alpha += alphaStep); 00140 } 00141 else if (span->array->ChanType == GL_UNSIGNED_SHORT) { 00142 const GLfixed alphaStep = span->alphaStep; 00143 GLfixed alpha = span->alpha; 00144 GLushort ref; 00145 CLAMPED_FLOAT_TO_USHORT(ref, ctx->Color.AlphaRef); 00146 ALPHA_TEST(FixedToInt(alpha), alpha += alphaStep); 00147 } 00148 else { 00149 const GLfloat alphaStep = span->alphaStep; 00150 GLfloat alpha = span->alpha; 00151 const GLfloat ref = ctx->Color.AlphaRef; 00152 ALPHA_TEST(alpha, alpha += alphaStep); 00153 } 00154 } 00155 00156 span->writeAll = GL_FALSE; 00157 00158 /* XXX examine mask[] values? */ 00159 return 1; 00160 } Generated on Sat May 26 2012 04:19:30 for ReactOS by
1.7.6.1
|