protected internal Texture3D(GraphicsDevice device, TextureDescription description3D, DataBox[] dataBoxes = null) : base(device, description3D, ViewType.Full, 0, 0) { #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES throw new NotImplementedException(); #else Target = TextureTarget.Texture3D; #endif }
/// <summary> /// Creates a new 1D <see cref="Texture" /> with a single level of mipmap. /// </summary> /// <typeparam name="T">Type of the initial data to upload to the texture</typeparam> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="format">Describes the format to use.</param> /// <param name="usage">The usage.</param> /// <param name="textureData">Texture data. Size of must be equal to sizeof(Format) * width </param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <returns>A new instance of <see cref="Texture" /> class.</returns> /// <remarks> /// The first dimension of mipMapTextures describes the number of array (Texture Array), second dimension is the mipmap, the third is the texture data for a particular mipmap. /// </remarks> public unsafe static Texture New1D <T>(GraphicsDevice device, int width, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : struct { return(New(device, TextureDescription.New1D(width, format, textureFlags, usage), new[] { GetDataBox(format, width, 1, 1, textureData, (IntPtr)Interop.Fixed(textureData)) })); }
// Gets a new temporary render target matching the description, but with scale and format overridable. private Texture GetScopedRenderTarget(TextureDescription desc, float scale, PixelFormat format) { return NewScopedRenderTarget2D( (int)(desc.Width * scale), (int)(desc.Height * scale), format, TextureFlags.ShaderResource | TextureFlags.RenderTarget); }
internal Texture InitializeFromPersistent(TextureDescription description, SharpVulkan.Image nativeImage) { NativeImage = nativeImage; return InitializeFrom(description); }
/// <summary> /// Creates a texture for output. /// </summary> /// <param name="description">The description.</param> /// <param name="viewFormat">The pixel format seen by the shader</param> /// <returns>Texture.</returns> protected virtual Texture CreateTexture(TextureDescription description, PixelFormat viewFormat) { return(Texture.New(GraphicsDevice, description)); }
/// <summary> /// Gets a render target with the specified description, scoped for the duration of the <see cref="DrawEffect.DrawCore"/>. /// </summary> /// <returns>A new instance of texture.</returns> protected Texture NewScopedRenderTarget2D(TextureDescription description) { // TODO: Check if we should introduce an enum for the kind of scope (per DrawCore, per Frame...etc.) CheckIsInDrawCore(); return PushScopedResource(Context.Allocator.GetTemporaryTexture2D(description)); }
protected internal Texture2D(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null, bool initialize = true) : base(device, description2D, TextureTarget.Texture2D, dataBoxes, initialize) { }
private unsafe void CreateBackBuffers() { // Create the texture object var backBufferDescription = new TextureDescription { ArraySize = 1, Dimension = TextureDimension.Texture2D, Height = Description.BackBufferHeight, Width = Description.BackBufferWidth, Depth = 1, Flags = TextureFlags.RenderTarget, Format = Description.BackBufferFormat, MipLevels = 1, MultiSampleLevel = MSAALevel.None, Usage = GraphicsResourceUsage.Default }; backbuffer.InitializeWithoutResources(backBufferDescription); var createInfo = new ImageViewCreateInfo { StructureType = StructureType.ImageViewCreateInfo, SubresourceRange = new ImageSubresourceRange(ImageAspectFlags.Color, 0, 1, 0, 1), Format = backbuffer.NativeFormat, }; // We initialize swapchain images to PresentSource, since we swap them out while in this layout. backbuffer.NativeAccessMask = AccessFlags.MemoryRead; backbuffer.NativeLayout = ImageLayout.PresentSource; var imageMemoryBarrier = new ImageMemoryBarrier { StructureType = StructureType.ImageMemoryBarrier, SubresourceRange = new ImageSubresourceRange(ImageAspectFlags.Color, 0, 1, 0, 1), OldLayout = ImageLayout.Undefined, NewLayout = ImageLayout.PresentSource, SourceAccessMask = AccessFlags.None, DestinationAccessMask = AccessFlags.MemoryRead }; var commandBuffer = GraphicsDevice.NativeCopyCommandBuffer; var beginInfo = new CommandBufferBeginInfo { StructureType = StructureType.CommandBufferBeginInfo }; commandBuffer.Begin(ref beginInfo); var buffers = GraphicsDevice.NativeDevice.GetSwapchainImages(swapChain); swapchainImages = new SwapChainImageInfo[buffers.Length]; for (int i = 0; i < buffers.Length; i++) { // Create image views swapchainImages[i].NativeImage = createInfo.Image = buffers[i]; swapchainImages[i].NativeColorAttachmentView = GraphicsDevice.NativeDevice.CreateImageView(ref createInfo); // Transition to default layout imageMemoryBarrier.Image = buffers[i]; commandBuffer.PipelineBarrier(PipelineStageFlags.AllCommands, PipelineStageFlags.AllCommands, DependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier); } // Close and submit commandBuffer.End(); var submitInfo = new SubmitInfo { StructureType = StructureType.SubmitInfo, CommandBufferCount = 1, CommandBuffers = new IntPtr(&commandBuffer), }; GraphicsDevice.NativeCommandQueue.Submit(1, &submitInfo, Fence.Null); GraphicsDevice.NativeCommandQueue.WaitIdle(); commandBuffer.Reset(CommandBufferResetFlags.None); // Get next image currentBufferIndex = GraphicsDevice.NativeDevice.AcquireNextImage(swapChain, ulong.MaxValue, GraphicsDevice.GetNextPresentSemaphore(), Fence.Null); // Apply the first swap chain image to the texture backbuffer.SetNativeHandles(swapchainImages[currentBufferIndex].NativeImage, swapchainImages[currentBufferIndex].NativeColorAttachmentView); }
protected internal TextureCube(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D, TextureTarget.TextureCubeMap) { throw new NotImplementedException(); }
/// <summary> /// Creates a new Cube <see cref="Texture" />. /// </summary> /// <param name="device">The <see cref="GraphicsDevice" />.</param> /// <param name="size">The size (in pixels) of the top-level faces of the cube texture.</param> /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param> /// <param name="format">Describes the format to use.</param> /// <param name="textureFlags">The texture flags.</param> /// <param name="usage">The usage.</param> /// <returns>A new instance of 2D <see cref="Texture" /> class.</returns> public static Texture NewCube(GraphicsDevice device, int size, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { return(new Texture(device).InitializeFrom(TextureDescription.NewCube(size, mipCount, format, textureFlags, usage))); }
protected internal Texture2DBase(GraphicsDevice device, TextureDescription description2D, TextureTarget textureTarget, DataBox[] dataBoxes = null, bool initialize = true) : base(device, description2D, ViewType.Full, 0, 0) { Target = textureTarget; if (initialize) Init(dataBoxes); }
protected Texture2D(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D, dataBoxes) { }
private static TextureDescription ConvertFromNativeDescription(ResourceDescription description, bool isShaderResource = false) { var desc = new TextureDescription() { Dimension = TextureDimension.Texture2D, Width = (int)description.Width, Height = description.Height, Depth = 1, MultiSampleLevel = (MSAALevel)description.SampleDescription.Count, Format = (PixelFormat)description.Format, MipLevels = description.MipLevels, Usage = GraphicsResourceUsage.Default, ArraySize = description.DepthOrArraySize, Flags = TextureFlags.None }; if ((description.Flags & ResourceFlags.AllowRenderTarget) != 0) desc.Flags |= TextureFlags.RenderTarget; if ((description.Flags & ResourceFlags.AllowUnorderedAccess) != 0) desc.Flags |= TextureFlags.UnorderedAccess; if ((description.Flags & ResourceFlags.AllowDepthStencil) != 0) desc.Flags |= TextureFlags.DepthStencil; if ((description.Flags & ResourceFlags.DenyShaderResource) == 0 && isShaderResource) desc.Flags |= TextureFlags.ShaderResource; return desc; }
/// <summary> /// Creates a new 1D <see cref="Texture" /> with a single level of mipmap. /// </summary> /// <param name="device">The <see cref="GraphicsDevice" />.</param> /// <param name="width">The width.</param> /// <param name="format">Describes the format to use.</param> /// <param name="dataPtr">Data ptr</param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <param name="usage">The usage.</param> /// <returns>A new instance of 1D <see cref="Texture" /> class.</returns> /// <remarks>The first dimension of mipMapTextures describes the number of array (Texture Array), second dimension is the mipmap, the third is the texture data for a particular mipmap.</remarks> public static Texture New1D(GraphicsDevice device, int width, PixelFormat format, IntPtr dataPtr, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) { return(New(device, TextureDescription.New1D(width, format, textureFlags, usage), new[] { new DataBox(dataPtr, 0, 0), })); }
protected Texture2D(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D, dataBoxes) { }
protected internal Texture2DBase(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D) { }
/// <summary> /// Creates a new 2D <see cref="Texture" />. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="usage">The usage.</param> /// <returns>A new instance of 2D <see cref="Texture" /> class.</returns> public static Texture New2D(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { return(new Texture(device).InitializeFrom(TextureDescription.New2D(width, height, mipCount, format, textureFlags, arraySize, usage))); }
/// <summary> /// Creates a new 3D <see cref="Texture"/>. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="depth">The depth.</param> /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param> /// <param name="format">Describes the format to use.</param> /// <param name="usage">The usage.</param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <returns> /// A new instance of 3D <see cref="Texture"/> class. /// </returns> public static Texture New3D(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { return(new Texture(device).InitializeFrom(TextureDescription.New3D(width, height, depth, mipCount, format, textureFlags, usage), textureData)); }
private static TextureDescription ConvertFromNativeDescription(Texture2DDescription description) { var desc = new TextureDescription() { Dimension = TextureDimension.Texture2D, Width = description.Width, Height = description.Height, Depth = 1, MultiSampleLevel = (MSAALevel)description.SampleDescription.Count, Format = (PixelFormat)description.Format, MipLevels = description.MipLevels, Usage = (GraphicsResourceUsage)description.Usage, ArraySize = description.ArraySize, Flags = TextureFlags.None }; if ((description.BindFlags & BindFlags.RenderTarget) != 0) desc.Flags |= TextureFlags.RenderTarget; if ((description.BindFlags & BindFlags.UnorderedAccess) != 0) desc.Flags |= TextureFlags.UnorderedAccess; if ((description.BindFlags & BindFlags.DepthStencil) != 0) desc.Flags |= TextureFlags.DepthStencil; if ((description.BindFlags & BindFlags.ShaderResource) != 0) desc.Flags |= TextureFlags.ShaderResource; return desc; }
protected internal Texture1D(GraphicsDevice device, TextureDescription description1D, DataBox[] dataBox = null) : base(device, description1D, ViewType.Full, 0, 0) { Target = TextureTarget1D; }
protected internal Texture1D(GraphicsDevice device, TextureDescription description1D, DataBox[] dataBox = null) : base(device, description1D, ViewType.Full, 0, 0) { Target = TextureTarget1D; }
internal Texture InitializeFromPersistent(TextureDescription description, SharpVulkan.Image nativeImage) { NativeImage = nativeImage; return(InitializeFrom(description)); }
protected internal Texture2D(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null, bool initialize = true) : base(device, description2D, TextureTarget.Texture2D, dataBoxes, initialize) { }
internal Texture InitializeWithoutResources(TextureDescription description) { isNotOwningResources = true; return(InitializeFrom(description)); }
/// <summary> /// Check and modify if necessary the mipmap levels of the image (Troubles with DXT images whose resolution in less than 4x4 in DX9.x). /// </summary> /// <param name="device">The graphics device.</param> /// <param name="description">The texture description.</param> /// <returns>The updated texture description.</returns> private static TextureDescription CheckMipLevels(GraphicsDevice device, ref TextureDescription description) { if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && (description.Flags & TextureFlags.DepthStencil) == 0 && description.Format.IsCompressed()) { description.MipLevels = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevels); } return description; }
protected internal TextureCube(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D, TextureTarget.TextureCubeMap) { throw new NotImplementedException(); }
internal Texture InitializeWithoutResources(TextureDescription description) { isNotOwningResources = true; return InitializeFrom(description); }
protected internal Texture2DBase(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D) { }
private unsafe void CreateBackBuffers() { // Create the texture object var backBufferDescription = new TextureDescription { ArraySize = 1, Dimension = TextureDimension.Texture2D, Height = Description.BackBufferHeight, Width = Description.BackBufferWidth, Depth = 1, Flags = TextureFlags.RenderTarget, Format = Description.BackBufferFormat, MipLevels = 1, MultiSampleLevel = MSAALevel.None, Usage = GraphicsResourceUsage.Default }; backbuffer.InitializeWithoutResources(backBufferDescription); var createInfo = new ImageViewCreateInfo { StructureType = StructureType.ImageViewCreateInfo, SubresourceRange = new ImageSubresourceRange(ImageAspectFlags.Color, 0, 1, 0, 1), Format = backbuffer.NativeFormat, }; // We initialize swapchain images to PresentSource, since we swap them out while in this layout. backbuffer.NativeAccessMask = AccessFlags.MemoryRead; backbuffer.NativeLayout = ImageLayout.PresentSource; var imageMemoryBarrier = new ImageMemoryBarrier { StructureType = StructureType.ImageMemoryBarrier, SubresourceRange = new ImageSubresourceRange(ImageAspectFlags.Color, 0, 1, 0, 1), OldLayout = ImageLayout.Undefined, NewLayout = ImageLayout.PresentSource, SourceAccessMask = AccessFlags.None, DestinationAccessMask = AccessFlags.MemoryRead }; var commandBuffer = GraphicsDevice.NativeCopyCommandBuffer; var beginInfo = new CommandBufferBeginInfo { StructureType = StructureType.CommandBufferBeginInfo }; commandBuffer.Begin(ref beginInfo); var buffers = GraphicsDevice.NativeDevice.GetSwapchainImages(swapChain); swapchainImages = new SwapChainImageInfo[buffers.Length]; for (int i = 0; i < buffers.Length; i++) { // Create image views swapchainImages[i].NativeImage = createInfo.Image = buffers[i]; swapchainImages[i].NativeColorAttachmentView = GraphicsDevice.NativeDevice.CreateImageView(ref createInfo); // Transition to default layout imageMemoryBarrier.Image = buffers[i]; commandBuffer.PipelineBarrier(PipelineStageFlags.AllCommands, PipelineStageFlags.AllCommands, DependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier); } // Close and submit commandBuffer.End(); var submitInfo = new SubmitInfo { StructureType = StructureType.SubmitInfo, CommandBufferCount = 1, CommandBuffers = new IntPtr(&commandBuffer), }; GraphicsDevice.NativeCommandQueue.Submit(1, &submitInfo, Fence.Null); GraphicsDevice.NativeCommandQueue.WaitIdle(); commandBuffer.Reset(CommandBufferResetFlags.None); // Get next image currentBufferIndex = GraphicsDevice.NativeDevice.AcquireNextImage(swapChain, ulong.MaxValue, GraphicsDevice.GetNextPresentSemaphore(), Fence.Null); // Apply the first swap chain image to the texture backbuffer.SetNativeHandles(swapchainImages[currentBufferIndex].NativeImage, swapchainImages[currentBufferIndex].NativeColorAttachmentView); }
/// <summary> /// Creates a new 1D <see cref="Texture"/>. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param> /// <param name="format">Describes the format to use.</param> /// <param name="usage">The usage.</param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <returns> /// A new instance of 1D <see cref="Texture"/> class. /// </returns> public static Texture New1D(GraphicsDevice device, int width, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { return(New(device, TextureDescription.New1D(width, mipCount, format, textureFlags, arraySize, usage))); }