private void LoadHeightMap(System.IO.FileInfo _FileName) { try { tabControlGenerators.Enabled = false; // Dispose of existing resources if (m_imageSourceHeightMap != null) { m_imageSourceHeightMap.Dispose(); } m_imageSourceHeightMap = null; if (m_textureTarget_CPU != null) { m_textureTarget_CPU.Dispose(); } m_textureTarget_CPU = null; if (m_textureTarget0 != null) { m_textureTarget0.Dispose(); } m_textureTarget0 = null; if (m_textureTarget1 != null) { m_textureTarget1.Dispose(); } m_textureTarget1 = null; if (m_textureSourceHeightMap != null) { m_textureSourceHeightMap.Dispose(); } m_textureSourceHeightMap = null; // Load the source image m_SourceFileName = _FileName; m_imageSourceHeightMap = new ImageUtility.ImageFile(_FileName); outputPanelInputHeightMap.Image = m_imageSourceHeightMap; W = m_imageSourceHeightMap.Width; H = m_imageSourceHeightMap.Height; // Build the source texture assuming the image is in linear space float4[] scanline = new float4[W]; PixelsBuffer SourceHeightMap = new PixelsBuffer(W * H * 4); // using ( System.IO.BinaryWriter Wr = SourceHeightMap.OpenStreamWrite() ) // for ( uint Y=0; Y < H; Y++ ) { // m_imageSourceHeightMap.ReadScanline( Y, scanline ); // for ( int X=0; X < W; X++ ) // Wr.Write( scanline[X].x ); // } using (System.IO.BinaryWriter Wr = SourceHeightMap.OpenStreamWrite()) { m_imageSourceHeightMap.ReadPixels((uint X, uint Y, ref float4 _color) => { Wr.Write(_color.x); }); } m_textureSourceHeightMap = new Texture2D(m_device, W, H, 1, 1, ImageUtility.PIXEL_FORMAT.R32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, new PixelsBuffer[] { SourceHeightMap }); // Build the target UAV & staging texture for readback m_textureTarget0 = new Texture2D(m_device, W, H, 1, 1, ImageUtility.PIXEL_FORMAT.R32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, true, null); m_textureTarget1 = new Texture2D(m_device, W, H, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, true, null); m_textureTarget_CPU = new Texture2D(m_device, W, H, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, true, false, null); tabControlGenerators.Enabled = true; buttonGenerate.Focus(); } catch (Exception _e) { MessageBox("An error occurred while opening the image:\n\n", _e); } }