Skip to content

Commit

Permalink
MESA UWP Integration (#16285)
Browse files Browse the repository at this point in the history
* [WINRT] Enable logging on __WINRT__ and bypass verbosidy in debug

* [UWP] wrong configuration prevents GLES to compile, common functions defines GL symbols

* [UWP] configure project to allow OPENGL on default configuration and copy MESA DLLs into UWP release

* [UWP] add MESA headers

* [UWP] add MESA EGL.lib needed for GLES context. However HAVE_OPENGL is better as GL cores use desktop version, so this is left for reference and to make the solution build with HAVE_OPENGLES

* [UWP] UWP is missing some GDI function definitions, implemented into MESA Gallium

* [UWP] Configure Release project too

* [UWP] Add mesa alpha-2 release dlls

* [UWP] allow griffin and vide_driver to have an OPENGL context

* [UWP] allow wgl context to work with mesa under WINRT

* [UWP] BUG: have to modify height/width getters and align them to MESA because the screen resolution is not right in gl context. Pending further investigation

* [UWP] fix ANGLE build

* [UWP] remove duplicate import code.

* (UWP) Cleanup filters file

* MESA screen destroy fix and Yabasanshiro hack. Align to alpha-2-hack tag

---------

Co-authored-by: Gabriel Morazán <[email protected]>
  • Loading branch information
aerisarn and GABO1423 authored Mar 2, 2024
1 parent 75c0ede commit 8b1e4a1
Show file tree
Hide file tree
Showing 36 changed files with 34,007 additions and 12 deletions.
37 changes: 37 additions & 0 deletions gfx/common/uwpgdi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef UWPGDI_H_
#define UWPGDI_H_


#include <windows.h>

#include <GL/gl.h>

#if !defined(_GDI32_)
#define WINGDIAPI_UWP __declspec(dllimport)
#else
#define WINGDIAPI_UWP __declspec(dllexport)
#endif

#ifdef __cplusplus
extern "C" {
#endif

/*
* Undeclared APIs exported by libgallium on UWP
*/

WINGDIAPI_UWP HGLRC WINAPI wglCreateContext(HDC);
WINGDIAPI_UWP BOOL WINAPI wglDeleteContext(HGLRC);
WINGDIAPI_UWP BOOL WINAPI wglMakeCurrent(HDC, HGLRC);
WINGDIAPI_UWP BOOL APIENTRY wglSwapBuffers(HDC hdc);
WINGDIAPI_UWP PROC APIENTRY wglGetProcAddress(LPCSTR lpszProc);
WINGDIAPI_UWP BOOL APIENTRY wglShareLists(
HGLRC unnamedParam1,
HGLRC unnamedParam2
);

#ifdef __cplusplus
}
#endif

#endif UWPGDI_H_
103 changes: 102 additions & 1 deletion gfx/drivers_context/wgl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#endif
#endif

#ifdef __WINRT__
#include "../common/uwpgdi.h"
#endif

#if (defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)) && !defined(HAVE_OPENGLES)
#include "../common/gl_common.h"
#endif
Expand Down Expand Up @@ -182,7 +186,11 @@ void create_gl_context(HWND hwnd, bool *quit)
bool debug = hwr->debug_context;
#endif

#ifdef __WINRT__
win32_hdc = (HDC)(hwnd);
#else
win32_hdc = GetDC(hwnd);
#endif

win32_setup_pixel_format(win32_hdc, true);

Expand Down Expand Up @@ -456,7 +464,11 @@ static void gfx_ctx_wgl_swap_buffers(void *data)
switch (win32_api)
{
case GFX_CTX_OPENGL_API:
#ifdef __WINRT__
wglSwapBuffers(win32_hdc);
#else
SwapBuffers(win32_hdc);
#endif
break;
case GFX_CTX_OPENGL_ES_API:
#if defined(HAVE_EGL)
Expand Down Expand Up @@ -514,19 +526,25 @@ static void gfx_ctx_wgl_destroy(void *data)

if (window && win32_hdc)
{
#ifndef __WINRT__
ReleaseDC(window, win32_hdc);
#endif
win32_hdc = NULL;
}

#ifndef __WINRT__
if (window)
{
win32_monitor_from_window();
win32_destroy_window();
}

#endif
if (g_win32_flags & WIN32_CMN_FLAG_RESTORE_DESKTOP)
{
#ifndef __WINRT__
win32_monitor_get_info();
#endif
g_win32_flags &= ~WIN32_CMN_FLAG_RESTORE_DESKTOP;
}

Expand All @@ -549,7 +567,9 @@ static void gfx_ctx_wgl_destroy(void *data)

static void *gfx_ctx_wgl_init(void *video_driver)
{
#ifndef __WINRT__
WNDCLASSEX wndclass = {0};
#endif
gfx_ctx_wgl_data_t *wgl = (gfx_ctx_wgl_data_t*)calloc(1, sizeof(*wgl));
uint8_t win32_flags = win32_get_flags();
settings_t *settings = config_get_ptr();
Expand All @@ -568,9 +588,11 @@ static void *gfx_ctx_wgl_init(void *video_driver)
#endif
#endif

#ifndef __WINRT__
win32_window_reset();
win32_monitor_init();


wndclass.lpfnWndProc = wnd_proc_wgl_common;
#ifdef HAVE_DINPUT
if (string_is_equal(settings->arrays.input_driver, "dinput"))
Expand All @@ -586,7 +608,16 @@ static void *gfx_ctx_wgl_init(void *video_driver)
free(wgl);
return NULL;
}

#else
bool quit = false;
create_gl_context(uwp_get_corewindow(), &quit);
if (quit)
{
RARCH_ERR("[UWP WGL]: create_gl_context failed.\n");
free(wgl);
return NULL;
}
#endif
return wgl;
}

Expand All @@ -601,6 +632,7 @@ static bool gfx_ctx_wgl_set_video_mode(void *data,
return false;
}


if (win32_api == GFX_CTX_OPENGL_API)
p_swap_interval = (BOOL (APIENTRY *)(int))gfx_ctx_wgl_get_proc_address("wglSwapIntervalEXT");

Expand Down Expand Up @@ -636,6 +668,25 @@ static void gfx_ctx_wgl_input_driver(void *data,
dinput_wgl = input_driver_init_wrap(&input_dinput, joypad_name);
*input = dinput_wgl ? &input_dinput : NULL;
*input_data = dinput_wgl;
#elif defined(__WINRT__)
/* Plain xinput is supported on UWP, but it
* supports joypad only (uwp driver was added later) */
if (string_is_equal(settings->arrays.input_driver, "xinput"))
{
void* xinput = input_driver_init_wrap(&input_xinput, joypad_name);
*input = xinput ? (input_driver_t*)&input_xinput : NULL;
*input_data = xinput;
}
else
{
void* uwp = input_driver_init_wrap(&input_uwp, joypad_name);
*input = uwp ? (input_driver_t*)&input_uwp : NULL;
*input_data = uwp;
}
#elif defined(_XBOX)
void* xinput = input_driver_init_wrap(&input_xinput, joypad_name);
*input = xinput ? (input_driver_t*)&input_xinput : NULL;
*input_data = xinput;
#endif
}

Expand Down Expand Up @@ -762,6 +813,56 @@ static void gfx_ctx_wgl_set_flags(void *data, uint32_t flags)
static void gfx_ctx_wgl_get_video_output_prev(void *data) { }
static void gfx_ctx_wgl_get_video_output_next(void *data) { }

//TODO: maybe create an uwp_mesa_common.c?
#ifdef __WINRT__

static void win32_get_video_size(void* data,
unsigned* width, unsigned* height)
{
bool quit = false;
bool resize = false;
win32_check_window(NULL, &quit, &resize, width, height);
width = uwp_get_width();
height = uwp_get_height();
}

void win32_get_video_output_size(void* data, unsigned* width, unsigned* height, char* desc, size_t desc_len)
{
win32_get_video_size(data, width, height);
}

bool win32_suspend_screensaver(void* data, bool enable)
{
return true;
}

float win32_get_refresh_rate(void* data)
{
return 60.0;
}

#define win32_get_refresh_rate NULL

HWND win32_get_window(void)
{
return (HWND)uwp_get_corewindow();
}

/* TODO/FIXME - static globals */
uint8_t g_win32_flags = 0;

uint8_t win32_get_flags(void)
{
return g_win32_flags;
}

void win32_setup_pixel_format(HDC hdc, bool supports_gl)
{
//NTD, already done by mesa
}

#endif

const gfx_ctx_driver_t gfx_ctx_wgl = {
gfx_ctx_wgl_init,
gfx_ctx_wgl_destroy,
Expand Down
Loading

0 comments on commit 8b1e4a1

Please sign in to comment.