Beispiel #1
0
        protected virtual void OnInitializeDevice()
        {
            Form.ClientSize = new System.Drawing.Size(Width, Height);

            // SwapChain description
            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(Width, Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device and SwapChain
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out _device, out _swapChain);
            outputMerger   = _device.OutputMerger;
            inputAssembler = _device.InputAssembler;

            Factory factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(Form.Handle, WindowAssociationFlags.None);
        }
Beispiel #2
0
        public InfoText(Device device)
        {
            this.device  = device;
            outputMerger = device.OutputMerger;

            font = new Font(device, 20, 0, FontWeight.Normal, 0, false, FontCharacterSet.Default,
                            FontPrecision.Default, FontQuality.ClearTypeNatural, FontPitchAndFamily.DontCare, "tahoma");

            renderTexture = new Texture2D(device, new Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.R8G8B8A8_UNorm,
                Height            = rect.Height,
                Width             = rect.Width,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default
            });
            renderTextureView = new RenderTargetView(device, renderTexture);
            renderViews       = new[] { renderTextureView };

            OverlayBufferRes = new ShaderResourceView(device, renderTexture, new ShaderResourceViewDescription()
            {
                Format    = Format.R8G8B8A8_UNorm,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels       = 1,
                    MostDetailedMip = 0
                }
            });
        }
Beispiel #3
0
        private void CreateDeviceAndSwapChain()
        {
            var desc = new SwapChainDescription
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(_width, _height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.AllowModeSwitch
            };

            Device _device;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.SingleThreaded, desc, out _device, out _swapChain);
            Device = _device;

            _immediateContext = Device.ImmediateContext;
            outputMerger      = _immediateContext.OutputMerger;
            inputAssembler    = _immediateContext.InputAssembler;

            Factory factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(Form.Handle, WindowAssociationFlags.None);
        }
Beispiel #4
0
 internal DeviceContext(Device device)
     : base(device)
 {
     _device         = device;
     _inputAssembler = new InputAssemblerStage(device);
     _vertexShader   = new VertexShaderStage(device);
     _geometryShader = new GeometryShaderStage(device);
     _rasterizer     = new RasterizerStage(device);
     _pixelShader    = new PixelShaderStage(device);
     _outputMerger   = new OutputMergerStage(device);
 }
Beispiel #5
0
        protected void OnInitializeDevice()
        {
            Form.ClientSize = new Size(Width, Height);

            // SwapChain description
            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(Width, Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
            };

            // Create Device and SwapChain
            SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out _device, out _swapChain);
            _immediateContext = _device.ImmediateContext;
            outputMerger      = _immediateContext.OutputMerger;
            inputAssembler    = _immediateContext.InputAssembler;

            Factory factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(Form.Handle, WindowAssociationFlags.None);


            var blendStateDesc = new BlendStateDescription();

            blendStateDesc.RenderTarget[0].IsBlendEnabled        = true;
            blendStateDesc.RenderTarget[0].SourceBlend           = BlendOption.SourceAlpha;
            blendStateDesc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            blendStateDesc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            blendStateDesc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            alphaBlendState = new BlendState(_device, blendStateDesc);

            blendStateDesc.RenderTarget[0].IsBlendEnabled        = true;
            blendStateDesc.RenderTarget[0].SourceBlend           = BlendOption.One;
            blendStateDesc.RenderTarget[0].DestinationBlend      = BlendOption.One;
            blendStateDesc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            blendStateDesc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            additiveBlendState = new BlendState(_device, blendStateDesc);
        }