Esempio n. 1
0
        internal void ApplyState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // We're now bound to a device... no one should
                // be changing the state of this object now!
                graphicsDevice = device;

                // Build the description.
                var desc = new SharpDX.Direct3D11.BlendStateDescription();

                var targetDesc = new SharpDX.Direct3D11.RenderTargetBlendDescription();

                // We're blending if we're not in the opaque state.
                targetDesc.IsBlendEnabled = !(ColorSourceBlend == Opaque.ColorSourceBlend &&
                                              ColorDestinationBlend == Opaque.ColorDestinationBlend &&
                                              AlphaSourceBlend == Opaque.AlphaSourceBlend &&
                                              AlphaDestinationBlend == Opaque.AlphaDestinationBlend);

                targetDesc.BlendOperation   = GetBlendOperation(ColorBlendFunction);
                targetDesc.SourceBlend      = GetBlendOption(ColorSourceBlend);
                targetDesc.DestinationBlend = GetBlendOption(ColorDestinationBlend);

                targetDesc.AlphaBlendOperation   = GetBlendOperation(AlphaBlendFunction);
                targetDesc.SourceAlphaBlend      = GetBlendOption(AlphaSourceBlend);
                targetDesc.DestinationAlphaBlend = GetBlendOption(AlphaDestinationBlend);

                // Set the first 4 targets to the same settings.
                desc.RenderTarget[0] = targetDesc;
                desc.RenderTarget[1] = targetDesc;
                desc.RenderTarget[2] = targetDesc;
                desc.RenderTarget[3] = targetDesc;

                // Set the color write controls per-target.
                desc.RenderTarget[0].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels);
                desc.RenderTarget[1].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels1);
                desc.RenderTarget[2].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels2);
                desc.RenderTarget[3].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels3);

                // These are new DX11 features we should consider exposing
                // as part of the extended MonoGame API.
                desc.AlphaToCoverageEnable  = false;
                desc.IndependentBlendEnable = false;

                // Create the state.
                _state = new SharpDX.Direct3D11.BlendState(graphicsDevice._d3dDevice, ref desc);
            }

            Debug.Assert(graphicsDevice == device, "The state was created for a different device!");

            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.

            // Apply the state!
            var d3dContext = device._d3dContext;

            d3dContext.OutputMerger.BlendFactor     = new SharpDX.Color4(BlendFactor.R / 255.0f, BlendFactor.G / 255.0f, BlendFactor.B / 255.0f, BlendFactor.A / 255.0f);
            d3dContext.OutputMerger.BlendSampleMask = -1;
            d3dContext.OutputMerger.BlendState      = _state;
        }
        internal void GetState(ref SharpDX.Direct3D11.RenderTargetBlendDescription desc)
        {
            // We're blending if we're not in the opaque state.
            desc.IsBlendEnabled = !(ColorSourceBlend == Blend.One &&
                                    ColorDestinationBlend == Blend.Zero &&
                                    AlphaSourceBlend == Blend.One &&
                                    AlphaDestinationBlend == Blend.Zero);

            desc.BlendOperation   = GetBlendOperation(ColorBlendFunction);
            desc.SourceBlend      = GetBlendOption(ColorSourceBlend, false);
            desc.DestinationBlend = GetBlendOption(ColorDestinationBlend, false);

            desc.AlphaBlendOperation   = GetBlendOperation(AlphaBlendFunction);
            desc.SourceAlphaBlend      = GetBlendOption(AlphaSourceBlend, true);
            desc.DestinationAlphaBlend = GetBlendOption(AlphaDestinationBlend, true);

            desc.RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels);
        }
Esempio n. 3
0
        internal void ApplyState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // We're now bound to a device... no one should
                // be changing the state of this object now!
                GraphicsDevice = device;

                // Build the description.
                var desc = new SharpDX.Direct3D11.BlendStateDescription();

                var targetDesc = new SharpDX.Direct3D11.RenderTargetBlendDescription();

                // We're blending if we're not in the opaque state.
                targetDesc.IsBlendEnabled = !(  ColorSourceBlend == Opaque.ColorSourceBlend &&
                                                ColorDestinationBlend == Opaque.ColorDestinationBlend &&
                                                AlphaSourceBlend == Opaque.AlphaSourceBlend &&
                                                AlphaDestinationBlend == Opaque.AlphaDestinationBlend);

                targetDesc.BlendOperation = GetBlendOperation(ColorBlendFunction);
                targetDesc.SourceBlend = GetBlendOption(ColorSourceBlend);
                targetDesc.DestinationBlend = GetBlendOption(ColorDestinationBlend);

                targetDesc.AlphaBlendOperation = GetBlendOperation(AlphaBlendFunction);
                targetDesc.SourceAlphaBlend = GetBlendOption(AlphaSourceBlend);
                targetDesc.DestinationAlphaBlend = GetBlendOption(AlphaDestinationBlend);

                // Set the first 4 targets to the same settings.
                desc.RenderTarget[0] = targetDesc;
                desc.RenderTarget[1] = targetDesc;
                desc.RenderTarget[2] = targetDesc;
                desc.RenderTarget[3] = targetDesc;
 
                // Set the color write controls per-target.
                desc.RenderTarget[0].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels);
                desc.RenderTarget[1].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels1);
                desc.RenderTarget[2].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels2);
                desc.RenderTarget[3].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels3);

                // These are new DX11 features we should consider exposing
                // as part of the extended MonoGame API.
                desc.AlphaToCoverageEnable = false;
                desc.IndependentBlendEnable = false;

                // Create the state.
                _state = new SharpDX.Direct3D11.BlendState(GraphicsDevice._d3dDevice, desc);
            }

            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.

            // Apply the state!
            var d3dContext = device._d3dContext;
            d3dContext.OutputMerger.BlendFactor = new SharpDX.Color4(BlendFactor.R / 255.0f, BlendFactor.G / 255.0f, BlendFactor.B / 255.0f, BlendFactor.A / 255.0f);
            d3dContext.OutputMerger.BlendSampleMask = -1;
            d3dContext.OutputMerger.BlendState = _state;
        }