/// <summary> /// SetupBlendState /// </summary> void SetupBlendState() { var rtbd = new RenderTargetBlendDescription(); bool enabled = true; if (BlendState.DstAlpha == Blend.Zero && BlendState.SrcAlpha == Blend.One && BlendState.DstColor == Blend.Zero && BlendState.SrcColor == Blend.One) { enabled = false; } rtbd.IsBlendEnabled = enabled; rtbd.BlendOperation = Converter.Convert(BlendState.ColorOp); rtbd.AlphaBlendOperation = Converter.Convert(BlendState.AlphaOp); rtbd.RenderTargetWriteMask = (ColorWriteMaskFlags)(int)BlendState.WriteMask; rtbd.DestinationBlend = Converter.Convert(BlendState.DstColor); rtbd.SourceBlend = Converter.Convert(BlendState.SrcColor); rtbd.DestinationAlphaBlend = Converter.Convert(BlendState.DstAlpha); rtbd.SourceAlphaBlend = Converter.Convert(BlendState.SrcAlpha); var bsd = new BlendStateDescription(); bsd.AlphaToCoverageEnable = false; bsd.IndependentBlendEnable = false; bsd.RenderTarget[0] = rtbd; blendFactor = SharpDXHelper.Convert(BlendState.BlendFactor); blendMsaaMask = BlendState.MultiSampleMask; blendState = new D3DBlendState(device.Device, bsd); }
/// <summary> /// /// </summary> public void RestoreBackbuffer() { SetTargets(BackbufferDepth, BackbufferColor); lock (deviceContext) { deviceContext.Rasterizer.SetViewport(SharpDXHelper.Convert(new ViewportF(0, 0, BackbufferColor.Width, BackbufferColor.Height))); } }
/// <summary> /// Converts to X3DAudio emitter. /// </summary> /// <returns></returns> internal SharpDX.X3DAudio.Emitter ToEmitter() { // Pulling out Vector properties for efficiency. var pos = this.Position; var vel = this.Velocity; var fwd = this.Forward; var up = this.Up; // From MSDN: // X3DAudio uses a left-handed Cartesian coordinate system, // with values on the x-axis increasing from left to right, on the y-axis from bottom to top, // and on the z-axis from near to far. // Azimuths are measured clockwise from a given reference direction. // // From MSDN: // The XNA Framework uses a right-handed coordinate system, // with the positive z-axis pointing toward the observer when the positive x-axis is pointing to the right, // and the positive y-axis is pointing up. // // Programmer Notes: // According to this description the z-axis (forward vector) is inverted between these two coordinate systems. // Therefore, we need to negate the z component of any position/velocity values, and negate any forward vectors. fwd *= -1.0f; pos.Z *= -1.0f; vel.Z *= -1.0f; var emitter = new SharpDX.X3DAudio.Emitter(); emitter.ChannelCount = 1; emitter.Position = SharpDXHelper.Convert(pos); emitter.Velocity = SharpDXHelper.Convert(vel); emitter.OrientFront = SharpDXHelper.Convert(fwd); emitter.OrientTop = SharpDXHelper.Convert(up); emitter.DopplerScaler = DopplerScale; emitter.CurveDistanceScaler = DistanceScale; emitter.VolumeCurve = volumeCurve; return(emitter); }
/// <summary> /// /// </summary> /// <param name="device"></param> internal D3DSamplerState Apply(GraphicsDevice device) { if (state == null) { var ssd = new SamplerStateDescription(); ssd.ComparisonFunction = Converter.Convert(this.compareFunc); ssd.AddressU = Converter.Convert(this.addressU); ssd.AddressV = Converter.Convert(this.addressV); ssd.AddressW = Converter.Convert(this.addressW); ssd.BorderColor = SharpDXHelper.Convert(this.borderColor); ssd.Filter = Converter.Convert(this.filter); ssd.MaximumAnisotropy = this.maxAnisotropy; ssd.MaximumLod = this.maxMipLevel; ssd.MinimumLod = this.minMipLevel; ssd.MipLodBias = this.mipMapBias; state = new D3DSamplerState(device.Device, ssd); } return(state); }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="w"></param> /// <param name="h"></param> public void SetViewport(ViewportF viewport) { lock (deviceContext) { deviceContext.Rasterizer.SetViewport(SharpDXHelper.Convert(viewport)); } }
/// <summary> /// Fills structured buffer with given values /// </summary> /// <param name="buffer"></param> /// <param name="values"></param> public void Clear(StructuredBuffer buffer, Int4 values) { lock (deviceContext) { deviceContext.ClearUnorderedAccessView(buffer.UAV, SharpDXHelper.Convert(values)); } }
/// <summary> /// Clears render target using given color /// </summary> /// <param name="surface"></param> /// <param name="color"></param> public void Clear(RenderTargetSurface surface, Color4 color) { lock (deviceContext) { deviceContext.ClearRenderTargetView(surface.RTV, SharpDXHelper.Convert(color)); } }