2012-10-24 15:17:01 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:41:52 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2016-12-03 04:36:23 +00:00
|
|
|
*
|
2012-10-24 15:17:01 +00: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 05:59:53 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2015-01-07 17:06:50 +00:00
|
|
|
/* Win32/WGL context. */
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2015-01-07 17:06:50 +00:00
|
|
|
/* necessary for mingw32 multimon defines: */
|
2013-06-20 14:06:13 +00:00
|
|
|
#ifndef _WIN32_WINNT
|
|
|
|
#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K
|
|
|
|
#endif
|
|
|
|
|
2016-12-03 04:36:23 +00:00
|
|
|
#define UNICODE
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
2015-09-05 12:10:16 +00:00
|
|
|
#include <string.h>
|
2015-10-20 00:44:28 +00:00
|
|
|
#include <math.h>
|
2015-09-05 12:10:16 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commdlg.h>
|
|
|
|
|
2015-09-05 12:38:55 +00:00
|
|
|
#include <dynamic/dylib.h>
|
|
|
|
|
2016-09-06 17:39:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-04-10 04:33:18 +00:00
|
|
|
#include "../../dynamic.h"
|
2015-03-15 01:47:23 +00:00
|
|
|
#include "../../runloop.h"
|
2015-01-12 20:53:04 +00:00
|
|
|
#include "../video_context_driver.h"
|
2015-11-17 07:01:33 +00:00
|
|
|
|
2015-04-09 03:16:02 +00:00
|
|
|
#include "../common/win32_common.h"
|
2015-11-17 07:01:33 +00:00
|
|
|
|
2016-05-16 06:34:56 +00:00
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
#include "../common/gl_common.h"
|
|
|
|
#endif
|
|
|
|
|
2016-03-28 22:45:36 +00:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
#include "../common/vulkan_common.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-16 06:34:56 +00:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_VULKAN)
|
2015-11-11 16:36:52 +00: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 12:10:16 +00:00
|
|
|
#endif
|
2016-05-16 06:34:56 +00:00
|
|
|
#endif
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-05-16 06:34:56 +00:00
|
|
|
#if defined(HAVE_OPENGL)
|
2015-11-20 13:32:46 +00:00
|
|
|
typedef HGLRC (APIENTRY *wglCreateContextAttribsProc)(HDC, HGLRC, const int*);
|
2016-05-16 06:34:56 +00:00
|
|
|
static wglCreateContextAttribsProc pcreate_context;
|
|
|
|
#endif
|
2015-11-20 13:32:46 +00:00
|
|
|
static BOOL (APIENTRY *p_swap_interval)(int);
|
|
|
|
|
2016-12-02 18:58:39 +00: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;
|
2015-11-11 04:32:00 +00:00
|
|
|
|
2016-03-28 22:45:36 +00:00
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00:00
|
|
|
static gfx_ctx_vulkan_data_t win32_vk;
|
2016-03-28 22:45:36 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
static unsigned win32_major = 0;
|
|
|
|
static unsigned win32_minor = 0;
|
|
|
|
static unsigned win32_interval = 0;
|
|
|
|
static enum gfx_ctx_api win32_api = GFX_CTX_NONE;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
static dylib_t dll_handle = NULL; /* Handle to OpenGL32.dll */
|
2015-02-08 00:24:44 +00:00
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
static void setup_pixel_format(HDC hdc)
|
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd = {0};
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 32;
|
|
|
|
pfd.cDepthBits = 0;
|
|
|
|
pfd.cStencilBits = 0;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
|
|
|
|
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
|
|
|
|
}
|
|
|
|
|
2016-05-16 06:34:56 +00:00
|
|
|
#if defined(HAVE_OPENGL)
|
2016-03-28 22:45:36 +00:00
|
|
|
static void create_gl_context(HWND hwnd, bool *quit)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00: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;
|
|
|
|
dll_handle = dylib_load("OpenGL32.dll");
|
|
|
|
win32_hdc = GetDC(hwnd);
|
2016-03-04 19:49:55 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
setup_pixel_format(win32_hdc);
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2014-04-19 14:21:37 +00:00
|
|
|
#ifdef GL_DEBUG
|
2015-01-10 16:51:00 +00:00
|
|
|
debug = true;
|
2014-04-19 14:21:37 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_hrc)
|
2015-01-10 16:51:00 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[WGL]: Using cached GL context.\n");
|
2016-05-08 12:10:28 +00:00
|
|
|
video_driver_set_video_cache_context_ack();
|
2015-01-10 16:51:00 +00:00
|
|
|
}
|
|
|
|
else
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_hrc = wglCreateContext(win32_hdc);
|
2014-10-27 13:35:23 +00:00
|
|
|
|
|
|
|
/* We'll create shared context later if not. */
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_hrc && !core_context && !debug)
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_hw_hrc = wglCreateContext(win32_hdc);
|
|
|
|
if (win32_hw_hrc)
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
if (!wglShareLists(win32_hrc, win32_hw_hrc))
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[WGL]: Failed to share contexts.\n");
|
2015-11-17 22:14:59 +00:00
|
|
|
*quit = true;
|
2014-04-19 14:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-11-17 22:14:59 +00:00
|
|
|
*quit = true;
|
2014-04-19 14:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 21:18:05 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_hrc)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
if (wglMakeCurrent(win32_hdc, win32_hrc))
|
2015-11-17 08:33:27 +00:00
|
|
|
g_inited = true;
|
2012-10-24 15:17:01 +00:00
|
|
|
else
|
2015-11-17 22:14:59 +00:00
|
|
|
*quit = true;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
else
|
2013-06-23 11:05:33 +00:00
|
|
|
{
|
2015-11-17 22:14:59 +00:00
|
|
|
*quit = true;
|
|
|
|
return;
|
2013-06-23 11:05:33 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:04:26 +00:00
|
|
|
if (core_context || debug)
|
2013-06-23 11:05:33 +00:00
|
|
|
{
|
2013-08-14 12:04:26 +00:00
|
|
|
int attribs[16];
|
|
|
|
int *aptr = attribs;
|
|
|
|
|
|
|
|
if (core_context)
|
|
|
|
{
|
|
|
|
*aptr++ = WGL_CONTEXT_MAJOR_VERSION_ARB;
|
2016-12-02 18:58:39 +00:00
|
|
|
*aptr++ = win32_major;
|
2013-08-14 12:04:26 +00:00
|
|
|
*aptr++ = WGL_CONTEXT_MINOR_VERSION_ARB;
|
2016-12-02 18:58:39 +00:00
|
|
|
*aptr++ = win32_minor;
|
2014-04-20 11:54:29 +00:00
|
|
|
|
2014-10-27 13:35:23 +00:00
|
|
|
/* Technically, we don't have core/compat until 3.2.
|
2016-12-03 04:36:23 +00:00
|
|
|
* Version 3.1 is either compat or not depending
|
2014-10-27 13:35:23 +00:00
|
|
|
* on GL_ARB_compatibility.
|
|
|
|
*/
|
2016-12-02 18:58:39 +00:00
|
|
|
if ((win32_major * 1000 + win32_minor) >= 3002)
|
2014-04-20 11:54:29 +00:00
|
|
|
{
|
|
|
|
*aptr++ = WGL_CONTEXT_PROFILE_MASK_ARB;
|
|
|
|
*aptr++ = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
|
|
|
|
}
|
2013-08-14 12:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
*aptr++ = WGL_CONTEXT_FLAGS_ARB;
|
|
|
|
*aptr++ = WGL_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aptr = 0;
|
2013-06-23 11:05:33 +00:00
|
|
|
|
|
|
|
if (!pcreate_context)
|
2014-10-27 13:35:23 +00:00
|
|
|
pcreate_context = (wglCreateContextAttribsProc)
|
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
2013-06-23 11:05:33 +00:00
|
|
|
|
|
|
|
if (pcreate_context)
|
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
HGLRC context = pcreate_context(win32_hdc, NULL, attribs);
|
2013-06-23 11:05:33 +00:00
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
wglMakeCurrent(NULL, NULL);
|
2016-12-02 18:58:39 +00:00
|
|
|
wglDeleteContext(win32_hrc);
|
|
|
|
win32_hrc = context;
|
|
|
|
if (!wglMakeCurrent(win32_hdc, win32_hrc))
|
2015-11-17 22:14:59 +00:00
|
|
|
*quit = true;
|
2013-06-23 11:05:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
RARCH_ERR("[WGL]: Failed to create core context. Falling back to legacy context.\n");
|
2014-04-19 14:21:37 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_use_hw_ctx)
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_hw_hrc = pcreate_context(win32_hdc, context, attribs);
|
|
|
|
if (!win32_hw_hrc)
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[WGL]: Failed to create shared context.\n");
|
2015-11-17 22:14:59 +00:00
|
|
|
*quit = true;
|
2014-04-19 14:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 11:05:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
RARCH_ERR("[WGL]: wglCreateContextAttribsARB not supported.\n");
|
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
2016-05-16 06:34:56 +00:00
|
|
|
#endif
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-03-28 22:45:36 +00:00
|
|
|
void create_graphics_context(HWND hwnd, bool *quit)
|
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2016-05-16 06:34:56 +00:00
|
|
|
#if defined(HAVE_OPENGL)
|
2016-03-28 22:45:36 +00:00
|
|
|
create_gl_context(hwnd, quit);
|
2016-05-16 06:34:56 +00:00
|
|
|
#endif
|
2016-03-28 22:45:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
RECT rect;
|
|
|
|
unsigned width = rect.right - rect.left;
|
|
|
|
unsigned height = rect.bottom - rect.top;
|
|
|
|
GetClientRect(hwnd, &rect);
|
|
|
|
HINSTANCE instance = GetModuleHandle(NULL);
|
2016-12-02 18:58:39 +00:00
|
|
|
if (!vulkan_surface_create(&win32_vk, VULKAN_WSI_WIN32,
|
2016-03-28 22:45:36 +00:00
|
|
|
&instance, &hwnd,
|
2016-12-02 18:58:39 +00:00
|
|
|
width, height, win32_interval))
|
2016-03-28 22:45:36 +00:00
|
|
|
*quit = true;
|
2016-03-29 16:02:32 +00:00
|
|
|
g_inited = true;
|
2016-03-28 22:45:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
2016-05-16 06:34:56 +00:00
|
|
|
break;
|
2016-03-28 22:45:36 +00:00
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 17:29:06 +00:00
|
|
|
void *dinput_wgl;
|
2013-11-05 19:49:04 +00:00
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_wgl_swap_interval(void *data, unsigned interval)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
#ifdef HAVE_OPENGL
|
2016-12-17 11:06:43 +00:00
|
|
|
win32_interval = interval;
|
2016-12-02 18:58:39 +00:00
|
|
|
if (!win32_hrc)
|
2016-03-28 22:45:36 +00:00
|
|
|
return;
|
|
|
|
if (!p_swap_interval)
|
|
|
|
return;
|
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
RARCH_LOG("[WGL]: wglSwapInterval(%u)\n", win32_interval);
|
|
|
|
if (!p_swap_interval(win32_interval))
|
2016-03-28 22:45:36 +00:00
|
|
|
RARCH_WARN("[WGL]: wglSwapInterval() failed.\n");
|
|
|
|
#endif
|
|
|
|
break;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-03-28 22:45:36 +00:00
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_interval != interval)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_interval = interval;
|
|
|
|
if (win32_vk.swapchain)
|
|
|
|
win32_vk.need_new_swapchain = true;
|
2016-03-28 22:45:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
2016-12-17 11:06:43 +00:00
|
|
|
win32_interval = interval;
|
2016-03-28 22:45:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_wgl_check_window(void *data, bool *quit,
|
2012-10-24 15:17:01 +00:00
|
|
|
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
|
|
|
{
|
2015-11-11 18:41:32 +00:00
|
|
|
win32_check_window(quit, resize, width, height);
|
2016-03-28 22:45:36 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_vk.need_new_swapchain)
|
2016-03-28 22:45:36 +00:00
|
|
|
*resize = true;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 13:59:15 +00:00
|
|
|
static void gfx_ctx_wgl_swap_buffers(void *data, video_frame_info_t video_info)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2016-03-28 22:45:36 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
#ifdef HAVE_OPENGL
|
2016-12-02 18:58:39 +00:00
|
|
|
SwapBuffers(win32_hdc);
|
2016-03-28 22:45:36 +00:00
|
|
|
#endif
|
2016-05-16 06:34:56 +00:00
|
|
|
break;
|
2016-03-28 22:45:36 +00:00
|
|
|
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00:00
|
|
|
vulkan_present(&win32_vk, win32_vk.context.current_swapchain_index);
|
|
|
|
vulkan_acquire_next_image(&win32_vk);
|
2016-03-28 22:45:36 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
static bool gfx_ctx_wgl_set_resize(void *data,
|
2014-10-08 16:09:01 +00:00
|
|
|
unsigned width, unsigned height)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-10-24 15:17:01 +00:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
2016-03-28 22:45:36 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00:00
|
|
|
if (!vulkan_create_swapchain(&win32_vk, width, height, win32_interval))
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[Win32/Vulkan]: Failed to update swapchain.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_vk.context.invalid_swapchain = true;
|
|
|
|
win32_vk.need_new_swapchain = false;
|
2016-03-28 22:45:36 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 13:42:07 +00:00
|
|
|
static void gfx_ctx_wgl_update_window_title(void *data, video_frame_info_t video_info)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-11-06 17:36:58 +00:00
|
|
|
char buf[128];
|
|
|
|
char buf_fps[128];
|
2016-06-06 06:01:26 +00:00
|
|
|
const ui_window_t *window = ui_companion_driver_get_window_ptr();
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-11-06 17:36:58 +00:00
|
|
|
buf[0] = buf_fps[0] = '\0';
|
|
|
|
|
2017-01-09 14:42:14 +00:00
|
|
|
if (window && video_monitor_get_fps(video_info, buf, sizeof(buf),
|
2015-03-07 22:03:56 +00:00
|
|
|
buf_fps, sizeof(buf_fps)))
|
2016-06-06 06:01:26 +00:00
|
|
|
window->set_title(&main_window, buf);
|
2017-01-09 13:42:07 +00:00
|
|
|
if (video_info.fps_show)
|
2016-12-22 22:36:11 +00:00
|
|
|
runloop_msg_queue_push(buf_fps, 1, 1, false);
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-14 15:39:27 +00:00
|
|
|
static void gfx_ctx_wgl_get_video_size(void *data,
|
|
|
|
unsigned *width, unsigned *height)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2015-11-17 08:41:18 +00:00
|
|
|
HWND window = win32_get_window();
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2015-11-17 08:41:18 +00:00
|
|
|
if (!window)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-01-16 15:22:19 +00:00
|
|
|
RECT mon_rect;
|
2012-10-31 20:36:17 +00:00
|
|
|
MONITORINFOEX current_mon;
|
2016-12-02 18:58:39 +00:00
|
|
|
unsigned mon_id = 0;
|
|
|
|
HMONITOR hm_to_use = NULL;
|
2012-10-31 20:36:17 +00:00
|
|
|
|
2015-11-11 16:47:56 +00:00
|
|
|
win32_monitor_info(¤t_mon, &hm_to_use, &mon_id);
|
2015-01-16 15:22:19 +00:00
|
|
|
mon_rect = current_mon.rcMonitor;
|
2012-10-31 20:36:17 +00:00
|
|
|
*width = mon_rect.right - mon_rect.left;
|
|
|
|
*height = mon_rect.bottom - mon_rect.top;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*width = g_resize_width;
|
|
|
|
*height = g_resize_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 15:18:57 +00:00
|
|
|
static void *gfx_ctx_wgl_init(void *video_driver)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-01-10 16:51:00 +00:00
|
|
|
WNDCLASSEX wndclass = {0};
|
|
|
|
|
2015-12-08 15:18:57 +00:00
|
|
|
(void)video_driver;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
if (g_inited)
|
2015-12-08 15:18:57 +00:00
|
|
|
return NULL;
|
2016-12-03 04:36:23 +00:00
|
|
|
|
2015-11-17 09:16:16 +00:00
|
|
|
win32_window_reset();
|
2015-11-11 16:36:52 +00:00
|
|
|
win32_monitor_init();
|
2015-11-28 20:50:28 +00:00
|
|
|
|
|
|
|
wndclass.lpfnWndProc = WndProcGL;
|
2015-11-19 07:30:37 +00:00
|
|
|
if (!win32_window_init(&wndclass, true, NULL))
|
2015-12-08 15:18:57 +00:00
|
|
|
return NULL;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00:00
|
|
|
if (!vulkan_context_init(&win32_vk, VULKAN_WSI_WIN32))
|
2016-03-28 22:45:36 +00:00
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
break;
|
2016-05-16 06:25:14 +00:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2016-03-28 22:45:36 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 15:18:57 +00:00
|
|
|
return (void*)"wgl";
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_wgl_destroy(void *data)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-11-17 08:41:18 +00:00
|
|
|
HWND window = win32_get_window();
|
2015-03-18 18:40:00 +00:00
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-03-28 22:45:36 +00:00
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
#ifdef HAVE_OPENGL
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_hrc)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
glFinish();
|
|
|
|
wglMakeCurrent(NULL, NULL);
|
2013-06-23 21:18:05 +00:00
|
|
|
|
2016-05-16 05:51:01 +00:00
|
|
|
if (!video_driver_is_video_cache_context())
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_hw_hrc)
|
|
|
|
wglDeleteContext(win32_hw_hrc);
|
|
|
|
wglDeleteContext(win32_hrc);
|
|
|
|
win32_hrc = NULL;
|
|
|
|
win32_hw_hrc = NULL;
|
2016-03-28 22:45:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_VULKAN_API:
|
|
|
|
#ifdef HAVE_VULKAN
|
2016-12-02 18:58:39 +00: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-28 22:45:36 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
if (window && win32_hdc)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
ReleaseDC(window, win32_hdc);
|
|
|
|
win32_hdc = NULL;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 08:41:18 +00:00
|
|
|
if (window)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-06-04 03:54:33 +00:00
|
|
|
win32_monitor_from_window();
|
2015-11-17 08:44:26 +00:00
|
|
|
win32_destroy_window();
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_restore_desktop)
|
|
|
|
{
|
2015-11-11 16:36:52 +00:00
|
|
|
win32_monitor_get_info();
|
2016-05-05 15:35:28 +00:00
|
|
|
g_restore_desktop = false;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_core_hw_context_enable = false;
|
|
|
|
g_inited = false;
|
|
|
|
win32_major = 0;
|
|
|
|
win32_minor = 0;
|
|
|
|
p_swap_interval = NULL;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 13:32:46 +00:00
|
|
|
static bool gfx_ctx_wgl_set_video_mode(void *data,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
2016-01-08 04:13:10 +00:00
|
|
|
if (!win32_set_video_mode(NULL, width, height, fullscreen))
|
2016-03-29 15:57:13 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[WGL]: win32_set_video_mode failed.\n");
|
2015-11-20 13:32:46 +00:00
|
|
|
goto error;
|
2016-03-29 15:57:13 +00:00
|
|
|
}
|
2015-11-20 13:32:46 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
p_swap_interval = (BOOL (APIENTRY *)(int))
|
|
|
|
wglGetProcAddress("wglSwapIntervalEXT");
|
|
|
|
#endif
|
|
|
|
break;
|
2015-11-20 13:32:46 +00:00
|
|
|
|
2016-03-29 11:27:45 +00:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2016-03-28 22:45:36 +00:00
|
|
|
}
|
2015-11-20 13:32:46 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
gfx_ctx_wgl_swap_interval(data, win32_interval);
|
2015-11-20 13:32:46 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gfx_ctx_wgl_destroy(data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_wgl_input_driver(void *data,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2017-01-10 18:48:19 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
dinput_wgl = input_dinput.init(settings->input.joypad_driver);
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2017-01-10 18:48:19 +00:00
|
|
|
*input = dinput_wgl ? &input_dinput : NULL;
|
|
|
|
*input_data = dinput_wgl;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_wgl_has_focus(void *data)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-11-17 07:58:49 +00:00
|
|
|
return win32_has_focus();
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool gfx_ctx_wgl_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
2015-10-10 06:13:58 +00:00
|
|
|
return win32_suppress_screensaver(data, enable);
|
2015-01-18 21:32:14 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_wgl_has_windowed(void *data)
|
2014-10-08 15:23:02 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-05-16 06:34:56 +00:00
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_VULKAN)
|
2016-11-14 16:23:11 +00:00
|
|
|
gfx_ctx_proc_t func = (gfx_ctx_proc_t)wglGetProcAddress(symbol);
|
2015-02-08 00:24:44 +00:00
|
|
|
if (func)
|
2016-11-14 16:23:11 +00:00
|
|
|
return func;
|
2016-05-16 06:34:56 +00:00
|
|
|
#endif
|
2015-09-05 12:38:55 +00:00
|
|
|
return (gfx_ctx_proc_t)GetProcAddress((HINSTANCE)dll_handle, symbol);
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 20:06:33 +00:00
|
|
|
static bool gfx_ctx_wgl_get_metrics(void *data,
|
2016-12-03 04:36:23 +00:00
|
|
|
enum display_metric_types type, float *value)
|
2015-04-08 20:06:33 +00:00
|
|
|
{
|
2015-04-09 03:19:29 +00:00
|
|
|
return win32_get_metrics(data, type, value);
|
2015-04-08 20:06:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_wgl_bind_api(void *data,
|
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_major = major;
|
|
|
|
win32_minor = minor;
|
|
|
|
win32_api = api;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-05-16 06:34:56 +00:00
|
|
|
#if defined(HAVE_OPENGL)
|
|
|
|
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 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_wgl_show_mouse(void *data, bool state)
|
2013-03-29 12:46:11 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2015-04-10 07:30:18 +00:00
|
|
|
win32_show_cursor(state);
|
2013-03-29 12:46:11 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_wgl_bind_hw_render(void *data, bool enable)
|
2014-04-19 14:21:37 +00:00
|
|
|
{
|
2016-12-02 18:58:39 +00:00
|
|
|
switch (win32_api)
|
2016-03-28 22:45:36 +00:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
#ifdef HAVE_OPENGL
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_use_hw_ctx = enable;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_hdc)
|
|
|
|
wglMakeCurrent(win32_hdc, enable ? win32_hw_hrc : win32_hrc);
|
2016-03-28 22:45:36 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-03-28 22:45:36 +00:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-04-19 14:21:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 11:27:45 +00:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
static void *gfx_ctx_wgl_get_context_data(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
2016-12-02 18:58:39 +00:00
|
|
|
return &win32_vk.context;
|
2014-04-19 14:21:37 +00:00
|
|
|
}
|
2016-03-29 11:27:45 +00:00
|
|
|
#endif
|
2014-04-19 14:21:37 +00:00
|
|
|
|
2016-05-05 03:35:35 +00:00
|
|
|
static uint32_t gfx_ctx_wgl_get_flags(void *data)
|
|
|
|
{
|
2016-05-05 15:35:28 +00:00
|
|
|
uint32_t flags = 0;
|
2016-12-02 18:58:39 +00:00
|
|
|
if (win32_core_hw_context_enable)
|
2016-05-05 15:35:28 +00:00
|
|
|
{
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_NONE);
|
|
|
|
}
|
2016-05-05 15:50:26 +00:00
|
|
|
return flags;
|
2016-05-05 15:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_wgl_set_flags(void *data, uint32_t flags)
|
|
|
|
{
|
|
|
|
if (BIT32_GET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT))
|
2016-12-02 18:58:39 +00:00
|
|
|
win32_core_hw_context_enable = true;
|
2016-05-05 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_wgl = {
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_wgl_init,
|
|
|
|
gfx_ctx_wgl_destroy,
|
|
|
|
gfx_ctx_wgl_bind_api,
|
|
|
|
gfx_ctx_wgl_swap_interval,
|
|
|
|
gfx_ctx_wgl_set_video_mode,
|
|
|
|
gfx_ctx_wgl_get_video_size,
|
2015-02-24 20:36:23 +00:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-08 20:06:33 +00:00
|
|
|
gfx_ctx_wgl_get_metrics,
|
2015-02-24 18:58:14 +00:00
|
|
|
NULL,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_wgl_update_window_title,
|
|
|
|
gfx_ctx_wgl_check_window,
|
|
|
|
gfx_ctx_wgl_set_resize,
|
|
|
|
gfx_ctx_wgl_has_focus,
|
2015-01-18 21:32:14 +00:00
|
|
|
gfx_ctx_wgl_suppress_screensaver,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_wgl_has_windowed,
|
|
|
|
gfx_ctx_wgl_swap_buffers,
|
|
|
|
gfx_ctx_wgl_input_driver,
|
|
|
|
gfx_ctx_wgl_get_proc_address,
|
2015-03-27 22:07:57 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_wgl_show_mouse,
|
2012-10-24 15:17:01 +00:00
|
|
|
"wgl",
|
2016-05-05 03:35:35 +00:00
|
|
|
gfx_ctx_wgl_get_flags,
|
2016-05-05 15:35:28 +00:00
|
|
|
gfx_ctx_wgl_set_flags,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_wgl_bind_hw_render,
|
2016-03-29 11:27:45 +00:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
gfx_ctx_wgl_get_context_data,
|
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
#endif
|
2016-08-31 05:33:35 +00:00
|
|
|
NULL
|
2012-10-24 15:17:01 +00:00
|
|
|
};
|
|
|
|
|