В примерах часто встречается пдобный код
foreach (ModelMesh mesh in newModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
textures[i++] = effect.Texture;
}
}Возникает вопрос, если BasicEffect это некий типичный Effect, то как именно работает свойсво Texture?
Можно ли получить объект текстуры без приведения к Basiceffect?
Armitage
> как именно работает свойсво Texture?
public Texture2D Texture { get { return this.basicTextureParam.GetValueTexture2D(); } set { this.basicTextureParam.SetValue( value); } } public unsafe Texture2D GetValueTexture2D( ) { EffectParameterType paramType = this._paramType; if ( paramType != EffectParameterType.Texture && paramType != EffectParameterType.Texture2D) { throw new InvalidCastException( ); } IDirect3DBaseTexture9* ptr = null; IDirect3DTexture9* ptr2 = null; Texture2D result = null; ID3DXBaseEffect* ptr3 = this.pEffect; int num = calli( System.Int32 modopt( System.Runtime.CompilerServices.IsLong) modopt( System.Runtime.CompilerServices.CallConvStdcall)( System.IntPtr,System.SByte modopt( System.Runtime.CompilerServices.IsSignUnspecifiedByte) modopt( System.Runtime.CompilerServices.IsConst)*,IDirect3DBaseTexture9**), ptr3, this._handle, ref ptr, *( *( int*)ptr3 + 212)); if ( num < 0) { throw Helpers.GetExceptionFromResult( num); } if ( ptr != null) { num = calli( System.Int32 modopt( System.Runtime.CompilerServices.IsLong) modopt( System.Runtime.CompilerServices.CallConvStdcall)( System.IntPtr,_GUID modopt( System.Runtime.CompilerServices.IsConst)* modopt( System.Runtime.CompilerServices.IsImplicitlyDereferenced),System.Void**), ptr, ref <Module>.IID_IDirect3DTexture9, ref ptr2, *( *( int*)ptr)); if ( num >= 0) { _D3DSURFACE_DESC d3DSURFACE_DESC; num = calli( System.Int32 modopt( System.Runtime.CompilerServices.IsLong) modopt( System.Runtime.CompilerServices.CallConvStdcall)( System.IntPtr,System.UInt32,_D3DSURFACE_DESC*), ptr2, 0, ref d3DSURFACE_DESC, *( *( int*)ptr2 + 68)); if ( num >= 0) { GraphicsDevice pCachedDevice = this._parent.pCachedDevice; result = Texture2D.GetManagedObject( ptr2, pCachedDevice, *( ref d3DSURFACE_DESC + 12)); } } if ( ptr != null) { IDirect3DBaseTexture9* expr_98 = ptr; object arg_A2_0 = calli( System.UInt32 modopt( System.Runtime.CompilerServices.IsLong) modopt( System.Runtime.CompilerServices.CallConvStdcall)( System.IntPtr), expr_98, *( *( int*)expr_98 + 8)); ptr = null; } if ( num < 0) { throw Helpers.GetExceptionFromResult( num); } } return result; }
Armitage
> Можно ли получить объект текстуры без приведения к Basiceffect?
По идее так:
Effect e;
foreach (EffectParameter p in e.Parameters)
{
Texture2D tex = p.GetValueTexture2D();
}Теперь все ясно, спасибо за ясный и за развернутый ответы.
Тема в архиве.
Тема закрыта.