ReadEffect() private method

private ReadEffect ( BinaryReader reader ) : void
reader BinaryReader
return void
Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }