public ISpriteTexture CreateSpriteTexture(int width, int height, byte[] data) { if (width <= 0 || width > 65536) { throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); } if (height <= 0 || height > 65536) { throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); } var desc = new d3d.Texture2DDescription { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = dxgi.Format.B8G8R8A8_UNorm, CpuAccessFlags = d3d.CpuAccessFlags.None, OptionFlags = d3d.ResourceOptionFlags.None, SampleDescription = new dxgi.SampleDescription(1, 0) }; desc.Usage = d3d.ResourceUsage.Immutable; desc.BindFlags = d3d.BindFlags.ShaderResource; var srcDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); var dataSource = new SharpDX.DataRectangle(srcDataPtr, width * sizeof(int)); var texture = new d3d.Texture2D(Device, desc, new[] { dataSource }); var shaderResourceView = new d3d.ShaderResourceView(Device, texture); return(new CSpriteTexture(texture, shaderResourceView)); }
public ISpriteTexture CreateSpriteTexture(int width, int height) { if (width <= 0 || width > 65536) { throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); } if (height <= 0 || height > 65536) { throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); } var desc = new d3d.Texture2DDescription { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = dxgi.Format.B8G8R8A8_UNorm, CpuAccessFlags = d3d.CpuAccessFlags.None, OptionFlags = d3d.ResourceOptionFlags.None, SampleDescription = new dxgi.SampleDescription(1, 0) }; desc.Usage = d3d.ResourceUsage.Default; desc.BindFlags = d3d.BindFlags.ShaderResource | d3d.BindFlags.RenderTarget; var texture = new d3d.Texture2D(Device, desc); var shaderResourceView = new d3d.ShaderResourceView(Device, texture); return(new CSpriteTexture(texture, shaderResourceView)); }
public ISurface CreateSurface(string filename, Color[] filterColors = null) { var bitmap = TextureLoader.LoadBitmap(new wic.ImagingFactory2(), filename); var texture = TextureLoader.CreateTexture2DFromBitmap(Device, bitmap, filterColors); d3d.ShaderResourceView shaderResourceView = new d3d.ShaderResourceView(Device, texture); return(new CSurface(texture, shaderResourceView)); }
public ISurface CreateSurface( int width, int height, PixelFormat pixelFormat, SurfaceType type, DataResource dataResource = null) { if (width <= 0 || width > 65536) { throw new ArgumentOutOfRangeException(nameof(width), "Must be between 1 and 65536"); } if (height <= 0 || height > 65536) { throw new ArgumentOutOfRangeException(nameof(height), "Must be between 1 and 65536"); } var desc = new d3d.Texture2DDescription { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = dxgi.Format.B8G8R8A8_UNorm, CpuAccessFlags = d3d.CpuAccessFlags.None, OptionFlags = d3d.ResourceOptionFlags.None, SampleDescription = new dxgi.SampleDescription(1, 0) }; switch (type) { case SurfaceType.Input: desc.Usage = d3d.ResourceUsage.Immutable; desc.BindFlags = d3d.BindFlags.ShaderResource; break; case SurfaceType.Output: desc.Usage = d3d.ResourceUsage.Default; desc.BindFlags = d3d.BindFlags.ShaderResource | d3d.BindFlags.RenderTarget; break; case SurfaceType.InputOutput: desc.Usage = d3d.ResourceUsage.Default; desc.BindFlags = d3d.BindFlags.ShaderResource | d3d.BindFlags.RenderTarget; break; } d3d.Texture2D texture; if (dataResource != null) { var srcDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(dataResource.Data, 0); var dataSource = new SharpDX.DataRectangle(srcDataPtr, dataResource.Stride); texture = new d3d.Texture2D(Device, desc, new[] { dataSource }); } else { texture = new d3d.Texture2D(Device, desc); } var shaderResourceView = new d3d.ShaderResourceView(Device, texture); return(new CSurface(texture, shaderResourceView)); }
public CSurface(d3d.Texture2D texture, d3d.ShaderResourceView shaderResourceView) { Texture = texture; ShaderResourceView = shaderResourceView; }