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

📄 i915_texprog.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************** *  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. *  * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: *  * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *  **************************************************************************/#include <strings.h>#include "glheader.h"#include "macros.h"#include "enums.h"#include "tnl/t_context.h"#include "intel_batchbuffer.h"#include "i915_reg.h"#include "i915_context.h"#include "i915_program.h"static GLuint translate_tex_src_bit( struct i915_fragment_program *p,				     GLubyte bit ){   switch (bit) {   case TEXTURE_1D_BIT:   return D0_SAMPLE_TYPE_2D;   case TEXTURE_2D_BIT:   return D0_SAMPLE_TYPE_2D;   case TEXTURE_RECT_BIT: return D0_SAMPLE_TYPE_2D;   case TEXTURE_3D_BIT:   return D0_SAMPLE_TYPE_VOLUME;   case TEXTURE_CUBE_BIT: return D0_SAMPLE_TYPE_CUBE;   default: i915_program_error(p, "TexSrcBit"); return 0;   }}static GLuint get_source( struct i915_fragment_program *p, 			  GLenum src, GLuint unit ){   switch (src) {   case GL_TEXTURE:       if (p->src_texture == UREG_BAD) {	 /* TODO: Use D0_CHANNEL_XY where possible.	  */	 GLuint dim = translate_tex_src_bit( p, p->ctx->Texture.Unit[unit]._ReallyEnabled);	 GLuint sampler = i915_emit_decl(p, REG_TYPE_S, unit, dim);	 GLuint texcoord = i915_emit_decl(p, REG_TYPE_T, unit, D0_CHANNEL_ALL);	 GLuint tmp = i915_get_temp( p );	 GLuint op = T0_TEXLD;	 if (p->VB->TexCoordPtr[unit]->size == 4)	    op = T0_TEXLDP;	 p->src_texture = i915_emit_texld( p, tmp, A0_DEST_CHANNEL_ALL, 					  sampler, texcoord, op );      }      return p->src_texture;      /* Crossbar: */   case GL_TEXTURE0:   case GL_TEXTURE1:   case GL_TEXTURE2:   case GL_TEXTURE3:   case GL_TEXTURE4:   case GL_TEXTURE5:   case GL_TEXTURE6:   case GL_TEXTURE7: {      return UREG_BAD;   }   case GL_CONSTANT:      return i915_emit_const4fv( p, p->ctx->Texture.Unit[unit].EnvColor );   case GL_PRIMARY_COLOR:      return i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL);   case GL_PREVIOUS:   default:       i915_emit_decl(p, 		GET_UREG_TYPE(p->src_previous),		GET_UREG_NR(p->src_previous), D0_CHANNEL_ALL);       return p->src_previous;   }}			static GLuint emit_combine_source( struct i915_fragment_program *p, 				   GLuint mask,				   GLuint unit,				   GLenum source, 				   GLenum operand ){   GLuint arg, src;   src = get_source(p, source, unit);   switch (operand) {   case GL_ONE_MINUS_SRC_COLOR:       /* Get unused tmp,       * Emit tmp = 1.0 + arg.-x-y-z-w       */      arg = i915_get_temp( p );      return i915_emit_arith( p, A0_ADD, arg, mask, 0,		  swizzle(src, ONE, ONE, ONE, ONE ),		  negate(src, 1,1,1,1), 0);   case GL_SRC_ALPHA:       if (mask == A0_DEST_CHANNEL_W)	 return src;      else	 return swizzle( src, W, W, W, W );   case GL_ONE_MINUS_SRC_ALPHA:       /* Get unused tmp,       * Emit tmp = 1.0 + arg.-w-w-w-w       */      arg = i915_get_temp( p );      return i915_emit_arith( p, A0_ADD, arg, mask, 0,			 swizzle(src, ONE, ONE, ONE, ONE ),			 negate( swizzle(src,W,W,W,W), 1,1,1,1), 0);   case GL_SRC_COLOR:    default:      return src;   }}static int nr_args( GLenum mode ){   switch (mode) {   case GL_REPLACE: return 1;    case GL_MODULATE: return 2;   case GL_ADD: return 2;   case GL_ADD_SIGNED: return 2;   case GL_INTERPOLATE:	return 3;   case GL_SUBTRACT: return 2;   case GL_DOT3_RGB_EXT: return 2;   case GL_DOT3_RGBA_EXT: return 2;   case GL_DOT3_RGB: return 2;   case GL_DOT3_RGBA: return 2;   default: return 0;   }}static GLboolean args_match( struct gl_texture_unit *texUnit ){   int i, nr = nr_args(texUnit->Combine.ModeRGB);   for (i = 0 ; i < nr ; i++) {      if (texUnit->Combine.SourceA[i] != texUnit->Combine.SourceRGB[i]) 	 return GL_FALSE;      switch(texUnit->Combine.OperandA[i]) {      case GL_SRC_ALPHA: 	 switch(texUnit->Combine.OperandRGB[i]) {	 case GL_SRC_COLOR: 	 case GL_SRC_ALPHA: 	    break;	 default:	    return GL_FALSE;	 }	 break;      case GL_ONE_MINUS_SRC_ALPHA: 	 switch(texUnit->Combine.OperandRGB[i]) {	 case GL_ONE_MINUS_SRC_COLOR: 	 case GL_ONE_MINUS_SRC_ALPHA: 	    break;	 default:	    return GL_FALSE;	 }	 break;      default: 	 return GL_FALSE;	/* impossible */      }   }   return GL_TRUE;}static GLuint emit_combine( struct i915_fragment_program *p,			    GLuint dest,			    GLuint mask,			    GLuint saturate,			    GLuint unit,			    GLenum mode,			    const GLenum *source,			    const GLenum *operand){   int tmp, src[3], nr = nr_args(mode);   int i;   for (i = 0; i < nr; i++)      src[i] = emit_combine_source( p, mask, unit, source[i], operand[i] );   switch (mode) {   case GL_REPLACE:       if (mask == A0_DEST_CHANNEL_ALL && !saturate)	 return src[0];      else	 return i915_emit_arith( p, A0_MOV, dest, mask, saturate, src[0], 0, 0 );   case GL_MODULATE:       return i915_emit_arith( p, A0_MUL, dest, mask, saturate,			     src[0], src[1], 0 );   case GL_ADD:       return i915_emit_arith( p, A0_ADD, dest, mask, saturate, 			     src[0], src[1], 0 );   case GL_ADD_SIGNED:      /* tmp = arg0 + arg1       * result = tmp + -.5       */      tmp = i915_emit_const1f(p, .5);      tmp = negate(swizzle(tmp,X,X,X,X),1,1,1,1);      i915_emit_arith( p, A0_ADD, dest, mask, 0, src[0], src[1], 0 );      i915_emit_arith( p, A0_ADD, dest, mask, saturate, dest, tmp, 0 );      return dest;   case GL_INTERPOLATE:		/* TWO INSTRUCTIONS */      /* Arg0 * (Arg2) + Arg1 * (1-Arg2)       *       * Arg0*Arg2 + Arg1 - Arg1Arg2        *       * tmp = Arg0*Arg2 + Arg1,        * result = (-Arg1)Arg2 + tmp        */      tmp = i915_get_temp( p );      i915_emit_arith( p, A0_MAD, tmp, mask, 0, src[0], src[2], src[1] );      i915_emit_arith( p, A0_MAD, dest, mask, saturate, 		      negate(src[1], 1,1,1,1), src[2], tmp );      return dest;   case GL_SUBTRACT:       /* negate src[1] */      return i915_emit_arith( p, A0_ADD, dest, mask, saturate, src[0],			 negate(src[1],1,1,1,1), 0 );   case GL_DOT3_RGBA:   case GL_DOT3_RGBA_EXT:    case GL_DOT3_RGB_EXT:   case GL_DOT3_RGB: {      GLuint tmp0 = i915_get_temp( p );      GLuint tmp1 = i915_get_temp( p );      GLuint neg1 = negate(swizzle(i915_emit_const1f(p, 1),X,X,X,X), 1,1,1,1);      GLuint two = swizzle(i915_emit_const1f(p, 2),X,X,X,X);      i915_emit_arith( p, A0_MAD, tmp0, A0_DEST_CHANNEL_ALL, 0, 		      two, src[0], neg1);      if (src[0] == src[1])	 tmp1 = tmp0;      else	 i915_emit_arith( p, A0_MAD, tmp1, A0_DEST_CHANNEL_ALL, 0, 			 two, src[1], neg1);      i915_emit_arith( p, A0_DP3, dest, mask, saturate, tmp0, tmp1, 0);      return dest;   }   default:       return src[0];   }}static GLuint get_dest( struct i915_fragment_program *p, int unit ){   if (p->ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)      return i915_get_temp( p );   else if (unit != p->last_tex_stage)      return i915_get_temp( p );   else      return UREG(REG_TYPE_OC, 0);}      static GLuint emit_texenv( struct i915_fragment_program *p, int unit ){   struct gl_texture_unit *texUnit = &p->ctx->Texture.Unit[unit];   GLenum envMode = texUnit->EnvMode;   struct gl_texture_object *tObj = texUnit->_Current;   GLenum format = tObj->Image[0][tObj->BaseLevel]->_BaseFormat;   GLuint saturate = unit < p->last_tex_stage ? A0_DEST_SATURATE : 0;   switch(envMode) {   case GL_BLEND: {      const int cf = get_source(p, GL_PREVIOUS, unit);      const int cc = get_source(p, GL_CONSTANT, unit);      const int cs = get_source(p, GL_TEXTURE, unit);      const int out = get_dest(p, unit);      if (format == GL_INTENSITY) {	 /* cv = cf(1 - cs) + cc.cs	  * cv = cf - cf.cs + cc.cs	  */	 /* u[2] = MAD( -cf * cs + cf )	  * cv   = MAD( cc * cs + u[2] )	  */	 	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0, 			 negate(cf,1,1,1,1), cs, cf );	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, 			 cc, cs, out );	 return out;      } else {	 /* cv = cf(1 - cs) + cc.cs	  * cv = cf - cf.cs + cc.cs	  * av =      af.as	  */	 /* u[2] = MAD( cf.-x-y-zw * cs.xyzw + cf.xyz0 )	  * oC   = MAD( cc.xyz0 * cs.xyz0 + u[2].xyzw )	  */	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0,			 negate(cf,1,1,1,0),  			 cs,			 swizzle(cf,X,Y,Z,ZERO) );	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate,			 swizzle(cc,X,Y,Z,ZERO),  			 swizzle(cs,X,Y,Z,ZERO),			 out );

⌨️ 快捷键说明

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