Пример #1
0
        /// <summary>
        /// Function to initialize the texture with optional initial data.
        /// </summary>
        /// <param name="initialData">Data used to populate the image.</param>
        protected override void OnInitialize(GorgonImageData initialData)
        {
            var desc = new D3D.Texture2DDescription
            {
                ArraySize         = Settings.ArrayCount,
                Format            = (GI.Format)Settings.Format,
                Width             = Settings.Width,
                Height            = Settings.Height,
                MipLevels         = Settings.MipCount,
                BindFlags         = GetBindFlags(false, false),
                Usage             = (D3D.ResourceUsage)Settings.Usage,
                OptionFlags       = Settings.IsTextureCube ? D3D.ResourceOptionFlags.TextureCube : D3D.ResourceOptionFlags.None,
                SampleDescription = GorgonMultisampling.Convert(Settings.Multisampling)
            };

            switch (Settings.Usage)
            {
            case BufferUsage.Staging:
                desc.CpuAccessFlags = D3D.CpuAccessFlags.Read | D3D.CpuAccessFlags.Write;
                break;

            case BufferUsage.Dynamic:
                desc.CpuAccessFlags = D3D.CpuAccessFlags.Write;
                break;

            default:
                desc.CpuAccessFlags = D3D.CpuAccessFlags.None;
                break;
            }

            D3DResource = initialData != null
                                                          ? new D3D.Texture2D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes)
                                      : new D3D.Texture2D(Graphics.D3DDevice, desc);
        }
Пример #2
0
        /// <summary>
        /// Function to initialize the texture with optional initial data.
        /// </summary>
        /// <param name="initialData">Data used to populate the image.</param>
        protected override void OnInitialize(GorgonImageData initialData)
        {
            var shaderBind = Settings.AllowShaderView ? BindFlags.ShaderResource : BindFlags.None;

            var desc = new Texture2DDescription
            {
                ArraySize         = Settings.ArrayCount,
                BindFlags         = GetBindFlags(true, false) | shaderBind,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Settings.AllowShaderView ? (Format)Settings.TextureFormat : (Format)Settings.Format,
                Height            = Settings.Height,
                Width             = Settings.Width,
                MipLevels         = Settings.MipCount,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = GorgonMultisampling.Convert(Settings.Multisampling)
            };

            Gorgon.Log.Print("{0} {1}: Creating 2D depth/stencil texture...", LoggingLevel.Verbose, GetType().Name, Name);

            // Create the texture.
            D3DResource = initialData != null
                                                          ? new Texture2D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes)
                                              : new Texture2D(Graphics.D3DDevice, desc);

            GorgonRenderStatistics.DepthBufferCount++;
            GorgonRenderStatistics.DepthBufferSize += SizeInBytes;

            InitializeResourceViews();

            _defaultView = GetDepthStencilView(Settings.Format, 0, 0, 1, Settings.DefaultDepthStencilViewFlags);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonSwapChainSettings"/> class.
 /// </summary>
 public GorgonSwapChainSettings()
 {
     IsWindowed         = true;
     Flags              = SwapChainUsageFlags.RenderTarget;
     SwapEffect         = SwapEffect.Discard;
     Multisampling      = new GorgonMultisampling(1, 0);
     DepthStencilFormat = BufferFormat.Unknown;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture2DSettings"/> class.
 /// </summary>
 public GorgonTexture2DSettings()
 {
     Width                     = 0;
     Height                    = 0;
     Format                    = BufferFormat.Unknown;
     MipCount                  = 1;
     ArrayCount                = 1;
     Multisampling             = new GorgonMultisampling(1, 0);
     ShaderViewFormat          = BufferFormat.Unknown;
     AllowUnorderedAccessViews = false;
     Usage                     = BufferUsage.Default;
 }
Пример #5
0
        /// <summary>
        /// Function to initialize the texture with optional initial data.
        /// </summary>
        /// <param name="initialData">Data used to populate the image.</param>
        protected override void OnInitialize(GorgonImageData initialData)
        {
            if ((Settings.Format != BufferFormat.Unknown) && (Settings.TextureFormat == BufferFormat.Unknown))
            {
                Settings.TextureFormat = Settings.Format;
            }

            var desc = new D3D.Texture2DDescription
            {
                ArraySize         = Settings.ArrayCount,
                Format            = (GI.Format)Settings.TextureFormat,
                Width             = Settings.Width,
                Height            = Settings.Height,
                MipLevels         = Settings.MipCount,
                BindFlags         = GetBindFlags(false, true),
                Usage             = D3D.ResourceUsage.Default,
                CpuAccessFlags    = D3D.CpuAccessFlags.None,
                OptionFlags       = D3D.ResourceOptionFlags.None,
                SampleDescription = GorgonMultisampling.Convert(Settings.Multisampling)
            };

            Gorgon.Log.Print("{0} {1}: Creating 2D render target texture...", LoggingLevel.Verbose, GetType().Name, Name);

            // Create the texture.
            D3DResource = initialData != null
                                                          ? new D3D.Texture2D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes)
                                                          : new D3D.Texture2D(Graphics.D3DDevice, desc);

            // Create the default render target view.
            _defaultRenderTargetView = GetRenderTargetView(Settings.Format, 0, 0, 1);

            GorgonRenderStatistics.RenderTargetCount++;
            GorgonRenderStatistics.RenderTargetSize += SizeInBytes;

            CreateDepthStencilBuffer();

            // Set default viewport.
            Viewport = new GorgonViewport(0, 0, Settings.Width, Settings.Height, 0.0f, 1.0f);
        }
Пример #6
0
        /// <summary>
        /// Function to intialize the swap chain.
        /// </summary>
        internal void Initialize()
        {
            var D3DSettings = new GI.SwapChainDescription();

            // Resize the window to match requested mode size.
            if ((_parentForm == Settings.Window) && (Settings.IsWindowed) && (!Settings.NoClientResize))
            {
                _parentForm.ClientSize = new Size(Settings.VideoMode.Width, Settings.VideoMode.Height);
            }

            AutoResize = !Settings.NoClientResize;
            Graphics.GetFullScreenSwapChains();
            D3DSettings.BufferCount = Settings.BufferCount;
            D3DSettings.Flags       = GI.SwapChainFlags.AllowModeSwitch;

            D3DSettings.IsWindowed        = true;
            D3DSettings.ModeDescription   = GorgonVideoMode.Convert(Settings.VideoMode);
            D3DSettings.OutputHandle      = Settings.Window.Handle;
            D3DSettings.SampleDescription = GorgonMultisampling.Convert(Settings.Multisampling);
            D3DSettings.SwapEffect        = GorgonSwapChainSettings.Convert(Settings.SwapEffect);

            if ((Settings.Flags & SwapChainUsageFlags.RenderTarget) == SwapChainUsageFlags.RenderTarget)
            {
                D3DSettings.Usage = GI.Usage.RenderTargetOutput;
            }

            if ((Settings.Flags & SwapChainUsageFlags.AllowShaderView) == SwapChainUsageFlags.AllowShaderView)
            {
                D3DSettings.Usage |= GI.Usage.ShaderInput;
            }

            if ((Settings.Flags & SwapChainUsageFlags.AllowUnorderedAccessView) == SwapChainUsageFlags.AllowUnorderedAccessView)
            {
                D3DSettings.Usage |= GI.Usage.UnorderedAccess;
            }

            Gorgon.Log.Print("GorgonSwapChain '{0}': Creating D3D11 swap chain...", LoggingLevel.Simple, Name);
            GISwapChain = new GI.SwapChain(Graphics.GIFactory, Graphics.D3DDevice, D3DSettings)
            {
                DebugName = Name + " DXGISwapChain"
            };

            // Due to an issue with winforms and DXGI, we have to manually handle transitions ourselves.
            Graphics.GIFactory.MakeWindowAssociation(Settings.Window.Handle, GI.WindowAssociationFlags.IgnoreAll);

            CreateResources();

            if (!Settings.IsWindowed)
            {
                ModeStateUpdate();
            }

            Settings.Window.Resize += Window_Resize;

            if (_parentForm == null)
            {
                return;
            }

            _parentForm.ResizeBegin += _parentForm_ResizeBegin;
            _parentForm.ResizeEnd   += _parentForm_ResizeEnd;
        }