Example #1
0
        public void SetBlendState(IBlendState rsBlend)
        {
            var mybs = rsBlend as CacheBlendState;

            if (mybs.Enabled)
            {
                GL.Enable(EnableCap.Blend);
                // these are all casts to copies of the same enum
                GL.BlendEquationSeparate(
                    (BlendEquationMode)(int)mybs.colorEquation,
                    (BlendEquationMode)(int)mybs.alphaEquation);
                GL.BlendFuncSeparate(
                    (BlendingFactorSrc)(int)mybs.colorSource,
                    (BlendingFactorDest)(int)mybs.colorDest,
                    (BlendingFactorSrc)(int)mybs.alphaSource,
                    (BlendingFactorDest)(int)mybs.alphaDest);
            }
            else
            {
                GL.Disable(EnableCap.Blend);
            }
            if (rsBlend == _rsBlendNoneOpaque)
            {
                //make sure constant color is set correctly
                GL.BlendColor(new Color4(255, 255, 255, 255));
            }
        }
Example #2
0
        public void SetBlendState(IBlendState rsBlend)
        {
            var mybs = rsBlend as CacheBlendState;

            if (mybs.Enabled)
            {
                dev.SetRenderState(RenderState.AlphaBlendEnable, true);
                dev.SetRenderState(RenderState.SeparateAlphaBlendEnable, true);

                dev.SetRenderState(RenderState.BlendOperation, ConvertBlendOp(mybs.colorEquation));
                dev.SetRenderState(RenderState.SourceBlend, ConvertBlendArg(mybs.colorSource));
                dev.SetRenderState(RenderState.DestinationBlend, ConvertBlendArg(mybs.colorDest));

                dev.SetRenderState(RenderState.BlendOperationAlpha, ConvertBlendOp(mybs.alphaEquation));
                dev.SetRenderState(RenderState.SourceBlendAlpha, ConvertBlendArg(mybs.alphaSource));
                dev.SetRenderState(RenderState.DestinationBlendAlpha, ConvertBlendArg(mybs.alphaDest));
            }
            else
            {
                dev.SetRenderState(RenderState.AlphaBlendEnable, false);
            }
            if (rsBlend == _rsBlendNoneOpaque)
            {
                //make sure constant color is set correctly
                dev.SetRenderState(RenderState.BlendFactor, -1);                 //white
            }
        }
Example #3
0
        public void SetBlendState(IBlendState rsBlend)
        {
#if DEBUG
            BlendStateSet = true;
#endif
            Flush();
            Owner.SetBlendState(rsBlend);
        }
Example #4
0
        public void SetBlendState(IBlendState blendState)
        {
            var command = new GLCommand
            {
                Type = CommandType.SetBlendState,
            };

            _commandList.Add(command);
        }
Example #5
0
        public void Begin(int width, int height)
        {
            Begin();

            CurrentBlendState = Gdi.BlendNormal;

            Projection = Owner.CreateGuiProjectionMatrix(width, height);
            Modelview  = Owner.CreateGuiViewMatrix(width, height);
        }
Example #6
0
        public void SetBlendState(IBlendState blendState)
        {
            var command = new D3D11Command
            {
                Type       = CommandType.SetBlendState,
                BlendState = (D3D11BlendState)blendState
            };

            _commandList.Add(command);
        }
Example #7
0
        internal static void Run(IRtvBindable dst, ISrvBindable src, IBlendState bs = null)
        {
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Example #8
0
        internal static void Run(IRtvBindable dst, ISrvBindable src, IBlendState bs = null)
        {
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Example #9
0
        internal void SetBlendState(IBlendState bs)
        {
            BlendState dxstate = null;

            if (bs != null)
            {
                IBlendStateInternal bsInternal = (IBlendStateInternal)bs;
                dxstate = bsInternal.Resource;
            }
            m_state.SetBlendState(dxstate);
            CheckErrors();
        }
Example #10
0
 public D3D11Pipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout,
                      IBlendState blendState, IDepthStencilState depthStencilState, IRasterizerState rasterizerState,
                      Viewport viewport, PrimitiveTopology primitiveTopology)
 {
     VertexShader      = vertexShader;
     PixelShader       = pixelShader;
     InputLayout       = inputLayout;
     BlendState        = blendState;
     DepthStencilState = depthStencilState;
     RasterizerState   = rasterizerState;
     Viewport          = viewport;
     PrimitiveTopology = primitiveTopology;
 }
Example #11
0
 public void InitStandard(string cmFilepath, string ngFilepath, string extFilepath)
 {
     m_srvs = new ISrvBindable[]
     {
         MyManagers.FileTextures.GetTexture(cmFilepath, MyFileTextureEnum.COLOR_METAL),
         MyManagers.FileTextures.GetTexture(ngFilepath, MyFileTextureEnum.NORMALMAP_GLOSS),
         MyManagers.FileTextures.GetTexture(extFilepath, MyFileTextureEnum.EXTENSIONS)
     };
     m_depthStencilState    = MyDepthStencilStateManager.DefaultDepthState;
     m_blendState           = null;
     m_rasterizerState      = null;
     m_isFaceCullingEnabled = true;
 }
Example #12
0
        public void SetBlendState(IBlendState rsBlend)
        {
            var mybs = rsBlend as MyBlendState;

            if (mybs.enabled)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendEquationSeparate(mybs.colorEquation, mybs.alphaEquation);
                GL.BlendFuncSeparate(mybs.colorSource, mybs.colorDest, mybs.alphaSource, mybs.alphaDest);
            }
            else
            {
                GL.Disable(EnableCap.Blend);
            }
        }
Example #13
0
        internal static void RunWithPixelStencilTest(IRtvBindable dst, ISrvBindable src, IBlendState bs = null,
            bool inverseTest = false, IDepthStencil depthStencil = null)
        {
            RC.SetDepthStencilState(null);
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.SetSrv(1, depthStencil == null ? MyGBuffer.Main.DepthStencil.SrvStencil : depthStencil.SrvStencil);
            if (!inverseTest)
                RC.PixelShader.Set(m_stencilTestPixelShader);
            else
                RC.PixelShader.Set(m_stencilInverseTestPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Example #14
0
        public static IBlendState New(VideoTypes videoType, IDisposableResource parent, IBlendStateDesc desc)
        {
            IBlendState api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.BlendState(parent, desc);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.BlendState(parent, desc);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.BlendState(parent, desc);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.BlendState(parent, desc);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.BlendState(parent, desc);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("BlendStateAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
Example #15
0
        public void SetBlendState(IBlendState rsBlend)
        {
            var mybs = rsBlend as CacheBlendState;

            if (mybs.Enabled)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendEquationSeparate(mybs.colorEquation, mybs.alphaEquation);
                GL.BlendFuncSeparate(mybs.colorSource, mybs.colorDest, mybs.alphaSource, mybs.alphaDest);
            }
            else
            {
                GL.Disable(EnableCap.Blend);
            }
            if (rsBlend == _rsBlendNoneOpaque)
            {
                //make sure constant color is set correctly
                GL.BlendColor(new Color4(255, 255, 255, 255));
            }
        }
Example #16
0
        public SpriteBatchRenderer(IDevice device, IBlobReader blobReader, ICameraFactory cameraFactory)
        {
            _device  = device;
            _context = _device.ImmediateContext;
            _camera  = cameraFactory.CreateOrhographicCamera();

            _buffer       = device.CreateVertexBuffer <Vertex2D>(MaxVertices, BufferUsage.Dynamic, BufferAccessFlags.Write);
            _indices      = device.CreateIndexBuffer(CreateIndices());
            _sampler      = device.CreateSampler(true);
            _blendState   = device.CreateBlendState();
            _cameraBuffer = device.CreateConstantBuffer(new Camera {
                Transform = _camera.ViewProjection
            });
            using var vertexShaderBlob = blobReader.ReadFromFile("Shaders/VertexShader2D.cso");
            _vertexShader             = device.CreateVertexShader(vertexShaderBlob);
            using var pixelShaderBlob = blobReader.ReadFromFile("Shaders/PixelShader2D.cso");
            _pixelShader = device.CreatePixelShader(pixelShaderBlob);

            _inputLayout = device.CreateInputLayout(new VertexLayout(3).Append("Position", VertexLayoutTypes.Position2D).Append("Textures", VertexLayoutTypes.Texture2D).Append("Color", VertexLayoutTypes.Float4Color), vertexShaderBlob);
        }
Example #17
0
 public void InitDecal(string cmFilepath, string ngFilepath, string extFilepath, string alphamaskFilepath, bool isPremultipliedAlpha, bool isCutout)
 {
     m_srvs = new ISrvBindable[]
     {
         MyManagers.FileTextures.GetTexture(cmFilepath, MyFileTextureEnum.COLOR_METAL),
         MyManagers.FileTextures.GetTexture(ngFilepath, MyFileTextureEnum.NORMALMAP_GLOSS),
         MyManagers.FileTextures.GetTexture(extFilepath, MyFileTextureEnum.EXTENSIONS),
         MyManagers.FileTextures.GetTexture(alphamaskFilepath, MyFileTextureEnum.ALPHAMASK)
     };
     m_depthStencilState = MyDepthStencilStateManager.DepthTestReadOnly;
     if (isCutout)
     {
         m_blendState = null;
     }
     else
     {
         m_blendState = GetAlphamaskBlendState(cmFilepath, ngFilepath, extFilepath, isPremultipliedAlpha);
     }
     m_rasterizerState      = MyRasterizerStateManager.DecalRasterizerState;
     m_isFaceCullingEnabled = true;
 }
Example #18
0
        internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState,
            IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null)
        {
            RC.SetBlendState(blendState);
            RC.SetRasterizerState(null);
            if (depthStencilState == null)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
                RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilMask);
                RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource);
            }

            RC.PixelShader.SetSrv(0, sourceResource);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Example #19
0
        protected override void Initialize()
        {
            base.Initialize();

            Window.Title = "Xacor.Demo";

            _viewMatrix       = Matrix.LookAtRH(new Vector3(0, 0, 10f), Vector3.Zero, Vector3.UnitY);
            _projectionMatrix = Matrix.PerspectiveFovRH(MathF.PI / 3.0f, _renderResolution.Width / (float)_renderResolution.Height, 0.1f, 4096f);
            _leftMvp          = new InputBuffer
            {
                ModelViewProjectionMatrix = Matrix.Translation(-1.5f, 1, -0.5f) * _viewMatrix * _projectionMatrix
            };

            _rightMvp = new InputBuffer
            {
                ModelViewProjectionMatrix = Matrix.Translation(1.5f, -1, 0.5f) * _viewMatrix * _projectionMatrix
            };

            _viewport                 = new Viewport(0, 0, _renderResolution.Width, _renderResolution.Height, 0.1f, 4096f);
            _defaultBlendState        = GraphicsFactory.CreateBlendState(true, Blend.SourceAlpha, Blend.InverseSourceAlpha, BlendOperation.Add, Blend.One, Blend.Zero, BlendOperation.Add);
            _defaultDepthStencilState = GraphicsFactory.CreateDepthStencilState();
            _defaultRasterizerState   = GraphicsFactory.CreateRasterizerState(CullMode.None, FillMode.Solid, true, false, false, false);

            var macros = new[] { ("TEST", "0") };
Example #20
0
 public void SetBlendState(IBlendState rsBlend)
 {
     //TODO for real
 }
Example #21
0
 public IPipeline CreatePipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout, IBlendState blendState,
                                 IDepthStencilState depthStencilState, IRasterizerState rasterizerState, Viewport viewport,
                                 PrimitiveTopology primitiveTopology)
 {
     throw new System.NotImplementedException();
 }
Example #22
0
 public IPipeline CreatePipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout,
                                 IBlendState blendState, IDepthStencilState depthStencilState, IRasterizerState rasterizerState,
                                 Viewport viewport, PrimitiveTopology primitiveTopology)
 {
     return(new D3D11Pipeline(vertexShader, pixelShader, inputLayout, blendState, depthStencilState, rasterizerState, viewport, primitiveTopology));
 }
Example #23
0
		public void SetBlendState(IBlendState rsBlend)
		{
#if DEBUG
			BlendStateSet = true;
#endif
			Flush();
			Owner.SetBlendState(rsBlend);
		}
Example #24
0
		public void SetBlendState(IBlendState rsBlend)
		{
			CurrentBlendState = rsBlend;
		}
Example #25
0
		public void Begin(int width, int height, bool yflipped = false)
		{
			Begin();

			CurrentBlendState = Gdi.BlendNormal;

			Projection = Owner.CreateGuiProjectionMatrix(width, height);
			Modelview = Owner.CreateGuiViewMatrix(width, height);
		}
Example #26
0
        internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState,
                                            IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null)
        {
            RC.SetBlendState(blendState);
            RC.SetRasterizerState(null);
            if (depthStencilState == null)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
                RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilMask);
                RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource);
            }

            RC.PixelShader.SetSrv(0, sourceResource);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Example #27
0
 public void SetBlendState(IBlendState rsBlend)
 {
     //TODO for real
 }
Example #28
0
		public void SetBlendState(IBlendState rsBlend)
		{
			
			var mybs = rsBlend as CacheBlendState;
			if (mybs.Enabled)
			{
				dev.SetRenderState(RenderState.AlphaBlendEnable, true);
				dev.SetRenderState(RenderState.SeparateAlphaBlendEnable, true);

				dev.SetRenderState(RenderState.BlendOperation, ConvertBlendOp(mybs.colorEquation));
				dev.SetRenderState(RenderState.SourceBlend, ConvertBlendArg(mybs.colorSource));
				dev.SetRenderState(RenderState.DestinationBlend, ConvertBlendArg(mybs.colorDest));

				dev.SetRenderState(RenderState.BlendOperationAlpha, ConvertBlendOp(mybs.alphaEquation));
				dev.SetRenderState(RenderState.SourceBlendAlpha, ConvertBlendArg(mybs.alphaSource));
				dev.SetRenderState(RenderState.DestinationBlendAlpha, ConvertBlendArg(mybs.alphaDest));
			}
			else dev.SetRenderState(RenderState.AlphaBlendEnable, false);
			if (rsBlend == _rsBlendNoneOpaque)
			{
				//make sure constant color is set correctly
				dev.SetRenderState(RenderState.BlendFactor, -1); //white
			}
		}
Example #29
0
		public void SetBlendState(IBlendState rsBlend)
		{
			var mybs = rsBlend as MyBlendState;
			if (mybs.enabled)
			{
				GL.Enable(EnableCap.Blend);
				GL.BlendEquationSeparate(mybs.colorEquation, mybs.alphaEquation);
				GL.BlendFuncSeparate(mybs.colorSource, mybs.colorDest, mybs.alphaSource, mybs.alphaDest);
			}
			else GL.Disable(EnableCap.Blend);
		}
Example #30
0
		public void SetBlendState(IBlendState rsBlend)
		{
			var mybs = rsBlend as CacheBlendState;
			if (mybs.Enabled)
			{
				GL.Enable(EnableCap.Blend);
				GL.BlendEquationSeparate(mybs.colorEquation, mybs.alphaEquation);
				GL.BlendFuncSeparate(mybs.colorSource, mybs.colorDest, mybs.alphaSource, mybs.alphaDest);
			}
			else GL.Disable(EnableCap.Blend);
			if (rsBlend == _rsBlendNoneOpaque)
			{
				//make sure constant color is set correctly
				GL.BlendColor(new Color4(255, 255, 255, 255));
			}
		}
Example #31
0
 public Stars(IDevice device, int starCount)
 {
     this.starCount = starCount;
     shaders = CreateShaders(device);
     timeUbuffer = CreateTimeUbuffer(device);
     vertexLayout = CreateVertexLayout(device, shaders.VertexShader);
     vertexBuffer = CreateVertexBuffer(device, starCount);
     indexBuffer = CreateIndexBuffer(device, starCount);
     rasterizerState = CreateRasterizerState(device);
     depthStencilState = CreateDepthStencilState(device);
     blendState = CreateBlendState(device);
 }
Example #32
0
        internal void Apply(IBlendState compareTo)
        {
            //AlphaToCoverage nicht unterstützt
            //IndependantBlend nicht unterstützt

            if (compareTo != null)
            {
                if (Info.RenderTargets != null)
                {
                    //States jedes einzelnen RenderTargets setzen
                    for (int i = 0; i < Info.RenderTargets.Length; i++)
                    {
                        bool compareRenderTargetExists = compareTo.Info.RenderTargets != null && compareTo.Info.RenderTargets.Length > i;

                        if (!compareRenderTargetExists || Info.RenderTargets[i].IsBlendEnabled != compareTo.Info.RenderTargets[i].IsBlendEnabled)
                        {
                            if (Info.RenderTargets[i].IsBlendEnabled)
                            {
                                GL.Enable(IndexedEnableCap.Blend, i);
                            }
                            else
                            {
                                GL.Disable(IndexedEnableCap.Blend, i);
                            }
                        }

                        if (graphicsDevice.OpenGLCapabilities.GLSLVersion.Major >= 4)
                        {
                            //BlendOperation und Blend für jedes RT einzeln setzen

                            if ((!compareRenderTargetExists || (compareTo.Info.RenderTargets[i].SrcBlend != Info.RenderTargets[i].SrcBlend || compareTo.Info.RenderTargets[i].DestBlend != Info.RenderTargets[i].DestBlend || compareTo.Info.RenderTargets[i].SrcBlendAlpha != Info.RenderTargets[i].SrcBlendAlpha || compareTo.Info.RenderTargets[i].DestBlendAlpha != Info.RenderTargets[i].DestBlendAlpha)))
                            {
                                GL.BlendFuncSeparate(i, EnumConverter.Convert(Info.RenderTargets[i].SrcBlend), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[i].DestBlend), EnumConverter.Convert(Info.RenderTargets[i].SrcBlendAlpha), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[i].DestBlendAlpha));
                            }

                            if (graphicsDevice.OpenGLCapabilities.GLSLVersion.Major >= 4 && (!compareRenderTargetExists || (Info.RenderTargets[i].BlendOp != compareTo.Info.RenderTargets[i].BlendOp || Info.RenderTargets[i].BlendOpAlpha != compareTo.Info.RenderTargets[i].BlendOpAlpha)))
                            {
                                GL.BlendEquationSeparate(i, EnumConverter.Convert(Info.RenderTargets[i].BlendOp), EnumConverter.Convert(Info.RenderTargets[i].BlendOpAlpha));
                            }
                        }
                        else
                        {
                            //BlendOperation und Blend setzen

                            compareRenderTargetExists = compareTo.Info.RenderTargets != null && compareTo.Info.RenderTargets.Length != 0;
                            if (compareRenderTargetExists || (compareTo.Info.RenderTargets[0].SrcBlend != Info.RenderTargets[0].SrcBlend && compareTo.Info.RenderTargets[0].DestBlend != Info.RenderTargets[0].DestBlend && compareTo.Info.RenderTargets[0].SrcBlendAlpha != Info.RenderTargets[0].SrcBlendAlpha && compareTo.Info.RenderTargets[0].DestBlendAlpha != Info.RenderTargets[0].DestBlendAlpha))
                            {
                                GL.BlendFuncSeparate(EnumConverter.Convert(Info.RenderTargets[0].SrcBlend), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[0].DestBlend), EnumConverter.Convert(Info.RenderTargets[0].SrcBlendAlpha), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[0].DestBlendAlpha));
                            }


                            if (!compareRenderTargetExists || (Info.RenderTargets[i].BlendOp != compareTo.Info.RenderTargets[0].BlendOp || Info.RenderTargets[0].BlendOpAlpha != compareTo.Info.RenderTargets[0].BlendOpAlpha))
                            {
                                GL.BlendEquationSeparate(EnumConverter.Convert(Info.RenderTargets[0].BlendOp), EnumConverter.Convert(Info.RenderTargets[0].BlendOpAlpha));
                            }
                        }

                        if (!compareRenderTargetExists || compareTo.Info.RenderTargets[i].RenderTargetWriteMask != Info.RenderTargets[i].RenderTargetWriteMask)
                        {
                            GL.ColorMask(i, Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Red), Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Blue), Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Green), Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Alpha));
                        }
                    }
                }
            }
            else
            {
                if (Info.RenderTargets != null)
                {
                    //States jedes einzelnen RenderTargets setzen
                    for (int i = 0; i < Info.RenderTargets.Length; i++)
                    {
                        if (Info.RenderTargets[i].IsBlendEnabled)
                        {
                            GL.Enable(IndexedEnableCap.Blend, i);
                        }
                        else
                        {
                            GL.Disable(IndexedEnableCap.Blend, i);
                        }

                        if (graphicsDevice.OpenGLCapabilities.GLSLVersion.Major >= 4)
                        {
                            //BlendOperation und Blend für jedes RT einzeln setzen

                            GL.BlendFuncSeparate(i, EnumConverter.Convert(Info.RenderTargets[i].SrcBlend), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[i].DestBlend), EnumConverter.Convert(Info.RenderTargets[i].SrcBlendAlpha), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[i].DestBlendAlpha));
                            GL.BlendEquationSeparate(i, EnumConverter.Convert(Info.RenderTargets[i].BlendOp), EnumConverter.Convert(Info.RenderTargets[i].BlendOpAlpha));
                        }

                        GL.ColorMask(i, Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Red), Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Blue), Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Green), Info.RenderTargets[i].RenderTargetWriteMask.HasFlag(ColorWriteMaskFlags.Alpha));
                    }
                    if (graphicsDevice.OpenGLCapabilities.GLSLVersion.Major < 4 && Info.RenderTargets != null && Info.RenderTargets.Length > 0)
                    {
                        //BlendOperation und Blend setzen

                        GL.BlendFuncSeparate(EnumConverter.Convert(Info.RenderTargets[0].SrcBlend), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[0].DestBlend), EnumConverter.Convert(Info.RenderTargets[0].SrcBlendAlpha), (BlendingFactorDest)EnumConverter.Convert(Info.RenderTargets[0].DestBlendAlpha));
                        GL.BlendEquationSeparate(EnumConverter.Convert(Info.RenderTargets[0].BlendOp), EnumConverter.Convert(Info.RenderTargets[0].BlendOpAlpha));
                    }
                }
            }
        }
Example #33
0
        // viewport, render target
        internal unsafe static void Draw(IRtvBindable rtv, MyViewport viewport, IBlendState blendstate = null)
        {
            if (StackTop.m_internalBatch.Texture != null && StackTop.m_internalBatch.Count > 0)
                StackTop.m_internalBatch.Commit();
            StackTop.m_internalBatch = new MySpritesBatch();

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);

            RC.SetInputLayout(m_inputLayout);
            //RC.SetScreenViewport();
            RC.SetViewport(viewport.OffsetX, viewport.OffsetY, viewport.Width, viewport.Height);

            RC.VertexShader.Set(m_vs);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.GetObjectCB(64));
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            //RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, MyRender11.Backbuffer);
            // to reset state
            RC.SetRtv(rtv);

            RC.SetBlendState(blendstate == null ? MyBlendStateManager.BlendAlphaPremult : blendstate);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil, 0);

            CheckBufferSize(StackTop.m_instances.Count);
            RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride);

            var mapping = MyMapping.MapDiscard(m_VB.Buffer);
            for (int i = 0; i < StackTop.m_instances.Count; i++)
            {
                var helper = StackTop.m_instances[i];
                mapping.WriteAndPosition(ref helper);
            }
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(64));
            var viewportSize = new Vector2(viewport.Width, viewport.Height);
            mapping.WriteAndPosition(ref viewportSize);
            mapping.Unmap();

            foreach (var batch in StackTop.m_batches)
            {
                if(batch.ScissorRectangle.HasValue)
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.ScissorTestRasterizerState);

                    var scissor = batch.ScissorRectangle.Value;
                    RC.SetScissorRectangle((int)scissor.X, (int)scissor.Y, (int)(scissor.X + scissor.Width), (int)(scissor.Y + scissor.Height));
                }
                else
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
                }

                RC.PixelShader.SetSrv(0, batch.Texture);
                RC.DrawInstanced(4, batch.Count, 0, batch.Start);
            }

            RC.SetBlendState(null);
            RC.SetRasterizerState(null);
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            StackTop.m_instances.Clear();
            StackTop.m_batches.Clear();
        }
Example #34
0
        internal static void RunWithPixelStencilTest(IRtvBindable dst, ISrvBindable src, IBlendState bs = null,
                                                     bool inverseTest = false, IDepthStencil depthStencil = null)
        {
            RC.SetDepthStencilState(null);
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.SetSrv(1, depthStencil == null ? MyGBuffer.Main.DepthStencil.SrvStencil : depthStencil.SrvStencil);
            if (!inverseTest)
            {
                RC.PixelShader.Set(m_stencilTestPixelShader);
            }
            else
            {
                RC.PixelShader.Set(m_stencilInverseTestPixelShader);
            }

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Example #35
0
 public void SetBlendState(IBlendState rsBlend)
 {
     CurrentBlendState = rsBlend;
 }
Example #36
0
        // viewport, render target
        internal unsafe static void Draw(IRtvBindable rtv, MyViewport viewport, IBlendState blendstate = null)
        {
            if (StackTop.m_internalBatch.Texture != null && StackTop.m_internalBatch.Count > 0)
            {
                StackTop.m_internalBatch.Commit();
            }
            StackTop.m_internalBatch = new MySpritesBatch();

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);

            RC.SetInputLayout(m_inputLayout);
            //RC.SetScreenViewport();
            RC.SetViewport(viewport.OffsetX, viewport.OffsetY, viewport.Width, viewport.Height);

            RC.VertexShader.Set(m_vs);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.GetObjectCB(64));
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            //RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, MyRender11.Backbuffer);
            // to reset state
            RC.SetRtv(rtv);

            RC.SetBlendState(blendstate == null ? MyBlendStateManager.BlendAlphaPremult : blendstate);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil, 0);

            CheckBufferSize(StackTop.m_instances.Count);
            RC.SetVertexBuffer(0, m_VB);

            var mapping = MyMapping.MapDiscard(m_VB);

            for (int i = 0; i < StackTop.m_instances.Count; i++)
            {
                var helper = StackTop.m_instances[i];
                mapping.WriteAndPosition(ref helper);
            }
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(64));
            var viewportSize = new Vector2(viewport.Width, viewport.Height);

            mapping.WriteAndPosition(ref viewportSize);
            mapping.Unmap();

            foreach (var batch in StackTop.m_batches)
            {
                if (batch.ScissorRectangle.HasValue)
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.ScissorTestRasterizerState);

                    var scissor = batch.ScissorRectangle.Value;
                    RC.SetScissorRectangle((int)scissor.X, (int)scissor.Y, (int)(scissor.X + scissor.Width), (int)(scissor.Y + scissor.Height));
                }
                else
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
                }

                RC.PixelShader.SetSrv(0, batch.Texture);
                RC.DrawInstanced(4, batch.Count, 0, batch.Start);
            }

            RC.SetBlendState(null);
            RC.SetRasterizerState(null);
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            StackTop.m_instances.Clear();
            StackTop.m_batches.Clear();
        }
        public MyBlendStateManager()
        {
            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].SourceBlend           = BlendOption.SourceAlpha;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.SourceAlpha;
                BlendGui = CreateResource("BlendGui", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.One;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                BlendAdditive = CreateResource("BlendAdditive", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.SourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                BlendAtmosphere = CreateResource("BlendAtmosphere", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].SourceBlend           = BlendOption.SourceAlpha;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.SourceAlpha;
                BlendTransparent = CreateResource("BlendTransparent", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                BlendAlphaPremult = CreateResource("BlendAlphaPremult", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.Zero;
                BlendAlphaPremultNoAlphaChannel            = CreateResource("BlendAlphaPremultNoAlphaChannel", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.SourceColor;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].SourceBlend           = BlendOption.Zero;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                BlendOutscatter = CreateResource("BlendOutscatter", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.IndependentBlendEnable = true;

                // color
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green |
                                                             ColorWriteMaskFlags.Blue;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.Zero;
                // metal
                desc.RenderTarget[2].IsBlendEnabled        = true;
                desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red;
                desc.RenderTarget[2].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[2].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[2].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[2].SourceBlend           = BlendOption.One;
                desc.RenderTarget[2].SourceAlphaBlend      = BlendOption.Zero;

                BlendDecalColor = CreateResource("BlendDecalColor", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.IndependentBlendEnable = true;

                // normal
                desc.RenderTarget[1].IsBlendEnabled        = true;
                desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green |
                                                             ColorWriteMaskFlags.Blue;
                desc.RenderTarget[1].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[1].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[1].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[1].SourceBlend           = BlendOption.SourceAlpha;
                desc.RenderTarget[1].SourceAlphaBlend      = BlendOption.Zero;
                // gloss
                desc.RenderTarget[2].IsBlendEnabled        = true;
                desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Green;
                desc.RenderTarget[2].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[2].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[2].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[2].SourceBlend           = BlendOption.One;
                desc.RenderTarget[2].SourceAlphaBlend      = BlendOption.Zero;

                BlendDecalNormal = CreateResource("BlendDecalNormal", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.IndependentBlendEnable = true;

                // color
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green |
                                                             ColorWriteMaskFlags.Blue;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.Zero;
                // normal
                desc.RenderTarget[1].IsBlendEnabled        = true;
                desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green |
                                                             ColorWriteMaskFlags.Blue;
                desc.RenderTarget[1].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[1].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[1].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[1].SourceBlend           = BlendOption.SourceAlpha;
                desc.RenderTarget[1].SourceAlphaBlend      = BlendOption.Zero;
                // metal/gloss
                desc.RenderTarget[2].IsBlendEnabled        = true;
                desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green;
                desc.RenderTarget[2].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[2].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[2].DestinationBlend      = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[2].SourceBlend           = BlendOption.One;
                desc.RenderTarget[2].SourceAlphaBlend      = BlendOption.Zero;

                BlendDecalNormalColor = CreateResource("BlendDecalNormalColor", ref desc);

                desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green |
                                                             ColorWriteMaskFlags.Blue;
                BlendDecalNormalColorExt = CreateResource("BlendDecalNormalColorExt", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.SourceAlpha;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.SourceAlpha;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                BlendWeightedTransparencyResolve           = CreateResource("BlendWeightedTransparencyResolve", ref desc);
            }

            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.IndependentBlendEnable = true;

                // accumulation target
                desc.RenderTarget[0].IsBlendEnabled        = true;
                desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[0].DestinationBlend      = BlendOption.One;
                desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
                desc.RenderTarget[0].SourceBlend           = BlendOption.One;
                desc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                // coverage target
                desc.RenderTarget[1].IsBlendEnabled        = true;
                desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                desc.RenderTarget[1].BlendOperation        = BlendOperation.Add;
                desc.RenderTarget[1].AlphaBlendOperation   = BlendOperation.Add;
                desc.RenderTarget[1].DestinationBlend      = BlendOption.InverseSourceColor;
                desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
                desc.RenderTarget[1].SourceBlend           = BlendOption.Zero;
                desc.RenderTarget[1].SourceAlphaBlend      = BlendOption.Zero;
                BlendWeightedTransparency = CreateResource("BlendWeightedTransparency", ref desc);
            }
        }
Example #38
0
        /// <summary>
        /// OpenGL States auf DirectX11 default Werte setzen
        /// </summary>
        private void CreateDefaultState()
        {
            IBlendState defaultBlend = graphicsDevice.Factory.CreateBlendState(new BlendStateInfo()
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false,
                RenderTargets          = new RTBlendInfo[] {
                    new RTBlendInfo()
                    {
                        IsBlendEnabled        = false,
                        SrcBlend              = Blend.One,
                        DestBlend             = Blend.Zero,
                        BlendOp               = Graphics.BlendOp.Add,
                        SrcBlendAlpha         = Blend.One,
                        DestBlendAlpha        = Blend.Zero,
                        BlendOpAlpha          = BlendOp.Add,
                        RenderTargetWriteMask = ColorWriteMaskFlags.All,
                    }
                },
            });

            IRasterizerState defaultRasterizer = graphicsDevice.Factory.CreateRasterizerState(new RasterizerStateInfo()
            {
                FillMode = FillMode.Solid,
                CullMode = CullMode.None,
                IsFrontCounterClockwise = false,
                DepthBias                = 0,
                SlopeScaledDepthBias     = 0.0f,
                DepthBiasClamp           = 0.0f,
                IsDepthClipEnabled       = true,
                IsScissorEnabled         = true,
                IsMultisampleEnabled     = false,
                IsAntialiasedLineEnabled = false,
            });

            IDepthStencilState defaultDepthStencil = graphicsDevice.Factory.CreateDepthStencilState(new DepthStencilStateInfo()
            {
                IsDepthEnabled   = true,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparsion  = Comparison.Less,
                IsStencilEnabled = false,
                StencilReadMask  = 0x0,
                StencilWriteMask = 0x0,
                FrontFace        = new DepthStencilOperator()
                {
                    Comparsion         = Comparison.Always,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                },
                BackFace = new DepthStencilOperator()
                {
                    Comparsion         = Comparison.Always,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                },
            });

            graphicsDevice.Cast <BlendState>(defaultBlend, "defaultBlend").Apply();
            graphicsDevice.Cast <RasterizerState>(defaultRasterizer, "defaultRasterizer").Apply();
            graphicsDevice.Cast <DepthStencilState>(defaultDepthStencil, "depthStencil").Apply(currentStencilReference);
        }
Example #39
0
        public ColorfulSpaceScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var geometryShader = Device.Create.GeometryShader(ShaderParser.Parse(GeometryShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, geometryShader, pixelShader);

            var vertexData = new Vertex[ParticleCount];
            for (int i = 0; i < vertexData.Length; i++)
                vertexData[i] = new Vertex((float)i / ParticleCount);

            vertexBuffer = Device.Create.Buffer(new BufferDescription
            {
                Usage = Usage.Immutable,
                SizeInBytes = ParticleCount * Vertex.SizeInBytes,
                BindFlags = BindFlags.VertexBuffer,
                ExtraFlags = ExtraFlags.Points
            }, new SubresourceData(vertexData));

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12)
            });

            timeBuffer = Device.Create.Buffer(new BufferDescription
            {
                Usage = Usage.Dynamic,
                SizeInBytes = Time.SizeInBytes,
                BindFlags = BindFlags.UniformBuffer
            });

            cameraBuffer = Device.Create.Buffer(new BufferDescription
            {
                Usage = Usage.Dynamic,
                SizeInBytes = Camera.SizeInBytes,
                BindFlags = BindFlags.UniformBuffer
            });

            blendState = Device.Create.BlendState(BlendDescription.Additive);
        }