コード例 #1
0
        private void _initializeGraphics()
        {
            Console.Write("Initializing graphic device... ");

            var desc = new SwapChainDescription() {
                BufferCount = 1,
                ModeDescription = new ModeDescription(
                    _appConfiguration.Width,
                    _appConfiguration.Height,
                    new Rational(60, 1),
                    Format.R8G8B8A8_UNorm),
                IsWindowed = !_appConfiguration.FullScreen,
                OutputHandle = DisplayHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            Device1.CreateWithSwapChain(
                DriverType.Hardware,
            #if DEBUG
             DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug | DeviceCreationFlags.SingleThreaded,
            #else
                DeviceCreationFlags.BgraSupport,
            #endif
             desc,
                out _device,
                out _swapChain);

            if (_device == null)
                throw new SharpDXException("Failed to initialize graphics device.");

            if (_swapChain == null)
                throw new SharpDXException("Failed to initialize swap chain.");

            ToDispose<Device1>(_device);
            ToDispose<SwapChain>(_swapChain);
            Factory2D = ToDispose<Factory2D>(new Factory2D());

            _factoryDXGI = ToDispose<FactoryDXGI>(_swapChain.GetParent<FactoryDXGI>());
            _factoryDXGI.MakeWindowAssociation(DisplayHandle, WindowAssociationFlags.IgnoreAll);

            _backBuffer = ToDispose<Texture2D>(Texture2D.FromSwapChain<Texture2D>(_swapChain, 0));
            _backBufferRenderTargetView = ToDispose<RenderTargetView>(new RenderTargetView(_device, _backBuffer));

            Viewport = new Viewport(0, 0, _appConfiguration.Width, _appConfiguration.Height);
            using (var surface = _backBuffer.QueryInterface<Surface>()) {
                RenderTarget2D = ToDispose<RenderTarget>(
                    new RenderTarget(Factory2D,
                        surface,
                        new RenderTargetProperties(
                            new PixelFormat(
                                Format.Unknown,
                                AlphaMode.Premultiplied))));
            }
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            _vsync = Config.VSync;

            ScreenSize = new DrawingSizeF(Viewport.Width, Viewport.Height);

            Console.WriteLine("done.");
        }
コード例 #2
0
ファイル: DemoApplication.cs プロジェクト: fealty/Frost
        private void HandleClientSizeChanged(object sender, EventArgs e)
        {
            // reconfigure the direct3d rendering surface
            _Device.OutputMerger.SetTargets((RenderTargetView)null);

            if(_RenderView != null)
            {
                _RenderView.Dispose();
            }

            _SwapChain.ResizeBuffers(
                1,
                Math.Max(1, _Form.ClientSize.Width),
                Math.Max(1, _Form.ClientSize.Height),
                Format.R8G8B8A8_UNorm,
                0);

            using(var backBuffer = Resource.FromSwapChain<Texture2D>(_SwapChain, 0))
            {
                _RenderView = new RenderTargetView(_Device, backBuffer);
            }

            _Device.OutputMerger.SetTargets(_RenderView);

            Viewport view = new Viewport
            {
                X = 0,
                Y = 0,
                Width = _Form.ClientSize.Width,
                Height = _Form.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f
            };

            _Device.Rasterizer.SetViewports(view);

            // reconfigure the Frost rendering surface
            Size formSize = new Size(_Form.ClientSize.Width, _Form.ClientSize.Height);

            if(_Target != null)
            {
                _Target.Forget();
            }

            _Target = new Canvas(formSize, SurfaceUsage.External);

            formSize = new Size(Math.Max(formSize.Width, 640), Math.Max(formSize.Height, 480));

            _Device2D.Resources.PageSize = new Size(formSize.Width * 2, formSize.Height * 2);

            _IsResetQueued = true;
        }
コード例 #3
0
 /// <summary>
 ///   Binds a single viewport to the rasterizer stage.
 /// </summary>
 /// <param name = "viewport">The viewport to bind.</param>
 public void SetViewports(Viewport viewport)
 {
     SetViewports(new Viewport[] { viewport });
 }
コード例 #4
0
        private void initD3D()
        {
            if (drawForm == null)
                return;

            swapChainDesc = new SwapChainDescription
            {
                BufferCount = 2,
                ModeDescription = new ModeDescription
                {
                    Width = drawForm.Width,
                    Height = drawForm.Height,
                    Format = Format.R8G8B8A8_UNorm,
                },
                Usage = Usage.RenderTargetOutput,
            };

            swapChainDesc.ModeDescription.RefreshRate.Numerator = 60;
            swapChainDesc.ModeDescription.RefreshRate.Denominator = 1;

            swapChainDesc.SampleDescription.Quality = 0;
            swapChainDesc.SampleDescription.Count = 1;

            swapChainDesc.OutputHandle = drawHandle;
            swapChainDesc.IsWindowed = true;

            D3D10.Device.CreateWithSwapChain(
                D3D10.DriverType.Hardware,
                DeviceCreationFlags.None,
                swapChainDesc,
                out d3d10Device,
                out swapChain
            );

            using (Texture2D backBuffer = swapChain.GetBackBuffer<Texture2D>(0))
                renderTargetView = new RenderTargetView(d3d10Device, backBuffer);

            d3d10Device.OutputMerger.SetTargets(renderTargetView);

            viewport = new Viewport
            {
                Width = drawForm.Width,
                Height = drawForm.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                X = 0,
                Y = 0
            };

            d3d10Device.Rasterizer.SetViewports(viewport);

            var zBufferTextureDescription = new Texture2DDescription
            {
                Format = Format.D16_UNorm,
                ArraySize = 1,
                MipLevels = 1,
                Width = drawForm.Width,
                Height = drawForm.Height,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            };
            using (var zBufferTexture = new Texture2D(this.d3d10Device, zBufferTextureDescription))
                depthStencilView = new DepthStencilView(this.d3d10Device, zBufferTexture);
            d3d10Device.OutputMerger.SetTargets(depthStencilView, renderTargetView);

            depthState = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,
                IsStencilEnabled = true,
                StencilReadMask = 0xFF,
                StencilWriteMask = 0xFF,
                FrontFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Always
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Decrement,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Always
                }
            };
            depthNonState = new DepthStencilStateDescription()
            {
                IsDepthEnabled = false
            };
            d3d10Device.OutputMerger.SetDepthStencilState(
                new DepthStencilState(
                    d3d10Device,
                    depthState
                ), 1
            );

            // Generic font?

            // Camera?

            d3d10Device.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            d3d10Device.Rasterizer.State = new RasterizerState(d3d10Device,
                new RasterizerStateDescription
                {
                    CullMode = CullMode.Back,
                    FillMode = FillMode.Solid
                }
            );
        }
コード例 #5
0
 public void SetViewport(Viewport viewport)
 {
     this.device.Rasterizer.SetViewports(viewport);
 }
コード例 #6
0
ファイル: VideoRender.cs プロジェクト: iejeecee/mediaviewer
 void IScene.RenderSizeChanged(SizeChangedInfo sizeChange)
 {
     viewport = setupViewport(videoPlayerViewModel.Width, videoPlayerViewModel.Height);
 }
コード例 #7
0
ファイル: VideoRender.cs プロジェクト: iejeecee/mediaviewer
        Viewport setupViewport(int videoWidth, int videoHeight)
        {
            DPFCanvas canvas = (DPFCanvas)Host;
            double screenWidth = canvas.ActualWidth;
            double screenHeight = canvas.ActualHeight;

            System.Drawing.Rectangle screenRect = new System.Drawing.Rectangle(0,0,(int)screenWidth, (int)screenHeight);

            System.Drawing.Rectangle videoRect = Utils.ImageUtils.stretchRectangle(new System.Drawing.Rectangle(0,0,videoWidth,videoHeight),
                screenRect);

            videoRect = Utils.ImageUtils.centerRectangle(screenRect, videoRect);

            Viewport viewport = new Viewport(new DrawingRectangle(videoRect.X, videoRect.Y, videoRect.Width, videoRect.Height));

            return (viewport);
        }
コード例 #8
0
ファイル: VideoRender.cs プロジェクト: iejeecee/mediaviewer
        void videoPanelViewModel_VideoOpened(Object sender, EventArgs e)
        {

            for (int i = 0; i < nrTextures; i++)
            {
                Disposer.RemoveAndDispose(ref this.yuvTexture[i]);
                Disposer.RemoveAndDispose(ref this.textureView[i]);
            }
                                
            if (videoPlayerViewModel.DecodedVideoFormat == VideoLib.VideoPlayer.DecodedVideoFormat.YUV420P)
            {               
                int width = videoPlayerViewModel.Width;
                int height = videoPlayerViewModel.Height;

                yuvTexture[0] = createTexture(width, height, Format.R8_UNorm);
                yuvTexture[1] = createTexture(width / 2, height / 2, Format.R8_UNorm);
                yuvTexture[2] = createTexture(width / 2, height / 2, Format.R8_UNorm);

                nrTextures = 3;
            }
            else
            {                
                yuvTexture[0] = createTexture(videoPlayerViewModel.Width, videoPlayerViewModel.Height, Format.B8G8R8A8_UNorm);

                nrTextures = 1;
            }

            Device device = Host.Device;

            for (int i = 0; i < nrTextures; i++)
            {
                ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
                desc.Format = yuvTexture[i].Description.Format;
                desc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                desc.Texture2D.MipLevels = yuvTexture[i].Description.MipLevels;
                desc.Texture2D.MostDetailedMip = yuvTexture[i].Description.MipLevels - 1;

                textureView[i] = new ShaderResourceView(device, yuvTexture[i], desc);

            }
  
            viewport = setupViewport(videoPlayerViewModel.Width, videoPlayerViewModel.Height);
           
            device.Flush();

            DPFCanvas canvas = (DPFCanvas)Host;
            canvas.StartRendering();
             
        }