/// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        public void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(host.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)host.ActualWidth,
                Height = (uint)host.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        } 
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)directControl.ClientSize.Width,
                Height = (uint)directControl.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        } 
Пример #3
0
        public D3D11RenderingPane( Factory dxgiFactory, SlimDX.Direct3D11.Device d3D11Device, DeviceContext d3D11DeviceContext, D3D11HwndDescription d3D11HwndDescription )
        {
            mDxgiFactory = dxgiFactory;
            mD3D11Device = d3D11Device;
            mD3D11DeviceContext = d3D11DeviceContext;

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

            mSwapChain = new SwapChain( mDxgiFactory, mD3D11Device, swapChainDescription );
            mDxgiFactory.SetWindowAssociation( d3D11HwndDescription.Handle, WindowAssociationFlags.IgnoreAll );

            CreateD3D11Resources( d3D11HwndDescription.Width, d3D11HwndDescription.Height );

            PauseRendering = false;
        }
Пример #4
0
		private void InitalizeGraphics()
		{
			if (Window.RenderCanvasHandle == IntPtr.Zero)
				throw new InvalidOperationException("Window handle cannot be zero");

			SwapChainDescription swapChainDesc = new SwapChainDescription()
			{
				BufferCount = 1,
				Flags = SwapChainFlags.None,
				IsWindowed = true,
				OutputHandle = Window.RenderCanvasHandle,
				SwapEffect = SwapEffect.Discard,
				Usage = Usage.RenderTargetOutput,
				ModeDescription = new ModeDescription()
				{
					Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
					//Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
					Width = Window.ClientSize.Width,
					Height = Window.ClientSize.Height,
					RefreshRate = new Rational(60, 1),
					Scaling = DisplayModeScaling.Unspecified,
					ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
				},
				SampleDescription = new SampleDescription(1, 0)
			};

			var giFactory = new SlimDX.DXGI.Factory();
			var adapter = giFactory.GetAdapter(0);

			Device device;
			SwapChain swapChain;
			Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);
			_swapChain = swapChain;
			GraphicsDevice = device;

			// create a view of our render target, which is the backbuffer of the swap chain we just created
			using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0))
			{
				_backBuffer = new RenderTargetView(device, resource);
			}

			// setting a viewport is required if you want to actually see anything
			var viewport = new Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
			device.OutputMerger.SetTargets(_backBuffer);
			device.Rasterizer.SetViewports(viewport);

			CreateDepthStencil();
			LoadVisualizationEffect();

			// Allocate a large buffer to write the PhysX visualization vertices into
			// There's more optimized ways of doing this, but for this sample a large buffer will do
			_userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);

			var elements = new[]
			{
				new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
				new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
			};
			_inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);
		}
Пример #5
0
        public static void CreateDeviceSwapChainAndRenderTarget(Form form,
            out Device device, out SwapChain swapChain, out RenderTargetView renderTarget)
        {
            try
            {
                // the debug mode requires the sdk to be installed otherwise an exception is thrown
                device = new Device(DeviceCreationFlags.Debug);
            }
            catch (Direct3D10Exception)
            {
                device = new Device(DeviceCreationFlags.None);
            }

            var swapChainDescription = new SwapChainDescription();
            var modeDescription = new ModeDescription();
            var sampleDescription = new SampleDescription();

            modeDescription.Format = Format.R8G8B8A8_UNorm;
            modeDescription.RefreshRate = new Rational(60, 1);
            modeDescription.Scaling = DisplayModeScaling.Unspecified;
            modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;

            modeDescription.Width = WIDTH;
            modeDescription.Height = HEIGHT;

            sampleDescription.Count = 1;
            sampleDescription.Quality = 0;

            swapChainDescription.ModeDescription = modeDescription;
            swapChainDescription.SampleDescription = sampleDescription;
            swapChainDescription.BufferCount = 1;
            swapChainDescription.Flags = SwapChainFlags.None;
            swapChainDescription.IsWindowed = true;
            swapChainDescription.OutputHandle = form.Handle;
            swapChainDescription.SwapEffect = SwapEffect.Discard;
            swapChainDescription.Usage = Usage.RenderTargetOutput;

            using (var factory = new Factory())
            {
                swapChain = new SwapChain(factory, device, swapChainDescription);
            }

            using (var resource = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTarget = new RenderTargetView(device, resource);
            }

            var viewport = new Viewport
            {
                X = 0,
                Y = 0,
                Width = WIDTH,
                Height = HEIGHT,
                MinZ = 0.0f,
                MaxZ = 1.0f
            };

            device.Rasterizer.SetViewports(viewport);
            device.OutputMerger.SetTargets(renderTarget);
        }
Пример #6
0
        public DX11SwapChain(DX11RenderContext context, IntPtr handle, Format format, SampleDescription sampledesc)
        {
            this.context = context;
            this.handle = handle;

            SwapChainDescription sd = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), format),
                IsWindowed = true,
                OutputHandle = handle,
                SampleDescription = sampledesc,
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput | Usage.ShaderInput,
                Flags = SwapChainFlags.None
            };

            if (sd.SampleDescription.Count == 1 && context.IsFeatureLevel11)
            {
                sd.Usage |= Usage.UnorderedAccess;
                this.allowuav = true;
            }

            this.swapchain = new SwapChain(context.Device.Factory, context.Device, sd);

            this.Resource = Texture2D.FromSwapChain<Texture2D>(this.swapchain, 0);

            this.context.Factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter);

            this.RTV = new RenderTargetView(context.Device, this.Resource);
            this.SRV = new ShaderResourceView(context.Device, this.Resource);
            if (this.allowuav) { this.UAV = new UnorderedAccessView(context.Device, this.Resource); }

            this.desc = this.Resource.Description;
        }
Пример #7
0
        public void TestException()
        {
            // Device is implicitly created with a DXGI Factory / Adapter
            var device = new Direct3D11.Device(DriverType.Hardware);

            // Create another DXGI Factory
            var factory = new SharpDX.DXGI.Factory1();

            try
            {
                // This call should raise a DXGI_ERROR_INVALID_CALL:
                // The reason is the SwapChain must be created with a d3d device that was created with the same factory
                // Because we were creating the D3D11 device without a DXGI factory, it is associated with another factory.
                var swapChain = new SwapChain(
                    factory,
                    device,
                    new SwapChainDescription()
                        {
                            BufferCount = 1,
                            Flags = SwapChainFlags.None,
                            IsWindowed = false,
                            ModeDescription = new ModeDescription(1024, 768, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                            SampleDescription = new SampleDescription(1, 0),
                            OutputHandle = IntPtr.Zero,
                            SwapEffect = SwapEffect.Discard,
                            Usage = Usage.RenderTargetOutput
                        });
            } catch (SharpDXException exception)
            {
                Assert.AreEqual(exception.Descriptor.NativeApiCode, "DXGI_ERROR_INVALID_CALL");
            }
        }
Пример #8
0
        protected D3DApp(IntPtr hInstance)
        {
            AppInst = hInstance;
            MainWindowCaption = "D3D11 Application";
            DriverType = DriverType.Hardware;
            ClientWidth = 800;
            ClientHeight = 600;
            Enable4XMsaa = false;
            Window = null;
            AppPaused = false;
            Minimized = false;
            Maximized = false;
            Resizing = false;
            Msaa4XQuality = 0;
            Device = null;
            ImmediateContext = null;
            SwapChain = null;
            DepthStencilBuffer = null;
            RenderTargetView = null;
            DepthStencilView = null;
            Viewport = new Viewport();
            Timer = new GameTimer();

            GD3DApp = this;
        }
Пример #9
0
        public override void Initialize()
        {
            using (var fac = new Factory())
            {
                using (var tmpDevice = new Device(fac.GetAdapter(0), DriverType.Hardware, DeviceCreationFlags.None))
                {
                    using (var rf = new RenderForm())
                    {
                        var desc = new SwapChainDescription
                        {
                            BufferCount = 1,
                            Flags = SwapChainFlags.None,
                            IsWindowed = true,
                            ModeDescription = new ModeDescription(100, 100, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                            OutputHandle = rf.Handle,
                            SampleDescription = new SampleDescription(1, 0),
                            SwapEffect = SwapEffect.Discard,
                            Usage = Usage.RenderTargetOutput
                        };
                        using (var sc = new SwapChain(fac, tmpDevice, desc))
                        {
                            PresentPointer = Pulse.Magic.GetObjectVtableFunction(sc.ComPointer, VMT_PRESENT);
                            ResetTargetPointer = Pulse.Magic.GetObjectVtableFunction(sc.ComPointer, VMT_RESIZETARGET);
                        }
                    }
                }
            }

            _presentDelegate = Pulse.Magic.RegisterDelegate<Direct3D10Present>(PresentPointer);
            _presentHook = Pulse.Magic.Detours.CreateAndApply(_presentDelegate, new Direct3D10Present(Callback), "D10Present");
        }
Пример #10
0
 public Renderer(int Width, int Height, IntPtr? OutputHandle)
 {
     if (Width < 1)
         Width = 1;
     if (Height < 1)
         Height = 1;
     bufferWidth = Width;
     bufferHeight = Height;
     deviceUsers++;
     if (device == null)
         device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_11_0);
     if (OutputHandle.HasValue)
     {
         SwapChainDescription swapChainDesc = new SwapChainDescription()
         {
             BufferCount = 1,
             ModeDescription = new ModeDescription(BufferWidth, BufferHeight, new Rational(120, 1), Format.R8G8B8A8_UNorm),
             IsWindowed = true,
             OutputHandle = OutputHandle.Value,
             SampleDescription = BufferSampleDescription,
             SwapEffect = SwapEffect.Discard,
             Usage = Usage.RenderTargetOutput,
             Flags = SwapChainFlags.AllowModeSwitch,
         };
         swapChain = new SwapChain(device.Factory, Device, swapChainDesc);
         using (var factory = swapChain.GetParent<Factory>())
             factory.SetWindowAssociation(OutputHandle.Value, WindowAssociationFlags.IgnoreAltEnter);
     }
     LightingSystem = new ForwardLighting(this);
     SetupRenderTargets();
     LightingSystem.Initialize();
 }
Пример #11
0
        //-------------------------------------------------------------------
        // Constructor
        //-------------------------------------------------------------------
        public DrawDevice()
        {
            m_hwnd = IntPtr.Zero;
            m_pDevice = null;
            m_pSwapChain = null;

            m_d3dpp = null;
            m_Data = IntPtr.Zero;

            m_format = Format.X8R8G8B8;
            m_width = 0;
            m_height = 0;
            m_lDefaultStride = 0;
            m_PixelAR.Denominator = m_PixelAR.Numerator = 1;
            m_rcDest = Rectangle.Empty;

            VideoFormatDefs = new VideoFormatGUID[] {
                new VideoFormatGUID(MFMediaType.RGB32, TransformImage_RGB32, ARGB32_To_RGB32),
                new VideoFormatGUID(MFMediaType.RGB24, TransformImage_RGB24, ARGB32_To_RGB24),
                new VideoFormatGUID(MFMediaType.YUY2, TransformImage_YUY2, ARGB32_To_YUY2),
                new VideoFormatGUID(MFMediaType.NV12, TransformImage_NV12, ARGB32_To_NV12)
            };

            m_convertFn = null;
            m_bmpconvertFn = null;
        }
Пример #12
0
        public override WriteableBitmap Initialize(Device device)
		{
			const int width = 600;
			const int height = 400;

			// Create device and swap chain.
            var swapChainPresenter = new WpfSwapChainPresenter();
			_swapChain = device.CreateSwapChain(width, height, swapChainPresenter);

			_deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
			_renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Create DepthStencilView.
			var depthStencilBuffer = device.CreateTexture2D(new Texture2DDescription
			{
				ArraySize = 1,
				MipLevels = 1,
				Width = width,
				Height = height,
				BindFlags = BindFlags.DepthStencil
			});
			var depthStencilView = device.CreateDepthStencilView(depthStencilBuffer);

			// Prepare all the stages.
			_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
			_deviceContext.OutputMerger.SetTargets(depthStencilView, _renderTargetView);

            return swapChainPresenter.Bitmap;
		}
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContext10"/> class.
        /// </summary>
        /// <param name="handle">The window handle to associate with the device.</param>
        /// <param name="settings">The settings used to configure the device.</param>
        internal DeviceContext10(IntPtr handle, DeviceSettings10 settings)
        {
            if (handle == IntPtr.Zero)
                throw new ArgumentException("Value must be a valid window handle.", "handle");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.settings = settings;

            factory = new Factory();
            device = new Direct3D10.Device(factory.GetAdapter(settings.AdapterOrdinal), Direct3D10.DriverType.Hardware, settings.CreationFlags);

            swapChain = new SwapChain(factory, device, new SwapChainDescription
            {
                BufferCount = 1,
                Flags = SwapChainFlags.None,
                IsWindowed = true,
                ModeDescription = new ModeDescription(settings.Width, settings.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle = handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            });

            factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);
        }
Пример #14
0
        public void AfterEngineInit()
        {
            // Basics.
            {
                var deviceDesc = new Device.Descriptor {DebugDevice = true};
                renderDevice = new ClearSight.RendererDX12.Device(ref deviceDesc,
                    ClearSight.RendererDX12.Device.FeatureLevel.Level_11_0);

                var descCQ = new CommandQueue.Descriptor() {Type = CommandListType.Graphics};
                commandQueue = renderDevice.Create(ref descCQ);

                var wih = new WindowInteropHelper(window);
                var swapChainDesc = new SwapChain.Descriptor()
                {
                    AssociatedGraphicsQueue = commandQueue,

                    MaxFramesInFlight = 3,
                    BufferCount = 3,

                    Width = (uint) window.Width,
                    Height = (uint) window.Height,
                    Format = Format.R8G8B8A8_UNorm,

                    SampleCount = 1,
                    SampleQuality = 0,

                    WindowHandle = wih.Handle,
                    Fullscreen = false
                };
                swapChain = renderDevice.Create(ref swapChainDesc);

                var commandListDesc = new CommandList.Descriptor()
                {
                    Type = CommandListType.Graphics,
                    AllocationPolicy = new CommandListInFlightFrameAllocationPolicy(CommandListType.Graphics, swapChain)
                };
                commandList = renderDevice.Create(ref commandListDesc);
            }

            // Render targets.
            {
                var descHeapDesc = new DescriptorHeap.Descriptor()
                {
                    Type = DescriptorHeap.Descriptor.ResourceDescriptorType.RenderTarget,
                    NumResourceDescriptors = swapChain.Desc.BufferCount
                };
                descHeapRenderTargets = renderDevice.Create(ref descHeapDesc);

                var rtvViewDesc = new RenderTargetViewDescription()
                {
                    Format = swapChain.Desc.Format,
                    Dimension = Dimension.Texture2D,
                    Texture = new TextureSubresourceDesc(mipSlice: 0)
                };
                for (uint i = 0; i < swapChain.Desc.BufferCount; ++i)
                {
                    renderDevice.CreateRenderTargetView(descHeapRenderTargets, i, swapChain.BackbufferResources[i], ref rtvViewDesc);
                }
            }
        }
 public RenderTarget(Device device, SwapChain swapChain)
     : this()
 {
     Texture = _disposer.Add(Texture2D.FromSwapChain<Texture2D>(swapChain, 0));
     RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture));
     ShaderResourceView = null;
     Viewport = new Viewport(0, 0, Width, Height, 0.0f, 1.0f);
 }
Пример #16
0
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            PresentInterval = presentationParameters.PresentationInterval;

            // Initialize the swap chain
            swapChain = ToDispose(CreateSwapChain());

            backBuffer = ToDispose(RenderTarget2D.New(device, swapChain.GetBackBuffer<Direct3D11.Texture2D>(0)));
        }
        void InitDevice()
        {
            // create Direct 3D device
            device = D3DDevice.CreateDeviceAndSwapChain(renderHost.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            // Create depth stencil texture
            Texture2DDescription descDepth = new Texture2DDescription()
            {
                Width = (uint)renderHost.ActualWidth,
                Height = (uint)renderHost.ActualHeight,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.D32Float,
                SampleDescription = new SampleDescription()
                {
                    Count = 1,
                    Quality = 0
                },
                BindingOptions = BindingOptions.DepthStencil,
            };

            depthStencil = device.CreateTexture2D(descDepth);

            // Create the depth stencil view
            DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
            {
                Format = descDepth.Format,
                ViewDimension = DepthStencilViewDimension.Texture2D
            };
            depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc);

            // bind the views to the device
            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)renderHost.ActualWidth,
                Height = (uint)renderHost.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };
            
            device.RS.Viewports = new Viewport[] { vp };
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            SetViews();

            meshManager = new XMeshManager(device);
            mesh = meshManager.Open("Media\\Tiger\\tiger.x");

            InitMatrices();
        }
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            PresentInterval = presentationParameters.PresentationInterval;

            // Initialize the swap chain
            swapChain = CreateSwapChain();

            backBuffer = new Texture(device).InitializeFrom(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0), Description.BackBufferFormat.IsSRgb());

            // Reload should get backbuffer from swapchain as well
            //backBufferTexture.Reload = graphicsResource => ((Texture)graphicsResource).Recreate(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture>(0));
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        public void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(host.Handle);
            swapChain = device.SwapChain;

            SetViews();

            meshManager = new XMeshManager(device);
            mesh = meshManager.Open("Media\\Tiger\\tiger.x");

            InitMatrices();
            needsResizing = false;
        }
Пример #21
0
 private void InitializeResources()
 {
     /* Creates a new DXGI swap chain */
     InternalSwapChain = new SwapChain(m_factory, m_device, new SwapChainDescription
     {
         BufferCount = 1,
         Flags = SwapChainFlags.None,
         IsWindowed = true,
         ModeDescription = new ModeDescription(m_width, m_height, new Rational(60, 1), Format.B8G8R8A8_UNorm),
         OutputHandle = m_hWnd,
         SampleDescription = new SampleDescription(1, 0),
         SwapEffect = SwapEffect.Discard,
         Usage = Usage.RenderTargetOutput | Usage.ShaderInput
     });
 }
Пример #22
0
        //-------------------------------------------------------------------
        // Constructor
        //-------------------------------------------------------------------
        public DrawDevice()
        {
            hwnd = IntPtr.Zero;
            pDevice = null;
            pSwapChain = null;

            d3dpp = null;

            format = Format.X8R8G8B8;
            width = 0;
            height = 0;
            lDefaultStride = 0;
            pixelAR.Denominator = pixelAR.Numerator = 1;
            rcDest = Rectangle.Empty;
            m_convertFn = null;
        }
Пример #23
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (DesignMode)
                return;

            // create swap chain, rendertarget
            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount = 1,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = videoPanel1.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard,
                SampleDescription = new SampleDescription(1, 0),
            };

            swapChain = new SwapChain(factory, device, swapChainDesc);

            // render target
            renderTarget = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
            renderTargetView = new RenderTargetView(device, renderTarget);

            // depth buffer
            var depthBufferDesc = new Texture2DDescription()
            {
                Width = videoPanel1.Width,
                Height = videoPanel1.Height,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.D32_Float, // necessary?
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None
            };
            depthStencil = new Texture2D(device, depthBufferDesc);
            depthStencilView = new DepthStencilView(device, depthStencil);

            // viewport
            viewport = new Viewport(0, 0, videoPanel1.Width, videoPanel1.Height, 0f, 1f);
        }
 public static SwapChain3 CreateSwapchain(RenderForm form, CommandQueue queue,Config config)
 {
     using (var Factory = new Factory4())
     {
         var swapChainDesc = new SwapChainDescription()
         {
             BufferCount = config.FrameCount,
             ModeDescription = new ModeDescription(config.Width, config.Height, new Rational(config.RefreshRate, 1), config.Format),
             Usage = Usage.RenderTargetOutput,
             SwapEffect = SwapEffect.FlipDiscard,
             OutputHandle = form.Handle,
             SampleDescription = new SampleDescription(config.SampleCount, config.SampleQuality),
             IsWindowed = true
         };
         var tempSwapChain = new SwapChain(Factory, queue, swapChainDesc);
         var SwapChain = tempSwapChain.QueryInterface<SwapChain3>();
         tempSwapChain.Dispose();
         return SwapChain;
     }
 }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice1.CreateDeviceAndSwapChain1(host.Handle);
            swapChain = device.SwapChain;

            SetViews();

            // Create the effect
            using (FileStream effectStream = File.OpenRead("Tutorial07.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }

            // Obtain the technique
            technique = effect.GetTechniqueByName("Render");

            // Obtain the variables
            worldVariable = effect.GetVariableByName("World").AsMatrix;
            viewVariable = effect.GetVariableByName("View").AsMatrix;
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix;
            meshColorVariable = effect.GetVariableByName("vMeshColor").AsVector;
            diffuseVariable = effect.GetVariableByName("txDiffuse").AsShaderResource;

            InitVertexLayout();
            InitVertexBuffer();
            InitIndexBuffer();

            // Set primitive topology
            device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;

            // Load the Texture
            using (FileStream stream = File.OpenRead("seafloor.png"))
            {
                textureRV = TextureLoader.LoadTexture(device, stream);
            }

            InitMatrices();

            diffuseVariable.Resource = textureRV;
            needsResizing = false;
        }
Пример #26
0
        // For WinForms tests
        public static void CreateHwndRenderSurface(IntPtr windowHandle, Device device, int width, int height, out Texture2D renderTexture, out SwapChain swapChain)
        {
            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = windowHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            using (var dxgiDevice = new SharpDX.DXGI.Device1(device.NativePointer))
            using (var adapter = dxgiDevice.GetParent<SharpDX.DXGI.Adapter1>())
            using (var factory = adapter.GetParent<Factory>())
            {
                swapChain = new SwapChain(factory, device, swapChainDesc);
            }

            renderTexture = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
        }
Пример #27
0
 public void Reset( Device device, PresentParameters param )
 {
     presentParams = param;
     renderWindow = presentParams.DeviceWindow;
     chain.Dispose( );
     chain = new SwapChain( device, param );
 }
Пример #28
0
 public void Reset( Device device )
 {
     chain.Dispose( );
     chain = new SwapChain( device, presentParams );
 }
Пример #29
0
 public void Release( )
 {
     chain.Dispose( );
     chain = null;
     presentParams = null;
 }
Пример #30
0
 public RenderTarget( Device device, PresentParameters param )
 {
     presentParams = param;
     renderWindow = presentParams.DeviceWindow;
     chain = new SwapChain( device, presentParams );
 }