예제 #1
0
        private Number4 GetBlendFactor(BlendOption blend, ref Number4 source, ref Number4 destination, ref Number4 blendFactor)
		{
			switch (blend)
			{
				case BlendOption.Zero:
                    return new Number4(0, 0, 0, 0);
				case BlendOption.One:
                    return new Number4(1, 1, 1, 1);
				case BlendOption.SourceColor:
					return source;
				case BlendOption.InverseSourceColor:
                    return Number4.Invert(ref source);
				case BlendOption.SourceAlpha:
                    return new Number4(source.A, source.A, source.A, source.A);
				case BlendOption.InverseSourceAlpha:
                    return Number4.Invert(new Number4(source.A, source.A, source.A, source.A));
				case BlendOption.DestinationAlpha:
                    return new Number4(destination.A, destination.A, destination.A, destination.A);
				case BlendOption.InverseDestinationAlpha:
                    return Number4.Invert(new Number4(destination.A, destination.A, destination.A, destination.A));
				case BlendOption.DestinationColor:
					return destination;
				case BlendOption.InverseDestinationColor:
                    return Number4.Invert(ref destination);
				case BlendOption.SourceAlphaSaturate:
                    return Number4.Saturate(new Number4(source.A, source.A, source.A, source.A));
				case BlendOption.BlendFactor:
					return blendFactor;
				case BlendOption.InverseBlendFactor:
					return Number4.Invert(ref blendFactor);
				default:
					throw new NotSupportedException();
			}
		}
예제 #2
0
        public BlendState(bool blendEnabled,
            BlendOperation blendOperation, BlendOperation alphaBlendOperation,
            BlendOption sourceBlend, BlendOption destinationBlend,
            BlendOption sourceAlphhaBlend, BlendOption destinationAlphaBlend)
        {
            RenderTargetBlendDescription targetDesc = new RenderTargetBlendDescription()
            {
                AlphaBlendOperation = alphaBlendOperation,
                BlendOperation = blendOperation,
                DestinationAlphaBlend = destinationAlphaBlend,
                SourceAlphaBlend = sourceAlphhaBlend,
                SourceBlend = sourceBlend,
                DestinationBlend = destinationBlend,
                IsBlendEnabled = blendEnabled,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            BlendStateDescription desc = new BlendStateDescription()
            {
                IndependentBlendEnable = false,
            };

            desc.RenderTarget[0] = targetDesc;

            NativeBlendState = new SharpDX.Direct3D11.BlendState(GraphicManager.Device, desc);

        }
예제 #3
0
 private static BlendState Create(Device5 device,
                                  string name,
                                  BlendOption sourceBlend,
                                  BlendOption destinationBlend,
                                  bool blendEnabled)
 {
     return(Create(
                device,
                name,
                new BlendStateDescription
     {
         AlphaToCoverageEnable = false,
         IndependentBlendEnable = false,
         RenderTarget =
         {
             [0] = new RenderTargetBlendDescription
             {
             IsBlendEnabled = blendEnabled,
             SourceBlend = sourceBlend,
             DestinationBlend = destinationBlend,
             SourceAlphaBlend = sourceBlend,
             DestinationAlphaBlend = destinationBlend,
             BlendOperation = BlendOperation.Add,
             AlphaBlendOperation = BlendOperation.Add,
             RenderTargetWriteMask = ColorWriteMaskFlags.All
             }
         }
     }));
 }
예제 #4
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="DirectXDevice"/>.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState" /> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(DirectXDevice device, BlendOption sourceBlend, BlendOption destinationBlend,
                              BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend,
                              BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask = ColorWriteMaskFlags.All,
                              int mask = -1)
 {
     return(New(device, sourceBlend, destinationBlend, blendOperation, sourceAlphaBlend, destinationAlphaBlend,
                alphaBlendOperation, renderTargetWriteMask, Color.White, mask));
 }
예제 #5
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="DirectXDevice"/>.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 /// <param name="blendFactor">The blend factor.</param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState"/> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(DirectXDevice device, BlendOption sourceBlend, BlendOption destinationBlend,
                              BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend,
                              BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask, Color4 blendFactor,
                              int mask = -1)
 {
     return(New(device,
                new RenderTargetBlendDescription(true, sourceBlend, destinationBlend, blendOperation, sourceAlphaBlend,
                                                 destinationAlphaBlend, alphaBlendOperation, renderTargetWriteMask), blendFactor, mask));
 }
예제 #6
0
 public void Load(BinaryReader reader)
 {
     AlphaBlendOperation   = (BlendOperation)reader.ReadByte();
     BlendOperation        = (BlendOperation)reader.ReadByte();
     ColourWriteMask       = (ColorWriteMaskFlags)reader.ReadByte();
     DestinationAlphaBlend = (BlendOption)reader.ReadByte();
     DestinationBlend      = (BlendOption)reader.ReadByte();
     SourceAlphaBlend      = (BlendOption)reader.ReadByte();
     SourceBlend           = (BlendOption)reader.ReadByte();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderTargetBlendDescription" /> struct.
 /// </summary>
 /// <param name="isBlendEnabled">The is blend enabled.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 public RenderTargetBlendDescription(bool isBlendEnabled, BlendOption sourceBlend, BlendOption destinationBlend, BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend, BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask)
 {
     IsBlendEnabled        = isBlendEnabled;
     SourceBlend           = sourceBlend;
     DestinationBlend      = destinationBlend;
     BlendOperation        = blendOperation;
     SourceAlphaBlend      = sourceAlphaBlend;
     DestinationAlphaBlend = destinationAlphaBlend;
     AlphaBlendOperation   = alphaBlendOperation;
     RenderTargetWriteMask = renderTargetWriteMask;
 }
예제 #8
0
        /// <summary>
        /// Set current blending state
        /// </summary>
        /// <param name="operation">Blend Operation</param>
        /// <param name="source">Source Option</param>
        /// <param name="destination">Destination Option</param>
        public void SetBlend(BlendOperation operation, BlendOption source, BlendOption destination)
        {
            Utilities.Dispose(ref _blendState);
            BlendStateDescription description = BlendStateDescription.Default();

            description.RenderTarget[0].BlendOperation   = operation;
            description.RenderTarget[0].SourceBlend      = source;
            description.RenderTarget[0].DestinationBlend = destination;
            description.RenderTarget[0].IsBlendEnabled   = true;
            _blendState = new BlendState(Device, description);
        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderTargetBlendDescription" /> struct.
 /// </summary>
 /// <param name="isBlendEnabled">The is blend enabled.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 public RenderTargetBlendDescription(bool isBlendEnabled, BlendOption sourceBlend, BlendOption destinationBlend, BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend, BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask)
 {
     IsBlendEnabled = isBlendEnabled;
     SourceBlend = sourceBlend;
     DestinationBlend = destinationBlend;
     BlendOperation = blendOperation;
     SourceAlphaBlend = sourceAlphaBlend;
     DestinationAlphaBlend = destinationAlphaBlend;
     AlphaBlendOperation = alphaBlendOperation;
     RenderTargetWriteMask = renderTargetWriteMask;
 }
예제 #10
0
 public BlendStateDescription(BlendOption sourceBlend, BlendOption destinationBlend)
     : this()
 {
     RenderTarget[0] = new RenderTargetBlendDescription
     {
         IsBlendEnabled        = true,
         SourceBlend           = sourceBlend,
         SourceAlphaBlend      = sourceBlend,
         DestinationBlend      = destinationBlend,
         DestinationAlphaBlend = destinationBlend
     };
 }
예제 #11
0
		public BlendStateDescription(BlendOption sourceBlend, BlendOption destinationBlend)
			: this()
		{
			RenderTarget[0] = new RenderTargetBlendDescription
			{
				IsBlendEnabled = true,
				SourceBlend = sourceBlend,
				SourceAlphaBlend = sourceBlend,
				DestinationBlend = destinationBlend,
				DestinationAlphaBlend = destinationBlend
			};
		}
예제 #12
0
        internal static BlendState New(GraphicsDevice device, string name, BlendOption sourceBlend, BlendOption destinationBlend)
        {
            var description = BlendStateDescription.Default();

            description.RenderTarget[0].IsBlendEnabled        = true;
            description.RenderTarget[0].SourceBlend           = sourceBlend;
            description.RenderTarget[0].DestinationBlend      = destinationBlend;
            description.RenderTarget[0].SourceAlphaBlend      = sourceBlend;
            description.RenderTarget[0].DestinationAlphaBlend = destinationBlend;

            return(new BlendState(device, description, Color.White, -1)
            {
                Name = name
            });
        }
예제 #13
0
 protected static BlendStateDescription GetBlendStateDescription(
     BlendOption source = BlendOption.SourceAlpha,
     BlendOption destination = BlendOption.InverseSourceAlpha)
 {
     var description = new BlendStateDescription();
     description.RenderTarget[0].IsBlendEnabled = (source != BlendOption.One) ||
         (destination != BlendOption.Zero);
     description.RenderTarget[0].SourceBlend =
         description.RenderTarget[0].SourceAlphaBlend = source;
     description.RenderTarget[0].DestinationBlend =
         description.RenderTarget[0].DestinationAlphaBlend = destination;
     description.RenderTarget[0].BlendOperation =
         description.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
     description.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
     return description;
 }
예제 #14
0
        private Number4 GetBlendFactor(BlendOption blend, ref Number4 source, ref Number4 destination, ref Number4 blendFactor)
        {
            switch (blend)
            {
            case BlendOption.Zero:
                return(new Number4(0, 0, 0, 0));

            case BlendOption.One:
                return(new Number4(1, 1, 1, 1));

            case BlendOption.SourceColor:
                return(source);

            case BlendOption.InverseSourceColor:
                return(Number4.Invert(ref source));

            case BlendOption.SourceAlpha:
                return(new Number4(source.A, source.A, source.A, source.A));

            case BlendOption.InverseSourceAlpha:
                return(Number4.Invert(new Number4(source.A, source.A, source.A, source.A)));

            case BlendOption.DestinationAlpha:
                return(new Number4(destination.A, destination.A, destination.A, destination.A));

            case BlendOption.InverseDestinationAlpha:
                return(Number4.Invert(new Number4(destination.A, destination.A, destination.A, destination.A)));

            case BlendOption.DestinationColor:
                return(destination);

            case BlendOption.InverseDestinationColor:
                return(Number4.Invert(ref destination));

            case BlendOption.SourceAlphaSaturate:
                return(Number4.Saturate(new Number4(source.A, source.A, source.A, source.A)));

            case BlendOption.BlendFactor:
                return(blendFactor);

            case BlendOption.InverseBlendFactor:
                return(Number4.Invert(ref blendFactor));

            default:
                throw new NotSupportedException();
            }
        }
예제 #15
0
        private static BlendState CreateBlendState(bool enable, BlendOption src, BlendOption dst)
        {
            var dev       = ImageFramework.DirectX.Device.Get();
            var blendDesc = new BlendStateDescription
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false
            };

            blendDesc.RenderTarget[0] = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = enable,
                BlendOperation        = BlendOperation.Add,
                AlphaBlendOperation   = BlendOperation.Add,
                SourceBlend           = src,
                DestinationBlend      = dst,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            return(new BlendState(dev.Handle, blendDesc));
        }
예제 #16
0
        internal static BlendState New(GraphicsDevice device, string name, BlendOption sourceBlend, BlendOption destinationBlend)
        {
            var description = BlendStateDescription.Default();

            description.RenderTarget[0].IsBlendEnabled = true;
            description.RenderTarget[0].SourceBlend = sourceBlend;
            description.RenderTarget[0].DestinationBlend = destinationBlend;
            description.RenderTarget[0].SourceAlphaBlend = sourceBlend;
            description.RenderTarget[0].DestinationAlphaBlend = destinationBlend;

            return new BlendState(device, description, Color.White, -1) {Name = name};
        }
예제 #17
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="GraphicsDevice"/>.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 /// <param name="blendFactor">The blend factor.</param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState"/> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(GraphicsDevice device, BlendOption sourceBlend, BlendOption destinationBlend, BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend, BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask, Color4 blendFactor, int mask = -1)
 {
     return New(device, new RenderTargetBlendDescription(true, sourceBlend, destinationBlend, blendOperation, sourceAlphaBlend, destinationAlphaBlend, alphaBlendOperation, renderTargetWriteMask), blendFactor, mask);
 }
예제 #18
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="GraphicsDevice"/>.</param>
 /// <param name="sourceBlend">The source blend.</param>
 /// <param name="destinationBlend">The destination blend.</param>
 /// <param name="blendOperation">The blend operation.</param>
 /// <param name="sourceAlphaBlend">The source alpha blend.</param>
 /// <param name="destinationAlphaBlend">The destination alpha blend.</param>
 /// <param name="alphaBlendOperation">The alpha blend operation.</param>
 /// <param name="renderTargetWriteMask">The render target write mask.</param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState" /> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(GraphicsDevice device, BlendOption sourceBlend, BlendOption destinationBlend, BlendOperation blendOperation, BlendOption sourceAlphaBlend, BlendOption destinationAlphaBlend, BlendOperation alphaBlendOperation, ColorWriteMaskFlags renderTargetWriteMask = ColorWriteMaskFlags.All, int mask = -1)
 {
     return New(device, sourceBlend, destinationBlend, blendOperation, sourceAlphaBlend, destinationAlphaBlend, alphaBlendOperation, renderTargetWriteMask, Color.White, mask);            
 }
예제 #19
0
 public void SetBlendOption(BlendOption blendoption)
 {
     option = blendoption;
 }
예제 #20
0
        public static BlendState CreateBlendState(Device device, bool blendEnable, BlendOperation op, BlendOption src, BlendOption dst, BlendOperation opAlpha, BlendOption srcAlpha, BlendOption dstAlpha, ColorWriteMaskFlags writeMask)
        {
            BlendStateDescription bsd = new BlendStateDescription();

            //ZeroMemory(&bsd, sizeof(bsd));
            bsd.RenderTarget[0].IsBlendEnabled        = blendEnable;
            bsd.RenderTarget[0].BlendOperation        = op;
            bsd.RenderTarget[0].SourceBlend           = src;
            bsd.RenderTarget[0].DestinationBlend      = dst;
            bsd.RenderTarget[0].AlphaBlendOperation   = opAlpha;
            bsd.RenderTarget[0].SourceAlphaBlend      = srcAlpha;
            bsd.RenderTarget[0].DestinationAlphaBlend = dstAlpha;
            bsd.RenderTarget[0].RenderTargetWriteMask = writeMask;
            BlendState bs = new BlendState(device, bsd);

            return(bs);
        }