本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Effect.ReadEffect方法的典型用法代码示例。如果您正苦于以下问题:C# Effect.ReadEffect方法的具体用法?C# Effect.ReadEffect怎么用?C# Effect.ReadEffect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.Effect
的用法示例。
在下文中一共展示了Effect.ReadEffect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Effect
public Effect(GraphicsDevice graphicsDevice, byte[] effectCode)
: this(graphicsDevice)
{
int hash = Hash.ComputeHash(effectCode);
Effect cloneSource;
if (!Effect.EffectCache.TryGetValue(hash, out cloneSource))
{
cloneSource = new Effect(graphicsDevice);
using (MemoryStream memoryStream = new MemoryStream(effectCode))
{
using (BinaryReader reader = new BinaryReader((Stream) memoryStream))
cloneSource.ReadEffect(reader);
}
Effect.EffectCache.Add(hash, cloneSource);
}
this._isClone = true;
this.Clone(cloneSource);
}
示例2: Effect
public Effect (GraphicsDevice graphicsDevice, byte[] effectCode)
: this(graphicsDevice)
{
// By default we currently cache all unique byte streams
// and use cloning to populate the effect with parameters,
// techniques, and passes.
//
// This means all the immutable types in an effect:
//
// - Shaders
// - Annotations
// - Names
// - State Objects
//
// Are shared for every instance of an effect while the
// parameter values and constant buffers are copied.
//
// This might need to change slightly if/when we support
// shared constant buffers as 'new' should return unique
// effects without any shared instance state.
#if PSM
var effectKey = MonoGame.Utilities.Hash.ComputeHash(effectCode);
int headerSize=0;
#else
//Read the header
MGFXHeader header = ReadHeader(effectCode);
var effectKey = header.EffectKey;
int headerSize = header.HeaderSize;
#endif
// First look for it in the cache.
//
Effect cloneSource;
if (!graphicsDevice.EffectCache.TryGetValue(effectKey, out cloneSource))
{
using (var stream = new MemoryStream(effectCode, headerSize, effectCode.Length - headerSize, false))
using (var reader = new BinaryReader(stream))
{
// Create one.
cloneSource = new Effect(graphicsDevice);
cloneSource.ReadEffect(reader);
// Cache the effect for later in its original unmodified state.
graphicsDevice.EffectCache.Add(effectKey, cloneSource);
}
}
// Clone it.
_isClone = true;
Clone(cloneSource);
}
示例3: Effect
public Effect (GraphicsDevice graphicsDevice, byte[] effectCode)
: this(graphicsDevice)
{
// By default we currently cache all unique byte streams
// and use cloning to populate the effect with parameters,
// techniques, and passes.
//
// This means all the immutable types in an effect:
//
// - Shaders
// - Annotations
// - Names
// - State Objects
//
// Are shared for every instance of an effect while the
// parameter values and constant buffers are copied.
//
// This might need to change slightly if/when we support
// shared constant buffers as 'new' should return unique
// effects without any shared instance state.
// First look for it in the cache.
//
// TODO: We could generate a strong and unique signature
// offline during content processing and just read it from
// the front of the effectCode instead of computing a fast
// hash here at runtime.
//
var effectKey = MonoGame.Utilities.Hash.ComputeHash(effectCode);
Effect cloneSource;
if (!EffectCache.TryGetValue(effectKey, out cloneSource))
{
// Create one.
cloneSource = new Effect(graphicsDevice);
using (var stream = new MemoryStream(effectCode))
using (var reader = new BinaryReader(stream))
cloneSource.ReadEffect(reader);
// Cache the effect for later in its original unmodified state.
EffectCache.Add(effectKey, cloneSource);
}
// Clone it.
_isClone = true;
Clone(cloneSource);
}