📄 i915_texprog.c
字号:
out ); return out; } } case GL_DECAL: { if (format == GL_RGB || format == GL_RGBA) { int cf = get_source( p, GL_PREVIOUS, unit ); int cs = get_source( p, GL_TEXTURE, unit ); int out = get_dest(p, unit); /* cv = cf(1-as) + cs.as * cv = cf.(-as) + cf + cs.as * av = af */ /* u[2] = mad( cf.xyzw * cs.-w-w-w1 + cf.xyz0 ) * oc = mad( cs.xyz0 * cs.www0 + u[2].xyzw ) */ i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0, cf, negate(swizzle(cs,W,W,W,ONE),1,1,1,0), swizzle(cf,X,Y,Z,ZERO) ); i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, swizzle(cs,X,Y,Z,ZERO), swizzle(cs,W,W,W,ZERO), out ); return out; } else { return get_source( p, GL_PREVIOUS, unit ); } } case GL_REPLACE: { const int cs = get_source( p, GL_TEXTURE, unit ); /* saturated */ switch (format) { case GL_ALPHA: { const int cf = get_source( p, GL_PREVIOUS, unit ); /* saturated */ i915_emit_arith( p, A0_MOV, cs, A0_DEST_CHANNEL_XYZ, 0, cf, 0, 0 ); return cs; } case GL_RGB: case GL_LUMINANCE: { const int cf = get_source( p, GL_PREVIOUS, unit ); /* saturated */ i915_emit_arith( p, A0_MOV, cs, A0_DEST_CHANNEL_W, 0, cf, 0, 0 ); return cs; } default: return cs; } } case GL_MODULATE: { const int cf = get_source( p, GL_PREVIOUS, unit ); const int cs = get_source( p, GL_TEXTURE, unit ); const int out = get_dest(p, unit); switch (format) { case GL_ALPHA: i915_emit_arith( p, A0_MUL, out, A0_DEST_CHANNEL_ALL, saturate, swizzle(cs, ONE, ONE, ONE, W), cf, 0 ); break; default: i915_emit_arith( p, A0_MUL, out, A0_DEST_CHANNEL_ALL, saturate, cs, cf, 0 ); break; } return out; } case GL_ADD: { int cf = get_source( p, GL_PREVIOUS, unit ); int cs = get_source( p, GL_TEXTURE, unit ); const int out = get_dest( p, unit ); if (format == GL_INTENSITY) { /* output-color.rgba = add( incoming, u[1] ) */ i915_emit_arith( p, A0_ADD, out, A0_DEST_CHANNEL_ALL, saturate, cs, cf, 0 ); return out; } else { /* cv.xyz = cf.xyz + cs.xyz * cv.w = cf.w * cs.w * * cv.xyzw = MAD( cf.111w * cs.xyzw + cf.xyz0 ) */ i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, swizzle(cf,ONE,ONE,ONE,W), cs, swizzle(cf,X,Y,Z,ZERO) ); return out; } break; } case GL_COMBINE: { GLuint rgb_shift, alpha_shift, out, shift; GLuint dest = get_dest(p, unit); /* The EXT version of the DOT3 extension does not support the * scale factor, but the ARB version (and the version in OpenGL * 1.3) does. */ switch (texUnit->Combine.ModeRGB) { case GL_DOT3_RGB_EXT: alpha_shift = texUnit->Combine.ScaleShiftA; rgb_shift = 0; break; case GL_DOT3_RGBA_EXT: alpha_shift = 0; rgb_shift = 0; break; default: rgb_shift = texUnit->Combine.ScaleShiftRGB; alpha_shift = texUnit->Combine.ScaleShiftA; break; } /* Emit the RGB and A combine ops */ if (texUnit->Combine.ModeRGB == texUnit->Combine.ModeA && args_match( texUnit )) { out = emit_combine( p, dest, A0_DEST_CHANNEL_ALL, saturate, unit, texUnit->Combine.ModeRGB, texUnit->Combine.SourceRGB, texUnit->Combine.OperandRGB ); } else if (texUnit->Combine.ModeRGB == GL_DOT3_RGBA_EXT || texUnit->Combine.ModeRGB == GL_DOT3_RGBA) { out = emit_combine( p, dest, A0_DEST_CHANNEL_ALL, saturate, unit, texUnit->Combine.ModeRGB, texUnit->Combine.SourceRGB, texUnit->Combine.OperandRGB ); } else { /* Need to do something to stop from re-emitting identical * argument calculations here: */ out = emit_combine( p, dest, A0_DEST_CHANNEL_XYZ, saturate, unit, texUnit->Combine.ModeRGB, texUnit->Combine.SourceRGB, texUnit->Combine.OperandRGB ); out = emit_combine( p, dest, A0_DEST_CHANNEL_W, saturate, unit, texUnit->Combine.ModeA, texUnit->Combine.SourceA, texUnit->Combine.OperandA ); } /* Deal with the final shift: */ if (alpha_shift || rgb_shift) { if (rgb_shift == alpha_shift) { shift = i915_emit_const1f(p, 1<<rgb_shift); shift = swizzle(shift,X,X,X,X); } else { shift = i915_emit_const2f(p, 1<<rgb_shift, 1<<alpha_shift); shift = swizzle(shift,X,X,X,Y); } return i915_emit_arith( p, A0_MUL, dest, A0_DEST_CHANNEL_ALL, saturate, out, shift, 0 ); } return out; } default: return get_source(p, GL_PREVIOUS, 0); }}static void emit_program_fini( struct i915_fragment_program *p ){ int cf = get_source( p, GL_PREVIOUS, 0 ); int out = UREG( REG_TYPE_OC, 0 ); if (p->ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) { /* Emit specular add. */ GLuint s = i915_emit_decl(p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_ALL); i915_emit_arith( p, A0_ADD, out, A0_DEST_CHANNEL_ALL, 0, cf, swizzle(s, X,Y,Z,ZERO), 0 ); } else if (cf != out) { /* Will wind up in here if no texture enabled or a couple of * other scenarios (GL_REPLACE for instance). */ i915_emit_arith( p, A0_MOV, out, A0_DEST_CHANNEL_ALL, 0, cf, 0, 0 ); }}static void i915EmitTextureProgram( i915ContextPtr i915 ){ GLcontext *ctx = &i915->intel.ctx; struct i915_fragment_program *p = &i915->tex_program; GLuint unit; if (0) fprintf(stderr, "%s\n", __FUNCTION__); i915_init_program( i915, p ); if (ctx->Texture._EnabledUnits) { for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++) if (ctx->Texture.Unit[unit]._ReallyEnabled) { p->last_tex_stage = unit; } for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) if (ctx->Texture.Unit[unit]._ReallyEnabled) { p->src_previous = emit_texenv( p, unit ); p->src_texture = UREG_BAD; p->temp_flag = 0xffff000; p->temp_flag |= 1 << GET_UREG_NR(p->src_previous); } } emit_program_fini( p ); i915_fini_program( p ); i915_upload_program( i915, p ); p->translated = 1;}void i915ValidateTextureProgram( i915ContextPtr i915 ){ intelContextPtr intel = &i915->intel; GLcontext *ctx = &intel->ctx; TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLuint index = tnl->render_inputs; int i, offset; GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK; GLuint s2 = S2_TEXCOORD_NONE; /* Important: */ VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; intel->vertex_attr_count = 0; intel->coloroffset = 0; intel->specoffset = 0; offset = 0; if (i915->vertex_fog == I915_FOG_PIXEL) { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); index &= ~_TNL_BIT_FOG; } else if (index & _TNL_BITS_TEX_ANY) { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); } else { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, S4_VFMT_XYZ, 12 ); } /* How undefined is undefined? */ if (index & _TNL_BIT_POINTSIZE) { EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, S4_VFMT_POINT_WIDTH, 4 ); } intel->coloroffset = offset / 4; EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, S4_VFMT_COLOR, 4 ); if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { if (index & _TNL_BIT_COLOR1) { intel->specoffset = offset / 4; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, S4_VFMT_SPEC_FOG, 3 ); } else EMIT_PAD( 3 ); if (index & _TNL_BIT_FOG) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, S4_VFMT_SPEC_FOG, 1 ); else EMIT_PAD( 1 ); } if (index & _TNL_BITS_TEX_ANY) { for (i = 0; i < 8; i++) { if (index & _TNL_BIT_TEX(i)) { int sz = VB->TexCoordPtr[i]->size; s2 &= ~S2_TEXCOORD_FMT(i, S2_TEXCOORD_FMT0_MASK); s2 |= S2_TEXCOORD_FMT(i, SZ_TO_HW(sz)); EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_SZ(sz), 0, sz * 4 ); } } } /* Only need to change the vertex emit code if there has been a * statechange to a new hardware vertex format: */ if (s2 != i915->state.Ctx[I915_CTXREG_LIS2] || s4 != i915->state.Ctx[I915_CTXREG_LIS4]) { I915_STATECHANGE( i915, I915_UPLOAD_CTX ); i915->tex_program.translated = 0; /* Must do this *after* statechange, so as not to affect * buffered vertices reliant on the old state: */ intel->vertex_size = _tnl_install_attrs( ctx, intel->vertex_attrs, intel->vertex_attr_count, intel->ViewportMatrix.m, 0 ); intel->vertex_size >>= 2; i915->state.Ctx[I915_CTXREG_LIS2] = s2; i915->state.Ctx[I915_CTXREG_LIS4] = s4; assert(intel->vtbl.check_vertex_size( intel, intel->vertex_size )); } if (!i915->tex_program.translated || i915->last_ReallyEnabled != ctx->Texture._EnabledUnits) { i915EmitTextureProgram( i915 ); i915->last_ReallyEnabled = ctx->Texture._EnabledUnits; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -