public void Init( string name, int width, int height, Format resourceFormat, Format srvFormat, BindFlags bindFlags, int samplesCount, int samplesQuality, ResourceOptionFlags roFlags, ResourceUsage ru, int mipmapLevels, CpuAccessFlags cpuAccessFlags) { m_name = name; m_size = new Vector2I(width, height); m_resourceFormat = resourceFormat; m_srvFormat = srvFormat; m_bindFlags = bindFlags; m_samplesCount = samplesCount; m_samplesQuality = samplesQuality; m_roFlags = roFlags; m_resourceUsage = ru; m_mipmapLevels = mipmapLevels; m_cpuAccessFlags = cpuAccessFlags; }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <param name="usage">The usage.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="cpuAccessFlags">The CPU access flags.</param> /// <param name="optionFlags">The option flags.</param> public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags) { SizeInBytes = sizeInBytes; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <param name="usage">The usage.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="cpuAccessFlags">The cpu access flags.</param> /// <param name="optionFlags">The option flags.</param> /// <param name="structureByteStride">The structure byte stride.</param> public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags, int structureByteStride) { SizeInBytes = sizeInBytes; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; StructureByteStride = structureByteStride; }
/// <summary> /// Gets the CPU access flags from the <see cref="ResourceUsage"/>. /// </summary> /// <param name="usage">The usage.</param> /// <returns>The CPU access flags</returns> protected static CpuAccessFlags GetCpuAccessFlagsFromUsage(ResourceUsage usage) { switch (usage) { case ResourceUsage.Dynamic: return CpuAccessFlags.Write; case ResourceUsage.Staging: return CpuAccessFlags.Read | CpuAccessFlags.Write; } return CpuAccessFlags.None; }
public IRtvTexture CreateRtv(string debugName, int width, int height, Format format, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags optionFlags = 0, ResourceUsage resourceUsage = ResourceUsage.Default, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MyRtvTexture tex; m_rtvTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, format, format, BindFlags.RenderTarget | BindFlags.ShaderResource, samplesCount, samplesQuality, optionFlags, resourceUsage, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) tex.OnDeviceInit(); return tex; }
public TextureCreationParameters(int width, int height, int depth, int mipLevels, SurfaceFormat format, ResourceUsage resourceUsage, ResourceManagementMode resourceManagementMode, Color colorKey, FilterOptions filter, FilterOptions mipFilter) { m_Width = width; m_Height = height; m_Depth = depth; m_MipLevels = mipLevels; m_Format = format; m_ResourceUsage = resourceUsage; m_ResourceManagementMode = resourceManagementMode; m_ColorKey = colorKey; m_Filter = filter; m_MipFilter = mipFilter; }
private static BufferDescription NewDescription(int bufferSize, int elementSize, BufferFlags bufferFlags, ResourceUsage usage) { var desc = new BufferDescription() { SizeInBytes = bufferSize, StructureByteStride = elementSize, // We keep the element size in the structure byte stride, even if it is not a structured buffer CpuAccessFlags = GetCputAccessFlagsFromUsage(usage), BindFlags = BindFlags.None, OptionFlags = ResourceOptionFlags.None, Usage = usage, }; if ((bufferFlags & BufferFlags.ConstantBuffer) != 0) desc.BindFlags |= BindFlags.ConstantBuffer; if ((bufferFlags & BufferFlags.IndexBuffer) != 0) desc.BindFlags |= BindFlags.IndexBuffer; if ((bufferFlags & BufferFlags.VertexBuffer) != 0) desc.BindFlags |= BindFlags.VertexBuffer; if ((bufferFlags & BufferFlags.RenderTarget) != 0) desc.BindFlags |= BindFlags.RenderTarget; if ((bufferFlags & BufferFlags.ShaderResource) != 0) desc.BindFlags |= BindFlags.ShaderResource; if ((bufferFlags & BufferFlags.UnorderedAccess) != 0) desc.BindFlags |= BindFlags.UnorderedAccess; if ((bufferFlags & BufferFlags.StreamOutput) != 0) desc.BindFlags |= BindFlags.StreamOutput; if ((bufferFlags & BufferFlags.StructuredBuffer) != 0) { desc.OptionFlags |= ResourceOptionFlags.BufferStructured; if (elementSize == 0) throw new ArgumentException("Element size cannot be set to 0 for structured buffer"); } if ((bufferFlags & BufferFlags.RawBuffer) == BufferFlags.RawBuffer) desc.OptionFlags |= ResourceOptionFlags.BufferAllowRawViews; if ((bufferFlags & BufferFlags.ArgumentBuffer) == BufferFlags.ArgumentBuffer) desc.OptionFlags |= ResourceOptionFlags.DrawIndirectArguments; return desc; }
/// <summary> /// Loads a 3D texture from a stream. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</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 3D</exception> /// <returns>A texture</returns> public static new Texture3D Load(GraphicsDevice 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)); }
private static IEnumerable<XElement> WithReducer(IEnumerable<XElement> elements, XName resourceName, ResourceUsage usage) { return elements.GetCurrentJDFResourceLinkPoolResolvedItemForUsage(usage).Where(item => { var ns = resourceName.NamespaceName; if (string.IsNullOrWhiteSpace(ns)) { ns = Globals.JdfNamespace.NamespaceName; } return item.Name != null && item.Name.LocalName == resourceName.LocalName && item.Name.NamespaceName == ns; }); }
/// <summary> /// Creates a new <see cref="Texture3D" /> with texture data for the firs map. /// </summary> /// <typeparam name="T">Type of the data to upload to the texture</typeparam> /// <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="textureData">The texture data, width * height * depth data </param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <returns>A new instance of <see cref="Texture3D" /> class.</returns> /// <remarks> /// The first dimension of mipMapTextures describes the number of is an array ot Texture3D Array /// </remarks> /// <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 unsafe static Texture3D New <T>(GraphicsDevice device, int width, int height, int depth, PixelFormat format, T[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) where T : struct { return(New(device, width, height, depth, 1, format, new[] { GetDataBox(format, width, height, depth, textureData, (IntPtr)Interop.Fixed(textureData)) }, flags, usage)); }
/// <summary> /// Creates a new <see cref="Texture3D" /> directly from an <see cref="Image"/>. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="image">An image in CPU memory.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="usage">The usage.</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, Image image, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { if (image == null) { throw new ArgumentNullException("image"); } if (image.Description.Dimension != TextureDimension.Texture3D) { throw new ArgumentException("Invalid image. Must be 3D", "image"); } return(new Texture3D(device, CreateTextureDescriptionFromImage(image, flags, usage), image.ToDataBox())); }
public static ICollection<string> EnumerateResources(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType) { NetResource pRsrc = new NetResource(); return EnumerateResources(pRsrc, scope, type, usage, displayType); }
public ConstantBufferProxy(int structSize, BindFlags bindFlags = BindFlags.ConstantBuffer, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, ResourceUsage usage = ResourceUsage.Default) : base(structSize) { bufferDesc = new BufferDescription() { SizeInBytes = structSize, BindFlags = bindFlags, CpuAccessFlags = cpuAccessFlags, OptionFlags = optionFlags, Usage = usage, StructureByteStride = 0 }; }
/// <summary> /// Sets the <see cref="ResourceUsage"/> to use when creating the <see cref="Buffer{TElement}"/>. /// See the <see cref="SupportedUsagesAttribute"/> on <see cref="Buffer{TElement}"/> for a list of permitted usages. /// </summary> /// <param name="usage">The usage to use/set.</param> /// <returns>An identical BufferBuilder with the specified <paramref name="usage"/> parameter.</returns> public override BufferBuilder <TElement> WithUsage(ResourceUsage usage) { return(new BufferBuilder <TElement>(usage, length, permittedBindings, InitialData)); }
public static Texture2D CreateDepth( Vector2i size, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags ) { return CreateDepth( size.x, size.y, usage, bindFlags, cpuAccessFlags ); }
/// <summary> /// Creates a new <see cref="TextureCube" /> from a initial data.. /// </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="usage">The usage.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="textureData">an array of 6 textures. See remarks</param> /// <returns>A new instance of <see cref="TextureCube" /> 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> /// The first dimension of mipMapTextures describes the number of array (TextureCube Array), the second is the texture data for a particular cube face. /// </remarks> public static TextureCube New(GraphicsDevice device, int size, PixelFormat format, DataBox[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { if (textureData.Length != 6) { throw new ArgumentException("Invalid texture data. First dimension must be equal to 6", "textureData"); } return(new TextureCube(device, NewTextureCubeDescription(size, format, flags | TextureFlags.ShaderResource, 1, usage), textureData)); }
protected static Texture2DDescription NewTextureCubeDescription(int size, PixelFormat format, TextureFlags flags, int mipCount, ResourceUsage usage) { var desc = NewDescription(size, size, format, flags, mipCount, 6, usage); desc.OptionFlags = ResourceOptionFlags.TextureCube; return(desc); }
/// <summary> /// Creates a new <see cref="TextureCube" /> from a initial data.. /// </summary> /// <typeparam name="T">Type of a pixel data</typeparam> /// <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="usage">The usage.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="textureData">an array of 6 textures. See remarks</param> /// <returns>A new instance of <see cref="TextureCube" /> 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> /// The first dimension of mipMapTextures describes the number of array (TextureCube Array), the second is the texture data for a particular cube face. /// </remarks> public unsafe static TextureCube New <T>(GraphicsDevice device, int size, PixelFormat format, T[][] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) where T : struct { if (textureData.Length != 6) { throw new ArgumentException("Invalid texture data. First dimension must be equal to 6", "textureData"); } var dataBox1 = GetDataBox(format, size, size, 1, textureData[0], (IntPtr)Interop.Fixed(textureData[0])); var dataBox2 = GetDataBox(format, size, size, 1, textureData[0], (IntPtr)Interop.Fixed(textureData[1])); var dataBox3 = GetDataBox(format, size, size, 1, textureData[0], (IntPtr)Interop.Fixed(textureData[2])); var dataBox4 = GetDataBox(format, size, size, 1, textureData[0], (IntPtr)Interop.Fixed(textureData[3])); var dataBox5 = GetDataBox(format, size, size, 1, textureData[0], (IntPtr)Interop.Fixed(textureData[4])); var dataBox6 = GetDataBox(format, size, size, 1, textureData[0], (IntPtr)Interop.Fixed(textureData[5])); return(new TextureCube(device, NewTextureCubeDescription(size, format, flags | TextureFlags.ShaderResource, 1, usage), dataBox1, dataBox2, dataBox3, dataBox4, dataBox5, dataBox6)); }
/// <summary> /// Creates a new <see cref="TextureCube"/>. /// </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="usage">The usage.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</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 TextureCube New(GraphicsDevice device, int size, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default) { return(new TextureCube(device, NewTextureCubeDescription(size, format, flags | TextureFlags.ShaderResource, mipCount, usage))); }
/// <summary> /// Creates a new <see cref="TextureCube"/>. /// </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="usage">The usage.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</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 TextureCube New(GraphicsDevice device, int size, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default) { return(New(device, size, false, format, flags, usage)); }
private List<NETRESOURCE> GetChildNetResources( ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NETRESOURCE NetResource ) { WinError error = WinError.NO_ERROR; IntPtr handle = new IntPtr(); List<NETRESOURCE> nrList = new List<NETRESOURCE>(); error = FileClient.FileClient.BeginEnumNetResources(dwScope, dwType, dwUsage, NetResource, out handle); if (error == WinError.NO_ERROR) { error = FileClient.FileClient.EnumNetResources(handle, out nrList); FileClient.FileClient.EndEnumNetResources(handle); } return nrList; }
public static string Str(this ResourceUsage usage, GraphicsAPI apitype) { if (apitype.IsD3D()) { switch (usage) { case ResourceUsage.VertexBuffer: return("Vertex Buffer"); case ResourceUsage.IndexBuffer: return("Index Buffer"); case ResourceUsage.VS_Constants: return("VS - Constant Buffer"); case ResourceUsage.GS_Constants: return("GS - Constant Buffer"); case ResourceUsage.HS_Constants: return("HS - Constant Buffer"); case ResourceUsage.DS_Constants: return("DS - Constant Buffer"); case ResourceUsage.CS_Constants: return("CS - Constant Buffer"); case ResourceUsage.PS_Constants: return("PS - Constant Buffer"); case ResourceUsage.All_Constants: return("All - Constant Buffer"); case ResourceUsage.SO: return("Stream Out"); case ResourceUsage.VS_Resource: return("VS - Resource"); case ResourceUsage.GS_Resource: return("GS - Resource"); case ResourceUsage.HS_Resource: return("HS - Resource"); case ResourceUsage.DS_Resource: return("DS - Resource"); case ResourceUsage.CS_Resource: return("CS - Resource"); case ResourceUsage.PS_Resource: return("PS - Resource"); case ResourceUsage.All_Resource: return("All - Resource"); case ResourceUsage.VS_RWResource: return("VS - UAV"); case ResourceUsage.HS_RWResource: return("HS - UAV"); case ResourceUsage.DS_RWResource: return("DS - UAV"); case ResourceUsage.GS_RWResource: return("GS - UAV"); case ResourceUsage.PS_RWResource: return("PS - UAV"); case ResourceUsage.CS_RWResource: return("CS - UAV"); case ResourceUsage.All_RWResource: return("All - UAV"); case ResourceUsage.InputTarget: return("Colour Input"); case ResourceUsage.ColourTarget: return("Rendertarget"); case ResourceUsage.DepthStencilTarget: return("Depthstencil"); case ResourceUsage.Indirect: return("Indirect argument"); case ResourceUsage.Clear: return("Clear"); case ResourceUsage.GenMips: return("Generate Mips"); case ResourceUsage.Resolve: return("Resolve"); case ResourceUsage.ResolveSrc: return("Resolve - Source"); case ResourceUsage.ResolveDst: return("Resolve - Dest"); case ResourceUsage.Copy: return("Copy"); case ResourceUsage.CopySrc: return("Copy - Source"); case ResourceUsage.CopyDst: return("Copy - Dest"); case ResourceUsage.Barrier: return("Barrier"); } } else if (apitype == GraphicsAPI.OpenGL || apitype == GraphicsAPI.Vulkan) { bool vk = (apitype == GraphicsAPI.Vulkan); switch (usage) { case ResourceUsage.VertexBuffer: return("Vertex Buffer"); case ResourceUsage.IndexBuffer: return("Index Buffer"); case ResourceUsage.VS_Constants: return("VS - Uniform Buffer"); case ResourceUsage.GS_Constants: return("GS - Uniform Buffer"); case ResourceUsage.HS_Constants: return("HS - Uniform Buffer"); case ResourceUsage.DS_Constants: return("DS - Uniform Buffer"); case ResourceUsage.CS_Constants: return("CS - Uniform Buffer"); case ResourceUsage.PS_Constants: return("PS - Uniform Buffer"); case ResourceUsage.All_Constants: return("All - Uniform Buffer"); case ResourceUsage.SO: return("Transform Feedback"); case ResourceUsage.VS_Resource: return("VS - Texture"); case ResourceUsage.GS_Resource: return("GS - Texture"); case ResourceUsage.HS_Resource: return("HS - Texture"); case ResourceUsage.DS_Resource: return("DS - Texture"); case ResourceUsage.CS_Resource: return("CS - Texture"); case ResourceUsage.PS_Resource: return("PS - Texture"); case ResourceUsage.All_Resource: return("All - Texture"); case ResourceUsage.VS_RWResource: return("VS - Image/SSBO"); case ResourceUsage.HS_RWResource: return("HS - Image/SSBO"); case ResourceUsage.DS_RWResource: return("DS - Image/SSBO"); case ResourceUsage.GS_RWResource: return("GS - Image/SSBO"); case ResourceUsage.PS_RWResource: return("PS - Image/SSBO"); case ResourceUsage.CS_RWResource: return("CS - Image/SSBO"); case ResourceUsage.All_RWResource: return("All - Image/SSBO"); case ResourceUsage.InputTarget: return("FBO Input"); case ResourceUsage.ColourTarget: return("FBO Colour"); case ResourceUsage.DepthStencilTarget: return("FBO Depthstencil"); case ResourceUsage.Indirect: return("Indirect argument"); case ResourceUsage.Clear: return("Clear"); case ResourceUsage.GenMips: return("Generate Mips"); case ResourceUsage.Resolve: return(vk ? "Resolve" : "Framebuffer blit"); case ResourceUsage.ResolveSrc: return(vk ? "Resolve - Source" : "Framebuffer blit - Source"); case ResourceUsage.ResolveDst: return(vk ? "Resolve - Dest" : "Framebuffer blit - Dest"); case ResourceUsage.Copy: return("Copy"); case ResourceUsage.CopySrc: return("Copy - Source"); case ResourceUsage.CopyDst: return("Copy - Dest"); case ResourceUsage.Barrier: return("Barrier"); } } return("Unknown Usage String"); }
public static Texture2D CreateFloat4( int width, int height, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags ) { return CreateTexture( width, height, 1, 1, Format.R32G32B32A32_Float, usage, bindFlags, cpuAccessFlags ); }
private static extern ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NetResource p, out IntPtr lphEnum);
// HACK: figure out a good way...maybe the D3D way really is the right way private static Texture2D CreateTexture( int width, int height, int arraySize, int mipLevels, Format format, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags ) { var wrapper = D3D10Wrapper.Instance; var desc = new Texture2DDescription { Width = width, Height = height, MipLevels = mipLevels, ArraySize = arraySize, Format = format, SampleDescription = new SampleDescription( 1, 0 ), Usage = usage, BindFlags = bindFlags, CpuAccessFlags = cpuAccessFlags, OptionFlags = ResourceOptionFlags.None }; if( mipLevels != 1 ) { desc.OptionFlags = ResourceOptionFlags.GenerateMipMaps; } return new Texture2D( wrapper.Device, desc ); }
public ServerEnum(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType, string kPath) { NETRESOURCE netRoot = new NETRESOURCE(); EnumerateServers(netRoot, scope, type, usage, displayType, kPath); }
public D3D11Texture(Device device, ref TextureDescription description) { _device = device; Width = description.Width; Height = description.Height; Depth = description.Depth; MipLevels = description.MipLevels; ArrayLayers = description.ArrayLayers; Format = description.Format; Usage = description.Usage; Type = description.Type; SampleCount = description.SampleCount; DxgiFormat = D3D11Formats.ToDxgiFormat( description.Format, (description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil); CpuAccessFlags cpuFlags = CpuAccessFlags.None; ResourceUsage resourceUsage = ResourceUsage.Default; BindFlags bindFlags = BindFlags.None; ResourceOptionFlags optionFlags = ResourceOptionFlags.None; if ((description.Usage & TextureUsage.RenderTarget) == TextureUsage.RenderTarget) { bindFlags |= BindFlags.RenderTarget; } if ((description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil) { bindFlags |= BindFlags.DepthStencil; } if ((description.Usage & TextureUsage.Sampled) == TextureUsage.Sampled) { bindFlags |= BindFlags.ShaderResource; } if ((description.Usage & TextureUsage.Storage) == TextureUsage.Storage) { bindFlags |= BindFlags.UnorderedAccess; } if ((description.Usage & TextureUsage.Staging) == TextureUsage.Staging) { cpuFlags = CpuAccessFlags.Read | CpuAccessFlags.Write; resourceUsage = ResourceUsage.Staging; } if ((description.Usage & TextureUsage.GenerateMipmaps) != 0) { bindFlags |= BindFlags.RenderTarget | BindFlags.ShaderResource; optionFlags |= ResourceOptionFlags.GenerateMipMaps; } int arraySize = (int)description.ArrayLayers; if ((description.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap) { optionFlags = ResourceOptionFlags.TextureCube; arraySize *= 6; } int roundedWidth = (int)description.Width; int roundedHeight = (int)description.Height; if (FormatHelpers.IsCompressedFormat(description.Format)) { roundedWidth = ((roundedWidth + 3) / 4) * 4; roundedHeight = ((roundedHeight + 3) / 4) * 4; } if (Type == TextureType.Texture1D) { Texture1DDescription desc1D = new Texture1DDescription() { Width = roundedWidth, MipLevels = (int)description.MipLevels, ArraySize = arraySize, Format = DxgiFormat, BindFlags = bindFlags, CpuAccessFlags = cpuFlags, Usage = resourceUsage, OptionFlags = optionFlags, }; DeviceTexture = new Texture1D(device, desc1D); } else if (Type == TextureType.Texture2D) { Texture2DDescription deviceDescription = new Texture2DDescription() { Width = roundedWidth, Height = roundedHeight, MipLevels = (int)description.MipLevels, ArraySize = arraySize, Format = DxgiFormat, BindFlags = bindFlags, CpuAccessFlags = cpuFlags, Usage = resourceUsage, SampleDescription = new SharpDX.DXGI.SampleDescription((int)FormatHelpers.GetSampleCountUInt32(SampleCount), 0), OptionFlags = optionFlags, }; DeviceTexture = new Texture2D(device, deviceDescription); } else { Debug.Assert(Type == TextureType.Texture3D); Texture3DDescription desc3D = new Texture3DDescription() { Width = roundedWidth, Height = roundedHeight, Depth = (int)description.Depth, MipLevels = (int)description.MipLevels, Format = DxgiFormat, BindFlags = bindFlags, CpuAccessFlags = cpuFlags, Usage = resourceUsage, OptionFlags = optionFlags, }; DeviceTexture = new Texture3D(device, desc3D); } }
/// <summary> /// Creates a new instance of the <see cref="T:SharpDX.Direct3D10.Buffer"/> class. /// </summary> /// <typeparam name="T">Type of the data to upload</typeparam> /// <param name="device">The device with which to associate the buffer.</param> /// <param name="bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param> /// <param name="data">Initial data used to initialize the buffer.</param> /// <param name="sizeInBytes">The size, in bytes, of the buffer. If 0 is specified, sizeof(T) is used.</param> /// <param name="usage">The usage pattern for the buffer.</param> /// <param name="accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param> /// <param name="optionFlags">Miscellaneous resource options.</param> /// <param name="structureByteStride">The size (in bytes) of the structure element for structured buffers.</param> /// <returns>An initialized buffer</returns> public static Buffer Create <T>(Device device, BindFlags bindFlags, T[] data, int sizeInBytes = 0, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) where T : struct { var buffer = new Buffer(IntPtr.Zero); var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes == 0 ? Utilities.SizeOf <T>() * data.Length : sizeInBytes, Usage = usage, }; unsafe { device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(data)), buffer); } return(buffer); }
public ServerEnum(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType, string kPath) { var netRoot = new NetResource(); EnumerateServers(netRoot, scope, type, usage, displayType, kPath); }
/// <summary> /// Creates a new instance of <see cref="IndexBufferImplementation"/>. /// </summary> /// <param name="indexFormat">The index format.</param> /// <param name="indexCount">The number of indices the buffer will contain.</param> /// <param name="usage">The resource usage specifying the type of memory the buffer should use.</param> protected IndexBufferImplementation(IndexFormat indexFormat, int indexCount, ResourceUsage usage) { _format = indexFormat; _indexCount = indexCount; _bufferUsage = usage; }
/// <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))); }
private static ICollection<string> EnumerateResources(NetResource pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType) { List<string> result = new List<string>(); uint bufferSize = 16384; IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize); try { IntPtr handle; uint cEntries = 1; ErrorCodes res = WNetOpenEnum(scope, type, usage, pRsrc, out handle); if (res == ErrorCodes.NoError) try { do { res = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize); if (res == ErrorCodes.NoError) { Marshal.PtrToStructure(buffer, pRsrc); if (pRsrc.dwDisplayType == displayType) result.Add(pRsrc.lpRemoteName); if ((pRsrc.dwUsage & ResourceUsage.Container) == ResourceUsage.Container) result.AddRange(EnumerateResources(pRsrc, scope, type, usage, displayType)); } else if (res != ErrorCodes.ErrorNoMoreItems) break; } while (res != ErrorCodes.ErrorNoMoreItems); } finally { WNetCloseEnum(handle); } } finally { Marshal.FreeHGlobal(buffer); } return result; }
/// <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 Texture2D CreateTexture2D(Device device, int width, int height, int mipLevels, int arraySize, Format format, int sampleCount, int sampleQuality, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags miscFlags) { Texture2DDescription td = new Texture2DDescription(); td.Width = width; td.Height = height; td.MipLevels = mipLevels; td.ArraySize = arraySize; td.Format = format; td.SampleDescription = new SampleDescription(sampleCount, sampleQuality); td.Usage = usage; td.BindFlags = bindFlags; td.CpuAccessFlags = cpuAccessFlags; td.OptionFlags = miscFlags; Texture2D t = new Texture2D(device, td); return(t); }
/// <summary> /// Loads a 3D texture from a stream. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="stream">The stream 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 3D</exception> /// <returns>A texture</returns> public static new Texture3D Load(GraphicsDevice device, Stream stream, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { var texture = Texture.Load(device, stream, flags, usage); if (!(texture is Texture3D)) { throw new ArgumentException(string.Format("Texture is not type of [Texture3D] but [{0}]", texture.GetType().Name)); } return((Texture3D)texture); }
private static extern ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NetResource p, out IntPtr lphEnum);
/// <summary> /// Sets the <see cref="ResourceUsage"/> to use when creating the <see cref="ConstantBuffer{TConstants}"/>. /// See the <see cref="SupportedUsagesAttribute"/> on <see cref="ConstantBuffer{TConstants}"/> for a list of permitted usages. /// </summary> /// <param name="usage">The usage to use/set.</param> /// <returns>An identical ConstantBufferBuilder with the specified <paramref name="usage"/> parameter.</returns> public override ConstantBufferBuilder <TConstants> WithUsage(ResourceUsage usage) { return(new ConstantBufferBuilder <TConstants>(usage, InitialData)); }
public static ICollection <string> EnumerateResources(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType) { NetResource pRsrc = new NetResource(); return(EnumerateResources(pRsrc, scope, type, usage, displayType)); }
private void AddResourceUsageEntry(uint start, uint end, ResourceUsage usage) { ToolStripItem item = null; if (start == end) item = rightclickMenu.Items.Add("EID " + start + ": " + usage.Str()); else item = rightclickMenu.Items.Add("EID " + start + "-" + end + ": " + usage.Str()); item.Click += new EventHandler(resourceContextItem_Click); item.Tag = end; }
public static extern int WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, [MarshalAs(UnmanagedType.AsAny)][In] Object lpNetResource, out IntPtr lphEnum);
public static Texture2D CreateDepth( int width, int height, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags ) { return CreateTexture( width, height, 1, 1, Format.D24_UNorm_S8_UInt, usage, bindFlags, cpuAccessFlags ); }
/// <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 : unmanaged { 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); }
public static Texture2D CreateUnsignedByte4Array( int width, int height, int arraySize, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags ) { return CreateTexture( width, height, arraySize, 1, Format.R8G8B8A8_UNorm, usage, bindFlags, cpuAccessFlags ); }
/// <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)); }
public static Texture2D CreateUnsignedByte4MipMapped( int width, int height, int mipLevels, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags ) { return CreateTexture( width, height, 1, mipLevels, Format.R8G8B8A8_UNorm, usage, bindFlags, cpuAccessFlags ); }
/// <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> /// Gets all resources with a particular usage associated with a JDF element. /// </summary> /// <param name="jdfElement">The JDF element to search</param> /// <param name="usage">The resorce usage -- input or output</param> /// <param name="resourceRoot">The root element for finding resources - default is the document root</param> /// <returns>An IEnumerable{XElement} containing a list of resources with the correct usage. /// The list will be empty if there are no resources linked with the given usage.</returns> /// <exception cref="PreconditionException">If the given XElement is not a JDf element.</exception> public static IEnumerable<XElement> ResourcesByUsage(this XElement jdfElement, ResourceUsage usage, XElement resourceRoot = null) { ParameterCheck.ParameterRequired(jdfElement, "jdfElement"); jdfElement.ThrowExceptionIfNotJdfElement(); var linkPool = jdfElement.Element(Element.ResourceLinkPool); if (linkPool == null) return new List<XElement>(); var qualifiedLinkIds = (from resourceLink in linkPool.Elements() where resourceLink.Attribute("Usage") != null && resourceLink.Attribute("Usage").Value == usage.ToString() && resourceLink.Attribute("rRef") != null select resourceLink.Attribute("rRef").Value); var resources = (from resource in (resourceRoot ?? linkPool.Document.Root).Descendants() where resource.Attribute("ID") != null && qualifiedLinkIds.Contains(resource.Attribute("ID").Value) select resource); return resources; }
//private void SetPSize(string[] args) //{ // if (args.Length <= 0) { LieroXNA.Instance.LieroConsole.AddLine("USAGE: 'psize [size]'"); return; } // int res; // if (!int.TryParse(args[0], out res)) { LieroXNA.Instance.LieroConsole.AddLine("Size is not a valid integer"); return; } // _particleSize = res; //} protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { ContentManager cm = PrimalDevistation.Instance.CM; GraphicsDevice gd = GraphicsDevice; _renderEffect = cm.Load <Effect>(@"Shaders/PointSpriteRenderVT"); if (_useMRT) { _updateEffect = cm.Load <Effect>(@"Shaders/ParticleUpdateMRT"); } else { _updateEffect = cm.Load <Effect>(@"Shaders/ParticleUpdate"); } _particleTexture = cm.Load <Texture2D>(@"Sprites/particle2x2"); PresentationParameters pp = GraphicsDevice.PresentationParameters; _bbResolveTarget = new ResolveTexture2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, pp.BackBufferFormat); // Create the sprite batch for render to textures _batch = new cSpriteBatch(gd); // Setting up some shader vars that will never change now _renderEffect.Parameters["View"].SetValue(Matrix.Identity); _renderEffect.Parameters["World"].SetValue(Matrix.Identity); _velocities = new RenderTarget2D[2]; _positions = new RenderTarget2D[2]; if (_useHV4) { _positions[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4); _positions[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4); _velocities[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4); _velocities[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4); } else { _positions[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4); _positions[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4); _velocities[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4); _velocities[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4); } gd.SetRenderTarget(0, _positions[0]); gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); gd.SetRenderTarget(0, _positions[1]); gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); gd.SetRenderTarget(0, _velocities[0]); gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); gd.SetRenderTarget(0, _velocities[1]); gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); gd.SetRenderTarget(0, null); if (_useHV4) { HalfVector4[] data = new HalfVector4[_maxParticles]; _positions[0].GetTexture().GetData <HalfVector4>(data); Vector2 s = PrimalDevistation.Instance.Level.Size; #if XBOX for (int i = 0; i < data.Length; i++) { data[i] = new HalfVector4(0, 0, cMath.Rand(0, s.Y / 2), cMath.Rand(0, s.X / 2)); } #else for (int i = 0; i < data.Length; i++) { data[i] = new HalfVector4(cMath.Rand(0, s.X / 2), cMath.Rand(0, s.Y / 2), 0, 0); } #endif _positions[0].GetTexture().SetData <HalfVector4>(data); _positions[1].GetTexture().SetData <HalfVector4>(data); } else { Vector4[] data = new Vector4[_maxParticles]; _positions[0].GetTexture().GetData <Vector4>(data); for (int i = 0; i < data.Length; i++) { data[i] = new Vector4(0, 0, 0, 0); } _positions[0].GetTexture().SetData <Vector4>(data); _positions[1].GetTexture().SetData <Vector4>(data); } _verts = new sVTPointVertex[_maxParticles]; _dec = new VertexDeclaration(gd, sVTPointVertex.Elements); float ratioW = 1f / (_textureWidth - 1); float ratioH = 1f / (_textureHeight - 1); int icounter = 0; for (int i = 0; i < _textureWidth; i++) { for (int j = 0; j < _textureHeight; j++) { _verts[icounter] = new sVTPointVertex(); _verts[icounter].texture = new Vector2(i * ratioW, j * ratioH); _verts[icounter].pointSize = cMath.Rand(1, 3); icounter++; } } // Create a dynamic vertex buffer. ResourceUsage usage = ResourceUsage.Dynamic | ResourceUsage.WriteOnly | ResourceUsage.Points; _vertexBuffer = new VertexBuffer(gd, sVTPointVertex.Size * _maxParticles, usage, ResourceManagementMode.Manual); _vertexBuffer.SetData(_verts); } }
private static ICollection<string> EnumerateResources(NetResource pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType) { List<string> result = new List<string>(); uint bufferSize = 16384; IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize); try { IntPtr handle; uint cEntries = 1; ErrorCodes res = WNetOpenEnum(scope, type, usage, pRsrc, out handle); if (res == ErrorCodes.NoError) try { do { res = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize); if (res == ErrorCodes.NoError) { Marshal.PtrToStructure(buffer, pRsrc); if (pRsrc.dwDisplayType == displayType) result.Add(pRsrc.lpRemoteName); // If the current NetworkResource is a container, we call EnumerateResources recursively. // In some situations, the lpRemoteName in the NetworkResource is null or empty. In this case // we do not call EnumerateResources recursively as this leads to an infinite loop of // recursive calls. For details see Jira MP2-356 if ((pRsrc.dwUsage & ResourceUsage.Container) == ResourceUsage.Container && !String.IsNullOrEmpty(pRsrc.lpRemoteName)) result.AddRange(EnumerateResources(pRsrc, scope, type, usage, displayType)); } else if (res != ErrorCodes.ErrorNoMoreItems) break; } while (res != ErrorCodes.ErrorNoMoreItems); } finally { WNetCloseEnum(handle); } } finally { Marshal.FreeHGlobal(buffer); } return result; }
public void Init( string name, int width, int height, Format resourceFormat, Format srvFormat, Format dsvFormat, BindFlags bindFlags, int samplesCount, int samplesQuality, ResourceOptionFlags roFlags, ResourceUsage ru, int mipmapLevels, CpuAccessFlags cpuAccessFlags) { base.Init(name, width, height, resourceFormat, srvFormat, bindFlags, samplesCount, samplesQuality, roFlags, ru, mipmapLevels, cpuAccessFlags); m_dsvFormat = dsvFormat; }
private static IEnumerable<string> EnumerateServers(NETRESOURCE pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType) { uint bufferSize = 16384; IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize); IntPtr handle = IntPtr.Zero; ErrorCodes result; uint cEntries = 1; result = WNetOpenEnum(scope, type, usage, pRsrc, out handle); if (result == ErrorCodes.NO_ERROR) { do { result = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize); if (result == ErrorCodes.NO_ERROR) { Marshal.PtrToStructure(buffer, pRsrc); if (pRsrc.dwDisplayType == displayType) yield return pRsrc.lpRemoteName; if ((pRsrc.dwUsage & ResourceUsage.RESOURCEUSAGE_CONTAINER) == ResourceUsage.RESOURCEUSAGE_CONTAINER) { foreach( string share in EnumerateServers(pRsrc, scope, type, usage, displayType)) yield return share; } } else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS) break; } while (result != ErrorCodes.ERROR_NO_MORE_ITEMS); WNetCloseEnum(handle); } Marshal.FreeHGlobal((IntPtr)buffer); }
private Buffer ArrayToBuffer(uint[] array, ResourceUsage usage) { var strm = new DataStream(sizeof(uint) * array.Length, true, true); for (int i = 0; i < array.Length; i++) strm.Write(array[i]); strm.Position = 0; return new Buffer(device, strm, new BufferDescription((int)strm.Length, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); }
private void EnumerateServers(NetResource pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType, string kPath) { uint bufferSize = 16384; var buffer = Marshal.AllocHGlobal((int)bufferSize); IntPtr handle; uint cEntries = 1; var serverenum = false; var result = WNetOpenEnum(scope, type, usage, pRsrc, out handle); if (result == ErrorCodes.NO_ERROR) { do { result = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize); if ((result == ErrorCodes.NO_ERROR)) { Marshal.PtrToStructure(buffer, pRsrc); if (kPath == "") { if ((pRsrc.dwDisplayType == displayType) || (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_DOMAIN)) _aData.Add(pRsrc.lpRemoteName + "|" + pRsrc.dwDisplayType); if ((pRsrc.dwUsage & ResourceUsage.RESOURCEUSAGE_CONTAINER) == ResourceUsage.RESOURCEUSAGE_CONTAINER) if ((pRsrc.dwDisplayType == displayType)) EnumerateServers(pRsrc, scope, type, usage, displayType, kPath); } else { if (pRsrc.dwDisplayType == displayType) { _aData.Add(pRsrc.lpRemoteName); EnumerateServers(pRsrc, scope, type, usage, displayType, kPath); serverenum = true; } if (!serverenum) { if (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_SHARE) _aData.Add(pRsrc.lpRemoteName + "-share"); } else serverenum = false; if ((kPath.IndexOf(pRsrc.lpRemoteName) >= 0) || (String.Compare(pRsrc.lpRemoteName, "Microsoft Windows Network") == 0)) EnumerateServers(pRsrc, scope, type, usage, displayType, kPath); } } else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS) break; } while (result != ErrorCodes.ERROR_NO_MORE_ITEMS); WNetCloseEnum(handle); } Marshal.FreeHGlobal(buffer); }
internal static VertexBufferId CreateVertexBuffer(int elements, int stride, BindFlags bind, ResourceUsage usage, IntPtr? data = null, string debugName = null) { bind |= BindFlags.VertexBuffer; BufferDescription desc = new BufferDescription(); desc.BindFlags = bind; desc.SizeInBytes = stride * elements; desc.Usage = usage; desc.CpuAccessFlags = usage == ResourceUsage.Dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None; return CreateVertexBuffer(desc, stride, data, debugName); }
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; }
private void EnumerateServers(NETRESOURCE pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType, string kPath) { uint bufferSize = 16384; IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize); IntPtr handle = IntPtr.Zero; ErrorCodes result; uint cEntries = 1; bool serverenum = false; result = WNetOpenEnum(scope, type, usage, pRsrc, out handle); if (result == ErrorCodes.NO_ERROR) { do { result = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize); if ((result == ErrorCodes.NO_ERROR)) { Marshal.PtrToStructure(buffer, pRsrc); if (String.Compare(kPath, "") == 0) { if ((pRsrc.dwDisplayType == displayType) || (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_DOMAIN)) { aData.Add(pRsrc.lpRemoteName + "|" + pRsrc.dwDisplayType); } if ((pRsrc.dwUsage & ResourceUsage.RESOURCEUSAGE_CONTAINER) == ResourceUsage.RESOURCEUSAGE_CONTAINER) { if ((pRsrc.dwDisplayType == displayType)) { EnumerateServers(pRsrc, scope, type, usage, displayType, kPath); } } } else { if (pRsrc.dwDisplayType == displayType) { aData.Add(pRsrc.lpRemoteName); EnumerateServers(pRsrc, scope, type, usage, displayType, kPath); //return; serverenum = true; } if (!serverenum) { if (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_SHARE) { aData.Add(pRsrc.lpRemoteName + "-share"); } } else { serverenum = false; } if ((kPath.IndexOf(pRsrc.lpRemoteName) >= 0) || (String.Compare(pRsrc.lpRemoteName, "Microsoft Windows Network") == 0)) { EnumerateServers(pRsrc, scope, type, usage, displayType, kPath); //return; } //} } } else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS) { break; } } while (result != ErrorCodes.ERROR_NO_MORE_ITEMS); WNetCloseEnum(handle); } Marshal.FreeHGlobal((IntPtr)buffer); }
private void AddResourceUsageEntry(List<ToolStripItem> items, uint start, uint end, ResourceUsage usage) { ToolStripItem item = null; if (start == end) item = new ToolStripMenuItem("EID " + start + ": " + usage.Str(m_Core.APIProps.pipelineType)); else item = new ToolStripMenuItem("EID " + start + "-" + end + ": " + usage.Str(m_Core.APIProps.pipelineType)); item.Click += new EventHandler(resourceContextItem_Click); item.Tag = end; item.Size = new System.Drawing.Size(180, 22); items.Add(item); }
/// <summary> /// /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> /// <param name="textureFlags"></param> /// <param name="mipCount"></param> /// <param name="arraySize"></param> /// <param name="usage"></param> /// <returns></returns> protected static Texture2DDescription NewDescription(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, ResourceUsage usage) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) { usage = ResourceUsage.Default; } var desc = new Texture2DDescription() { Width = width, Height = height, ArraySize = arraySize, SampleDescription = new DXGI.SampleDescription(1, 0), BindFlags = GetBindFlagsFromTextureFlags(textureFlags), Format = format, MipLevels = CalculateMipMapCount(mipCount, width, height), Usage = usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(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); }
internal static IndexBufferId CreateIndexBuffer(int elements, Format format, BindFlags bind, ResourceUsage usage, IntPtr? data = null, string debugName = null) { bind |= BindFlags.IndexBuffer; Debug.Assert(format == Format.R32_UInt || format == Format.R16_UInt); BufferDescription desc = new BufferDescription(); desc.BindFlags = bind; desc.SizeInBytes = elements * (format == Format.R32_UInt ? 4 : 2); desc.Usage = usage; desc.CpuAccessFlags = usage == ResourceUsage.Dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None; return CreateIndexBuffer(desc, format, data, debugName); }
/// <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)); }