private async void HandleWindowSize() { var currentSize = ImGui.GetWindowContentRegionMax() - ImGui.GetWindowContentRegionMin(); if (currentSize == size || resizing) { return; } // If there isn't a size yet, we haven't rendered at all - boot up an inlay in the render process // TODO: Edge case - if a user _somehow_ makes the size zero, this will freak out and generate a new render inlay // TODO: Maybe consolidate the request types? dunno. var request = size == Vector2.Zero ? new NewInlayRequest() { Guid = RenderGuid, FrameTransportMode = config.FrameTransportMode, Url = inlayConfig.Url, Width = (int)currentSize.X, Height = (int)currentSize.Y, } : new ResizeInlayRequest() { Guid = RenderGuid, Width = (int)currentSize.X, Height = (int)currentSize.Y, } as DownstreamIpcRequest; resizing = true; var response = await renderProcess.Send <FrameTransportResponse>(request); if (!response.Success) { PluginLog.LogError("Texture build failure, retrying..."); resizing = false; return; } size = currentSize; resizing = false; var oldTextureHandler = textureHandler; try { textureHandler = response.Data switch { TextureHandleResponse textureHandleResponse => new SharedTextureHandler(textureHandleResponse), BitmapBufferResponse bitmapBufferResponse => new BitmapBufferTextureHandler(bitmapBufferResponse), _ => throw new Exception($"Unhandled frame transport {response.GetType().Name}"), }; } catch (Exception e) { textureRenderException = e; } if (oldTextureHandler != null) { oldTextureHandler.Dispose(); } }
public SharedTextureHandler(TextureHandleResponse response) { var texture = DxHandler.Device.OpenSharedResource <D3D11.Texture2D>(response.TextureHandle); var view = new D3D11.ShaderResourceView(DxHandler.Device, texture, new D3D11.ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = D3D.ShaderResourceViewDimension.Texture2D, Texture2D = { MipLevels = texture.Description.MipLevels }, }); textureWrap = new D3DTextureWrap(view, texture.Description.Width, texture.Description.Height); }