public void Destroy(IPluginIO pin, FeralTic.DX11.DX11RenderContext context, bool force) { for (int i = 0; i < this.FTextureOut.SliceCount; i++) { if (this.FTextureOut[i] != null) { this.FTextureOut[i].Dispose(context); } } }
public void WriteImage(DX11Resource<DX11Texture2D> resource, FeralTic.DX11.DX11RenderContext context, string filename, SlimDX.Direct3D11.ImageFileFormat format) { var saver = GetAvailableSaver(); saver.Save(resource[context], context, filename, format); }
public void Save(DX11Texture2D texture, FeralTic.DX11.DX11RenderContext context, string filename, SlimDX.Direct3D11.ImageFileFormat format) { if (texture == null) { throw (new Exception("No texture")); } CurrentState = State.Saving; if (FBackSurface == null || FBackSurface.Description.Width != texture.Width || FBackSurface.Description.Height != texture.Height || context != FContext) { if (FBackSurface != null) { FBackSurface.Dispose(); } var description = new Texture2DDescription() { Width = texture.Width, Height = texture.Height, Format = texture.Format, MipLevels = 1, Usage = ResourceUsage.Staging, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, SampleDescription = new SampleDescription(1, 0), ArraySize = 1 }; FBackSurface = new Texture2D(context.Device, description); FContext = context; } context.CurrentDeviceContext.CopyResource(texture.Resource, FBackSurface); FFilename = filename; FFormat = format; //FThread = new Thread(ThreadedFunction); //FThread.Name = "Recorder"; //FThread.Start(); ThreadedFunction(); }
public void Update(IPluginIO pin, FeralTic.DX11.DX11RenderContext context) { for (int i = 0; i < this.FTextureOut.SliceCount; i++) { if (!this.FTextureOut[i].Contains(context)) { Bitmap bmp = ComputeQRCode(i); DX11DynamicTexture2D tex = new DX11DynamicTexture2D(context, bmp.Width, bmp.Height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); int pitch = tex.GetRowPitch(); var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat); if (pitch != bmp.Width * 4) { tex.WriteDataPitch(data.Scan0, bmp.Width * bmp.Height * 4); } else { tex.WriteData(data.Scan0, bmp.Width * bmp.Height * 4); } this.FTextureOut[i][context] = tex; } } }
public void Update(IPluginIO pin, FeralTic.DX11.DX11RenderContext context) { foreach (var instance in FInstances) { instance.Update(context); } }
public void Destroy(IPluginIO pin, FeralTic.DX11.DX11RenderContext context, bool force) { foreach(var instance in FInstances) { instance.Destroy(context); } }
public void Process(DX11Resource<DX11Texture2D> input, FeralTic.DX11.DX11RenderContext context) { DX11Texture2D t = input[context]; var height = t.Height; var width = t.Width; var imageLink = Output; var imageAttributes = imageLink.ImageAttributes; var desiredImageFormat = ToOpenCVFormat(t.Format); if (desiredImageFormat == TColorFormat.UnInitialised) throw (new Exception("No suitible image type available for this texture type " + t.Format.ToString())); //-- //check attributes and reinitialise the image and offscreen buffer if we haven't got the right description ready // if (imageAttributes == null || FOffscreenBuffer == null || !imageAttributes.Initialised || FOffscreenBuffer.Description.Format != t.Description.Format || imageAttributes.Width != t.Width || imageAttributes.Height != t.Height || imageAttributes.ColorFormat != desiredImageFormat) { if (FOffscreenBuffer != null) FOffscreenBuffer.Dispose(); var description = new Texture2DDescription() { Width = width, Height = height, Format = t.Format, MipLevels = 1, Usage = ResourceUsage.Staging, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, SampleDescription = new SampleDescription(1, 0), ArraySize = 1 }; FOffscreenBuffer = new Texture2D(context.Device, description); imageLink.Initialise(new CVImageAttributes(desiredImageFormat, t.Width, t.Height)); } // //-- //-- //copy the texture to offscreen buffer // context.CurrentDeviceContext.CopyResource(t.Resource, FOffscreenBuffer); // //-- //-- //copy the data out of the offscreen buffer // var surface = FOffscreenBuffer.AsSurface(); var bytesPerRow = imageAttributes.Stride; var data = MapForRead(context.CurrentDeviceContext); lock (imageLink.BackLock) { var image = imageLink.BackImage; try { var source = data.Data.DataPointer; image.SetPixels(source); var destination = image.Data; for (int row = 0; row < t.Height; row++) { CopyMemory(destination, source, bytesPerRow); source += data.RowPitch; destination += bytesPerRow; } } finally { UnMap(context.CurrentDeviceContext); } } // //-- imageLink.Swap(); }