Пример #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 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);
        }
Пример #2
0
        /// <summary>
        /// Function to retrieve the 2D depth/stencil buffer associated with this view.
        /// </summary>
        /// <param name="view">The view to evaluate.</param>
        /// <returns>The 2D depth/stencil buffer associated with this view.</returns>
        public static GorgonDepthStencil2D ToDepthStencil2D(GorgonDepthStencilView view)
        {
            if (view._depth2D == null)
            {
                throw new InvalidCastException(string.Format(Resources.GORGFX_VIEW_RESOURCE_NOT_DEPTHSTENCIL, "2D"));
            }

            return(view._depth2D);
        }
Пример #3
0
        /// <summary>
        /// Function to create/retrieve a depth/stencil view in the cache.
        /// </summary>
        /// <param name="format">Format of the depth/stencil view.</param>
        /// <param name="mipSlice">Mip slice.</param>
        /// <param name="arrayIndex">Array index.</param>
        /// <param name="arrayCount">Array count.</param>
        /// <param name="flags">Flags for the depth/stencil view.</param>
        /// <returns>The cached depth/stencil view.</returns>
        public GorgonDepthStencilView GetDepthStencilView(BufferFormat format,
                                                          int mipSlice,
                                                          int arrayIndex,
                                                          int arrayCount,
                                                          DepthStencilViewFlags flags)
        {
            var key = new ViewKey(format, mipSlice, arrayIndex, arrayCount, (int)flags);

            lock (_syncLock)
            {
                GorgonDepthStencilView result;

                if (_depthViews.TryGetValue(key, out result))
                {
                    return(result);
                }

                switch (_resource.ResourceType)
                {
                case ResourceType.Texture1D:
                case ResourceType.Texture2D:
                    result = new GorgonDepthStencilView(_resource, format, mipSlice, arrayIndex, arrayCount, flags);
                    break;
                }

                // This should never happen.
                if (result == null)
                {
                    throw new GorgonException(GorgonResult.CannotCreate,
                                              string.Format(Resources.GORGFX_IMAGE_TYPE_INVALID, _resource.ResourceType));
                }

                result.Initialize();
                _depthViews.Add(key, result);

                return(result);
            }
        }