internal PixelShader(SlimDX.Direct3D11.PixelShader pixelShader) { #if ASSERT if (pixelShader == null) { throw new ArgumentNullException("pixelShader"); } #endif resourceOwner = false; this.pixelShader = pixelShader; uniqueId = new UniqueId<PixelShader>(); }
internal PixelShader(SlimDX.Direct3D11.Device device, SlimDX.D3DCompiler.ShaderBytecode pixelShaderCode) { #if ASSERT if (device == null) { throw new ArgumentNullException("device"); } if (pixelShaderCode == null) { throw new ArgumentNullException("pixelShaderCode"); } #endif resourceOwner = true; pixelShader = new SlimDX.Direct3D11.PixelShader(device, pixelShaderCode); uniqueId = new UniqueId<PixelShader>(); }
internal PixelShader(SlimDX.Direct3D11.Device device, string shaderCode, string entryPoint, SlimDX.D3DCompiler.ShaderFlags shaderFlags) { #if ASSERT if (device == null) { throw new ArgumentNullException("device"); } if (shaderCode == null) { throw new ArgumentNullException("shaderCode"); } if (shaderCode.Length == 0) { throw new ArgumentOutOfRangeException("shaderCode"); } if (entryPoint == null) { throw new ArgumentNullException("entryPoint"); } if (entryPoint.Length == 0) { throw new ArgumentOutOfRangeException("entryPoint"); } #endif resourceOwner = true; uniqueId = new UniqueId<PixelShader>(); using (var pixelShaderCode = SlimDX.D3DCompiler.ShaderBytecode.Compile(shaderCode, entryPoint, "ps_5_0", shaderFlags, SlimDX.D3DCompiler.EffectFlags.None)) { pixelShader = new SlimDX.Direct3D11.PixelShader(device, pixelShaderCode); } }
public void Dispose() { if (resourceOwner && pixelShader != null) { pixelShader.Dispose(); } pixelShader = null; }
public override void Render() { SlimDX.Direct3D11.DepthStencilState oldDSState = DeviceManager.Instance.context.OutputMerger.DepthStencilState; SlimDX.Direct3D11.BlendState oldBlendState = DeviceManager.Instance.context.OutputMerger.BlendState; SlimDX.Direct3D11.RasterizerState oldRasterizerState = DeviceManager.Instance.context.Rasterizer.State; SlimDX.Direct3D11.VertexShader oldVertexShader = DeviceManager.Instance.context.VertexShader.Get(); SlimDX.Direct3D11.Buffer[] oldVSCBuffers = DeviceManager.Instance.context.VertexShader.GetConstantBuffers(0, 10); SlimDX.Direct3D11.PixelShader oldPixelShader = DeviceManager.Instance.context.PixelShader.Get(); SlimDX.Direct3D11.Buffer[] oldPSCBuffers = DeviceManager.Instance.context.PixelShader.GetConstantBuffers(0, 10); SlimDX.Direct3D11.ShaderResourceView[] oldShaderResources = DeviceManager.Instance.context.PixelShader.GetShaderResources(0, 10); SlimDX.Direct3D11.GeometryShader oldGeometryShader = DeviceManager.Instance.context.GeometryShader.Get(); base.Render(); DeviceManager.Instance.context.OutputMerger.DepthStencilState = oldDSState; DeviceManager.Instance.context.OutputMerger.BlendState = oldBlendState; DeviceManager.Instance.context.Rasterizer.State = oldRasterizerState; DeviceManager.Instance.context.VertexShader.Set(oldVertexShader); DeviceManager.Instance.context.VertexShader.SetConstantBuffers(oldVSCBuffers, 0, 10); DeviceManager.Instance.context.PixelShader.Set(oldPixelShader); DeviceManager.Instance.context.PixelShader.SetConstantBuffers(oldPSCBuffers, 0, 10); DeviceManager.Instance.context.PixelShader.SetShaderResources(oldShaderResources, 0, 10); DeviceManager.Instance.context.GeometryShader.Set(oldGeometryShader); foreach (RenderInstance instance in _renderInstances) { if (instance.Name == null) { continue; } SlimDX.Matrix world = instance.Transform; SlimDX.Matrix view = CameraManager.Instance.frameCamera.View; SlimDX.Matrix projection = CameraManager.Instance.frameCamera.Perspective; //SlimDX.Matrix viewProj = view * projection; SlimDX.Matrix worldViewProjection = world * view * projection; SlimDX.Direct3D11.Viewport vp = DeviceManager.Instance.context.Rasterizer.GetViewports()[0]; SlimDX.Vector3 position3D = SlimDX.Vector3.Project(SlimDX.Vector3.Zero, vp.X, vp.Y, vp.Width, vp.Height, vp.MinZ, vp.MaxZ, worldViewProjection); SlimDX.Vector2 position2D = new SlimDX.Vector2(position3D.X, position3D.Y); if (position3D.Z < vp.MaxZ) { SlimDX.Vector3 objPos = SlimDX.Vector3.Zero; objPos = SlimDX.Vector3.TransformCoordinate(objPos, instance.Transform); SlimDX.Vector3 camPos = CameraManager.Instance.frameCamera.eye; SlimDX.Vector3 objOffset = objPos - camPos; float scale = Math.Min(2.0f, 5.0f / (float)Math.Sqrt(Math.Max(1.0f, objOffset.Length()))); RenderManager.Instance.DrawString(instance.Name, position2D, 16 * scale, new SlimDX.Color4(1.0f, 1.0f, 1.0f)); } } DeviceManager.Instance.context.OutputMerger.DepthStencilState = oldDSState; DeviceManager.Instance.context.OutputMerger.BlendState = oldBlendState; DeviceManager.Instance.context.Rasterizer.State = oldRasterizerState; DeviceManager.Instance.context.VertexShader.Set(oldVertexShader); DeviceManager.Instance.context.VertexShader.SetConstantBuffers(oldVSCBuffers, 0, 10); DeviceManager.Instance.context.PixelShader.Set(oldPixelShader); DeviceManager.Instance.context.PixelShader.SetConstantBuffers(oldPSCBuffers, 0, 10); DeviceManager.Instance.context.PixelShader.SetShaderResources(oldShaderResources, 0, 10); DeviceManager.Instance.context.GeometryShader.Set(oldGeometryShader); }