コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonRenderTargetView"/> class.
        /// </summary>
        /// <param name="resource">The resource to bind to the view.</param>
        /// <param name="format">The format of the view.</param>
        protected GorgonRenderTargetView(GorgonResource resource, BufferFormat format)
            : base(resource, format)
        {
            switch (resource.ResourceType)
            {
            case ResourceType.Buffer:
                _bufferTarget = (GorgonRenderTargetBuffer)resource;
                break;

            case ResourceType.Texture1D:
                _1DTarget = (GorgonRenderTarget1D)resource;
                break;

            case ResourceType.Texture2D:
                _2DTarget = (GorgonRenderTarget2D)resource;
                if (_2DTarget.IsSwapChain)
                {
                    _swapChain = (GorgonSwapChain)_2DTarget;
                }
                break;

            case ResourceType.Texture3D:
                _3DTarget = (GorgonRenderTarget3D)resource;
                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Function to initialize the texture from a swap chain.
        /// </summary>
        /// <param name="swapChain">The swap chain used to initialize the texture.</param>
        internal void InitializeSwapChain(GorgonSwapChain swapChain)
        {
            if (D3DResource != null)
            {
                CleanUpResource();
            }

            D3DResource = D3D.Resource.FromSwapChain <D3D.Texture2D>(swapChain.GISwapChain, 0);
            D3D.Texture2DDescription desc = ((D3D.Texture2D)D3DResource).Description;

            Settings.Width            = desc.Width;
            Settings.Height           = desc.Height;
            Settings.ArrayCount       = desc.ArraySize;
            Settings.Format           = (BufferFormat)desc.Format;
            Settings.MipCount         = desc.MipLevels;
            Settings.ShaderViewFormat = (swapChain.Settings.Flags & SwapChainUsageFlags.AllowShaderView) ==
                                        SwapChainUsageFlags.AllowShaderView
                                                            ? swapChain.Settings.Format
                                                            : BufferFormat.Unknown;
            Settings.AllowUnorderedAccessViews = (desc.BindFlags & D3D.BindFlags.UnorderedAccess) == D3D.BindFlags.UnorderedAccess;
            Settings.Multisampling             = new GorgonMultisampling(desc.SampleDescription.Count, desc.SampleDescription.Quality);
            Settings.IsTextureCube             = (desc.OptionFlags & D3D.ResourceOptionFlags.TextureCube) ==
                                                 D3D.ResourceOptionFlags.TextureCube;
            Settings.DepthStencilFormat = swapChain.Settings.DepthStencilFormat;
            Settings.TextureFormat      = swapChain.Settings.Format;

            _swapChain = swapChain;

#if DEBUG
            Graphics.Output.ValidateRenderTargetSettings(Settings);
#endif

            GorgonRenderStatistics.TextureCount++;
            GorgonRenderStatistics.TextureSize += SizeInBytes;
            GorgonRenderStatistics.RenderTargetCount++;
            GorgonRenderStatistics.RenderTargetSize += SizeInBytes * swapChain.Settings.BufferCount;

            // Set default viewport.
            Viewport = new GorgonViewport(0, 0, Settings.Width, Settings.Height, 0.0f, 1.0f);

            // Re-initialize any released resource views.
            InitializeResourceViews();

            CreateDepthStencilBuffer();

            if (DepthStencilBuffer != null)
            {
                DepthStencilBuffer.SwapChain = swapChain;
            }

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

            if ((swapChain.Settings.Flags & SwapChainUsageFlags.AllowShaderView) == SwapChainUsageFlags.AllowShaderView)
            {
                CreateDefaultResourceView();
            }
        }
コード例 #3
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Remove link to a swap chain.
                _swapChain = null;
            }

            base.Dispose(disposing);
            _disposed = true;
        }
コード例 #4
0
        /// <summary>
        /// Function to create a new 2D renderer interface.
        /// </summary>
        /// <param name="graphics">Graphics interface used to create the 2D interface.</param>
        /// <param name="window">Window to use for rendering.</param>
        /// <param name="width">Width of the video mode used for rendering.</param>
        /// <param name="height">Height of the video mode used for rendering.</param>
        /// <param name="format">[Optional] Format of the video mode used for rendering.</param>
        /// <param name="isWindowed">[Optional] TRUE to use windowed mode, FALSE to to use full screen mode.</param>
        /// <param name="depthStencilFormat">[Optional] Depth/stencil buffer format.</param>
        /// <param name="vertexCacheSize">[Optional] The number of vertices that the renderer will cache when drawing.</param>
        /// <returns>A new 2D graphics interface.</returns>
        /// <remarks>This method creates an internal swap chain and uses that for the display.  To have more control over the initial render target, use the <see cref="Create2DRenderer(GorgonLibrary.Graphics.GorgonOutputMerger,GorgonLibrary.Graphics.GorgonRenderTargetView,int)">Create2DRenderer(GorgonRenderTarget)</see> extension overload.
        /// <para>The depth/stencil buffer is optional, and will only be used when <paramref name="depthStencilFormat"/> is not set to Unknown.</para>
        /// <para>The <paramref name="vertexCacheSize"/> allows for adjustment to the size of the cache that stores vertices when rendering.  More vertices means a larger buffer and more memory used, but may
        /// provide a performance increase by rendering many objects at the same time.  Lower values means a smaller buffer and possibly reduced performance because not as many objects can be drawn
        /// at a given time.  Any performance increase from this value depends upon multiple factors such as available RAM, video driver, video card, etc...</para>
        /// </remarks>
        /// <exception cref="System.ArgumentException">Thrown when the target was not created by the same graphics interface as the one creating the 2D interface.
        /// <para>Thrown when the <paramref name="window"/> parameter is NULL (Nothing in VB.Net), and the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application window</see> is NULL.</para>
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="format"/> parameter cannot be used by the video device for displaying data or for the depth/stencil buffer.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the video output could not be determined from the window.
        /// <para>-or-</para>
        /// <para>Thrown when the swap chain is going to full screen mode and another swap chain is already on the video output.</para>
        /// </exception>
        public static Gorgon2D Create2DRenderer(this GorgonOutputMerger graphics, Control window, int width, int height, BufferFormat format = BufferFormat.Unknown, bool isWindowed = true, BufferFormat depthStencilFormat = BufferFormat.Unknown, int vertexCacheSize = 32768)
        {
            GorgonSwapChain swapChain = graphics.CreateSwapChain("Gorgon2D.DefaultSwapChain", new GorgonSwapChainSettings
            {
                BufferCount        = 2,
                DepthStencilFormat = depthStencilFormat,
                Flags         = SwapChainUsageFlags.RenderTarget,
                Format        = format,
                Height        = height,
                IsWindowed    = isWindowed,
                Multisampling = new GorgonMultisampling(1, 0),
                SwapEffect    = SwapEffect.Discard,
                Width         = width,
                Window        = window
            });

            return(Create2DRenderer(swapChain, true, vertexCacheSize));
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonAfterSwapChainResizedEventArgs" /> class.
 /// </summary>
 /// <param name="target">Render target that was resized.</param>
 public GorgonAfterSwapChainResizedEventArgs(GorgonSwapChain target)
 {
     Width      = target.Settings.Width;
     Height     = target.Settings.Height;
     IsWindowed = target.Settings.IsWindowed;
 }
コード例 #6
0
 /// <summary>
 /// Function to retrieve the render target view for a swap chain.
 /// </summary>
 /// <param name="swapChain">Swap chain to evaluate.</param>
 /// <returns>The render target view for the swap chain.</returns>
 public static GorgonRenderTargetView ToRenderTargetView(GorgonSwapChain swapChain)
 {
     return(swapChain == null ? null : swapChain._renderTarget);
 }