ReadEffect() private method

private ReadEffect ( BinaryReader reader ) : void
reader BinaryReader
return void
コード例 #1
0
ファイル: Effect.cs プロジェクト: zwcloud/FNA
        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 (!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.
                        EffectCache.Add(effectKey, cloneSource);
                    }
            }

            // Clone it.
            _isClone = true;
            Clone(cloneSource);
        }
コード例 #2
0
ファイル: Effect.cs プロジェクト: Breadmouth/Gravitas
        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);
        }
コード例 #3
0
ファイル: Effect.cs プロジェクト: conankzhang/fez
 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);
 }
コード例 #4
0
ファイル: Effect.cs プロジェクト: tanis2000/FEZ
 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);
 }
コード例 #5
0
ファイル: Effect.cs プロジェクト: KennethYap/MonoGame
        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);
        }
コード例 #6
0
ファイル: Effect.cs プロジェクト: DrPandemic/EraParadox
        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);
        }