Skip to content

Commit

Permalink
Sokol: Fix less than Windows 10
Browse files Browse the repository at this point in the history
  • Loading branch information
pbdot committed Dec 27, 2024
1 parent 7e5e0a8 commit 2e60e6b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions source_files/edge/render/sokol/sokol_d3d11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static const IID _sapp_IID_IDXGIFactory = {
typedef struct
{
HWND hwnd;
bool is_win10_or_greater;
} _sapp_win32_t;

typedef struct
Expand All @@ -62,12 +63,27 @@ typedef struct
int framebuffer_width;
int framebuffer_height;
int sample_count;
int swap_interval;

int swap_interval;
} _sapp_t;

static _sapp_t _sapp;

/* don't laugh, but this seems to be the easiest and most robust
way to check if we're running on Win10
From: https://github.com/videolan/vlc/blob/232fb13b0d6110c4d1b683cde24cf9a7f2c5c2ea/modules/video_output/win32/d3d11_swapchain.c#L263
*/
bool _sapp_win32_is_win10_or_greater(void) {
HMODULE h = GetModuleHandleW(L"kernel32.dll");
if (NULL != h) {
return (NULL != GetProcAddress(h, "GetSystemCpuSetInformation"));
}
else {
return false;
}
}


static inline HRESULT _sapp_dxgi_GetBuffer(IDXGISwapChain *self, UINT Buffer, REFIID riid, void **ppSurface)
{
#if defined(__cplusplus)
Expand Down Expand Up @@ -197,7 +213,7 @@ static void _sapp_d3d11_create_device_and_swapchain(void)
sc_desc->BufferDesc.RefreshRate.Denominator = 1;
sc_desc->OutputWindow = _sapp.win32.hwnd;
sc_desc->Windowed = true;
if (true) //_sapp.win32.is_win10_or_greater)
if (_sapp.win32.is_win10_or_greater)
{
sc_desc->BufferCount = 2;
sc_desc->SwapEffect = (DXGI_SWAP_EFFECT)_SAPP_DXGI_SWAP_EFFECT_FLIP_DISCARD;
Expand Down Expand Up @@ -381,7 +397,7 @@ void sapp_d3d11_resize_default_render_target(int32_t width, int32_t height)
void sapp_d3d11_present(bool do_not_wait)
{
UINT flags = 0;
if (/*_sapp.win32.is_win10_or_greater &&*/ do_not_wait)
if (_sapp.win32.is_win10_or_greater && do_not_wait)
{
/* this hack/workaround somewhat improves window-movement and -sizing
responsiveness when rendering is controlled via WM_TIMER during window
Expand All @@ -402,6 +418,7 @@ void sapp_d3d11_init(SDL_Window *window, int32_t width, int32_t height)
_sapp.framebuffer_height = height;
_sapp.sample_count = 1;
_sapp.swap_interval = 0;
_sapp.win32.is_win10_or_greater = _sapp_win32_is_win10_or_greater();

_sapp_d3d11_create_device_and_swapchain();
_sapp_d3d11_create_default_render_target();
Expand Down

0 comments on commit 2e60e6b

Please sign in to comment.