Beispiel #1
0
        /// <summary>
        /// Loads the resource.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="resources">Parent ResourceDictionary.</param>
        protected override void LoadResourceInternal(EngineDevice device, ResourceDictionary resources)
        {
            // Create default blend state
            m_defaultBlendState = new Lazy <D3D11.BlendState>(() =>
            {
                D3D11.BlendStateDescription blendDesc = D3D11.BlendStateDescription.Default();
                return(new D3D11.BlendState(device.DeviceD3D11_1, blendDesc));
            });

            // Create alpha blending blend state
            m_alphaBlendingBlendState = new Lazy <D3D11.BlendState>(() =>
            {
                //Define the blend state (based on http://www.rastertek.com/dx11tut26.html)
                D3D11.BlendStateDescription blendDesc           = D3D11.BlendStateDescription.Default();
                blendDesc.RenderTarget[0].IsBlendEnabled        = true;
                blendDesc.RenderTarget[0].SourceBlend           = D3D11.BlendOption.SourceAlpha;
                blendDesc.RenderTarget[0].DestinationBlend      = D3D11.BlendOption.InverseSourceAlpha;
                blendDesc.RenderTarget[0].BlendOperation        = D3D11.BlendOperation.Add;
                blendDesc.RenderTarget[0].DestinationAlphaBlend = D3D11.BlendOption.One;
                blendDesc.RenderTarget[0].SourceAlphaBlend      = D3D11.BlendOption.One;
                blendDesc.RenderTarget[0].AlphaBlendOperation   = D3D11.BlendOperation.Maximum;
                blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All;

                //Create the blendstate object
                return(new D3D11.BlendState(device.DeviceD3D11_1, blendDesc));
            });

            // Create default depth stencil state
            m_depthStencilStateDefault = new Lazy <D3D11.DepthStencilState>(() =>
            {
                D3D11.DepthStencilStateDescription stateDesc = D3D11.DepthStencilStateDescription.Default();
                stateDesc.DepthComparison = D3D11.Comparison.LessEqual;
                return(new D3D11.DepthStencilState(device.DeviceD3D11_1, stateDesc));
            });

            // Create the depth stencil state for diabling z writes
            m_depthStencilStateDisableZWrites = new Lazy <D3D11.DepthStencilState>(() =>
            {
                D3D11.DepthStencilStateDescription stateDesc = D3D11.DepthStencilStateDescription.Default();
                stateDesc.DepthWriteMask  = D3D11.DepthWriteMask.Zero;
                stateDesc.DepthComparison = D3D11.Comparison.LessEqual;
                return(new D3D11.DepthStencilState(device.DeviceD3D11_1, stateDesc));
            });

            m_depthStencilStateAllwaysPass = new Lazy <D3D11.DepthStencilState>(() =>
            {
                D3D11.DepthStencilStateDescription stateDesc = D3D11.DepthStencilStateDescription.Default();
                stateDesc.DepthWriteMask  = D3D11.DepthWriteMask.Zero;
                stateDesc.DepthComparison = D3D11.Comparison.Always;
                stateDesc.IsDepthEnabled  = false;
                return(new D3D11.DepthStencilState(device.DeviceD3D11_1, stateDesc));
            });

            // Create the depth stencil state for inverting z logic
            m_depthStencilStateInvertedZTest = new Lazy <D3D11.DepthStencilState>(() =>
            {
                D3D11.DepthStencilStateDescription stateDesc = D3D11.DepthStencilStateDescription.Default();
                stateDesc.DepthComparison = D3D11.Comparison.Greater;
                stateDesc.DepthWriteMask  = D3D11.DepthWriteMask.Zero;
                return(new D3D11.DepthStencilState(device.DeviceD3D11_1, stateDesc));
            });

            // Create default rasterizer state
            m_rasterStateDefault = new Lazy <D3D11.RasterizerState>(() =>
            {
                return(new D3D11.RasterizerState(device.DeviceD3D11_1, D3D11.RasterizerStateDescription.Default()));
            });

            // Create a raster state with depth bias
            m_rasterStateBiased = new Lazy <D3D11.RasterizerState>(() =>
            {
                D3D11.RasterizerStateDescription rasterDesc = D3D11.RasterizerStateDescription.Default();
                rasterDesc.DepthBias = GraphicsHelper.GetDepthBiasValue(device, -0.00003f);
                return(new D3D11.RasterizerState(device.DeviceD3D11_1, rasterDesc));
            });

            // Create a raster state for wireframe rendering
            m_rasterStateWireframe = new Lazy <SharpDX.Direct3D11.RasterizerState>(() =>
            {
                D3D11.RasterizerStateDescription rasterDesc = D3D11.RasterizerStateDescription.Default();
                rasterDesc.FillMode = D3D11.FillMode.Wireframe;
                return(new D3D11.RasterizerState(device.DeviceD3D11_1, rasterDesc));
            });

            // Create the rasterizer state for line rendering
            m_rasterStateLines = new Lazy <D3D11.RasterizerState>(() =>
            {
                D3D11.RasterizerStateDescription stateDesc = D3D11.RasterizerStateDescription.Default();
                stateDesc.CullMode = D3D11.CullMode.None;
                stateDesc.IsAntialiasedLineEnabled = true;
                stateDesc.FillMode = D3D11.FillMode.Solid;
                return(new D3D11.RasterizerState(device.DeviceD3D11_1, stateDesc));
            });

            // Create sampler states
            m_samplerStateLow = new Lazy <D3D11.SamplerState>(() =>
            {
                return(GraphicsHelper.CreateDefaultTextureSampler(device, TextureSamplerQualityLevel.Low));
            });
            m_samplerStateMedium = new Lazy <D3D11.SamplerState>(() =>
            {
                return(GraphicsHelper.CreateDefaultTextureSampler(device, TextureSamplerQualityLevel.Medium));
            });
            m_samplerStateHigh = new Lazy <D3D11.SamplerState>(() =>
            {
                return(GraphicsHelper.CreateDefaultTextureSampler(device, TextureSamplerQualityLevel.High));
            });
        }