private SetConstantBuffers ( Microsoft.Xna.Framework.Graphics.GraphicsDevice device ) : void | ||
device | Microsoft.Xna.Framework.Graphics.GraphicsDevice | |
return | void |
private void ApplyState() { // Apply RasterizerState now, as it depends on other device states GLDevice.ApplyRasterizerState( RasterizerState, RenderTargetCount > 0 ); // TODO: MSAA? if (VertexShader == null) { throw new InvalidOperationException("A vertex shader must be set!"); } if (PixelShader == null) { throw new InvalidOperationException("A pixel shader must be set!"); } if (vertexShaderDirty || pixelShaderDirty) { ActivateShaderProgram(); vertexShaderDirty = pixelShaderDirty = false; } vertexConstantBuffers.SetConstantBuffers(this, shaderProgram); pixelConstantBuffers.SetConstantBuffers(this, shaderProgram); }
private void ApplyState() { // Apply RasterizerState now, as it depends on other device states GLDevice.ApplyRasterizerState( RasterizerState, RenderTargetCount > 0 ); while (ModifiedSamplers.Count > 0) { int sampler = ModifiedSamplers.Dequeue(); GLDevice.VerifySampler( sampler, Textures[sampler], SamplerStates[sampler] ); } // TODO: MSAA? if (VertexShader == null) { throw new InvalidOperationException("A vertex shader must be set!"); } if (PixelShader == null) { throw new InvalidOperationException("A pixel shader must be set!"); } if (vertexShaderDirty || pixelShaderDirty) { ActivateShaderProgram(); vertexShaderDirty = pixelShaderDirty = false; } vertexConstantBuffers.SetConstantBuffers(this, shaderProgram); pixelConstantBuffers.SetConstantBuffers(this, shaderProgram); }
private void ApplyState() { // Apply BlendState OpenGLDevice.Instance.AlphaBlendEnable.Set( !(BlendState.ColorSourceBlend == Blend.One && BlendState.ColorDestinationBlend == Blend.Zero && BlendState.AlphaSourceBlend == Blend.One && BlendState.AlphaDestinationBlend == Blend.Zero) ); OpenGLDevice.Instance.BlendColor.Set(BlendState.BlendFactor); OpenGLDevice.Instance.BlendOp.Set(BlendState.ColorBlendFunction); OpenGLDevice.Instance.BlendOpAlpha.Set(BlendState.AlphaBlendFunction); OpenGLDevice.Instance.SrcBlend.Set(BlendState.ColorSourceBlend); OpenGLDevice.Instance.DstBlend.Set(BlendState.ColorDestinationBlend); OpenGLDevice.Instance.SrcBlendAlpha.Set(BlendState.AlphaSourceBlend); OpenGLDevice.Instance.DstBlendAlpha.Set(BlendState.AlphaDestinationBlend); OpenGLDevice.Instance.ColorWriteEnable.Set(BlendState.ColorWriteChannels); // Apply DepthStencilState OpenGLDevice.Instance.ZEnable.Set(DepthStencilState.DepthBufferEnable); OpenGLDevice.Instance.ZWriteEnable.Set(DepthStencilState.DepthBufferWriteEnable); OpenGLDevice.Instance.DepthFunc.Set(DepthStencilState.DepthBufferFunction); OpenGLDevice.Instance.StencilEnable.Set(DepthStencilState.StencilEnable); OpenGLDevice.Instance.StencilWriteMask.Set(DepthStencilState.StencilWriteMask); OpenGLDevice.Instance.SeparateStencilEnable.Set(DepthStencilState.TwoSidedStencilMode); OpenGLDevice.Instance.StencilRef.Set(DepthStencilState.ReferenceStencil); OpenGLDevice.Instance.StencilMask.Set(DepthStencilState.StencilMask); OpenGLDevice.Instance.StencilFunc.Set(DepthStencilState.StencilFunction); OpenGLDevice.Instance.CCWStencilFunc.Set(DepthStencilState.CounterClockwiseStencilFunction); OpenGLDevice.Instance.StencilFail.Set(DepthStencilState.StencilFail); OpenGLDevice.Instance.StencilZFail.Set(DepthStencilState.StencilDepthBufferFail); OpenGLDevice.Instance.StencilPass.Set(DepthStencilState.StencilPass); OpenGLDevice.Instance.CCWStencilFail.Set(DepthStencilState.CounterClockwiseStencilFail); OpenGLDevice.Instance.CCWStencilZFail.Set(DepthStencilState.CounterClockwiseStencilDepthBufferFail); OpenGLDevice.Instance.CCWStencilPass.Set(DepthStencilState.CounterClockwiseStencilPass); // Apply RasterizerState if (RenderTargetCount > 0) { OpenGLDevice.Instance.CullFrontFace.Set(RasterizerState.CullMode); } else { // When not rendering offscreen the faces change order. if (RasterizerState.CullMode == CullMode.None) { OpenGLDevice.Instance.CullFrontFace.Set(RasterizerState.CullMode); } else { OpenGLDevice.Instance.CullFrontFace.Set( RasterizerState.CullMode == CullMode.CullClockwiseFace ? CullMode.CullCounterClockwiseFace : CullMode.CullClockwiseFace ); } } OpenGLDevice.Instance.GLFillMode.Set(RasterizerState.FillMode); OpenGLDevice.Instance.ScissorTestEnable.Set(RasterizerState.ScissorTestEnable); OpenGLDevice.Instance.DepthBias.Set(RasterizerState.DepthBias); OpenGLDevice.Instance.SlopeScaleDepthBias.Set(RasterizerState.SlopeScaleDepthBias); // TODO: MSAA? if (VertexShader == null) { throw new InvalidOperationException("A vertex shader must be set!"); } if (PixelShader == null) { throw new InvalidOperationException("A pixel shader must be set!"); } if (vertexShaderDirty || pixelShaderDirty) { ActivateShaderProgram(); vertexShaderDirty = pixelShaderDirty = false; } vertexConstantBuffers.SetConstantBuffers(this, shaderProgram); pixelConstantBuffers.SetConstantBuffers(this, shaderProgram); // Apply Textures/Samplers for (int i = 0; i < OpenGLDevice.Instance.MaxTextureSlots; i += 1) { SamplerState sampler = SamplerStates[i]; Texture texture = Textures[i]; if (sampler != null && texture != null) { OpenGLDevice.Instance.Samplers[i].Texture.Set(texture.texture); OpenGLDevice.Instance.Samplers[i].Target.Set(texture.texture.Target); texture.texture.WrapS.Set(sampler.AddressU); texture.texture.WrapT.Set(sampler.AddressV); texture.texture.WrapR.Set(sampler.AddressW); texture.texture.Filter.Set(sampler.Filter); texture.texture.Anistropy.Set(sampler.MaxAnisotropy); texture.texture.MaxMipmapLevel.Set(sampler.MaxMipLevel); texture.texture.LODBias.Set(sampler.MipMapLevelOfDetailBias); } else if (texture == null) { OpenGLDevice.Instance.Samplers[i].Texture.Set(OpenGLDevice.OpenGLTexture.NullTexture); } } // Flush the GL state! OpenGLDevice.Instance.FlushGLState(); }