2012-10-24 17:17:01 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-12-11 23:55:31 -08:00
|
|
|
*
|
2012-10-24 17:17:01 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-10-23 07:59:53 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
2015-01-07 18:06:50 +01:00
|
|
|
/* Win32/WGL context. */
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2015-01-07 18:06:50 +01:00
|
|
|
/* necessary for mingw32 multimon defines: */
|
2013-06-20 16:06:13 +02:00
|
|
|
#ifndef _WIN32_WINNT
|
|
|
|
#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K
|
|
|
|
#endif
|
|
|
|
|
2016-12-02 23:36:23 -05:00
|
|
|
#include <tchar.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
2015-09-05 14:10:16 +02:00
|
|
|
#include <string.h>
|
2015-10-19 19:44:28 -05:00
|
|
|
#include <math.h>
|
2015-09-05 14:10:16 +02:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commdlg.h>
|
|
|
|
|
2015-09-05 14:38:55 +02:00
|
|
|
#include <dynamic/dylib.h>
|
2017-05-19 16:20:30 +02:00
|
|
|
#include <string/stdstring.h>
|
2015-09-05 14:38:55 +02:00
|
|
|
|
2016-09-06 19:39:02 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2017-01-10 19:51:06 +01:00
|
|
|
#include "../../configuration.h"
|
2015-04-10 06:33:18 +02:00
|
|
|
#include "../../dynamic.h"
|
2019-06-17 15:10:22 +02:00
|
|
|
#include "../../retroarch.h"
|
2019-02-02 22:02:24 +01:00
|
|
|
#include "../../verbosity.h"
|
2019-02-15 15:58:52 -05:00
|
|
|
#include "../../frontend/frontend_driver.h"
|
2015-11-17 08:01:33 +01:00
|
|
|
|
2015-04-09 05:16:02 +02:00
|
|
|
#include "../common/win32_common.h"
|
2015-11-17 08:01:33 +01:00
|
|
|
|
2019-04-22 22:48:23 +02:00
|
|
|
#if defined(HAVE_OPENGL)
|
2016-05-16 08:34:56 +02:00
|
|
|
#include "../common/gl_common.h"
|
2019-04-24 03:23:57 +02:00
|
|
|
#elif defined(HAVE_OPENGL_CORE)
|
|
|
|
#include "../common/gl_core_common.h"
|
2019-04-22 22:48:23 +02:00
|
|
|
#elif defined(HAVE_OPENGL1)
|
|
|
|
#include "../common/gl1_common.h"
|
2016-05-16 08:34:56 +02:00
|
|
|
#endif
|
|
|
|
|
2016-03-29 00:45:36 +02:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
#include "../common/vulkan_common.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) || defined(HAVE_VULKAN)
|
2015-11-11 17:36:52 +01:00
|
|
|
#ifndef WGL_CONTEXT_MAJOR_VERSION_ARB
|
|
|
|
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_CONTEXT_MINOR_VERSION_ARB
|
|
|
|
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_CONTEXT_PROFILE_MASK_ARB
|
|
|
|
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_CONTEXT_CORE_PROFILE_BIT_ARB
|
|
|
|
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x0001
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_CONTEXT_FLAGS_ARB
|
|
|
|
#define WGL_CONTEXT_FLAGS_ARB 0x2094
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_CONTEXT_DEBUG_BIT_ARB
|
|
|
|
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
|
2015-09-05 14:10:16 +02:00
|
|
|
#endif
|
2016-05-16 08:34:56 +02:00
|
|
|
#endif
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2019-10-03 17:45:59 +02:00
|
|
|
static void gfx_ctx_wgl_destroy(void *data);
|
|
|
|
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2015-11-20 14:32:46 +01:00
|
|
|
typedef HGLRC (APIENTRY *wglCreateContextAttribsProc)(HDC, HGLRC, const int*);
|
2016-05-16 08:34:56 +02:00
|
|
|
static wglCreateContextAttribsProc pcreate_context;
|
|
|
|
#endif
|
2015-11-20 14:32:46 +01:00
|
|
|
static BOOL (APIENTRY *p_swap_interval)(int);
|
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
static HGLRC win32_hrc;
|
|
|
|
static HGLRC win32_hw_hrc;
|
|
|
|
static HDC win32_hdc;
|
|
|
|
static bool win32_use_hw_ctx = false;
|
|
|
|
static bool win32_core_hw_context_enable = false;
|
2018-09-12 03:59:25 +02:00
|
|
|
static bool wgl_adaptive_vsync = false;
|
2015-11-11 05:32:00 +01:00
|
|
|
|
2016-03-29 00:45:36 +02:00
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
static gfx_ctx_vulkan_data_t win32_vk;
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
static unsigned win32_major = 0;
|
|
|
|
static unsigned win32_minor = 0;
|
2018-09-12 00:07:43 +02:00
|
|
|
static int win32_interval = 0;
|
2016-12-02 19:58:39 +01:00
|
|
|
static enum gfx_ctx_api win32_api = GFX_CTX_NONE;
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2018-01-24 02:12:58 +01:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2016-12-02 19:58:39 +01:00
|
|
|
static dylib_t dll_handle = NULL; /* Handle to OpenGL32.dll */
|
2018-01-24 02:12:58 +01:00
|
|
|
#endif
|
2015-02-08 01:24:44 +01:00
|
|
|
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2018-09-12 03:59:25 +02:00
|
|
|
static bool wgl_has_extension(const char *extension, const char *extensions)
|
|
|
|
{
|
|
|
|
const char *start = NULL;
|
|
|
|
const char *terminator = NULL;
|
|
|
|
const char *where = strchr(extension, ' ');
|
|
|
|
|
|
|
|
if (where || *extension == '\0')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!extensions)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
start = extensions;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
where = strstr(start, extension);
|
|
|
|
if (!where)
|
|
|
|
break;
|
|
|
|
|
|
|
|
terminator = where + strlen(extension);
|
|
|
|
if (where == start || *(where - 1) == ' ')
|
|
|
|
if (*terminator == ' ' || *terminator == '\0')
|
|
|
|
return true;
|
|
|
|
|
|
|
|
start = terminator;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
typedef struct gfx_ctx_cgl_data
|
|
|
|
{
|
2018-09-12 03:59:25 +02:00
|
|
|
void *empty;
|
2018-03-01 21:16:54 +01:00
|
|
|
} gfx_ctx_wgl_data_t;
|
|
|
|
|
2017-05-16 22:46:56 +02:00
|
|
|
static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol)
|
|
|
|
{
|
|
|
|
switch (win32_api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2017-05-16 22:46:56 +02:00
|
|
|
{
|
|
|
|
gfx_ctx_proc_t func = (gfx_ctx_proc_t)wglGetProcAddress(symbol);
|
|
|
|
if (func)
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-24 02:12:58 +01:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2017-05-16 22:46:56 +02:00
|
|
|
return (gfx_ctx_proc_t)GetProcAddress((HINSTANCE)dll_handle, symbol);
|
2018-01-24 02:12:58 +01:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2017-05-16 22:46:56 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2016-03-29 00:45:36 +02:00
|
|
|
static void create_gl_context(HWND hwnd, bool *quit)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
struct retro_hw_render_callback *hwr = video_driver_get_hw_context();
|
|
|
|
bool debug = hwr->debug_context;
|
|
|
|
bool core_context = (win32_major * 1000 + win32_minor) >= 3001;
|
|
|
|
win32_hdc = GetDC(hwnd);
|
2016-03-04 20:49:55 +01:00
|
|
|
|
2019-08-28 23:58:15 +02:00
|
|
|
win32_setup_pixel_format(win32_hdc, true);
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2014-04-19 16:21:37 +02:00
|
|
|
#ifdef GL_DEBUG
|
2015-01-10 17:51:00 +01:00
|
|
|
debug = true;
|
2014-04-19 16:21:37 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_hrc)
|
2015-01-10 17:51:00 +01:00
|
|
|
{
|
|
|
|
RARCH_LOG("[WGL]: Using cached GL context.\n");
|
2016-05-08 14:10:28 +02:00
|
|
|
video_driver_set_video_cache_context_ack();
|
2015-01-10 17:51:00 +01:00
|
|
|
}
|
|
|
|
else
|
2014-04-19 16:21:37 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_hrc = wglCreateContext(win32_hdc);
|
2017-12-11 23:55:31 -08:00
|
|
|
|
2014-10-27 14:35:23 +01:00
|
|
|
/* We'll create shared context later if not. */
|
2017-12-11 23:55:31 -08:00
|
|
|
if (win32_hrc && !core_context && !debug)
|
2014-04-19 16:21:37 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_hw_hrc = wglCreateContext(win32_hdc);
|
|
|
|
if (win32_hw_hrc)
|
2014-04-19 16:21:37 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
if (!wglShareLists(win32_hrc, win32_hw_hrc))
|
2014-04-19 16:21:37 +02:00
|
|
|
{
|
|
|
|
RARCH_LOG("[WGL]: Failed to share contexts.\n");
|
2015-11-17 23:14:59 +01:00
|
|
|
*quit = true;
|
2014-04-19 16:21:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-11-17 23:14:59 +01:00
|
|
|
*quit = true;
|
2014-04-19 16:21:37 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 23:18:05 +02:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_hrc)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
if (wglMakeCurrent(win32_hdc, win32_hrc))
|
2018-05-12 19:03:39 +02:00
|
|
|
g_win32_inited = true;
|
2012-10-24 17:17:01 +02:00
|
|
|
else
|
2018-05-12 19:03:39 +02:00
|
|
|
*quit = true;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
else
|
2013-06-23 13:05:33 +02:00
|
|
|
{
|
2015-11-17 23:14:59 +01:00
|
|
|
*quit = true;
|
|
|
|
return;
|
2013-06-23 13:05:33 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 14:04:26 +02:00
|
|
|
if (core_context || debug)
|
2013-06-23 13:05:33 +02:00
|
|
|
{
|
2019-08-05 10:46:17 -04:00
|
|
|
int attribs[16] = {0};
|
2013-08-14 14:04:26 +02:00
|
|
|
int *aptr = attribs;
|
|
|
|
|
|
|
|
if (core_context)
|
|
|
|
{
|
|
|
|
*aptr++ = WGL_CONTEXT_MAJOR_VERSION_ARB;
|
2016-12-02 19:58:39 +01:00
|
|
|
*aptr++ = win32_major;
|
2013-08-14 14:04:26 +02:00
|
|
|
*aptr++ = WGL_CONTEXT_MINOR_VERSION_ARB;
|
2016-12-02 19:58:39 +01:00
|
|
|
*aptr++ = win32_minor;
|
2014-04-20 13:54:29 +02:00
|
|
|
|
2014-10-27 14:35:23 +01:00
|
|
|
/* Technically, we don't have core/compat until 3.2.
|
2017-12-11 23:55:31 -08:00
|
|
|
* Version 3.1 is either compat or not depending
|
2014-10-27 14:35:23 +01:00
|
|
|
* on GL_ARB_compatibility.
|
|
|
|
*/
|
2016-12-02 19:58:39 +01:00
|
|
|
if ((win32_major * 1000 + win32_minor) >= 3002)
|
2014-04-20 13:54:29 +02:00
|
|
|
{
|
|
|
|
*aptr++ = WGL_CONTEXT_PROFILE_MASK_ARB;
|
|
|
|
*aptr++ = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
|
|
|
|
}
|
2013-08-14 14:04:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
*aptr++ = WGL_CONTEXT_FLAGS_ARB;
|
|
|
|
*aptr++ = WGL_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aptr = 0;
|
2013-06-23 13:05:33 +02:00
|
|
|
|
|
|
|
if (!pcreate_context)
|
2017-05-16 22:46:09 +02:00
|
|
|
pcreate_context = (wglCreateContextAttribsProc)gfx_ctx_wgl_get_proc_address("wglCreateContextAttribsARB");
|
2013-06-23 13:05:33 +02:00
|
|
|
|
2019-08-05 10:46:17 -04:00
|
|
|
/* In order to support the core info "required_hw_api" field correctly, we should try to init the highest available
|
|
|
|
* version GL context possible. This means trying successively lower versions until it works, because GL has
|
|
|
|
* no facility for determining the highest possible supported version.
|
|
|
|
*/
|
2013-06-23 13:05:33 +02:00
|
|
|
if (pcreate_context)
|
|
|
|
{
|
2019-08-05 10:46:17 -04:00
|
|
|
int i;
|
2019-08-07 12:24:24 -04:00
|
|
|
int gl_versions[][2] = {{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}, {3, 1}, {3, 0}};
|
2019-08-05 10:46:17 -04:00
|
|
|
int gl_version_rows = ARRAY_SIZE(gl_versions);
|
|
|
|
int (*versions)[2];
|
|
|
|
int version_rows = 0;
|
|
|
|
HGLRC context = NULL;
|
|
|
|
|
|
|
|
versions = gl_versions;
|
|
|
|
version_rows = gl_version_rows;
|
|
|
|
|
2019-08-12 12:28:51 +02:00
|
|
|
/* only try higher versions when core_context is true */
|
|
|
|
if (!core_context)
|
|
|
|
version_rows = 1;
|
|
|
|
|
|
|
|
/* try versions from highest down to requested version */
|
2019-08-05 10:46:17 -04:00
|
|
|
for (i = 0; i < version_rows; i++)
|
2013-06-23 13:05:33 +02:00
|
|
|
{
|
2019-08-12 12:28:51 +02:00
|
|
|
if (core_context)
|
|
|
|
{
|
|
|
|
attribs[1] = versions[i][0];
|
|
|
|
attribs[3] = versions[i][1];
|
|
|
|
}
|
2019-08-05 10:46:17 -04:00
|
|
|
|
|
|
|
context = pcreate_context(win32_hdc, NULL, attribs);
|
|
|
|
|
|
|
|
if (context)
|
2014-04-19 16:21:37 +02:00
|
|
|
{
|
2019-08-05 10:46:17 -04:00
|
|
|
wglMakeCurrent(NULL, NULL);
|
|
|
|
wglDeleteContext(win32_hrc);
|
|
|
|
win32_hrc = context;
|
|
|
|
|
|
|
|
if (!wglMakeCurrent(win32_hdc, win32_hrc))
|
|
|
|
{
|
|
|
|
*quit = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-07 12:24:24 -04:00
|
|
|
|
|
|
|
if (win32_use_hw_ctx)
|
|
|
|
{
|
|
|
|
win32_hw_hrc = pcreate_context(win32_hdc, context, attribs);
|
|
|
|
|
|
|
|
if (!win32_hw_hrc)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[WGL]: Failed to create shared context.\n");
|
|
|
|
*quit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* found a suitable version that is high enough, we can stop now */
|
|
|
|
break;
|
2019-08-05 10:46:17 -04:00
|
|
|
}
|
2019-08-07 14:46:47 -04:00
|
|
|
else if (versions[i][0] == win32_major && versions[i][1] == win32_minor)
|
2019-08-06 17:53:15 -04:00
|
|
|
{
|
2019-08-07 14:46:47 -04:00
|
|
|
/* The requested version was tried and is not supported, go ahead and fail since everything else will be lower than that. */
|
|
|
|
break;
|
2019-08-06 17:53:15 -04:00
|
|
|
}
|
2019-08-05 10:46:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[WGL]: Failed to create core context. Falling back to legacy context.\n");
|
|
|
|
*quit = true;
|
2014-04-19 16:21:37 +02:00
|
|
|
}
|
2013-06-23 13:05:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
RARCH_ERR("[WGL]: wglCreateContextAttribsARB not supported.\n");
|
|
|
|
}
|
2018-09-12 03:59:25 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
|
|
|
const char *extensions = NULL;
|
|
|
|
|
|
|
|
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
|
|
|
|
gfx_ctx_wgl_get_proc_address("wglGetExtensionsStringARB");
|
|
|
|
if (wglGetExtensionsStringARB)
|
|
|
|
{
|
2019-08-15 13:39:19 +02:00
|
|
|
extensions = wglGetExtensionsStringARB(win32_hdc);
|
|
|
|
RARCH_LOG("[WGL] extensions: %s\n", extensions);
|
|
|
|
if (wgl_has_extension("WGL_EXT_swap_control_tear", extensions))
|
|
|
|
{
|
|
|
|
RARCH_LOG("[WGL]: Adaptive VSync supported.\n");
|
|
|
|
wgl_adaptive_vsync = true;
|
|
|
|
}
|
2018-09-12 03:59:25 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
2016-05-16 08:34:56 +02:00
|
|
|
#endif
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2016-03-29 00:45:36 +02:00
|
|
|
void create_graphics_context(HWND hwnd, bool *quit)
|
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2016-03-29 00:45:36 +02:00
|
|
|
create_gl_context(hwnd, quit);
|
2016-05-16 08:34:56 +02:00
|
|
|
#endif
|
2016-03-29 00:45:36 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
RECT rect;
|
2017-08-09 13:51:33 +02:00
|
|
|
HINSTANCE instance;
|
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
|
|
|
|
2016-03-29 00:45:36 +02:00
|
|
|
GetClientRect(hwnd, &rect);
|
2017-08-09 13:51:33 +02:00
|
|
|
|
|
|
|
instance = GetModuleHandle(NULL);
|
|
|
|
width = rect.right - rect.left;
|
|
|
|
height = rect.bottom - rect.top;
|
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
if (!vulkan_surface_create(&win32_vk, VULKAN_WSI_WIN32,
|
2017-12-11 23:55:31 -08:00
|
|
|
&instance, &hwnd,
|
2016-12-02 19:58:39 +01:00
|
|
|
width, height, win32_interval))
|
2016-03-29 00:45:36 +02:00
|
|
|
*quit = true;
|
2017-08-09 13:51:33 +02:00
|
|
|
|
2018-05-12 19:03:39 +02:00
|
|
|
g_win32_inited = true;
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
}
|
2016-05-16 08:34:56 +02:00
|
|
|
break;
|
2016-03-29 00:45:36 +02:00
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:29:06 +01:00
|
|
|
void *dinput_wgl;
|
2013-11-05 20:49:04 +01:00
|
|
|
|
2018-09-12 00:07:43 +02:00
|
|
|
static void gfx_ctx_wgl_swap_interval(void *data, int interval)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2016-12-17 12:06:43 +01:00
|
|
|
win32_interval = interval;
|
2016-12-02 19:58:39 +01:00
|
|
|
if (!win32_hrc)
|
2016-03-29 00:45:36 +02:00
|
|
|
return;
|
|
|
|
if (!p_swap_interval)
|
|
|
|
return;
|
|
|
|
|
2018-09-12 03:59:25 +02:00
|
|
|
RARCH_LOG("[WGL]: wglSwapInterval(%i)\n", win32_interval);
|
2016-12-02 19:58:39 +01:00
|
|
|
if (!p_swap_interval(win32_interval))
|
2016-03-29 00:45:36 +02:00
|
|
|
RARCH_WARN("[WGL]: wglSwapInterval() failed.\n");
|
|
|
|
#endif
|
|
|
|
break;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2016-03-29 00:45:36 +02:00
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_interval != interval)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_interval = interval;
|
|
|
|
if (win32_vk.swapchain)
|
|
|
|
win32_vk.need_new_swapchain = true;
|
2016-03-29 00:45:36 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
2016-12-17 12:06:43 +01:00
|
|
|
win32_interval = interval;
|
2016-03-29 00:45:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_wgl_check_window(void *data, bool *quit,
|
2017-01-23 01:02:33 +01:00
|
|
|
bool *resize, unsigned *width, unsigned *height,
|
|
|
|
bool is_shutdown)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2015-11-11 19:41:32 +01:00
|
|
|
win32_check_window(quit, resize, width, height);
|
2016-03-29 00:45:36 +02:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_vk.need_new_swapchain)
|
2016-03-29 00:45:36 +02:00
|
|
|
*resize = true;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2017-05-19 03:34:53 +02:00
|
|
|
static void gfx_ctx_wgl_swap_buffers(void *data, void *data2)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2016-03-29 00:45:36 +02:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2017-08-22 17:44:40 +02:00
|
|
|
SwapBuffers(win32_hdc);
|
2016-05-16 08:34:56 +02:00
|
|
|
break;
|
2016-03-29 00:45:36 +02:00
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
vulkan_present(&win32_vk, win32_vk.context.current_swapchain_index);
|
|
|
|
vulkan_acquire_next_image(&win32_vk);
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2016-01-07 00:58:33 +01:00
|
|
|
static bool gfx_ctx_wgl_set_resize(void *data,
|
2014-10-08 18:09:01 +02:00
|
|
|
unsigned width, unsigned height)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2012-10-24 17:17:01 +02:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
2016-03-29 00:45:36 +02:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
if (!vulkan_create_swapchain(&win32_vk, width, height, win32_interval))
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
RARCH_ERR("[Win32/Vulkan]: Failed to update swapchain.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-01 14:13:02 +02:00
|
|
|
if (win32_vk.created_new_swapchain)
|
|
|
|
vulkan_acquire_next_image(&win32_vk);
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_vk.context.invalid_swapchain = true;
|
|
|
|
win32_vk.need_new_swapchain = false;
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-07 00:58:33 +01:00
|
|
|
return false;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2017-05-19 03:34:53 +02:00
|
|
|
static void gfx_ctx_wgl_update_title(void *data, void *data2)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2019-02-15 15:58:52 -05:00
|
|
|
video_frame_info_t* video_info = (video_frame_info_t*)data2;
|
2017-12-31 13:54:34 +01:00
|
|
|
char title[128];
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2017-12-31 13:54:34 +01:00
|
|
|
title[0] = '\0';
|
2017-01-19 00:33:52 -05:00
|
|
|
|
2017-12-31 13:54:34 +01:00
|
|
|
video_driver_get_window_title(title, sizeof(title));
|
2017-01-19 00:33:52 -05:00
|
|
|
|
2017-12-31 13:54:34 +01:00
|
|
|
if (title[0])
|
|
|
|
{
|
|
|
|
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
2017-01-19 00:33:52 -05:00
|
|
|
|
2017-12-31 13:54:34 +01:00
|
|
|
if (window)
|
2017-01-19 00:33:52 -05:00
|
|
|
window->set_title(&main_window, title);
|
|
|
|
}
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2016-02-14 16:39:27 +01:00
|
|
|
static void gfx_ctx_wgl_get_video_size(void *data,
|
|
|
|
unsigned *width, unsigned *height)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2015-11-17 09:41:18 +01:00
|
|
|
HWND window = win32_get_window();
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2017-08-12 18:15:26 +02:00
|
|
|
(void)data;
|
|
|
|
|
2015-11-17 09:41:18 +01:00
|
|
|
if (!window)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2015-01-16 16:22:19 +01:00
|
|
|
RECT mon_rect;
|
2012-10-31 21:36:17 +01:00
|
|
|
MONITORINFOEX current_mon;
|
2016-12-02 19:58:39 +01:00
|
|
|
unsigned mon_id = 0;
|
|
|
|
HMONITOR hm_to_use = NULL;
|
2012-10-31 21:36:17 +01:00
|
|
|
|
2015-11-11 17:47:56 +01:00
|
|
|
win32_monitor_info(¤t_mon, &hm_to_use, &mon_id);
|
2015-01-16 16:22:19 +01:00
|
|
|
mon_rect = current_mon.rcMonitor;
|
2012-10-31 21:36:17 +01:00
|
|
|
*width = mon_rect.right - mon_rect.left;
|
|
|
|
*height = mon_rect.bottom - mon_rect.top;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-12 19:03:39 +02:00
|
|
|
*width = g_win32_resize_width;
|
|
|
|
*height = g_win32_resize_height;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 18:29:22 +01:00
|
|
|
static void *gfx_ctx_wgl_init(video_frame_info_t *video_info, void *video_driver)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2018-03-01 21:16:54 +01:00
|
|
|
WNDCLASSEX wndclass = {0};
|
|
|
|
gfx_ctx_wgl_data_t *wgl = (gfx_ctx_wgl_data_t*)calloc(1, sizeof(*wgl));
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
if (!wgl)
|
|
|
|
return NULL;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2018-05-12 19:03:39 +02:00
|
|
|
if (g_win32_inited)
|
2019-10-03 17:45:59 +02:00
|
|
|
gfx_ctx_wgl_destroy(NULL);
|
2017-07-03 08:56:17 +02:00
|
|
|
|
2018-01-24 02:12:58 +01:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2017-07-03 08:56:17 +02:00
|
|
|
dll_handle = dylib_load("OpenGL32.dll");
|
2018-01-24 02:12:58 +01:00
|
|
|
#endif
|
2017-12-11 23:55:31 -08:00
|
|
|
|
2015-11-17 10:16:16 +01:00
|
|
|
win32_window_reset();
|
2015-11-11 17:36:52 +01:00
|
|
|
win32_monitor_init();
|
2015-11-28 21:50:28 +01:00
|
|
|
|
|
|
|
wndclass.lpfnWndProc = WndProcGL;
|
2015-11-19 08:30:37 +01:00
|
|
|
if (!win32_window_init(&wndclass, true, NULL))
|
2018-03-01 21:16:54 +01:00
|
|
|
goto error;
|
2012-10-24 17:17:01 +02:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
if (!vulkan_context_init(&win32_vk, VULKAN_WSI_WIN32))
|
2018-03-01 21:16:54 +01:00
|
|
|
goto error;
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
break;
|
2016-05-16 08:25:14 +02:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2016-03-29 00:45:36 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
return wgl;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (wgl)
|
|
|
|
free(wgl);
|
|
|
|
return NULL;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_wgl_destroy(void *data)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2018-03-01 21:16:54 +01:00
|
|
|
HWND window = win32_get_window();
|
|
|
|
gfx_ctx_wgl_data_t *wgl = (gfx_ctx_wgl_data_t*)data;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2016-03-29 00:45:36 +02:00
|
|
|
case GFX_CTX_OPENGL_API:
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_hrc)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
glFinish();
|
|
|
|
wglMakeCurrent(NULL, NULL);
|
2013-06-23 23:18:05 +02:00
|
|
|
|
2016-05-16 07:51:01 +02:00
|
|
|
if (!video_driver_is_video_cache_context())
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_hw_hrc)
|
|
|
|
wglDeleteContext(win32_hw_hrc);
|
|
|
|
wglDeleteContext(win32_hrc);
|
|
|
|
win32_hrc = NULL;
|
|
|
|
win32_hw_hrc = NULL;
|
2016-03-29 00:45:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 19:58:39 +01:00
|
|
|
vulkan_context_destroy(&win32_vk, win32_vk.vk_surface != VK_NULL_HANDLE);
|
|
|
|
if (win32_vk.context.queue_lock)
|
|
|
|
slock_free(win32_vk.context.queue_lock);
|
|
|
|
memset(&win32_vk, 0, sizeof(win32_vk));
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
if (window && win32_hdc)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
ReleaseDC(window, win32_hdc);
|
|
|
|
win32_hdc = NULL;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 09:41:18 +01:00
|
|
|
if (window)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2016-06-04 05:54:33 +02:00
|
|
|
win32_monitor_from_window();
|
2015-11-17 09:44:26 +01:00
|
|
|
win32_destroy_window();
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 19:03:39 +02:00
|
|
|
if (g_win32_restore_desktop)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2015-11-11 17:36:52 +01:00
|
|
|
win32_monitor_get_info();
|
2018-05-12 19:03:39 +02:00
|
|
|
g_win32_restore_desktop = false;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 02:12:58 +01:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2017-07-03 08:57:26 +02:00
|
|
|
dylib_close(dll_handle);
|
2018-01-24 02:12:58 +01:00
|
|
|
#endif
|
2017-07-03 08:56:17 +02:00
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
if (wgl)
|
|
|
|
free(wgl);
|
|
|
|
|
2018-09-12 03:59:25 +02:00
|
|
|
wgl_adaptive_vsync = false;
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_core_hw_context_enable = false;
|
2018-05-12 19:03:39 +02:00
|
|
|
g_win32_inited = false;
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_major = 0;
|
|
|
|
win32_minor = 0;
|
|
|
|
p_swap_interval = NULL;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2015-11-20 14:32:46 +01:00
|
|
|
static bool gfx_ctx_wgl_set_video_mode(void *data,
|
2017-01-18 17:41:27 +01:00
|
|
|
video_frame_info_t *video_info,
|
2015-11-20 14:32:46 +01:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
2018-09-09 01:28:09 +02:00
|
|
|
#ifdef HAVE_VULKAN
|
2018-09-08 16:27:25 +02:00
|
|
|
win32_vk.fullscreen = fullscreen;
|
2018-09-09 01:28:09 +02:00
|
|
|
#endif
|
2018-09-08 16:27:25 +02:00
|
|
|
|
2016-01-08 05:13:10 +01:00
|
|
|
if (!win32_set_video_mode(NULL, width, height, fullscreen))
|
2016-03-29 17:57:13 +02:00
|
|
|
{
|
|
|
|
RARCH_ERR("[WGL]: win32_set_video_mode failed.\n");
|
2015-11-20 14:32:46 +01:00
|
|
|
goto error;
|
2016-03-29 17:57:13 +02:00
|
|
|
}
|
2015-11-20 14:32:46 +01:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2017-05-16 22:46:09 +02:00
|
|
|
p_swap_interval = (BOOL (APIENTRY *)(int))gfx_ctx_wgl_get_proc_address("wglSwapIntervalEXT");
|
2016-03-29 00:45:36 +02:00
|
|
|
break;
|
2016-03-29 13:27:45 +02:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2016-03-29 00:45:36 +02:00
|
|
|
}
|
2015-11-20 14:32:46 +01:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
gfx_ctx_wgl_swap_interval(data, win32_interval);
|
2015-11-20 14:32:46 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gfx_ctx_wgl_destroy(data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_wgl_input_driver(void *data,
|
2017-01-16 00:13:57 +01:00
|
|
|
const char *joypad_name,
|
2019-07-27 02:21:24 +02:00
|
|
|
input_driver_t **input, void **input_data)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2017-05-19 16:13:32 +02:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2017-05-23 21:02:53 -04:00
|
|
|
#if _WIN32_WINNT >= 0x0501
|
|
|
|
/* winraw only available since XP */
|
2018-01-16 22:53:38 +01:00
|
|
|
if (string_is_equal(settings->arrays.input_driver, "raw"))
|
2017-05-19 16:13:32 +02:00
|
|
|
{
|
|
|
|
*input_data = input_winraw.init(joypad_name);
|
|
|
|
if (*input_data)
|
|
|
|
{
|
2018-01-16 22:53:38 +01:00
|
|
|
*input = &input_winraw;
|
2017-05-19 16:13:32 +02:00
|
|
|
dinput_wgl = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 21:02:53 -04:00
|
|
|
#endif
|
2017-05-19 16:13:32 +02:00
|
|
|
|
2018-03-16 21:03:43 +00:00
|
|
|
#ifdef HAVE_DINPUT
|
2017-05-19 16:13:32 +02:00
|
|
|
dinput_wgl = input_dinput.init(joypad_name);
|
|
|
|
*input = dinput_wgl ? &input_dinput : NULL;
|
|
|
|
*input_data = dinput_wgl;
|
2018-03-16 21:03:43 +00:00
|
|
|
#endif
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool gfx_ctx_wgl_has_focus(void *data)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2015-11-17 08:58:49 +01:00
|
|
|
return win32_has_focus();
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
static enum gfx_ctx_api gfx_ctx_wgl_get_api(void *data)
|
|
|
|
{
|
|
|
|
return win32_api;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool gfx_ctx_wgl_bind_api(void *data,
|
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2012-10-24 17:17:01 +02:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_major = major;
|
|
|
|
win32_minor = minor;
|
|
|
|
win32_api = api;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2016-05-16 08:34:56 +02:00
|
|
|
if (api == GFX_CTX_OPENGL_API)
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_VULKAN)
|
|
|
|
if (api == GFX_CTX_VULKAN_API)
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
2012-10-24 17:17:01 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_wgl_show_mouse(void *data, bool state)
|
2013-03-29 13:46:11 +01:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2015-04-10 09:30:18 +02:00
|
|
|
win32_show_cursor(state);
|
2013-03-29 13:46:11 +01:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_wgl_bind_hw_render(void *data, bool enable)
|
2014-04-19 16:21:37 +02:00
|
|
|
{
|
2016-12-02 19:58:39 +01:00
|
|
|
switch (win32_api)
|
2016-03-29 00:45:36 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2016-12-02 19:58:39 +01:00
|
|
|
win32_use_hw_ctx = enable;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2016-12-02 19:58:39 +01:00
|
|
|
if (win32_hdc)
|
|
|
|
wglMakeCurrent(win32_hdc, enable ? win32_hw_hrc : win32_hrc);
|
2016-03-29 00:45:36 +02:00
|
|
|
#endif
|
|
|
|
break;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2016-03-29 00:45:36 +02:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-04-19 16:21:37 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 13:27:45 +02:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
static void *gfx_ctx_wgl_get_context_data(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
2016-12-02 19:58:39 +01:00
|
|
|
return &win32_vk.context;
|
2014-04-19 16:21:37 +02:00
|
|
|
}
|
2016-03-29 13:27:45 +02:00
|
|
|
#endif
|
2014-04-19 16:21:37 +02:00
|
|
|
|
2016-05-05 05:35:35 +02:00
|
|
|
static uint32_t gfx_ctx_wgl_get_flags(void *data)
|
|
|
|
{
|
2019-06-17 14:10:55 +02:00
|
|
|
uint32_t flags = 0;
|
2018-09-12 02:41:45 +02:00
|
|
|
|
|
|
|
switch (win32_api)
|
2016-05-05 17:35:28 +02:00
|
|
|
{
|
2018-09-12 02:41:45 +02:00
|
|
|
case GFX_CTX_OPENGL_API:
|
2018-09-12 03:59:25 +02:00
|
|
|
if (wgl_adaptive_vsync)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC);
|
2018-09-12 02:41:45 +02:00
|
|
|
|
|
|
|
if (win32_core_hw_context_enable)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
|
2019-03-13 14:06:09 +01:00
|
|
|
|
|
|
|
if (string_is_equal(video_driver_get_ident(), "gl1")) { }
|
2019-06-01 21:21:45 +02:00
|
|
|
else if (string_is_equal(video_driver_get_ident(), "glcore"))
|
|
|
|
{
|
2019-06-17 14:10:55 +02:00
|
|
|
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
|
2019-06-01 21:21:45 +02:00
|
|
|
#endif
|
|
|
|
}
|
2019-03-13 14:06:09 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CG
|
|
|
|
if (!win32_core_hw_context_enable)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_CG);
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GLSL
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case GFX_CTX_VULKAN_API:
|
2019-06-17 14:10:55 +02:00
|
|
|
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
|
2019-03-13 14:06:09 +01:00
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
|
|
|
|
#endif
|
2018-09-12 02:41:45 +02:00
|
|
|
break;
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-05 17:35:28 +02:00
|
|
|
}
|
2018-09-12 02:41:45 +02:00
|
|
|
|
2016-05-05 17:50:26 +02:00
|
|
|
return flags;
|
2016-05-05 17:35:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_wgl_set_flags(void *data, uint32_t flags)
|
|
|
|
{
|
2018-09-12 02:41:45 +02:00
|
|
|
switch (win32_api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2019-04-24 03:23:57 +02:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
2018-09-12 03:59:25 +02:00
|
|
|
if (BIT32_GET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC))
|
|
|
|
wgl_adaptive_vsync = true;
|
2018-09-12 02:41:45 +02:00
|
|
|
|
|
|
|
if (BIT32_GET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT))
|
|
|
|
win32_core_hw_context_enable = true;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:35:35 +02:00
|
|
|
}
|
|
|
|
|
2017-08-09 04:17:32 +02:00
|
|
|
static void gfx_ctx_wgl_get_video_output_size(void *data,
|
|
|
|
unsigned *width, unsigned *height)
|
|
|
|
{
|
|
|
|
win32_get_video_output_size(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_wgl_get_video_output_prev(void *data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_wgl_get_video_output_next(void *data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:17:01 +02:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_wgl = {
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_wgl_init,
|
|
|
|
gfx_ctx_wgl_destroy,
|
2018-03-01 21:16:54 +01:00
|
|
|
gfx_ctx_wgl_get_api,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_wgl_bind_api,
|
|
|
|
gfx_ctx_wgl_swap_interval,
|
|
|
|
gfx_ctx_wgl_set_video_mode,
|
|
|
|
gfx_ctx_wgl_get_video_size,
|
2018-04-15 19:33:38 -05:00
|
|
|
win32_get_refresh_rate,
|
2017-08-09 04:17:32 +02:00
|
|
|
gfx_ctx_wgl_get_video_output_size,
|
|
|
|
gfx_ctx_wgl_get_video_output_prev,
|
|
|
|
gfx_ctx_wgl_get_video_output_next,
|
2019-08-29 00:02:50 +02:00
|
|
|
win32_get_metrics,
|
2015-02-24 19:58:14 +01:00
|
|
|
NULL,
|
2017-01-18 17:41:27 +01:00
|
|
|
gfx_ctx_wgl_update_title,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_wgl_check_window,
|
|
|
|
gfx_ctx_wgl_set_resize,
|
|
|
|
gfx_ctx_wgl_has_focus,
|
2019-08-29 00:02:50 +02:00
|
|
|
win32_suppress_screensaver,
|
2019-07-26 06:23:20 +02:00
|
|
|
true, /* has_windowed */
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_wgl_swap_buffers,
|
|
|
|
gfx_ctx_wgl_input_driver,
|
|
|
|
gfx_ctx_wgl_get_proc_address,
|
2015-03-27 23:07:57 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_wgl_show_mouse,
|
2012-10-24 17:17:01 +02:00
|
|
|
"wgl",
|
2016-05-05 05:35:35 +02:00
|
|
|
gfx_ctx_wgl_get_flags,
|
2016-05-05 17:35:28 +02:00
|
|
|
gfx_ctx_wgl_set_flags,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_wgl_bind_hw_render,
|
2016-03-29 13:27:45 +02:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
gfx_ctx_wgl_get_context_data,
|
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
#endif
|
2016-08-31 01:33:35 -04:00
|
|
|
NULL
|
2012-10-24 17:17:01 +02:00
|
|
|
};
|