Пример #1
0
        /// <summary>
        /// Function to retrieve a render target view.
        /// </summary>
        /// <param name="format">Format of the view.</param>
        /// <param name="mipSlice">Mip level to use in the view.</param>
        /// <param name="arrayDepthIndex">First array index to use in the view.</param>
        /// <param name="arrayDepthCount">Number of array indices to use in the view.</param>
        /// <returns>The cached render target view.</returns>
        public GorgonRenderTargetView GetRenderTargetView(BufferFormat format,
                                                          int mipSlice,
                                                          int arrayDepthIndex,
                                                          int arrayDepthCount)
        {
            var key = new ViewKey(format, mipSlice, arrayDepthIndex, arrayDepthCount, 0);

            lock (_syncLock)
            {
                GorgonRenderTargetView result;

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

                switch (_resource.ResourceType)
                {
                case ResourceType.Buffer:
                    result = new GorgonRenderTargetBufferView(_resource, format, mipSlice, arrayDepthIndex);
                    break;

                case ResourceType.Texture1D:
                case ResourceType.Texture2D:
                case ResourceType.Texture3D:
                    result = new GorgonRenderTargetTextureView(_resource, format, mipSlice, arrayDepthIndex, arrayDepthCount);
                    break;
                }

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

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

                return(result);
            }
        }
Пример #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)
        {
            if ((Settings.Format != BufferFormat.Unknown) && (Settings.TextureFormat == BufferFormat.Unknown))
            {
                Settings.TextureFormat = Settings.Format;
            }

            var desc = new D3D.Texture3DDescription
            {
                Format         = (Format)Settings.TextureFormat,
                Width          = Settings.Width,
                Height         = Settings.Height,
                Depth          = Settings.Depth,
                MipLevels      = Settings.MipCount,
                BindFlags      = GetBindFlags(false, true),
                Usage          = D3D.ResourceUsage.Default,
                CpuAccessFlags = D3D.CpuAccessFlags.None,
                OptionFlags    = D3D.ResourceOptionFlags.None
            };

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

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

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

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

            // Set default viewport.
            Viewport = new GorgonViewport(0, 0, Settings.Width, 1.0f, 0.0f, 1.0f);
        }
Пример #3
0
 /// <summary>
 /// Function to retrieve the 3D render target associated with this view.
 /// </summary>
 /// <param name="view">The view to evaluate.</param>
 /// <returns>The 3D render target associated with this view.</returns>
 public static GorgonRenderTarget3D ToRenderTarget3D(GorgonRenderTargetTextureView view)
 {
     return(view == null ? null : (GorgonRenderTarget3D)view.Resource);
 }