public TextureItem(TexturePackage package, string name, TextureFlags flags) { Package = package; Name = name; Flags = flags; _subItems = new Dictionary<TextureSubItemType, TextureSubItem>(); }
public TextureItem(TexturePackage package, string name, TextureFlags flags, string primarySubItemName, int width, int height) { Package = package; Name = name; Flags = flags; var baseItem = new TextureSubItem(TextureSubItemType.Base, this, primarySubItemName, width, height); _subItems = new Dictionary<TextureSubItemType, TextureSubItem> {{TextureSubItemType.Base, baseItem}}; }
private static TextureDescription New1D(int width, PixelFormat format, TextureFlags flags, int mipCount, int arraySize, GraphicsResourceUsage usage) { usage = (flags & TextureFlags.UnorderedAccess) != 0 ? GraphicsResourceUsage.Default : usage; var desc = new TextureDescription() { Dimension = TextureDimension.Texture1D, Width = width, Height = 1, Depth = 1, ArraySize = arraySize, Flags = flags, Format = format, MipLevels = Texture.CalculateMipMapCount(mipCount, width), Usage = Texture.GetUsageWithFlags(usage, flags), }; return desc; }
private static TextureDescription New3D(int width, int height, int depth, PixelFormat format, TextureFlags flags, int mipCount, GraphicsResourceUsage usage) { var desc = new TextureDescription() { Width = width, Height = height, Depth = depth, Flags = flags, Format = format, MipLevels = Texture.CalculateMipMapCount(mipCount, width, height, depth), Usage = Texture.GetUsageWithFlags(usage, flags), ArraySize = 1, Dimension = TextureDimension.Texture3D, MultiSampleLevel = MSAALevel.None }; return desc; }
private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) usage = GraphicsResourceUsage.Default; var desc = new TextureDescription() { Dimension = TextureDimension.Texture2D, Width = width, Height = height, Depth = 1, ArraySize = arraySize, MultiSampleLevel = MSAALevel.None, Flags = textureFlags, Format = format, MipLevels = Texture.CalculateMipMapCount(mipCount, width, height), Usage = Texture.GetUsageWithFlags(usage, textureFlags), }; return desc; }
public static GLTexture Create(string name, Bitmap bitmap, int width, int height, TextureFlags flags) { if (Exists(name)) { Delete(name); } var actualBitmap = bitmap; if (ForceNonPowerOfTwoResize || !SupportsNonPowerOfTwo()) { var w = NextPowerOfTwo(bitmap.Width); var h = NextPowerOfTwo(bitmap.Height); if (w != bitmap.Width || h != bitmap.Height) actualBitmap = new Bitmap(bitmap, w, h); } var data = actualBitmap.LockBits( new Rectangle(0, 0, actualBitmap.Width, actualBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); var tex = CreateAndBindTexture(); SetTextureParameters(); GL.TexImage2D( TextureTarget.Texture2D, 0, PixelInternalFormat, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0 ); actualBitmap.UnlockBits(data); if (actualBitmap != bitmap) { actualBitmap.Dispose(); } var texobj = new GLTexture(tex, name, flags) { Width = width, Height = height }; Textures.Add(name, texobj); return texobj; }
/// <summary> /// Initializes a new instance of the <see cref="MyTexture"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="manager">The manager.</param> /// <param name="loadMethod">The load method. See <code>LoadMethod</code> enum.</param> /// <param name="flags">The flags.</param> protected MyTexture(string path, LoadMethod loadMethod, TextureFlags flags) { this.flags = flags; this.Name = path; // this.Manager = manager; switch (loadMethod) { case LoadMethod.External: this.LoadState = LoadState.Pending; break; case LoadMethod.Lazy: this.LoadState = LoadState.LoadYourself; break; case LoadMethod.LazyBackground: this.LoadState = LoadState.LoadYourselfBackground; break; default: throw new ArgumentOutOfRangeException("loadMethod"); } }
public static extern ushort bgfx_create_texture_cube(ushort size, byte numMips, TextureFormat format, TextureFlags flags, MemoryBlock.DataPtr* mem);
/// <summary> /// Initializes a new instance of the <see cref="MyTexture2D"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="manager">The manager.</param> /// <param name="loadMethod">if set to <c>true</c> [external load].</param> /// <param name="flags">The flags.</param> public MyTextureCube(string path, LoadMethod loadMethod, TextureFlags flags) : base(path, loadMethod, flags) { }
/// <summary> /// Gets a render target output for the specified description, scoped for the duration of the <see cref="DrawEffect.DrawCore"/>. /// </summary> /// <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="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <returns>A new instance of texture class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> protected Texture NewScopedRenderTarget2D(int width, int height, PixelFormat format, MipMapCount mipCount, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { CheckIsInDrawCore(); return PushScopedResource(Context.Allocator.GetTemporaryTexture2D(width, height, format, mipCount, flags, arraySize)); }
protected static Texture1DDescription NewRenderTargetDescription(int width, PixelFormat format, TextureFlags textureFlags,int mipCount, int arraySize) { var desc = Texture1DBase.NewDescription(width, format, textureFlags, mipCount, arraySize, ResourceUsage.Default); return desc; }
/// <summary> /// Creates a new texture description <see cref="RenderTarget2D" />. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</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="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { return CreateDescription(device.MainDevice, width, height, format, flags, mipCount, arraySize, MSAALevel.None); }
private static void EmitTextureQuery(EmitterContext context, bool bindless) { OpCodeTex op = (OpCodeTex)context.CurrOp; if (op.Rd.IsRZ) { return; } TextureProperty property = (TextureProperty)op.RawOpCode.Extract(22, 6); // TODO: Validate and use property. Instruction inst = Instruction.TextureSize; SamplerType type = SamplerType.Texture2D; TextureFlags flags = bindless ? TextureFlags.Bindless : TextureFlags.None; int raIndex = op.Ra.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } List <Operand> sourcesList = new List <Operand>(); if (bindless) { sourcesList.Add(Ra()); } sourcesList.Add(Ra()); Operand[] sources = sourcesList.ToArray(); int rdIndex = op.Rd.Index; Operand GetDest() { if (rdIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(Register(rdIndex++, RegisterType.Gpr)); } int handle = !bindless ? op.HandleOffset : 0; for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) != 0) { Operand dest = GetDest(); TextureOperation operation = context.CreateTextureOperation( inst, type, flags, handle, compIndex, dest, sources); context.Add(operation); } } }
private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage, MultisampleCount multisampleCount) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) { usage = GraphicsResourceUsage.Default; } var desc = new TextureDescription { Dimension = TextureDimension.Texture2D, Width = width, Height = height, Depth = 1, ArraySize = arraySize, MultisampleCount = multisampleCount, Flags = textureFlags, Format = format, MipLevels = Texture.CalculateMipMapCount(mipCount, width, height), Usage = Texture.GetUsageWithFlags(usage, textureFlags), }; return(desc); }
/// <summary> /// Creates a new <see cref="TextureDescription" />. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</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">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> /// <param name="multisampleCount">The multisample count.</param> /// <returns>A new instance of <see cref="TextureDescription" /> class.</returns> public static TextureDescription New2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None) { return(New2D(width, height, format, textureFlags, mipCount, arraySize, usage, multisampleCount)); }
/// <summary> /// Sets a texture to use for drawing primitives. /// </summary> /// <param name="textureUnit">The texture unit to set.</param> /// <param name="sampler">The sampler uniform.</param> /// <param name="texture">The texture to set.</param> /// <param name="flags">Sampling flags that override the default flags in the texture itself.</param> public void SetTexture(byte textureUnit, Uniform sampler, Texture texture, TextureFlags flags) { NativeMethods.bgfx_encoder_set_texture(ptr, textureUnit, sampler.handle, texture.handle, (uint)flags); }
public static TextureDescription NewDescription(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) { usage = GraphicsResourceUsage.Default; } var desc = new TextureDescription() { Dimension = TextureDimension.Texture2D, Width = width, Height = height, Depth = 1, ArraySize = arraySize, Level = MSAALevel.None, Flags = textureFlags, Format = format, MipLevels = CalculateMipMapCount(mipCount, width, height), Usage = GetUsageWithFlags(usage, textureFlags), }; return(desc); }
private static void EmitTextureSample(EmitterContext context, TextureFlags flags) { OpCodeTexture op = (OpCodeTexture)context.CurrOp; bool isBindless = (flags & TextureFlags.Bindless) != 0; if (op.Rd.IsRZ) { return; } int raIndex = op.Ra.Index; int rbIndex = op.Rb.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } Operand Rb() { if (rbIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(rbIndex++, RegisterType.Gpr))); } Operand arrayIndex = op.IsArray ? Ra() : null; List <Operand> sourcesList = new List <Operand>(); if (isBindless) { sourcesList.Add(Rb()); } SamplerType type = ConvertSamplerType(op.Dimensions); bool hasLod = op.LodMode > TextureLodMode.LodZero; if (type == SamplerType.Texture1D && (flags & ~TextureFlags.Bindless) == TextureFlags.IntCoords && !(hasLod || op.HasDepthCompare || op.HasOffset || op.IsArray || op.IsMultisample)) { // For bindless, we don't have any way to know the texture type, // so we assume it's texture buffer when the sampler type is 1D, since that's more common. bool isTypeBuffer = isBindless || context.Config.GpuAccessor.QueryIsTextureBuffer(op.HandleOffset); if (isTypeBuffer) { type = SamplerType.TextureBuffer; } } int coordsCount = type.GetDimensions(); for (int index = 0; index < coordsCount; index++) { sourcesList.Add(Ra()); } if (Sample1DAs2D && type == SamplerType.Texture1D) { sourcesList.Add(ConstF(0)); type = SamplerType.Texture2D; } if (op.IsArray) { sourcesList.Add(arrayIndex); type |= SamplerType.Array; } Operand lodValue = hasLod ? Rb() : ConstF(0); Operand packedOffs = op.HasOffset ? Rb() : null; if (op.HasDepthCompare) { sourcesList.Add(Rb()); type |= SamplerType.Shadow; } if ((op.LodMode == TextureLodMode.LodZero || op.LodMode == TextureLodMode.LodLevel || op.LodMode == TextureLodMode.LodLevelA) && !op.IsMultisample && type != SamplerType.TextureBuffer) { sourcesList.Add(lodValue); flags |= TextureFlags.LodLevel; } if (op.HasOffset) { for (int index = 0; index < coordsCount; index++) { sourcesList.Add(context.BitfieldExtractS32(packedOffs, Const(index * 4), Const(4))); } flags |= TextureFlags.Offset; } if (op.LodMode == TextureLodMode.LodBias || op.LodMode == TextureLodMode.LodBiasA) { sourcesList.Add(lodValue); flags |= TextureFlags.LodBias; } if (op.IsMultisample) { sourcesList.Add(Rb()); type |= SamplerType.Multisample; } Operand[] sources = sourcesList.ToArray(); int rdIndex = op.Rd.Index; Operand GetDest() { if (rdIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(Register(rdIndex++, RegisterType.Gpr)); } int handle = !isBindless ? op.HandleOffset : 0; for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) != 0) { Operand dest = GetDest(); TextureOperation operation = context.CreateTextureOperation( Instruction.TextureSample, type, flags, handle, compIndex, dest, sources); context.Add(operation); } } }
/// <summary> /// Creates a new Cube <see cref="TextureDescription"/>. /// </summary> /// <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 <see cref="TextureDescription"/> class.</returns> public static TextureDescription NewCube(int size, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { return NewCube(size, format, textureFlags, mipCount, usage); }
public static void Suld(EmitterContext context) { context.Config.SetUsedFeature(FeatureFlags.IntegerSampling); OpCodeImage op = (OpCodeImage)context.CurrOp; SamplerType type = ConvertSamplerType(op.Dimensions); if (type == SamplerType.None) { context.Config.GpuAccessor.Log("Invalid image store sampler type."); return; } // Rb is Rd on the SULD instruction. int rdIndex = op.Rb.Index; int raIndex = op.Ra.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } List <Operand> sourcesList = new List <Operand>(); if (op.IsBindless) { sourcesList.Add(context.Copy(Register(op.Rc))); } int coordsCount = type.GetDimensions(); for (int index = 0; index < coordsCount; index++) { sourcesList.Add(Ra()); } if (Sample1DAs2D && (type & SamplerType.Mask) == SamplerType.Texture1D) { sourcesList.Add(Const(0)); type &= ~SamplerType.Mask; type |= SamplerType.Texture2D; } if (type.HasFlag(SamplerType.Array)) { sourcesList.Add(Ra()); type |= SamplerType.Array; } Operand[] sources = sourcesList.ToArray(); int handle = !op.IsBindless ? op.HandleOffset : 0; TextureFlags flags = op.IsBindless ? TextureFlags.Bindless : TextureFlags.None; if (op.UseComponents) { int componentMask = (int)op.Components; for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) == 0) { continue; } if (rdIndex == RegisterConsts.RegisterZeroIndex) { break; } Operand rd = Register(rdIndex++, RegisterType.Gpr); TextureOperation operation = context.CreateTextureOperation( Instruction.ImageLoad, type, flags, handle, compIndex, rd, sources); if (!op.IsBindless) { operation.Format = context.Config.GetTextureFormat(handle); } context.Add(operation); } } else { if (op.ByteAddress) { int xIndex = op.IsBindless ? 1 : 0; sources[xIndex] = context.ShiftRightS32(sources[xIndex], Const(GetComponentSizeInBytesLog2(op.Size))); } int components = GetComponents(op.Size); for (int compIndex = 0; compIndex < components; compIndex++) { if (rdIndex == RegisterConsts.RegisterZeroIndex) { break; } Operand rd = Register(rdIndex++, RegisterType.Gpr); TextureOperation operation = context.CreateTextureOperation( Instruction.ImageLoad, type, GetTextureFormat(op.Size), flags, handle, compIndex, rd, sources); context.Add(operation); switch (op.Size) { case IntegerSize.U8: context.Copy(rd, ZeroExtendTo32(context, rd, 8)); break; case IntegerSize.U16: context.Copy(rd, ZeroExtendTo32(context, rd, 16)); break; case IntegerSize.S8: context.Copy(rd, SignExtendTo32(context, rd, 8)); break; case IntegerSize.S16: context.Copy(rd, SignExtendTo32(context, rd, 16)); break; } } } }
/// <summary> /// Creates a new <see cref="RenderTarget3D" />. /// </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="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 3D array, default to 1.</param> /// <returns>A new instance of <see cref="RenderTarget3D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> public static RenderTarget3D New(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { return new RenderTarget3D(device, NewRenderTargetDescription(width, height, depth, format, flags | TextureFlags.RenderTarget, mipCount)); }
public static void Sust(EmitterContext context) { OpCodeImage op = (OpCodeImage)context.CurrOp; SamplerType type = ConvertSamplerType(op.Dimensions); if (type == SamplerType.None) { context.Config.GpuAccessor.Log("Invalid image store sampler type."); return; } int raIndex = op.Ra.Index; int rbIndex = op.Rb.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } Operand Rb() { if (rbIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(rbIndex++, RegisterType.Gpr))); } List <Operand> sourcesList = new List <Operand>(); if (op.IsBindless) { sourcesList.Add(context.Copy(Register(op.Rc))); } int coordsCount = type.GetDimensions(); for (int index = 0; index < coordsCount; index++) { sourcesList.Add(Ra()); } if (Sample1DAs2D && (type & SamplerType.Mask) == SamplerType.Texture1D) { sourcesList.Add(Const(0)); type &= ~SamplerType.Mask; type |= SamplerType.Texture2D; } if (type.HasFlag(SamplerType.Array)) { sourcesList.Add(Ra()); type |= SamplerType.Array; } TextureFormat format = TextureFormat.Unknown; if (op.UseComponents) { int componentMask = (int)op.Components; for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) != 0) { sourcesList.Add(Rb()); } } if (!op.IsBindless) { format = context.Config.GetTextureFormat(op.HandleOffset); } } else { if (op.ByteAddress) { int xIndex = op.IsBindless ? 1 : 0; sourcesList[xIndex] = context.ShiftRightS32(sourcesList[xIndex], Const(GetComponentSizeInBytesLog2(op.Size))); } int components = GetComponents(op.Size); for (int compIndex = 0; compIndex < components; compIndex++) { sourcesList.Add(Rb()); } format = GetTextureFormat(op.Size); } Operand[] sources = sourcesList.ToArray(); int handle = !op.IsBindless ? op.HandleOffset : 0; TextureFlags flags = op.IsBindless ? TextureFlags.Bindless : TextureFlags.None; TextureOperation operation = context.CreateTextureOperation( Instruction.ImageStore, type, format, flags, handle, 0, null, sources); context.Add(operation); }
protected static Texture1DDescription NewDescription(int width, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, ResourceUsage usage) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) usage = ResourceUsage.Default; var desc = new Texture1DDescription() { Width = width, ArraySize = arraySize, BindFlags = GetBindFlagsFromTextureFlags(textureFlags), Format = format, MipLevels = CalculateMipMapCount(mipCount, width), Usage = usage, CpuAccessFlags = GetCputAccessFlagsFromUsage(usage), OptionFlags = ResourceOptionFlags.None }; // If the texture is a RenderTarget + ShaderResource + MipLevels > 1, then allow for GenerateMipMaps method if ((desc.BindFlags & BindFlags.RenderTarget) != 0 && (desc.BindFlags & BindFlags.ShaderResource) != 0 && desc.MipLevels > 1) { desc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; } return desc; }
public static void Tld4(EmitterContext context) { IOpCodeTld4 op = (IOpCodeTld4)context.CurrOp; if (op.Rd.IsRZ) { return; } int raIndex = op.Ra.Index; int rbIndex = op.Rb.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } Operand Rb() { if (rbIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(rbIndex++, RegisterType.Gpr))); } Operand arrayIndex = op.IsArray ? Ra() : null; List <Operand> sourcesList = new List <Operand>(); SamplerType type = ConvertSamplerType(op.Dimensions); TextureFlags flags = TextureFlags.Gather; if (op.Bindless) { sourcesList.Add(Rb()); flags |= TextureFlags.Bindless; } int coordsCount = type.GetDimensions(); for (int index = 0; index < coordsCount; index++) { sourcesList.Add(Ra()); } bool is1DTo2D = Sample1DAs2D && type == SamplerType.Texture1D; if (is1DTo2D) { sourcesList.Add(ConstF(0)); type = SamplerType.Texture2D; } if (op.IsArray) { sourcesList.Add(arrayIndex); type |= SamplerType.Array; } Operand[] packedOffs = new Operand[2]; packedOffs[0] = op.Offset != TextureGatherOffset.None ? Rb() : null; packedOffs[1] = op.Offset == TextureGatherOffset.Offsets ? Rb() : null; if (op.HasDepthCompare) { sourcesList.Add(Rb()); type |= SamplerType.Shadow; } if (op.Offset != TextureGatherOffset.None) { int offsetTexelsCount = op.Offset == TextureGatherOffset.Offsets ? 4 : 1; for (int index = 0; index < coordsCount * offsetTexelsCount; index++) { Operand packed = packedOffs[(index >> 2) & 1]; sourcesList.Add(context.BitfieldExtractS32(packed, Const((index & 3) * 8), Const(6))); } if (is1DTo2D) { for (int index = 0; index < offsetTexelsCount; index++) { sourcesList.Add(Const(0)); } } flags |= op.Offset == TextureGatherOffset.Offsets ? TextureFlags.Offsets : TextureFlags.Offset; } sourcesList.Add(Const(op.GatherCompIndex)); Operand[] sources = sourcesList.ToArray(); int rdIndex = op.Rd.Index; Operand GetDest() { if (rdIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(Register(rdIndex++, RegisterType.Gpr)); } int handle = op.HandleOffset; for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) != 0) { Operand dest = GetDest(); TextureOperation operation = context.CreateTextureOperation( Instruction.TextureSample, type, flags, handle, compIndex, dest, sources); context.Add(operation); } } }
public static extern ushort bgfx_create_texture_2d_scaled(BackbufferRatio ratio, byte numMips, TextureFormat format, TextureFlags flags);
private static void EmitTextureMipMapLevel(EmitterContext context, bool isBindless) { OpCodeTexture op = (OpCodeTexture)context.CurrOp; if (op.Rd.IsRZ) { return; } int raIndex = op.Ra.Index; int rbIndex = op.Rb.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } Operand Rb() { if (rbIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(rbIndex++, RegisterType.Gpr))); } TextureFlags flags = TextureFlags.None; List <Operand> sourcesList = new List <Operand>(); if (isBindless) { sourcesList.Add(Rb()); flags |= TextureFlags.Bindless; } SamplerType type = ConvertSamplerType(op.Dimensions); int coordsCount = type.GetDimensions(); Operand arrayIndex = op.IsArray ? Ra() : null; for (int index = 0; index < coordsCount; index++) { sourcesList.Add(Ra()); } if (Sample1DAs2D && type == SamplerType.Texture1D) { sourcesList.Add(ConstF(0)); type = SamplerType.Texture2D; } if (op.IsArray) { sourcesList.Add(arrayIndex); type |= SamplerType.Array; } Operand[] sources = sourcesList.ToArray(); int rdIndex = op.Rd.Index; Operand GetDest() { if (rdIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(Register(rdIndex++, RegisterType.Gpr)); } int handle = !isBindless ? op.HandleOffset : 0; for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) != 0) { Operand dest = GetDest(); // Components z and w aren't standard, we return 0 in this case and add a comment. if (compIndex >= 2) { context.Add(new CommentNode("Unsupported component z or w found")); context.Copy(dest, Const(0)); } else { Operand tempDest = Local(); TextureOperation operation = context.CreateTextureOperation( Instruction.Lod, type, flags, handle, compIndex ^ 1, // The instruction component order is the inverse of GLSL's. tempDest, sources); context.Add(operation); tempDest = context.FPMultiply(tempDest, ConstF(256.0f)); Operand fixedPointValue = context.FPConvertToS32(tempDest); context.Copy(dest, fixedPointValue); } } } }
public static extern ushort bgfx_create_frame_buffer(ushort width, ushort height, TextureFormat format, TextureFlags flags);
public static void Txd(EmitterContext context) { OpCodeTxd op = (OpCodeTxd)context.CurrOp; if (op.Rd.IsRZ) { return; } int raIndex = op.Ra.Index; int rbIndex = op.Rb.Index; Operand Ra() { if (raIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(raIndex++, RegisterType.Gpr))); } Operand Rb() { if (rbIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(context.Copy(Register(rbIndex++, RegisterType.Gpr))); } TextureFlags flags = TextureFlags.Derivatives; List <Operand> sourcesList = new List <Operand>(); if (op.IsBindless) { sourcesList.Add(Ra()); flags |= TextureFlags.Bindless; } SamplerType type = ConvertSamplerType(op.Dimensions); int coordsCount = type.GetDimensions(); for (int index = 0; index < coordsCount; index++) { sourcesList.Add(Ra()); } bool is1DTo2D = Sample1DAs2D && type == SamplerType.Texture1D; if (is1DTo2D) { sourcesList.Add(ConstF(0)); type = SamplerType.Texture2D; } Operand packedParams = Ra(); if (op.IsArray) { sourcesList.Add(context.BitwiseAnd(packedParams, Const(0xffff))); type |= SamplerType.Array; } // Derivatives (X and Y). for (int dIndex = 0; dIndex < 2 * coordsCount; dIndex++) { sourcesList.Add(Rb()); if (is1DTo2D) { sourcesList.Add(ConstF(0)); } } if (op.HasOffset) { for (int index = 0; index < coordsCount; index++) { sourcesList.Add(context.BitfieldExtractS32(packedParams, Const(16 + index * 4), Const(4))); } if (is1DTo2D) { sourcesList.Add(Const(0)); } flags |= TextureFlags.Offset; } Operand[] sources = sourcesList.ToArray(); int rdIndex = op.Rd.Index; Operand GetDest() { if (rdIndex > RegisterConsts.RegisterZeroIndex) { return(Const(0)); } return(Register(rdIndex++, RegisterType.Gpr)); } int handle = !op.IsBindless ? op.HandleOffset : 0; for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++) { if ((compMask & 1) != 0) { Operand dest = GetDest(); TextureOperation operation = context.CreateTextureOperation( Instruction.TextureSample, type, flags, handle, compIndex, dest, sources); context.Add(operation); } } }
/// <summary> /// Creates a new <see cref="RenderTargetCube" />. /// </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="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns>A new instance of <see cref="RenderTargetCube" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static RenderTargetCube New(GraphicsDevice device, int size, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource) { return new RenderTargetCube(device, NewRenderTargetDescription(size, format, flags | TextureFlags.RenderTarget, mipCount)); }
internal static TextureDescription CreateTextureDescriptionFromImage(Image image, TextureFlags flags, ResourceUsage usage) { var desc = (TextureDescription)image.Description; desc.BindFlags = BindFlags.ShaderResource; desc.Usage = usage; if ((flags & TextureFlags.UnorderedAccess) != 0) { desc.Usage = ResourceUsage.Default; } desc.BindFlags = GetBindFlagsFromTextureFlags(flags); desc.CpuAccessFlags = GetCpuAccessFlagsFromUsage(usage); return(desc); }
/// <summary> /// Loads a 2D texture from a stream. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="filePath">The file to load the texture from.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="usage">Usage of the resource. Default is <see cref="ResourceUsage.Immutable"/> </param> /// <exception cref="ArgumentException">If the texture is not of type 2D</exception> /// <returns>A texture</returns> public static new Texture2D Load(Device device, string filePath, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { using (var stream = new NativeFileStream(filePath, NativeFileMode.Open, NativeFileAccess.Read)) return(Load(device, stream, flags, usage)); }
/// <summary> /// Creates a new <see cref="RenderTarget1D" /> with a single mipmap. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="width">The width.</param> /// <param name="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 1D array, default to 1.</param> /// <returns>A new instance of <see cref="RenderTarget1D" /> class.</returns> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public static RenderTarget1D New(Device device, int width, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { return(New(device, width, false, format, flags | TextureFlags.RenderTarget, arraySize)); }
public TextureItem(string name, TextureFlags flags) { Name = name; Flags = flags; SubItems = new Dictionary <TextureSubItemType, TextureSubItem>(); }
/// <summary> /// Creates a new <see cref="RenderTarget1D" />. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</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="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 1D array, default to 1.</param> /// <returns>A new instance of <see cref="RenderTarget1D" /> class.</returns> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public static RenderTarget1D New(Device device, int width, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { return(new RenderTarget1D(device, NewRenderTargetDescription(width, format, flags | TextureFlags.RenderTarget, mipCount, arraySize))); }
public static extern ushort bgfx_create_texture(MemoryBlock.DataPtr *mem, TextureFlags flags, byte skip, out Texture.TextureInfo info);
/// <summary> /// /// </summary> /// <param name="width"></param> /// <param name="format"></param> /// <param name="textureFlags"></param> /// <param name="mipCount"></param> /// <param name="arraySize"></param> /// <returns></returns> protected static Texture1DDescription NewRenderTargetDescription(int width, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize) { var desc = Texture1DBase.NewDescription(width, format, textureFlags, mipCount, arraySize, ResourceUsage.Default); return(desc); }
internal static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, MSAALevel multiSampleCount) { // Make sure that the texture to create is a render target textureFlags |= TextureFlags.RenderTarget; var desc = Texture2DBase.NewDescription(width, height, format, textureFlags, mipCount, arraySize, ResourceUsage.Default); // Sets the MSAALevel int maximumMSAA = (int)device.Features[format].MSAALevelMax; desc.SampleDescription.Count = Math.Max(1, Math.Min((int)multiSampleCount, maximumMSAA)); return desc; }
/// <summary> /// Creates a new 2D texture that scales with backbuffer size. /// </summary> /// <param name="ratio">The amount to scale when the backbuffer resizes.</param> /// <param name="hasMips">Indicates that texture contains full mip-map chain.</param> /// <param name="arrayLayers">Number of layers in texture array. Must be 1 if Texture2DArray caps flag not set.</param> /// <param name="format">The format of the texture data.</param> /// <param name="flags">Flags that control texture behavior.</param> /// <returns> /// The newly created texture handle. /// </returns> public static Texture Create2D(BackbufferRatio ratio, bool hasMips, int arrayLayers, TextureFormat format, TextureFlags flags = TextureFlags.None) { var info = new TextureInfo { Format = format, Layers = (ushort)arrayLayers }; var handle = NativeMethods.bgfx_create_texture_2d_scaled(ratio, hasMips, (ushort)arrayLayers, format, flags); return(new Texture(handle, ref info)); }
private static TextureDescription NewCube(int size, PixelFormat format, TextureFlags textureFlags, int mipCount, GraphicsResourceUsage usage) { var desc = New2D(size, size, format, textureFlags, mipCount, 6, usage); desc.Dimension = TextureDimension.TextureCube; return desc; }
/// <summary> /// Creates a new 3D texture. /// </summary> /// <param name="width">The width of the texture.</param> /// <param name="height">The height of the texture.</param> /// <param name="depth">The depth of the texture.</param> /// <param name="hasMips">Indicates that texture contains full mip-map chain.</param> /// <param name="format">The format of the texture data.</param> /// <param name="flags">Flags that control texture behavior.</param> /// <param name="memory">If not <c>null</c>, contains the texture's image data.</param> /// <returns>The newly created texture handle.</returns> public static Texture Create3D(int width, int height, int depth, bool hasMips, TextureFormat format, TextureFlags flags = TextureFlags.None, MemoryBlock?memory = null) { var info = new TextureInfo(); NativeMethods.bgfx_calc_texture_size(ref info, (ushort)width, (ushort)height, (ushort)depth, false, hasMips, 1, format); var handle = NativeMethods.bgfx_create_texture_3d(info.Width, info.Height, info.Depth, hasMips, format, flags, memory == null ? null : memory.Value.ptr); return(new Texture(handle, ref info)); }
/// <summary> /// Creates a new <see cref="RenderTarget3D" /> with a single mipmap. /// </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="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 3D array, default to 1.</param> /// <returns>A new instance of <see cref="RenderTarget3D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> public static RenderTarget3D New(GraphicsDevice device, int width, int height, int depth, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { return New(device, width, height, depth, false, format, flags | TextureFlags.RenderTarget, arraySize); }
/// <summary> /// Creates a new cube texture. /// </summary> /// <param name="size">The size of each cube face.</param> /// <param name="hasMips">Indicates that texture contains full mip-map chain.</param> /// <param name="arrayLayers">Number of layers in texture array. Must be 1 if Texture2DArray caps flag not set.</param> /// <param name="format">The format of the texture data.</param> /// <param name="flags">Flags that control texture behavior.</param> /// <param name="memory">If not <c>null</c>, contains the texture's image data.</param> /// <returns> /// The newly created texture handle. /// </returns> public static Texture CreateCube(int size, bool hasMips, int arrayLayers, TextureFormat format, TextureFlags flags = TextureFlags.None, MemoryBlock?memory = null) { var info = new TextureInfo(); NativeMethods.bgfx_calc_texture_size(ref info, (ushort)size, (ushort)size, 1, true, hasMips, (ushort)arrayLayers, format); var handle = NativeMethods.bgfx_create_texture_cube(info.Width, hasMips, (ushort)arrayLayers, format, flags, memory == null ? null : memory.Value.ptr); return(new Texture(handle, ref info)); }
protected static Texture3DDescription NewRenderTargetDescription(int width, int height, int depth, PixelFormat format, TextureFlags textureFlags,int mipCount) { var desc = Texture3DBase.NewDescription(width, height, depth, format, textureFlags, mipCount, ResourceUsage.Default); return desc; }
/// <summary> /// Checks whether a texture with the given parameters would be considered valid. /// </summary> /// <param name="depth">The depth of the texture.</param> /// <param name="isCube"><c>true</c> if the texture contains a cubemap.</param> /// <param name="arrayLayers">Number of layers in texture array.</param> /// <param name="format">The format of the texture data.</param> /// <param name="flags">Flags that control texture behavior.</param> /// <returns></returns> public static bool IsValid(int depth, bool isCube, int arrayLayers, TextureFormat format, TextureFlags flags = TextureFlags.None) { return(NativeMethods.bgfx_is_texture_valid((ushort)depth, isCube, (ushort)arrayLayers, format, flags)); }
internal static BindFlags GetBindFlagsFromTextureFlags(TextureFlags flags) { var result = BindFlags.None; if ((flags & TextureFlags.ShaderResource) != 0) result |= BindFlags.ShaderResource; if ((flags & TextureFlags.RenderTarget) != 0) result |= BindFlags.RenderTarget; if ((flags & TextureFlags.UnorderedAccess) != 0) result |= BindFlags.UnorderedAccess; if ((flags & TextureFlags.DepthStencil) != 0) result |= BindFlags.DepthStencil; return result; }
/// <summary> /// Override internal texture by creating a new 2D texture. /// </summary> /// <param name="width">The width of the texture.</param> /// <param name="height">The height of the texture.</param> /// <param name="mipCount">The number of mip levels.</param> /// <param name="format">The format of the texture data.</param> /// <param name="flags">Flags that control texture behavior.</param> /// <returns> /// Native API pointer to the texture. If result is <see cref="IntPtr.Zero"/>, the texture is not yet /// created from the main thread. /// </returns> public IntPtr OverrideInternal(int width, int height, int mipCount, TextureFormat format, TextureFlags flags = TextureFlags.None) { Width = width; Height = height; MipLevels = mipCount; Format = format; return(NativeMethods.bgfx_override_internal_texture(handle, (ushort)width, (ushort)height, (byte)mipCount, format, flags)); }
/// <summary> /// Initializes a new instance of the <see cref="MyTexture2D"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="manager">The manager.</param> /// <param name="loadMethod">if set to <c>true</c> [external load].</param> /// <param name="flags">The flags.</param> public MyTexture2D(string contentDir, string path, LoadMethod loadMethod, TextureFlags flags) : base(contentDir, path, loadMethod, flags) { }
/// <summary> /// Creates a new <see cref="Texture3D"/> with a single mipmap. /// </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="format">Describes the format to use.</param> /// <param name="usage">The usage.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns> /// A new instance of <see cref="Texture3D"/> class. /// </returns> /// <msdn-id>ff476522</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> public static Texture3D New(GraphicsDevice device, int width, int height, int depth, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default) { return(New(device, width, height, depth, false, format, flags, usage)); }
public static extern ushort bgfx_create_texture(MemoryBlock.DataPtr* mem, TextureFlags flags, byte skip, out Texture.TextureInfo info);
/// <summary> /// Creates a new <see cref="Texture3D"/>. /// </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="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns> /// A new instance of <see cref="Texture3D"/> class. /// </returns> /// <msdn-id>ff476522</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> public static Texture3D New(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default) { return(new Texture3D(device, NewDescription(width, height, depth, format, flags, mipCount, usage))); }
public static extern ushort bgfx_create_texture_3d(ushort width, ushort _height, ushort _depth, byte numMips, TextureFormat format, TextureFlags flags, MemoryBlock.DataPtr* mem);
/// <summary> /// Creates a new <see cref="Texture3D"/>. /// </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="textureData">DataBox used to fill texture data.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns> /// A new instance of <see cref="Texture3D"/> class. /// </returns> /// <msdn-id>ff476522</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short> public static Texture3D New(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default) { // TODO Add check for number of texture data according to width/height/depth/mipCount. return(new Texture3D(device, NewDescription(width, height, depth, format, flags, mipCount, usage), textureData)); }
public static extern IntPtr bgfx_override_internal_texture(ushort handle, ushort width, ushort height, byte numMips, TextureFormat format, TextureFlags flags);
private unsafe Texture CreateDebugTexture(GraphicsDevice device, byte[] data, int width, int height, int mipmaps, int arraySize, PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage) { fixed(byte *pData = data) { var sizeInBytes = format.SizeInBytes(); var offset = 0; var dataBoxes = new DataBox[arraySize * mipmaps]; for (int array = 0; array < arraySize; array++) { for (int mip = 0; mip < mipmaps; mip++) { var w = width >> mip; var h = height >> mip; var rowStride = w * sizeInBytes; var sliceStride = rowStride * h; dataBoxes[array * mipmaps + mip] = new DataBox((IntPtr)pData + offset, rowStride, sliceStride); offset += sliceStride; } } return(Texture.New2D(device, width, height, mipmaps, format, dataBoxes, flags, arraySize, usage)); } }
public static extern ushort bgfx_create_frame_buffer_scaled(BackbufferRatio ratio, TextureFormat format, TextureFlags flags);
/// <summary> /// Creates a new <see cref="Texture2D" /> with a single mipmap. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</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 <see cref="Texture2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static Texture2D New(Device device, int width, int height, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, int arraySize = 1, ResourceUsage usage = ResourceUsage.Default) { return(New(device, width, height, false, format, flags, arraySize, usage)); }
/// <summary> /// Creates a new <see cref="RenderTargetCube" /> with a single mipmap. /// </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="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns>A new instance of <see cref="RenderTargetCube" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static RenderTargetCube New(GraphicsDevice device, int size, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource) { return New(device, size, false, format, flags | TextureFlags.RenderTarget); }
/// <summary> /// Creates a new <see cref="Texture2D" /> with a single level of mipmap. /// </summary> /// <typeparam name="T">Type of the pixel data to upload to the texture.</typeparam> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="usage">The usage.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="textureData">The texture data for a single mipmap and a single array slice. See remarks</param> /// <returns>A new instance of <see cref="Texture2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> /// <remarks> /// Each value in textureData is a pixel in the destination texture. /// </remarks> public unsafe static Texture2D New <T>(Device device, int width, int height, PixelFormat format, T[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) where T : struct { Texture2D texture = null; Utilities.Pin(textureData, ptr => { texture = New(device, width, height, 1, format, new[] { GetDataBox(format, width, height, 1, textureData, ptr) }, flags, 1, usage); }); return(texture); }
protected static Texture2DDescription NewRenderTargetDescription(int size, PixelFormat format, TextureFlags flags, int mipCount) { var desc = Texture2DBase.NewDescription(size, size, format, flags, mipCount, 6, ResourceUsage.Default); desc.OptionFlags = ResourceOptionFlags.TextureCube; return desc; }
/// <summary> /// Creates a new <see cref="Texture2D" />. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</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="textureData">Texture data through an array of <see cref="DataBox"/> </param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</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 <see cref="Texture2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static Texture2D New(Device device, int width, int height, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags flags = TextureFlags.ShaderResource, int arraySize = 1, ResourceUsage usage = ResourceUsage.Default) { return(new Texture2D(device, NewDescription(width, height, format, flags, mipCount, arraySize, usage), textureData)); }