Exemple #1
0
        public GpuTexture2D(
            Size size,
            GpuPixelFormat pixelFormat,
            GpuDevice device,
            GpuResourceInfo resourceInfo) :
            base(device, size.Width * size.Height * GpuConvert.SizeOfInBytes(pixelFormat), resourceInfo)
        {
            Size        = new Size(size.Width, size.Height);
            PixelFormat = pixelFormat;

            mRowPitch = Size.Width * GpuConvert.SizeOfInBytes(PixelFormat);

            mResource = new SharpDX.Direct3D11.Texture2D(GpuDevice.Device, new SharpDX.Direct3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = GpuConvert.ToBindUsage(ResourceInfo.BindUsage),
                CpuAccessFlags    = GpuConvert.ToCpuAccessFlag(ResourceInfo.CpuAccessFlag),
                Format            = GpuConvert.ToPixelFormat(PixelFormat),
                Width             = Size.Width,
                Height            = Size.Height,
                MipLevels         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = GpuConvert.ToHeapType(ResourceInfo.HeapType)
            });
        }
Exemple #2
0
        public GpuSwapChain(
            IntPtr handle,
            Size <int> size,
            GpuPixelFormat pixelFormat,
            GpuDevice device)
        {
            //size property
            Size        = size;
            PixelFormat = pixelFormat;
            GpuDevice   = device;

            //get factory
            using (var factory = GpuDevice.Adapter.Adapter.GetParent <SharpDX.DXGI.Factory>())
            {
                //set swapchain desc
                var swapChainDesc = new SharpDX.DXGI.SwapChainDescription()
                {
                    BufferCount     = 1,
                    Flags           = SharpDX.DXGI.SwapChainFlags.None,
                    IsWindowed      = true,
                    ModeDescription = new SharpDX.DXGI.ModeDescription()
                    {
                        Format           = GpuConvert.ToPixelFormat(PixelFormat),
                        Height           = Size.Height,
                        Width            = Size.Width,
                        RefreshRate      = new SharpDX.DXGI.Rational(60, 1),
                        Scaling          = SharpDX.DXGI.DisplayModeScaling.Unspecified,
                        ScanlineOrdering = SharpDX.DXGI.DisplayModeScanlineOrder.Unspecified
                    },
                    OutputHandle      = handle,
                    SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                    SwapEffect        = SharpDX.DXGI.SwapEffect.Discard,
                    Usage             = SharpDX.DXGI.Usage.RenderTargetOutput
                };

                mSwapChain = new SharpDX.DXGI.SwapChain(factory, GpuDevice.Device, swapChainDesc);

                //report error, if create swapchain failed
                LogEmitter.Assert(mSwapChain != null, LogLevel.Error,
                                  "[Create SwapChain Failed] [Width = {0}] [Height = {1}] [Format = {2}]", Size.Width, Size.Height, PixelFormat);

                RenderTarget = new GpuRenderTarget(GpuDevice, this);
            }
        }
Exemple #3
0
 public static int SizeOfInBytes(GpuPixelFormat pixelFormat)
 {
     return(SharpDX.DXGI.FormatHelper.SizeOfInBytes(ToPixelFormat(pixelFormat)));
 }
Exemple #4
0
 public static SharpDX.DXGI.Format ToPixelFormat(GpuPixelFormat pixelFormat)
 {
     return((SharpDX.DXGI.Format)pixelFormat);
 }