Exemple #1
0
        /// <summary>
        /// Function to set a single viewport.
        /// </summary>
        /// <param name="viewPort">Viewport to set.</param>
        /// <remarks>Viewports must have a width and height greater than 0.</remarks>
        public void SetViewport(GorgonViewport viewPort)
        {
            if ((_viewPorts == null) || (_viewPorts.Length != 1))
            {
                _viewPorts = new[]
                {
                    viewPort
                };
                _dxViewports = new[]
                {
                    viewPort.Convert()
                };
            }
            else
            {
                if (GorgonViewport.Equals(ref _viewPorts[0], ref viewPort))
                {
                    return;
                }

                _viewPorts[0]   = viewPort;
                _dxViewports[0] = viewPort.Convert();
            }

            Graphics.Context.Rasterizer.SetViewport(viewPort.Left, viewPort.Top, viewPort.Width, viewPort.Height, viewPort.MinimumZ, viewPort.MaximumZ);
        }
Exemple #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();
            }
        }
Exemple #3
0
        /// <summary>
        /// Function to return all the viewports.
        /// </summary>
        /// <returns>An array containing all the viewports.</returns>
        /// <remarks>This will return an array with all of the viewports bound to the pipeline.</remarks>
        public GorgonViewport[] GetViewports()
        {
            var result = new GorgonViewport[_viewPorts == null ? 0 : _viewPorts.Length];

            if ((_viewPorts != null) && (_viewPorts.Length > 0))
            {
                _viewPorts.CopyTo(result, 0);
            }

            return(result);
        }
Exemple #4
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);
        }