public void GridSingleClick(Point mouseLocation) { string pickedTexture; renderer.PickSceneAtScreenLocation((float)mouseLocation.X, (float)mouseLocation.Y, out pickedTexture); ClickedTexture = pickedTexture; renderHost.RequestRender(); }
public async Task ReplaceTextureAsync(string textureName, string newTexturePath) { await Task.Yield(); try { using (var fs = new FileStream(newTexturePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous)) { var buffer = new byte[fs.Length]; await fs.ReadAsync(buffer, 0, buffer.Length); var texture = Resource.FromMemory <Texture2D>(device, buffer); var srv = new ShaderResourceView(device, texture); var newValue = new TextureAndSRV(texture, srv); TextureAndSRV previousTextureAndSrv = null; textures.AddOrUpdate( textureName, add => newValue, (key, existingValue) => { previousTextureAndSrv = existingValue; return(newValue); }); if (previousTextureAndSrv != null) { previousTextureAndSrv.Texture.Dispose(); previousTextureAndSrv.SRV.Dispose(); } } renderHost.RequestRender(); } catch (Exception e) { Console.Error.WriteLine(e); } }