Example #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)
        {
            if ((Settings.Format != BufferFormat.Unknown) && (Settings.TextureFormat == BufferFormat.Unknown))
            {
                Settings.TextureFormat = Settings.Format;
            }

            var desc = new D3D.Texture1DDescription
            {
                ArraySize      = Settings.ArrayCount,
                Format         = (Format)Settings.TextureFormat,
                Width          = Settings.Width,
                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 1D render target texture...", LoggingLevel.Verbose, GetType().Name, Name);

            // Create the texture.
            D3DResource = initialData != null
                                                          ? new D3D.Texture1D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes)
                              : new D3D.Texture1D(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, 1.0f, 0.0f, 1.0f);
        }
Example #2
0
        /// <summary>
        /// Function to create an image with initial data.
        /// </summary>
        /// <param name="initialData">Data to use when creating the image.</param>
        /// <remarks>
        /// The <paramref name="initialData" /> can be NULL (Nothing in VB.Net) IF the texture is not created with an Immutable usage flag.
        /// <para>To initialize the texture, create a new <see cref="GorgonLibrary.Graphics.GorgonImageData">GorgonImageData</see> object and fill it with image information.</para>
        /// </remarks>
        protected override void OnInitialize(GorgonImageData initialData)
        {
            var desc = new D3D.Texture1DDescription
            {
                ArraySize   = Settings.ArrayCount,
                BindFlags   = GetBindFlags(false, false),
                Format      = (GI.Format)Settings.Format,
                Width       = Settings.Width,
                MipLevels   = Settings.MipCount,
                OptionFlags = D3D.ResourceOptionFlags.None,
                Usage       = (D3D.ResourceUsage)Settings.Usage
            };

            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;
            }

            if ((initialData != null) && (initialData.Buffers.Count > 0))
            {
                D3DResource = new D3D.Texture1D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes);
            }
            else
            {
                D3DResource = new D3D.Texture1D(Graphics.D3DDevice, desc);
            }
        }