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

📄 r200_texstate.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
   return ok;}#undef REF_COLOR#undef REF_ALPHA#define TEXOBJ_TXFILTER_MASK (R200_MAX_MIP_LEVEL_MASK |		\			      R200_MIN_FILTER_MASK | 		\			      R200_MAG_FILTER_MASK |		\			      R200_MAX_ANISO_MASK |		\			      R200_YUV_TO_RGB |			\			      R200_YUV_TEMPERATURE_MASK |	\			      R200_CLAMP_S_MASK | 		\			      R200_CLAMP_T_MASK | 		\			      R200_BORDER_MODE_D3D )#define TEXOBJ_TXFORMAT_MASK (R200_TXFORMAT_WIDTH_MASK |	\			      R200_TXFORMAT_HEIGHT_MASK |	\			      R200_TXFORMAT_FORMAT_MASK |	\			      R200_TXFORMAT_F5_WIDTH_MASK |	\			      R200_TXFORMAT_F5_HEIGHT_MASK |	\			      R200_TXFORMAT_ALPHA_IN_MAP |	\			      R200_TXFORMAT_CUBIC_MAP_ENABLE |	\			      R200_TXFORMAT_NON_POWER2)#define TEXOBJ_TXFORMAT_X_MASK (R200_DEPTH_LOG2_MASK |		\                                R200_TEXCOORD_MASK |		\                                R200_CLAMP_Q_MASK | 		\                                R200_VOLUME_FILTER_MASK)static void import_tex_obj_state( r200ContextPtr rmesa,				  int unit,				  r200TexObjPtr texobj ){/* do not use RADEON_DB_STATE to avoid stale texture caches */   int *cmd = &rmesa->hw.tex[unit].cmd[TEX_CMD_0];   R200_STATECHANGE( rmesa, tex[unit] );   cmd[TEX_PP_TXFILTER] &= ~TEXOBJ_TXFILTER_MASK;   cmd[TEX_PP_TXFILTER] |= texobj->pp_txfilter & TEXOBJ_TXFILTER_MASK;   cmd[TEX_PP_TXFORMAT] &= ~TEXOBJ_TXFORMAT_MASK;   cmd[TEX_PP_TXFORMAT] |= texobj->pp_txformat & TEXOBJ_TXFORMAT_MASK;   cmd[TEX_PP_TXFORMAT_X] &= ~TEXOBJ_TXFORMAT_X_MASK;   cmd[TEX_PP_TXFORMAT_X] |= texobj->pp_txformat_x & TEXOBJ_TXFORMAT_X_MASK;   cmd[TEX_PP_TXSIZE] = texobj->pp_txsize; /* NPOT only! */   cmd[TEX_PP_TXPITCH] = texobj->pp_txpitch; /* NPOT only! */   cmd[TEX_PP_BORDER_COLOR] = texobj->pp_border_color;   if (rmesa->r200Screen->drmSupportsFragShader) {      cmd[TEX_PP_TXOFFSET_NEWDRM] = texobj->pp_txoffset;   }   else {      cmd[TEX_PP_TXOFFSET_OLDDRM] = texobj->pp_txoffset;   }   if (texobj->base.tObj->Target == GL_TEXTURE_CUBE_MAP) {      int *cube_cmd = &rmesa->hw.cube[unit].cmd[CUBE_CMD_0];      GLuint bytesPerFace = texobj->base.totalSize / 6;      ASSERT(texobj->base.totalSize % 6 == 0);      R200_STATECHANGE( rmesa, cube[unit] );      cube_cmd[CUBE_PP_CUBIC_FACES] = texobj->pp_cubic_faces;      if (rmesa->r200Screen->drmSupportsFragShader) {	 /* that value is submitted twice. could change cube atom	    to not include that command when new drm is used */	 cmd[TEX_PP_CUBIC_FACES] = texobj->pp_cubic_faces;      }      cube_cmd[CUBE_PP_CUBIC_OFFSET_F1] = texobj->pp_txoffset + 1 * bytesPerFace;      cube_cmd[CUBE_PP_CUBIC_OFFSET_F2] = texobj->pp_txoffset + 2 * bytesPerFace;      cube_cmd[CUBE_PP_CUBIC_OFFSET_F3] = texobj->pp_txoffset + 3 * bytesPerFace;      cube_cmd[CUBE_PP_CUBIC_OFFSET_F4] = texobj->pp_txoffset + 4 * bytesPerFace;      cube_cmd[CUBE_PP_CUBIC_OFFSET_F5] = texobj->pp_txoffset + 5 * bytesPerFace;   }   texobj->dirty_state &= ~(1<<unit);}static void set_texgen_matrix( r200ContextPtr rmesa, 			       GLuint unit,			       const GLfloat *s_plane,			       const GLfloat *t_plane,			       const GLfloat *r_plane,			       const GLfloat *q_plane ){   GLfloat m[16];   m[0]  = s_plane[0];   m[4]  = s_plane[1];   m[8]  = s_plane[2];   m[12] = s_plane[3];   m[1]  = t_plane[0];   m[5]  = t_plane[1];   m[9]  = t_plane[2];   m[13] = t_plane[3];   m[2]  = r_plane[0];   m[6]  = r_plane[1];   m[10] = r_plane[2];   m[14] = r_plane[3];   m[3]  = q_plane[0];   m[7]  = q_plane[1];   m[11] = q_plane[2];   m[15] = q_plane[3];   _math_matrix_loadf( &(rmesa->TexGenMatrix[unit]), m);   _math_matrix_analyse( &(rmesa->TexGenMatrix[unit]) );   rmesa->TexGenEnabled |= R200_TEXMAT_0_ENABLE<<unit;}static GLuint r200_need_dis_texgen(const GLbitfield texGenEnabled,				   const GLfloat *planeS,				   const GLfloat *planeT,				   const GLfloat *planeR,				   const GLfloat *planeQ){   GLuint needtgenable = 0;   if (!(texGenEnabled & S_BIT)) {      if (((texGenEnabled & T_BIT) && planeT[0] != 0.0) ||	 ((texGenEnabled & R_BIT) && planeR[0] != 0.0) ||	 ((texGenEnabled & Q_BIT) && planeQ[0] != 0.0)) {	 needtgenable |= S_BIT;      }   }   if (!(texGenEnabled & T_BIT)) {      if (((texGenEnabled & S_BIT) && planeS[1] != 0.0) ||	 ((texGenEnabled & R_BIT) && planeR[1] != 0.0) ||	 ((texGenEnabled & Q_BIT) && planeQ[1] != 0.0)) {	 needtgenable |= T_BIT;     }   }   if (!(texGenEnabled & R_BIT)) {      if (((texGenEnabled & S_BIT) && planeS[2] != 0.0) ||	 ((texGenEnabled & T_BIT) && planeT[2] != 0.0) ||	 ((texGenEnabled & Q_BIT) && planeQ[2] != 0.0)) {	 needtgenable |= R_BIT;      }   }   if (!(texGenEnabled & Q_BIT)) {      if (((texGenEnabled & S_BIT) && planeS[3] != 0.0) ||	 ((texGenEnabled & T_BIT) && planeT[3] != 0.0) ||	 ((texGenEnabled & R_BIT) && planeR[3] != 0.0)) {	 needtgenable |= Q_BIT;      }   }   return needtgenable;}/* * Returns GL_FALSE if fallback required.   */static GLboolean r200_validate_texgen( GLcontext *ctx, GLuint unit ){     r200ContextPtr rmesa = R200_CONTEXT(ctx);   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];   GLuint inputshift = R200_TEXGEN_0_INPUT_SHIFT + unit*4;   GLuint tgi, tgcm;   GLuint mode = 0;   GLboolean mixed_fallback = GL_FALSE;   static const GLfloat I[16] = {      1,  0,  0,  0,      0,  1,  0,  0,      0,  0,  1,  0,      0,  0,  0,  1 };   static const GLfloat reflect[16] = {      -1,  0,  0,  0,       0, -1,  0,  0,       0,  0,  -1, 0,       0,  0,  0,  1 };   rmesa->TexGenCompSel &= ~(R200_OUTPUT_TEX_0 << unit);   rmesa->TexGenEnabled &= ~(R200_TEXGEN_TEXMAT_0_ENABLE<<unit);   rmesa->TexGenEnabled &= ~(R200_TEXMAT_0_ENABLE<<unit);   rmesa->TexGenNeedNormals[unit] = GL_FALSE;   tgi = rmesa->hw.tcg.cmd[TCG_TEX_PROC_CTL_1] & ~(R200_TEXGEN_INPUT_MASK <<						   inputshift);   tgcm = rmesa->hw.tcg.cmd[TCG_TEX_PROC_CTL_2] & ~(R200_TEXGEN_COMP_MASK <<						    (unit * 4));   if (0)       fprintf(stderr, "%s unit %d\n", __FUNCTION__, unit);   if (texUnit->TexGenEnabled & S_BIT) {      mode = texUnit->GenModeS;   } else {      tgcm |= R200_TEXGEN_COMP_S << (unit * 4);   }   if (texUnit->TexGenEnabled & T_BIT) {      if (texUnit->GenModeT != mode)	 mixed_fallback = GL_TRUE;   } else {      tgcm |= R200_TEXGEN_COMP_T << (unit * 4);   }   if (texUnit->TexGenEnabled & R_BIT) {      if (texUnit->GenModeR != mode)	 mixed_fallback = GL_TRUE;   } else {      tgcm |= R200_TEXGEN_COMP_R << (unit * 4);   }   if (texUnit->TexGenEnabled & Q_BIT) {      if (texUnit->GenModeQ != mode)	 mixed_fallback = GL_TRUE;   } else {      tgcm |= R200_TEXGEN_COMP_Q << (unit * 4);   }   if (mixed_fallback) {      if (R200_DEBUG & DEBUG_FALLBACKS)	 fprintf(stderr, "fallback mixed texgen, 0x%x (0x%x 0x%x 0x%x 0x%x)\n",		 texUnit->TexGenEnabled, texUnit->GenModeS, texUnit->GenModeT,		 texUnit->GenModeR, texUnit->GenModeQ);      return GL_FALSE;   }/* we CANNOT do mixed mode if the texgen mode requires a plane where the input   is not enabled for texgen, since the planes are concatenated into texmat,   and thus the input will come from texcoord rather than tex gen equation!   Either fallback or just hope that those texcoords aren't really needed...   Assuming the former will cause lots of unnecessary fallbacks, the latter will   generate bogus results sometimes - it's pretty much impossible to really know   when a fallback is needed, depends on texmat and what sort of texture is bound   etc, - for now fallback if we're missing either S or T bits, there's a high   probability we need the texcoords in that case.   That's a lot of work for some obscure texgen mixed mode fixup - why oh why   doesn't the chip just directly accept the plane parameters :-(. */   switch (mode) {   case GL_OBJECT_LINEAR: {      GLuint needtgenable = r200_need_dis_texgen( texUnit->TexGenEnabled,				texUnit->ObjectPlaneS, texUnit->ObjectPlaneT,				texUnit->ObjectPlaneR, texUnit->ObjectPlaneQ );      if (needtgenable & (S_BIT | T_BIT)) {	 if (R200_DEBUG & DEBUG_FALLBACKS)	 fprintf(stderr, "fallback mixed texgen / obj plane, 0x%x\n",		 texUnit->TexGenEnabled);	 return GL_FALSE;      }      if (needtgenable & (R_BIT)) {	 tgcm &= ~(R200_TEXGEN_COMP_R << (unit * 4));      }      if (needtgenable & (Q_BIT)) {	 tgcm &= ~(R200_TEXGEN_COMP_Q << (unit * 4));      }      tgi |= R200_TEXGEN_INPUT_OBJ << inputshift;      set_texgen_matrix( rmesa, unit, 	 (texUnit->TexGenEnabled & S_BIT) ? texUnit->ObjectPlaneS : I,	 (texUnit->TexGenEnabled & T_BIT) ? texUnit->ObjectPlaneT : I + 4,	 (texUnit->TexGenEnabled & R_BIT) ? texUnit->ObjectPlaneR : I + 8,	 (texUnit->TexGenEnabled & Q_BIT) ? texUnit->ObjectPlaneQ : I + 12);      }      break;   case GL_EYE_LINEAR: {      GLuint needtgenable = r200_need_dis_texgen( texUnit->TexGenEnabled,				texUnit->EyePlaneS, texUnit->EyePlaneT,				texUnit->EyePlaneR, texUnit->EyePlaneQ );      if (needtgenable & (S_BIT | T_BIT)) {	 if (R200_DEBUG & DEBUG_FALLBACKS)	 fprintf(stderr, "fallback mixed texgen / eye plane, 0x%x\n",		 texUnit->TexGenEnabled);	 return GL_FALSE;      }      if (needtgenable & (R_BIT)) {	 tgcm &= ~(R200_TEXGEN_COMP_R << (unit * 4));      }      if (needtgenable & (Q_BIT)) {	 tgcm &= ~(R200_TEXGEN_COMP_Q << (unit * 4));      }      tgi |= R200_TEXGEN_INPUT_EYE << inputshift;      set_texgen_matrix( rmesa, unit,	 (texUnit->TexGenEnabled & S_BIT) ? texUnit->EyePlaneS : I,	 (texUnit->TexGenEnabled & T_BIT) ? texUnit->EyePlaneT : I + 4,	 (texUnit->TexGenEnabled & R_BIT) ? texUnit->EyePlaneR : I + 8,	 (texUnit->TexGenEnabled & Q_BIT) ? texUnit->EyePlaneQ : I + 12);      }      break;   case GL_REFLECTION_MAP_NV:      rmesa->TexGenNeedNormals[unit] = GL_TRUE;      tgi |= R200_TEXGEN_INPUT_EYE_REFLECT << inputshift;      /* pretty weird, must only negate when lighting is enabled? */      if (ctx->Light.Enabled)	 set_texgen_matrix( rmesa, unit, 	    (texUnit->TexGenEnabled & S_BIT) ? reflect : I,	    (texUnit->TexGenEnabled & T_BIT) ? reflect + 4 : I + 4,	    (texUnit->TexGenEnabled & R_BIT) ? reflect + 8 : I + 8,	    I + 12);      break;   case GL_NORMAL_MAP_NV:      rmesa->TexGenNeedNormals[unit] = GL_TRUE;      tgi |= R200_TEXGEN_INPUT_EYE_NORMAL<<inputshift;      break;   case GL_SPHERE_MAP:      rmesa->TexGenNeedNormals[unit] = GL_TRUE;      tgi |= R200_TEXGEN_INPUT_SPHERE<<inputshift;      break;   case 0:      /* All texgen units were disabled, so just pass coords through. */      tgi |= unit << inputshift;      break;   default:      /* Unsupported mode, fallback:       */      if (R200_DEBUG & DEBUG_FALLBACKS)	 fprintf(stderr, "fallback unsupported texgen, %d\n",		 texUnit->GenModeS);      return GL_FALSE;   }   rmesa->TexGenEnabled |= R200_TEXGEN_TEXMAT_0_ENABLE << unit;   rmesa->TexGenCompSel |= R200_OUTPUT_TEX_0 << unit;   if (tgi != rmesa->hw.tcg.cmd[TCG_TEX_PROC_CTL_1] ||        tgcm != rmesa->hw.tcg.cmd[TCG_TEX_PROC_CTL_2])   {      R200_STATECHANGE(rmesa, tcg);      rmesa->hw.tcg.cmd[TCG_TEX_PROC_CTL_1] = tgi;      rmesa->hw.tcg.cmd[TCG_TEX_PROC_CTL_2] = tgcm;   }   return GL_TRUE;}static void disable_tex( GLcontext *ctx, int unit ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   if (rmesa->hw.ctx.cmd[CTX_PP_CNTL] & (R200_TEX_0_ENABLE<<unit)) {      /* Texture unit disabled */      if ( rmesa->state.texture.unit[unit].texobj != NULL ) {	 /* The old texture is no longer bound to this texture unit.	  * Mark it as such.	  */	 rmesa->state.texture.unit[unit].texobj->base.bound &= ~(1UL << unit);	 rmesa->state.texture.unit[unit].texobj = NULL;      }      R200_STATECHANGE( rmesa, ctx );      rmesa->hw.ctx.cmd[CTX_PP_CNTL] &= ~(R200_TEX_0_ENABLE << unit);	       R200_STATECHANGE( rmesa, vtx );      rmesa->hw.vtx.cmd[VTX_TCL_OUTPUT_VTXFMT_1] &= ~(7 << (unit * 3));	       if (rmesa->TclFallback & (R200_TCL_FALLBACK_TEXGEN_0<<unit)) {	 TCL_FALLBACK( ctx, (R200_TCL_FALLBACK_TEXGEN_0<<unit), GL_FALSE);      }      /* Actually want to keep all units less than max active texture       * enabled, right?  Fix this for >2 texunits.       */      {	 GLuint tmp = rmesa->TexGenEnabled;	 rmesa->TexGenEnabled &= ~(R200_TEXGEN_TEXMAT_0_ENABLE<<unit);	 rmesa->TexGenEnabled &= ~(R200_TEXMAT_0_ENABLE<<unit);	 rmesa->TexGenNeedNormals[unit] = GL_FALSE;	 rmesa->TexGenCompSel &= ~(R200_OUTPUT_TEX_0 << unit);	 if (tmp != rmesa->TexGenEnabled) {	    rmesa->recheck_texgen[unit] = GL_TRUE;	    rmesa->NewGLState |= _NEW_TEXTURE_MATRIX;	 }      }   }}void set_re_cntl_d3d( GLcontext *ctx, int unit, GLboolean use_d3d ){   r200ContextPtr rmesa = R200_CONTEXT(ctx);   GLuint re_cntl;   re_cntl = rmesa->hw.set.cmd[SET_RE_CNTL] & ~(R200_VTX_STQ0_D3D << (2 * unit));

⌨️ 快捷键说明

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