From d0340217a628c3c10a2a7f6853a3d846c417c557 Mon Sep 17 00:00:00 2001 From: Scali Date: Wed, 22 May 2024 14:00:33 +0200 Subject: [PATCH 01/12] Quick-and-dirty patches to make code work with CEF 124 and the new ID3DDevice1-based shared texture interface for accelerated rendering. --- src/d3d11.cpp | 13 ++++++++----- src/d3d11.h | 10 +++++----- src/main.cpp | 4 +++- src/web_layer.cpp | 31 +++++++++++++++++-------------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/d3d11.cpp b/src/d3d11.cpp index 9700466..ea89fa2 100644 --- a/src/d3d11.cpp +++ b/src/d3d11.cpp @@ -280,7 +280,7 @@ namespace d3d11 { { } - void* Texture2D::share_handle() const + HANDLE Texture2D::share_handle() const { return share_handle_; } @@ -329,7 +329,7 @@ namespace d3d11 { } } - Device::Device(ID3D11Device* pdev, ID3D11DeviceContext* pctx) + Device::Device(ID3D11Device1* pdev, ID3D11DeviceContext* pctx) : device_(to_com_ptr(pdev)) , ctx_(make_shared(pctx)) { @@ -573,10 +573,10 @@ namespace d3d11 { return nullptr; } - shared_ptr Device::open_shared_texture(void* handle) + shared_ptr Device::open_shared_texture(HANDLE handle) { ID3D11Texture2D* tex = nullptr; - auto hr = device_->OpenSharedResource( + auto hr = device_->OpenSharedResource1( handle, __uuidof(ID3D11Texture2D), (void**)(&tex)); if (FAILED(hr)) { return nullptr; @@ -839,6 +839,7 @@ float4 main(VS_OUTPUT input) : SV_Target ID3D11Device* pdev = nullptr; + ID3D11Device1* pdev1 = nullptr; ID3D11DeviceContext* pctx = nullptr; D3D_FEATURE_LEVEL selected_level; @@ -872,7 +873,9 @@ float4 main(VS_OUTPUT input) : SV_Target if (SUCCEEDED(hr)) { - auto const dev = make_shared(pdev, pctx); + pdev->QueryInterface(&pdev1); + + auto const dev = make_shared(pdev1, pctx); log_message("d3d11: selected adapter: %s\n", dev->adapter_name().c_str()); diff --git a/src/d3d11.h b/src/d3d11.h index f48a2ff..0c23b0c 100644 --- a/src/d3d11.h +++ b/src/d3d11.h @@ -50,11 +50,11 @@ namespace d3d11 { class Device { public: - Device(ID3D11Device*, ID3D11DeviceContext*); + Device(ID3D11Device1*, ID3D11DeviceContext*); std::string adapter_name() const; - operator ID3D11Device*() { + operator ID3D11Device1*() { return device_.get(); } @@ -72,7 +72,7 @@ namespace d3d11 { const void* data, size_t row_stride); - std::shared_ptr open_shared_texture(void*); + std::shared_ptr open_shared_texture(HANDLE); std::shared_ptr create_default_effect(); @@ -93,7 +93,7 @@ namespace d3d11 { HMODULE _lib_compiler; - std::shared_ptr const device_; + std::shared_ptr const device_; std::shared_ptr const ctx_; }; @@ -145,7 +145,7 @@ namespace d3d11 { bool lock_key(uint64_t key, uint32_t timeout_ms); void unlock_key(uint64_t key); - void* share_handle() const; + HANDLE share_handle() const; void copy_from(std::shared_ptr const&); diff --git a/src/main.cpp b/src/main.cpp index d4ec2b2..88b5418 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -405,7 +405,9 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) // default to webgl aquarium demo if (url.empty()) { - url = "https://webglsamples.org/aquarium/aquarium.html"; + //url = "https://webglsamples.org/aquarium/aquarium.html"; + //url = "https://webglsamples.org/blob/blob.html"; + url = "https://www.youtube.com/watch?v=7oAjnqu_wxE"; } if (width <= 0) { width = 1280; diff --git a/src/web_layer.cpp b/src/web_layer.cpp index 5503332..03506eb 100644 --- a/src/web_layer.cpp +++ b/src/web_layer.cpp @@ -145,7 +145,7 @@ class MixerHandler : // notify the browser process that we want stats auto message = CefProcessMessage::Create("mixer-request-stats"); if (message != nullptr && browser_ != nullptr) { - browser_->SendProcessMessage(PID_BROWSER, message); + //browser_->SendProcessMessage(PID_BROWSER, message); } return true; } @@ -322,7 +322,7 @@ class FrameBuffer // // called in response to Cef's OnAcceleratedPaint notification // - void on_gpu_paint(void* shared_handle) + void on_gpu_paint(HANDLE shared_handle) { // Note: we're not handling keyed mutexes yet @@ -339,7 +339,7 @@ class FrameBuffer // open the shared texture if (!shared_buffer_) { - shared_buffer_ = device_->open_shared_texture((void*)shared_handle); + shared_buffer_ = device_->open_shared_texture(shared_handle); if (!shared_buffer_) { log_message("could not open shared texture!"); } @@ -485,7 +485,7 @@ class WebView : public CefClient, bool OnProcessMessageReceived( CefRefPtr /*browser*/, CefProcessId /*source_process*/, - CefRefPtr message) override + CefRefPtr message) //override { auto name = message->GetName().ToString(); if (name == "mixer-request-stats") @@ -549,7 +549,7 @@ class WebView : public CefClient, CefRefPtr /*browser*/, PaintElementType type, const RectList& dirtyRects, - void* share_handle) override + const CefAcceleratedPaintInfo& info) override { if (type == PET_VIEW) { @@ -560,7 +560,7 @@ class WebView : public CefClient, } if (view_buffer_) { - view_buffer_->on_gpu_paint((void*)share_handle); + view_buffer_->on_gpu_paint(info.shared_texture_handle); } if ((now - fps_start_) > 1000000) @@ -582,7 +582,7 @@ class WebView : public CefClient, // metrics for the view if (popup_buffer_) { - popup_buffer_->on_gpu_paint((void*)share_handle); + popup_buffer_->on_gpu_paint(info.shared_texture_handle); } } } @@ -671,6 +671,7 @@ class WebView : public CefClient, CefWindowInfo& window_info, CefRefPtr& client, CefBrowserSettings& settings, + CefRefPtr& extra_info, bool* no_javascript_access) override { shared_ptr composition; @@ -705,6 +706,7 @@ class WebView : public CefClient, view, target_url, settings, + nullptr, nullptr); // create a new layer to handle drawing for the web popup @@ -788,7 +790,7 @@ class WebView : public CefClient, args->SetDictionary(0, dict); - browser->SendProcessMessage(PID_RENDERER, message); + //browser->SendProcessMessage(PID_RENDERER, message); } void resize(int width, int height) @@ -833,10 +835,10 @@ class WebView : public CefClient, CefWindowInfo windowInfo; windowInfo.SetAsPopup(nullptr, "Developer Tools"); windowInfo.style = WS_VISIBLE | WS_OVERLAPPEDWINDOW; - windowInfo.x = 0; - windowInfo.y = 0; - windowInfo.width = 640; - windowInfo.height = 480; + windowInfo.bounds.x = 0; + windowInfo.bounds.y = 0; + windowInfo.bounds.width = 640; + windowInfo.bounds.height = 480; browser->GetHost()->ShowDevTools(windowInfo, new DevToolsClient(), CefBrowserSettings(), { 0, 0 }); } } @@ -911,7 +913,7 @@ class WebLayer : public Layer std::shared_ptr const& device, bool want_input, CefRefPtr const& view) - : Layer(device, want_input, view->use_shared_textures()) + : Layer(device, want_input, false/*view->use_shared_textures()*/) , view_(view) { } @@ -1206,6 +1208,7 @@ shared_ptr create_web_layer( view, url, settings, + nullptr, nullptr); return create_web_layer(device, want_input, view); @@ -1226,7 +1229,7 @@ shared_ptr create_popup_layer( // int cef_initialize(HINSTANCE instance) { - CefEnableHighDPISupport(); + //CefEnableHighDPISupport(); { // check first if we need to run as a worker process From 883a0ad4be8215eeb87969efffea72cd8bf4374b Mon Sep 17 00:00:00 2001 From: Scali Date: Wed, 22 May 2024 14:40:50 +0200 Subject: [PATCH 02/12] Fix message communication so stats updates can be communicated again. --- src/web_layer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/web_layer.cpp b/src/web_layer.cpp index 03506eb..b4925c6 100644 --- a/src/web_layer.cpp +++ b/src/web_layer.cpp @@ -145,7 +145,7 @@ class MixerHandler : // notify the browser process that we want stats auto message = CefProcessMessage::Create("mixer-request-stats"); if (message != nullptr && browser_ != nullptr) { - //browser_->SendProcessMessage(PID_BROWSER, message); + browser_->GetFocusedFrame()->SendProcessMessage(PID_BROWSER, message); } return true; } @@ -241,8 +241,9 @@ class WebApp : public CefApp, // CefRenderProcessHandler::OnProcessMessageReceived // bool OnProcessMessageReceived(CefRefPtr browser, + CefRefPtr frame, CefProcessId /*source_process*/, - CefRefPtr message) + CefRefPtr message) override { auto const name = message->GetName().ToString(); if (name == "mixer-update-stats") @@ -484,8 +485,9 @@ class WebView : public CefClient, bool OnProcessMessageReceived( CefRefPtr /*browser*/, + CefRefPtr /*frame*/, CefProcessId /*source_process*/, - CefRefPtr message) //override + CefRefPtr message) override { auto name = message->GetName().ToString(); if (name == "mixer-request-stats") @@ -790,7 +792,7 @@ class WebView : public CefClient, args->SetDictionary(0, dict); - //browser->SendProcessMessage(PID_RENDERER, message); + browser->GetFocusedFrame()->SendProcessMessage(PID_RENDERER, message); } void resize(int width, int height) From aa211e3aa3fd8d2e87bb19572f1540579607be12 Mon Sep 17 00:00:00 2001 From: Scali Date: Wed, 22 May 2024 14:52:06 +0200 Subject: [PATCH 03/12] Comment out unused parameter 'frame'. --- src/web_layer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web_layer.cpp b/src/web_layer.cpp index b4925c6..838d5df 100644 --- a/src/web_layer.cpp +++ b/src/web_layer.cpp @@ -241,7 +241,7 @@ class WebApp : public CefApp, // CefRenderProcessHandler::OnProcessMessageReceived // bool OnProcessMessageReceived(CefRefPtr browser, - CefRefPtr frame, + CefRefPtr /*frame*/, CefProcessId /*source_process*/, CefRefPtr message) override { From ca664797a60e30c82e40bb36b2467faee053b713 Mon Sep 17 00:00:00 2001 From: Dennis de Bruijn Date: Wed, 22 May 2024 16:12:28 +0200 Subject: [PATCH 04/12] Fix typo 'immedidate_context' to 'immediate_context'. --- src/d3d11.cpp | 2 +- src/d3d11.h | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d3d11.cpp b/src/d3d11.cpp index ea89fa2..d605df6 100644 --- a/src/d3d11.cpp +++ b/src/d3d11.cpp @@ -359,7 +359,7 @@ namespace d3d11 { return "n/a"; } - shared_ptr Device::immedidate_context() + shared_ptr Device::immediate_context() { return ctx_; } diff --git a/src/d3d11.h b/src/d3d11.h index 0c23b0c..999679a 100644 --- a/src/d3d11.h +++ b/src/d3d11.h @@ -58,7 +58,7 @@ namespace d3d11 { return device_.get(); } - std::shared_ptr immedidate_context(); + std::shared_ptr immediate_context(); std::shared_ptr create_swapchain(HWND, int width=0, int height=0); diff --git a/src/main.cpp b/src/main.cpp index 88b5418..2fcfd61 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -148,7 +148,7 @@ class Window void render() { - auto ctx = device_->immedidate_context(); + auto ctx = device_->immediate_context(); if (!ctx || !swapchain_) { return; } From 4da19e26d585d8e366006b80cb3e0e0bdfbe4dc2 Mon Sep 17 00:00:00 2001 From: Scalibq Date: Wed, 22 May 2024 18:16:03 +0200 Subject: [PATCH 05/12] Add script for generating VS2022 projects and solution. --- gen_vs2022.bat | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 gen_vs2022.bat diff --git a/gen_vs2022.bat b/gen_vs2022.bat new file mode 100644 index 0000000..1535b44 --- /dev/null +++ b/gen_vs2022.bat @@ -0,0 +1,15 @@ +@echo off + +rem set CEF_ROOT=c:\cef\cef_binary_3.3325.1742.g5caccda_windows64 + +set BASE_DIR=%~dp0 +rem echo %BASE_DIR% + +mkdir "%BASE_DIR%\build" + +cd "%BASE_DIR%\build" + +rem Visual Studio 2022 +cmake -G "Visual Studio 17" -A x64 "%BASE_DIR%" + +cd %BASE_DIR% \ No newline at end of file From 2d57861080605c50b94a32587a4166002bd8af98 Mon Sep 17 00:00:00 2001 From: Scalibq Date: Wed, 22 May 2024 19:02:19 +0200 Subject: [PATCH 06/12] Add the "/std:c++latest" compiler option for MSVC, in order to build recent CEF versions, using new language features. NOTE: This must also be added to the CMakeLists.txt from the cef-binary package, in order to build libcef_dll_wrapper properly. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8ced04..3f1167f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,6 +189,7 @@ find_package(CEF REQUIRED) # we only bother with UNICODE builds on Windows if(MSVC) add_definitions(-DUNICODE -D_UNICODE) + add_compile_options("/std:c++latest") endif() set( From 8112ec9f040f4584ddf8b38554e7e404f322a42f Mon Sep 17 00:00:00 2001 From: Scalibq Date: Wed, 22 May 2024 19:46:03 +0200 Subject: [PATCH 07/12] Update list of CEF files to match recent CEF releases. --- cmake/cef_variables.cmake | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/cmake/cef_variables.cmake b/cmake/cef_variables.cmake index d56807c..ab3f4a7 100644 --- a/cmake/cef_variables.cmake +++ b/cmake/cef_variables.cmake @@ -198,18 +198,15 @@ if(OS_LINUX) set(CEF_BINARY_FILES chrome-sandbox libcef.so - natives_blob.bin snapshot_blob.bin v8_context_snapshot.bin ) # List of CEF resource files. set(CEF_RESOURCE_FILES - cef.pak - cef_100_percent.pak - cef_200_percent.pak - cef_extensions.pak - devtools_resources.pak + chrome_100_percent.pak + chrome_200_percent.pak + resources.pak icudtl.dat locales ) @@ -419,24 +416,19 @@ if(OS_WINDOWS) # List of CEF binary files. set(CEF_BINARY_FILES chrome_elf.dll - d3dcompiler_43.dll d3dcompiler_47.dll libcef.dll libEGL.dll libGLESv2.dll - natives_blob.bin snapshot_blob.bin v8_context_snapshot.bin - swiftshader ) # List of CEF resource files. set(CEF_RESOURCE_FILES - cef.pak - cef_100_percent.pak - cef_200_percent.pak - cef_extensions.pak - devtools_resources.pak + chrome_100_percent.pak + chrome_200_percent.pak + resources.pak icudtl.dat locales ) From 14b524ac07e826d778aadca04d083b3062374a72 Mon Sep 17 00:00:00 2001 From: Scali Date: Wed, 22 May 2024 23:24:25 +0200 Subject: [PATCH 08/12] Allow passing in the shared handle when creating a Texture2D, because the new SHAREDNT-type handles cannot be retrieved via IDXGIResource->GetSharedHandle(). --- src/d3d11.cpp | 21 ++++++++++++--------- src/d3d11.h | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/d3d11.cpp b/src/d3d11.cpp index d605df6..2aa600f 100644 --- a/src/d3d11.cpp +++ b/src/d3d11.cpp @@ -202,18 +202,21 @@ namespace d3d11 { Texture2D::Texture2D( ID3D11Texture2D* tex, - ID3D11ShaderResourceView* srv) + ID3D11ShaderResourceView* srv, HANDLE share_handle) : texture_(to_com_ptr(tex)) , srv_(to_com_ptr(srv)) { - share_handle_ = nullptr; - - IDXGIResource* res = nullptr; - if (SUCCEEDED(texture_->QueryInterface( - __uuidof(IDXGIResource), reinterpret_cast(&res)))) + if (share_handle != nullptr) + share_handle_ = share_handle; + else { - res->GetSharedHandle(&share_handle_); - res->Release(); + IDXGIResource* res = nullptr; + if (SUCCEEDED(texture_->QueryInterface( + __uuidof(IDXGIResource), reinterpret_cast(&res)))) + { + res->GetSharedHandle(&share_handle_); + res->Release(); + } } // are we using a keyed mutex? @@ -603,7 +606,7 @@ namespace d3d11 { } } - return make_shared(tex, srv); + return make_shared(tex, srv, handle); } shared_ptr Device::create_texture( diff --git a/src/d3d11.h b/src/d3d11.h index 999679a..5885a42 100644 --- a/src/d3d11.h +++ b/src/d3d11.h @@ -131,7 +131,8 @@ namespace d3d11 { public: Texture2D( ID3D11Texture2D* tex, - ID3D11ShaderResourceView* srv); + ID3D11ShaderResourceView* srv, + HANDLE share_handle = nullptr); void bind(std::shared_ptr const& ctx); void unbind(); From b271a81013fe518ca7cab776c78ee374123916f4 Mon Sep 17 00:00:00 2001 From: Scali Date: Wed, 22 May 2024 23:35:09 +0200 Subject: [PATCH 09/12] Perform sanity check and release original ID3D11Device after retrieving ID3D11Device1. --- src/d3d11.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d3d11.cpp b/src/d3d11.cpp index 2aa600f..4936940 100644 --- a/src/d3d11.cpp +++ b/src/d3d11.cpp @@ -875,9 +875,12 @@ float4 main(VS_OUTPUT input) : SV_Target } if (SUCCEEDED(hr)) - { - pdev->QueryInterface(&pdev1); + hr = pdev->QueryInterface(&pdev1); + + pdev->Release(); + if (SUCCEEDED(hr)) + { auto const dev = make_shared(pdev1, pctx); log_message("d3d11: selected adapter: %s\n", dev->adapter_name().c_str()); From 012ceda1695aea3a05e6a25f7464f7c86f52313d Mon Sep 17 00:00:00 2001 From: Scalibq Date: Thu, 23 May 2024 14:54:17 +0200 Subject: [PATCH 10/12] Fix log message in regular OnPaint from OnAcceleratedPaint to OnPaint. --- src/web_layer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web_layer.cpp b/src/web_layer.cpp index 838d5df..43b0a40 100644 --- a/src/web_layer.cpp +++ b/src/web_layer.cpp @@ -529,7 +529,7 @@ class WebView : public CefClient, auto const w = view_buffer_ ? view_buffer_->width() : 0; auto const h = view_buffer_ ? view_buffer_->height() : 0; - log_message("html: OnAcceleratedPaint (%dx%d), fps: %3.2f\n", w, h, fps); + log_message("html: OnPaint (%dx%d), fps: %3.2f\n", w, h, fps); frame_ = 0; fps_start_ = time_now(); From 29e4358e8dd4b7705c817be328f270162c677ac0 Mon Sep 17 00:00:00 2001 From: Dennis de Bruijn Date: Thu, 25 Jul 2024 13:09:34 +0200 Subject: [PATCH 11/12] Add support for running in fullscreen mode. --- src/d3d11.cpp | 14 +++++++++++--- src/d3d11.h | 2 +- src/main.cpp | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/d3d11.cpp b/src/d3d11.cpp index 4936940..a0016f6 100644 --- a/src/d3d11.cpp +++ b/src/d3d11.cpp @@ -367,7 +367,7 @@ namespace d3d11 { return ctx_; } - shared_ptr Device::create_swapchain(HWND window, int width, int height) + shared_ptr Device::create_swapchain(HWND window, int width, int height, bool fullscreen) { HRESULT hr; IDXGIFactory1* dxgi_factory = nullptr; @@ -422,9 +422,17 @@ namespace d3d11 { sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; + DXGI_SWAP_CHAIN_FULLSCREEN_DESC fsd = { 0 }; + if (fullscreen) + { + fsd.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE; + fsd.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; + fsd.Windowed = false; + } + IDXGISwapChain1* swapchain1 = nullptr; hr = dxgi_factory2->CreateSwapChainForHwnd( - device_.get(), window, &sd, nullptr, nullptr, &swapchain1); + device_.get(), window, &sd, fullscreen ? &fsd : nullptr, nullptr, &swapchain1); if (SUCCEEDED(hr)) { hr = swapchain1->QueryInterface(__uuidof(IDXGISwapChain), reinterpret_cast(&swapchain)); @@ -448,7 +456,7 @@ namespace d3d11 { sd.OutputWindow = window; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; - sd.Windowed = TRUE; + sd.Windowed = !fullscreen; hr = dxgi_factory->CreateSwapChain(device_.get(), &sd, &swapchain); } diff --git a/src/d3d11.h b/src/d3d11.h index 5885a42..a378909 100644 --- a/src/d3d11.h +++ b/src/d3d11.h @@ -60,7 +60,7 @@ namespace d3d11 { std::shared_ptr immediate_context(); - std::shared_ptr create_swapchain(HWND, int width=0, int height=0); + std::shared_ptr create_swapchain(HWND, int width=0, int height=0, bool fullscreen=false); std::shared_ptr create_quad( float x, float y, float width, float height, bool flip=false); diff --git a/src/main.cpp b/src/main.cpp index 2fcfd61..581f084 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,8 @@ #include #include +#define FULLSCREEN true + // // if we're running on a system with hybrid graphics ... // try to force the selection of the high-performance gpu @@ -285,7 +287,7 @@ class Window void on_create() { // create a D3D11 swapchain for the window - swapchain_ = device_->create_swapchain(hwnd()); + swapchain_ = device_->create_swapchain(hwnd(), 0, 0, FULLSCREEN); } void on_new_window() From 045c0c9695ea86b83db81983d6ce399379b2dda6 Mon Sep 17 00:00:00 2001 From: Dennis de Bruijn Date: Mon, 12 Aug 2024 16:06:51 +0200 Subject: [PATCH 12/12] Use IDXGIOutput->WaitForVBlank() as a workaround for jerky CEF animation when vsynced/fullscreen. --- src/d3d11.cpp | 7 +++++++ src/d3d11.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/d3d11.cpp b/src/d3d11.cpp index a0016f6..c6b8baf 100644 --- a/src/d3d11.cpp +++ b/src/d3d11.cpp @@ -35,6 +35,9 @@ namespace d3d11 { , swapchain_(to_com_ptr(swapchain)) , rtv_(to_com_ptr(rtv)) { + IDXGIOutput* pOutput = NULL; + swapchain_->GetContainingOutput(&pOutput); + output_ = shared_ptr(to_com_ptr(pOutput)); } void SwapChain::bind(shared_ptr const& ctx) @@ -76,6 +79,10 @@ namespace d3d11 { void SwapChain::present(int sync_interval) { + // Workaround for jerky animation when vsynced/fullscreen + if (sync_interval > 0) + output_->WaitForVBlank(); + swapchain_->Present(sync_interval, 0); } diff --git a/src/d3d11.h b/src/d3d11.h index a378909..c9d4d23 100644 --- a/src/d3d11.h +++ b/src/d3d11.h @@ -122,6 +122,7 @@ namespace d3d11 { std::shared_ptr const sampler_; std::shared_ptr const blender_; std::shared_ptr const swapchain_; + std::shared_ptr output_; std::shared_ptr rtv_; std::shared_ptr ctx_; };