/// <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.Texture3DDescription { Format = (Format)Settings.Format, Width = Settings.Width, Height = Settings.Height, Depth = Settings.Depth, MipLevels = Settings.MipCount, BindFlags = GetBindFlags(false, false), Usage = (D3D.ResourceUsage)Settings.Usage, OptionFlags = D3D.ResourceOptionFlags.None }; 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.Texture3D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes); } else { D3DResource = new D3D.Texture3D(Graphics.D3DDevice, desc); } }
/// <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); }