/// <summary>
        /// Returns default values for <see cref="BlendStateDescription1"/>. 
        /// </summary>
        /// <remarks>
        /// See MSDN documentation for default values.
        /// </remarks>
        public static BlendStateDescription1 Default()
        {
            var description = new BlendStateDescription1()
            {
                AlphaToCoverageEnable = false,
                IndependentBlendEnable = false,
            };
            var renderTargets = description.RenderTarget;
            for (int i = 0; i < renderTargets.Length; i++)
            {
                renderTargets[i].IsBlendEnabled = false;
                renderTargets[i].IsLogicOperationEnabled = false;

                renderTargets[i].SourceBlend = BlendOption.One;
                renderTargets[i].DestinationBlend = BlendOption.Zero;
                renderTargets[i].BlendOperation = BlendOperation.Add;

                renderTargets[i].SourceAlphaBlend = BlendOption.One;
                renderTargets[i].DestinationAlphaBlend = BlendOption.Zero;
                renderTargets[i].AlphaBlendOperation = BlendOperation.Add;

                renderTargets[i].RenderTargetWriteMask = ColorWriteMaskFlags.All;

                renderTargets[i].LogicOperation = LogicOperation.Noop;
            }

            return description;
        }
示例#2
0
        /// <summary>
        /// Returns default values for <see cref="BlendStateDescription1"/>.
        /// </summary>
        /// <remarks>
        /// See MSDN documentation for default values.
        /// </remarks>
        public static BlendStateDescription1 Default()
        {
            var description = new BlendStateDescription1()
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false,
            };
            var renderTargets = description.RenderTarget;

            for (int i = 0; i < renderTargets.Length; i++)
            {
                renderTargets[i].IsBlendEnabled          = false;
                renderTargets[i].IsLogicOperationEnabled = false;

                renderTargets[i].SourceBlend      = BlendOption.One;
                renderTargets[i].DestinationBlend = BlendOption.Zero;
                renderTargets[i].BlendOperation   = BlendOperation.Add;

                renderTargets[i].SourceAlphaBlend      = BlendOption.One;
                renderTargets[i].DestinationAlphaBlend = BlendOption.Zero;
                renderTargets[i].AlphaBlendOperation   = BlendOperation.Add;

                renderTargets[i].RenderTargetWriteMask = ColorWriteMaskFlags.All;

                renderTargets[i].LogicOperation = LogicOperation.Noop;
            }

            return(description);
        }
 /// <summary>
 /// Clones this instance.
 /// </summary>
 /// <returns>A copy of this instance.</returns>
 /// <remarks>
 /// Because this structure contains an array, it is not possible to modify it without making an explicit clone method.
 /// </remarks>
 public BlendStateDescription1 Clone()
 {
     var description = new BlendStateDescription1 {AlphaToCoverageEnable = AlphaToCoverageEnable, IndependentBlendEnable = IndependentBlendEnable};
     var sourceRenderTargets = RenderTarget;
     var destRenderTargets = description.RenderTarget;
     for (int i = 0; i < sourceRenderTargets.Length; i++)
         destRenderTargets[i] = sourceRenderTargets[i];
     return description;
 }
示例#4
0
        /// <summary>
        /// Function to build the D3D11 blend state.
        /// </summary>
        /// <param name="device">The device used to create the blend state.</param>
        internal void BuildD3D11BlendState(D3D11.Device5 device)
        {
            Debug.Assert(D3DBlendState == null, "D3D Blend state already assigned to this pipeline state.");

            (int start, int count) = RwBlendStates.GetDirtyItems();
            var desc = new D3D11.BlendStateDescription1
            {
                AlphaToCoverageEnable  = IsAlphaToCoverageEnabled,
                IndependentBlendEnable = IsIndependentBlendingEnabled
            };

            for (int i = 0; i < count; ++i)
            {
                GorgonBlendState state = RwBlendStates[start + i];

                if (state == null)
                {
                    continue;
                }

                desc.RenderTarget[i] = new D3D11.RenderTargetBlendDescription1
                {
                    AlphaBlendOperation     = (D3D11.BlendOperation)state.AlphaBlendOperation,
                    BlendOperation          = (D3D11.BlendOperation)state.ColorBlendOperation,
                    IsLogicOperationEnabled = state.LogicOperation != LogicOperation.Noop,
                    IsBlendEnabled          = state.IsBlendingEnabled,
                    RenderTargetWriteMask   = (D3D11.ColorWriteMaskFlags)state.WriteMask,
                    LogicOperation          = (D3D11.LogicOperation)state.LogicOperation,
                    SourceAlphaBlend        = (D3D11.BlendOption)state.SourceAlphaBlend,
                    SourceBlend             = (D3D11.BlendOption)state.SourceColorBlend,
                    DestinationAlphaBlend   = (D3D11.BlendOption)state.DestinationAlphaBlend,
                    DestinationBlend        = (D3D11.BlendOption)state.DestinationColorBlend
                };
            }

            for (int i = count; i < D3D11.OutputMergerStage.SimultaneousRenderTargetCount; ++i)
            {
                desc.RenderTarget[i] = new D3D11.RenderTargetBlendDescription1
                {
                    AlphaBlendOperation     = D3D11.BlendOperation.Add,
                    BlendOperation          = D3D11.BlendOperation.Add,
                    IsLogicOperationEnabled = false,
                    IsBlendEnabled          = false,
                    RenderTargetWriteMask   = D3D11.ColorWriteMaskFlags.All,
                    LogicOperation          = D3D11.LogicOperation.Noop,
                    SourceAlphaBlend        = D3D11.BlendOption.One,
                    SourceBlend             = D3D11.BlendOption.One,
                    DestinationAlphaBlend   = D3D11.BlendOption.Zero,
                    DestinationBlend        = D3D11.BlendOption.Zero
                };
            }

            D3DBlendState = new D3D11.BlendState1(device, desc)
            {
                DebugName = nameof(GorgonBlendState)
            };
        }
示例#5
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A copy of this instance.</returns>
        /// <remarks>
        /// Because this structure contains an array, it is not possible to modify it without making an explicit clone method.
        /// </remarks>
        public BlendStateDescription1 Clone()
        {
            var description = new BlendStateDescription1 {
                AlphaToCoverageEnable = AlphaToCoverageEnable, IndependentBlendEnable = IndependentBlendEnable
            };
            var sourceRenderTargets = RenderTarget;
            var destRenderTargets   = description.RenderTarget;

            for (int i = 0; i < sourceRenderTargets.Length; i++)
            {
                destRenderTargets[i] = sourceRenderTargets[i];
            }
            return(description);
        }
示例#6
0
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.BlendState1" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The state description.</param>
 /// <returns>The newly created object.</returns>
 public BlendState1(Device1 device, ref BlendStateDescription1 description)
     : base(IntPtr.Zero)
 {
     device.CreateBlendState1(ref description, this);
 }
        private void CreateD3D_rDto(string assetUrl)
        {
            RenderDTO rDto = new RenderDTO();

            rDto.D3DPrimitiveDTO = new D3DPrimitiveDTO();

            //SafeDispose(ref rDto.D3DPrimitiveDTO.VertexBuffer);
            //rDto.D3DPrimitiveDTO.IsRenderable = true;
            // Remove previous buffer
            //SafeDispose(ref rDto.D3DPrimitiveDTO.ConstantBuffer);

            // Setup local variables
            var d3dDevice = _deviceManager.DeviceDirect3D;
            var d3dContext = _deviceManager.ContextDirect3D;
            var d2dDevice = _deviceManager.DeviceDirect2D;
            var d2dContext = _deviceManager.ContextDirect2D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_VS.fxo");

            rDto.D3DPrimitiveDTO.VertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            rDto.D3DPrimitiveDTO.PixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            rDto.D3DPrimitiveDTO.Layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
                    });


            // Instantiate Vertex buffer from vertex data
            float thicknessToUse = 0.15f;
            thicknessToUse = 1.0f; //project.Thickness;

            rDto.D3DPrimitiveDTO.VertexCount = 36; //6 * 6
            rDto.D3DPrimitiveDTO.VertexBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, sizeof(float) * 6, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            rDto.D3DPrimitiveDTO.VertexBuffer = GenerateVertexBuffer6Sided(d3dDevice, thicknessToUse);

            //vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0);
            rDto.D3DPrimitiveDTO.VertexBufferBinding = new VertexBufferBinding(rDto.D3DPrimitiveDTO.VertexBuffer, sizeof(float) * 6, 0);

            // Create Constant Buffer
            rDto.D3DPrimitiveDTO.ConstantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            //TextureView
            RenderD3DDto(assetUrl, rDto);

            rDto.D3DPrimitiveDTO.Sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = 0,
                MaximumLod = 16,
            });

            BlendStateDescription1 blendDesc = new BlendStateDescription1();
            blendDesc.AlphaToCoverageEnable = true;  //set to true to get nice blending betweent sprites
            blendDesc.IndependentBlendEnable = false;
            blendDesc.RenderTarget[0].IsBlendEnabled = false;
            blendDesc.RenderTarget[0].IsLogicOperationEnabled = false;
            blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
            blendDesc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate;
            blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Maximum;
            blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
            blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
            blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other
            blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            rDto.D3DPrimitiveDTO.BlendState = new BlendState1(d3dDevice, blendDesc);

            _renderTree.Add(rDto);

        }