/// <summary> /// Initializes a new instance of the <see cref="TypelessTexture2D"/> class. /// </summary> /// <param name="usage">The usage.</param> /// <param name="textureUsage">The texture usage.</param> /// <param name="fmt">The FMT.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="dp">The dp.</param> public TypelessTexture2D(GraphicsDevice device, Usage usage, TextureUsage textureUsage, CPUAccess cpuAccess, PixelFormat fmt, uint width, uint height, uint mipmaps, uint sampleCount, uint sampleQuality, GraphicsLocality locality, byte[][] data) : base(usage, textureUsage, cpuAccess, locality) { Validate(mipmaps, width, height); this.width = width; this.height = height; this.format = fmt; this.mipmapCount = mipmaps == 0 ? Images.MipmapHelper.MipmapCount(width, height) : mipmaps; // We create driver part. if (locality != GraphicsLocality.SystemMemoryOnly) { this.device = device; this.driverPart = device.DriverDevice.CreateTexture2D(usage, fmt.CommonFormatLayout, CPUAccess, width, height, mipmaps, textureUsage, sampleCount, sampleQuality, data); } // We may need to create sw part. if (locality == GraphicsLocality.DeviceAndSystemMemory || locality == GraphicsLocality.SystemMemoryOnly) { this.swData = data; } }
/// <summary> /// Creates a graphics buffer directly on hardware, with set usage, /// format (e.g. is typed) and element count. /// </summary> /// <param name="device"></param> /// <param name="format"></param> /// <param name="elementCount"></param> public TypelessBuffer([NotNull] GraphicsDevice device, Usage usage, BufferUsage bufferUsage, CPUAccess access, GraphicsLocality locality, byte[] data) : this(usage, bufferUsage, access, locality, 0) { this.swData = data.Clone() as byte[]; BindToDevice(device); }
/// <summary> /// Initializes a new instance of the <see cref="Texture"/> class. /// </summary> /// <param name="usage">The usage.</param> /// <param name="texUsage">The texture usage.</param> public TypelessTexture(Usage usage, TextureUsage texUsage, CPUAccess cpuAccess, GraphicsLocality locality) { this.usage = usage; textureUsage = texUsage; this.locality = locality; this.cpuAccess = cpuAccess; }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsBuffer"/> class. /// </summary> /// <param name="usage">The usage.</param> /// <param name="bufferUsage">The buffer usage.</param> /// <param name="access">The access.</param> /// <param name="locality">The locality.</param> /// <param name="format">The format.</param> /// <param name="elementCount">The element count.</param> public TypelessBuffer(Usage usage, BufferUsage bufferUsage, CPUAccess access, GraphicsLocality locality, ulong byteSize) { this.usage = usage; this.bufferUsage = bufferUsage; this.cpuAccess = access; this.locality = locality; this.byteSize = byteSize; this.swData = new byte[byteSize]; }
/// <summary> /// A helper to create a vertex buffer. /// </summary> /// <returns></returns> public static VertexBufferView Create(GraphicsDevice device, VertexFormat format, Usage usage, CPUAccess access, GraphicsLocality locality, ulong elementCount) { TypelessBuffer buffer = new TypelessBuffer(usage, BufferUsage.VertexBuffer, access, locality, format.ByteSize * elementCount); buffer.DisposeOnViewDispose = true; return(buffer.CreateVertexBuffer(format)); }
/// <summary> /// Creates a constant buffer layout. /// </summary> /// <returns></returns> public static ConstantBufferView Create(GraphicsDevice device, Usage usage, CPUAccess access, GraphicsLocality locality, ConstantBufferLayout layout) { TypelessBuffer buffer = new TypelessBuffer(device, usage, BufferUsage.ConstantBuffer, access, locality, layout.MinimumBufferSizeInBytes); buffer.DisposeOnViewDispose = true; return(buffer.CreateConstantBuffer(layout)); }
public override IntPtr Lock(CPUAccess cpuAccess = CPUAccess.Read) { lock (buffer) { if (IsLocked) { return(pter); } handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); pter = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); IsLocked = true; } return(pter); }
/// <summary> /// Initializes a new instance of the <see cref="Texture2D"/> class. /// </summary> /// <param name="usage">The usage.</param> /// <param name="textureUsage">The texture usage.</param> /// <param name="fmt">The FMT.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="mipmaps">The number of mipmaps.</param> /// <param name="locality">The locality.</param> /// <param name="data">The data.</param> public TypelessTexture2D(Usage usage, TextureUsage textureUsage, CPUAccess cpuAccess, PixelFormat fmt, uint width, uint height, uint mipmaps, GraphicsLocality locality, byte[][] data) : base(usage, textureUsage, cpuAccess, locality) { // Mipmaps first. Validate(mipmaps, width, height); this.mipmapCount = mipmaps == 0 ? Images.MipmapHelper.MipmapCount(width, height) : mipmaps; // We copy data if it exists, otherwise we dont do it. if (data != null) { if (data.Length != mipmapCount) { throw new ArgumentException("Data is not provided for all mipmaps."); } swData = new byte[mipmapCount][]; for (uint i = 0; i < mipmapCount; i++) { if (data[i].Length != fmt.Size * width * height) { throw new ArgumentOutOfRangeException( "Byte size is not the same as texture size for mipmap " + i.ToString()); } // We copy the data now. swData[i] = data[i]; } } else { swData = new byte[mipmapCount][]; for (uint i = 0; i < mipmapCount; i++) { uint w, h; Images.MipmapHelper.ComputeDimensions(width, height, i, out w, out h); swData[i] = new byte[w * h * fmt.Size]; } } // And we copy all data. this.width = width; this.height = height; this.format = fmt; }
/// <summary> /// Creates and fills vertex buffer. /// </summary> /// <returns></returns> public static VertexBufferView Create <T>(GraphicsDevice device, VertexFormat format, Usage usage, CPUAccess access, GraphicsLocality locality, params T[] elements) where T : struct { VertexBufferView buffer = Create(device, format, usage, access, locality, (ulong)elements.LongLength); try { buffer.SetData <T>(elements); } catch (Exception) { buffer.Dispose(); throw; } return(buffer); }
/// <summary> /// Creates a graphics buffer directly on hardware, with set usage, /// format (e.g. is typed) and element count. /// </summary> /// <param name="device"></param> /// <param name="format"></param> /// <param name="elementCount"></param> public TypelessBuffer([NotNull] GraphicsDevice device, Usage usage, BufferUsage bufferUsage, CPUAccess access, GraphicsLocality locality, ulong byteSize) : this(usage, bufferUsage, access, locality, byteSize) { BindToDevice(device); }
public abstract IntPtr Lock(CPUAccess cpuAccess = CPUAccess.Read);
public ComputeBuffer(CPUAccess cpuAccess, GPUAccess gpuAccess, int lenght) { this.cpuAccess = cpuAccess; this.gpuAccess = gpuAccess; this.lenght = lenght; }
private CpuBuffer(CPUAccess cPUAccess, GPUAccess gPUAccess, int lenght) : base(CPUAccess.ReadWrite, GPUAccess.None, lenght) { }