Create context get_api function

This commit is contained in:
twinaphex 2018-03-01 21:16:54 +01:00
parent ba0e6bcdea
commit 16c1bd7a03
23 changed files with 295 additions and 69 deletions

View File

@ -366,11 +366,18 @@ static void android_gfx_ctx_input_driver(void *data,
*input_data = androidinput;
}
static enum gfx_ctx_api android_gfx_ctx_get_api(void *data)
{
return android_api;
}
static bool android_gfx_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
unsigned version;
android_api = api;
switch (api)
{
case GFX_CTX_OPENGL_API:
@ -385,15 +392,11 @@ static bool android_gfx_ctx_bind_api(void *data,
g_es3 = true;
if (api == GFX_CTX_OPENGL_ES_API)
{
android_api = api;
return true;
}
#endif
break;
case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
android_api = api;
return true;
#else
break;
@ -594,6 +597,7 @@ static void android_gfx_ctx_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_android = {
android_gfx_ctx_init,
android_gfx_ctx_destroy,
android_gfx_ctx_get_api,
android_gfx_ctx_bind_api,
android_gfx_ctx_set_swap_interval,
android_gfx_ctx_set_video_mode,

View File

@ -54,6 +54,8 @@ extern CGLError CGLSetSurface(CGLContextObj gl, CGSConnectionID cid, CGSWindowID
}
#endif
static enum gfx_ctx_api cgl_api = GFX_CTX_NONE;
typedef struct gfx_ctx_cgl_data
{
CGLContextObj glCtx;
@ -171,6 +173,11 @@ static bool gfx_ctx_cgl_suppress_screensaver(void *data, bool enable)
return false;
}
static enum gfx_ctx_api gfx_ctx_cgl_get_api(void *data)
{
return cgl_api;
}
static bool gfx_ctx_cgl_bind_api(void *data, enum gfx_ctx_api api,
unsigned major, unsigned minor)
{
@ -179,7 +186,13 @@ static bool gfx_ctx_cgl_bind_api(void *data, enum gfx_ctx_api api,
(void)major;
(void)minor;
return api == GFX_CTX_OPENGL_API;
if (api == GFX_CTX_OPENGL_API)
{
cgl_api = api;
return true;
}
return false;
}
static void gfx_ctx_cgl_show_mouse(void *data, bool state)
@ -325,6 +338,7 @@ static void gfx_ctx_cgl_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_cgl = {
gfx_ctx_cgl_init,
gfx_ctx_cgl_destroy,
gfx_ctx_cgl_get_api,
gfx_ctx_cgl_bind_api,
gfx_ctx_cgl_swap_interval,
gfx_ctx_cgl_set_video_mode,

View File

@ -85,6 +85,8 @@
#define RAScreen NSScreen
#endif
static enum gfx_ctx_api cocoagl_api = GFX_CTX_NONE;
typedef struct cocoa_ctx_data
{
bool core_hw_context_enable;
@ -275,6 +277,11 @@ static void cocoagl_gfx_ctx_destroy(void *data)
free(cocoa_ctx);
}
static enum gfx_ctx_api cocoagl_gfx_ctx_get_api(void *data)
{
return cocoagl_api;
}
static bool cocoagl_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
@ -286,8 +293,9 @@ static bool cocoagl_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned
return false;
#endif
g_minor = minor;
g_major = major;
cocoagl_api = api;
g_minor = minor;
g_major = major;
return true;
}
@ -653,6 +661,7 @@ static void cocoagl_gfx_ctx_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_cocoagl = {
cocoagl_gfx_ctx_init,
cocoagl_gfx_ctx_destroy,
cocoagl_gfx_ctx_get_api,
cocoagl_gfx_ctx_bind_api,
cocoagl_gfx_ctx_swap_interval,
cocoagl_gfx_ctx_set_video_mode,

View File

@ -58,8 +58,15 @@
static bool widescreen_mode = false;
#endif
typedef struct gfx_ctx_d3d_data
{
void *empty;
} gfx_ctx_d3d_data_t;
void *dinput;
static enum gfx_ctx_api d3d_api = GFX_CTX_NONE;
static bool gfx_ctx_d3d_set_resize(void *data,
unsigned new_width, unsigned new_height)
{
@ -172,6 +179,11 @@ static bool gfx_ctx_d3d_has_windowed(void *data)
#endif
}
static enum gfx_ctx_api gfx_ctx_d3d_get_api(void *data)
{
return d3d_api;
}
static bool gfx_ctx_d3d_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -179,6 +191,8 @@ static bool gfx_ctx_d3d_bind_api(void *data,
(void)major;
(void)minor;
d3d_api = api;
switch (api)
{
case GFX_CTX_DIRECT3D8_API:
@ -198,16 +212,24 @@ static bool gfx_ctx_d3d_bind_api(void *data,
static void *gfx_ctx_d3d_init(video_frame_info_t *video_info, void *video_driver)
{
gfx_ctx_d3d_data_t *d3d = (gfx_ctx_d3d_data_t*)calloc(1, sizeof(*d3d));
if (!d3d)
return NULL;
#ifndef _XBOX
win32_monitor_init();
#endif
return video_driver;
return d3d;
}
static void gfx_ctx_d3d_destroy(void *data)
{
(void)data;
gfx_ctx_d3d_data_t *d3d = (gfx_ctx_d3d_data_t*)data;
if (d3d)
free(d3d);
}
static void gfx_ctx_d3d_input_driver(void *data,
@ -388,6 +410,7 @@ static void gfx_ctx_d3d_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_d3d = {
gfx_ctx_d3d_init,
gfx_ctx_d3d_destroy,
gfx_ctx_d3d_get_api,
gfx_ctx_d3d_bind_api,
gfx_ctx_d3d_swap_interval,
gfx_ctx_d3d_set_video_mode,

View File

@ -789,16 +789,21 @@ static bool gfx_ctx_drm_suppress_screensaver(void *data, bool enable)
return false;
}
static enum gfx_ctx_api gfx_ctx_drm_get_api(void *data)
{
return drm_api;
}
static bool gfx_ctx_drm_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)video_driver;
drm_api = api;
#ifdef HAVE_EGL
g_egl_major = major;
g_egl_minor = minor;
#endif
drm_api = api;
switch (api)
{

View File

@ -47,6 +47,7 @@ typedef struct
static int emscripten_initial_width;
static int emscripten_initial_height;
static enum gfx_ctx_api emscripten_api = GFX_CTX_NONE;
static void gfx_ctx_emscripten_swap_interval(void *data, unsigned interval)
{
@ -254,6 +255,11 @@ static bool gfx_ctx_emscripten_set_video_mode(void *data,
return true;
}
static enum gfx_ctx_api gfx_ctx_emscripten_get_api(void *data)
{
return emscripten_api;
}
static bool gfx_ctx_emscripten_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -261,6 +267,8 @@ static bool gfx_ctx_emscripten_bind_api(void *data,
(void)major;
(void)minor;
emscripten_api = api;
switch (api)
{
case GFX_CTX_OPENGL_ES_API:
@ -363,6 +371,7 @@ static void gfx_ctx_emscripten_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_emscripten = {
gfx_ctx_emscripten_init,
gfx_ctx_emscripten_destroy,
gfx_ctx_emscripten_get_api,
gfx_ctx_emscripten_bind_api,
gfx_ctx_emscripten_swap_interval,
gfx_ctx_emscripten_set_video_mode,

View File

@ -48,6 +48,11 @@ static unsigned win32_gdi_minor = 0;
static unsigned win32_gdi_interval = 0;
static enum gfx_ctx_api win32_gdi_api = GFX_CTX_NONE;
typedef struct gfx_ctx_gdi_data
{
void *empty;
} gfx_ctx_gdi_data_t;
void *dinput_gdi;
static void setup_gdi_pixel_format(HDC hdc)
@ -130,19 +135,21 @@ static void gfx_ctx_gdi_get_video_size(void *data,
static void *gfx_ctx_gdi_init(
video_frame_info_t *video_info, void *video_driver)
{
WNDCLASSEX wndclass = {0};
WNDCLASSEX wndclass = {0};
gfx_ctx_gdi_data_t *gdi = (gfx_ctx_gdi_data_t*)calloc(1, sizeof(*gdi));
(void)video_driver;
if (!gdi)
return NULL;
if (g_inited)
return NULL;
goto error;
win32_window_reset();
win32_monitor_init();
wndclass.lpfnWndProc = WndProcGDI;
if (!win32_window_init(&wndclass, true, NULL))
return NULL;
goto error;
switch (win32_gdi_api)
{
@ -151,14 +158,18 @@ static void *gfx_ctx_gdi_init(
break;
}
return (void*)"gdi";
return gdi;
error:
if (gdi)
free(gdi);
return NULL;
}
static void gfx_ctx_gdi_destroy(void *data)
{
HWND window = win32_get_window();
(void)data;
gfx_ctx_gdi_data_t *gdi = (gfx_ctx_gdi_data_t*)data;
HWND window = win32_get_window();
switch (win32_gdi_api)
{
@ -185,6 +196,9 @@ static void gfx_ctx_gdi_destroy(void *data)
g_restore_desktop = false;
}
if (gdi)
free(gdi);
g_inited = false;
win32_gdi_major = 0;
win32_gdi_minor = 0;
@ -271,6 +285,11 @@ static bool gfx_ctx_gdi_get_metrics(void *data,
return win32_get_metrics(data, type, value);
}
static enum gfx_ctx_api gfx_ctx_gdi_get_api(void *data)
{
return win32_gdi_api;
}
static bool gfx_ctx_gdi_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -328,6 +347,7 @@ void create_gdi_context(HWND hwnd, bool *quit)
const gfx_ctx_driver_t gfx_ctx_gdi = {
gfx_ctx_gdi_init,
gfx_ctx_gdi_destroy,
gfx_ctx_gdi_get_api,
gfx_ctx_gdi_bind_api,
gfx_ctx_gdi_swap_interval,
gfx_ctx_gdi_set_video_mode,

View File

@ -86,6 +86,11 @@ static bool gfx_ctx_null_suppress_screensaver(void *data, bool enable)
return false;
}
static enum gfx_ctx_api gfx_ctx_null_get_api(void *data)
{
return GFX_CTX_NONE;
}
static bool gfx_ctx_null_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
@ -131,6 +136,7 @@ static void gfx_ctx_null_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_null = {
gfx_ctx_null_init,
gfx_ctx_null_destroy,
gfx_ctx_null_get_api,
gfx_ctx_null_bind_api,
gfx_ctx_null_swap_interval,
gfx_ctx_null_set_video_mode,

View File

@ -28,6 +28,8 @@ typedef struct
unsigned height;
} khr_display_ctx_data_t;
static enum gfx_ctx_api khr_api = GFX_CTX_NONE;
static void gfx_ctx_khr_display_destroy(void *data)
{
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;
@ -152,13 +154,24 @@ static void gfx_ctx_khr_display_input_driver(void *data,
*input_data = NULL;
}
static enum gfx_ctx_api gfx_ctx_khr_display_get_api(void *data)
{
return khr_api;
}
static bool gfx_ctx_khr_display_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
(void)major;
(void)minor;
return api == GFX_CTX_VULKAN_API;
khr_api = api;
if (api == GFX_CTX_VULKAN_API)
return true;
return false;
}
static bool gfx_ctx_khr_display_has_focus(void *data)
@ -218,6 +231,7 @@ static void *gfx_ctx_khr_display_get_context_data(void *data)
const gfx_ctx_driver_t gfx_ctx_khr_display = {
gfx_ctx_khr_display_init,
gfx_ctx_khr_display_destroy,
gfx_ctx_khr_display_get_api,
gfx_ctx_khr_display_bind_api,
gfx_ctx_khr_display_set_swap_interval,
gfx_ctx_khr_display_set_video_mode,

View File

@ -209,12 +209,21 @@ static void gfx_ctx_mali_fbdev_input_driver(void *data,
*input_data = NULL;
}
static enum gfx_ctx_api gfx_ctx_mali_fbdev_get_api(void *data)
{
return mali_api;
}
static bool gfx_ctx_mali_fbdev_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
mali_api = api;
return api == GFX_CTX_OPENGL_ES_API;
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
}
static bool gfx_ctx_mali_fbdev_has_focus(void *data)
@ -280,6 +289,7 @@ static void gfx_ctx_mali_fbdev_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_mali_fbdev = {
gfx_ctx_mali_fbdev_init,
gfx_ctx_mali_fbdev_destroy,
gfx_ctx_mali_fbdev_get_api,
gfx_ctx_mali_fbdev_bind_api,
gfx_ctx_mali_fbdev_set_swap_interval,
gfx_ctx_mali_fbdev_set_video_mode,

View File

@ -40,6 +40,8 @@ typedef struct
unsigned width, height;
} opendingux_ctx_data_t;
static enum gfx_ctx_api opendingux_api = GFX_CTX_NONE;
static void gfx_ctx_opendingux_destroy(void *data)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
@ -183,11 +185,21 @@ static void gfx_ctx_opendingux_input_driver(void *data,
*input_data = NULL;
}
static enum gfx_ctx_api gfx_ctx_opendingux_get_api(void *data)
{
return opendingux_api;
}
static bool gfx_ctx_opendingux_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
return api == GFX_CTX_OPENGL_ES_API;
opendingux_api = api;
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
}
static bool gfx_ctx_opendingux_has_focus(void *data)
@ -254,6 +266,7 @@ static void gfx_ctx_opendingux_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev = {
gfx_ctx_opendingux_init,
gfx_ctx_opendingux_destroy,
gfx_ctx_opendingux_get_api,
gfx_ctx_opendingux_bind_api,
gfx_ctx_opendingux_set_swap_interval,
gfx_ctx_opendingux_set_video_mode,

View File

@ -48,6 +48,8 @@ static int g_osmesa_format = OSMESA_RGBA;
static int g_osmesa_bpp = 4;
static const char *g_osmesa_fifo = "/tmp/osmesa-retroarch.sock";
static enum gfx_ctx_api osmesa_api = GFX_CTX_NONE;
typedef struct gfx_osmesa_ctx_data
{
uint8_t *screen;
@ -209,12 +211,19 @@ static void osmesa_ctx_destroy(void *data)
free(osmesa);
}
static bool osmesa_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major,
unsigned minor)
static enum gfx_ctx_api osmesa_ctx_get_api(void *data)
{
return osmesa_api;
}
static bool osmesa_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major,
unsigned minor)
{
if (api != GFX_CTX_OPENGL_API)
return false;
osmesa_api = api;
g_osmesa_profile = OSMESA_COMPAT_PROFILE;
if (major)
@ -384,6 +393,7 @@ const gfx_ctx_driver_t gfx_ctx_osmesa =
{
osmesa_ctx_init,
osmesa_ctx_destroy,
osmesa_ctx_get_api,
osmesa_ctx_bind_api,
osmesa_ctx_swap_interval,
osmesa_ctx_set_video_mode,

View File

@ -45,6 +45,8 @@ typedef struct gfx_ctx_ps3_data
#endif
} gfx_ctx_ps3_data_t;
static enum gfx_ctx_api ps3_api = GFX_CTX_NONE;
static void gfx_ctx_ps3_get_resolution(unsigned idx,
unsigned *width, unsigned *height)
{
@ -317,6 +319,11 @@ static void gfx_ctx_ps3_input_driver(void *data,
*input_data = ps3input;
}
static enum gfx_ctx_api gfx_ctx_ps3_get_api(void *data)
{
return ps3_api;
}
static bool gfx_ctx_ps3_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -324,7 +331,15 @@ static bool gfx_ctx_ps3_bind_api(void *data,
(void)major;
(void)minor;
return api == GFX_CTX_OPENGL_API || GFX_CTX_OPENGL_ES_API;
ps3_api = api;
if (
api == GFX_CTX_OPENGL_API ||
api == GFX_CTX_OPENGL_ES_API
)
return true;
return false;
}
static void gfx_ctx_ps3_get_video_output_size(void *data,
@ -398,6 +413,7 @@ static void gfx_ctx_ps3_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_ps3 = {
gfx_ctx_ps3_init,
gfx_ctx_ps3_destroy,
gfx_ctx_ps3_get_api,
gfx_ctx_ps3_bind_api,
gfx_ctx_ps3_set_swap_interval,
gfx_ctx_ps3_set_video_mode,

View File

@ -60,6 +60,8 @@ typedef struct
bool resize;
} qnx_ctx_data_t;
static enum gfx_ctx_api qnx_api = GFX_CTX_NONE;
static void gfx_ctx_qnx_destroy(void *data)
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
@ -330,11 +332,22 @@ static void gfx_ctx_qnx_input_driver(void *data,
*input_data = qnxinput;
}
static enum gfx_ctx_api gfx_ctx_qnx_get_api(void *data)
{
return qnx_api;
}
static bool gfx_ctx_qnx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
return api == GFX_CTX_OPENGL_ES_API;
qnx_api = api;
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
}
static bool gfx_ctx_qnx_has_focus(void *data)
@ -453,6 +466,7 @@ static void gfx_ctx_qnx_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_qnx = {
gfx_ctx_qnx_init,
gfx_ctx_qnx_destroy,
gfx_ctx_qnx_get_api,
gfx_ctx_qnx_bind_api,
gfx_ctx_qnx_set_swap_interval,
gfx_ctx_qnx_set_video_mode,

View File

@ -28,7 +28,7 @@
#include "SDL.h"
static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API;
static unsigned g_major = 2;
static unsigned g_major = 2;
static unsigned g_minor = 1;
typedef struct gfx_ctx_sdl_data
@ -119,8 +119,14 @@ static void sdl_ctx_destroy(void *data)
free(sdl);
}
static bool sdl_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major,
unsigned minor)
static enum gfx_ctx_api sdl_ctx_get_api(void *data)
{
return sdl_api;
}
static bool sdl_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major,
unsigned minor)
{
#ifdef HAVE_SDL2
unsigned profile;
@ -412,6 +418,7 @@ const gfx_ctx_driver_t gfx_ctx_sdl_gl =
{
sdl_ctx_init,
sdl_ctx_destroy,
sdl_ctx_get_api,
sdl_ctx_bind_api,
sdl_ctx_swap_interval,
sdl_ctx_set_video_mode,

View File

@ -75,7 +75,7 @@ typedef struct
VGImage vgimage[MAX_EGLIMAGE_TEXTURES];
} vc_ctx_data_t;
static enum gfx_ctx_api vc_api;
static enum gfx_ctx_api vc_api = GFX_CTX_NONE;
static PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR;
static PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR;
@ -359,6 +359,11 @@ static bool gfx_ctx_vc_set_video_mode(void *data,
return true;
}
stati bool gfx_ctx_api gfx_ctx_vc_get_api(void *data)
{
return vc_api;
}
static bool gfx_ctx_vc_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -701,6 +706,7 @@ static void gfx_ctx_vc_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_videocore = {
gfx_ctx_vc_init,
gfx_ctx_vc_destroy,
gfx_ctx_vc_get_api,
gfx_ctx_vc_bind_api,
gfx_ctx_vc_set_swap_interval,
gfx_ctx_vc_set_video_mode,
@ -728,5 +734,4 @@ const gfx_ctx_driver_t gfx_ctx_videocore = {
gfx_ctx_vc_bind_hw_render,
NULL,
NULL
};

View File

@ -42,6 +42,8 @@ typedef struct
unsigned width, height;
} vivante_ctx_data_t;
static enum gfx_ctx_api viv_api = GFX_CTX_NONE;
static void gfx_ctx_vivante_destroy(void *data)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
@ -190,11 +192,20 @@ static void gfx_ctx_vivante_input_driver(void *data,
*input_data = NULL;
}
static enum gfx_ctx_api gfx_ctx_vivante_get_api(void *data)
{
return viv_api;
}
static bool gfx_ctx_vivante_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
return api == GFX_CTX_OPENGL_ES_API;
viv_api = api;
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
}
static bool gfx_ctx_vivante_has_focus(void *data)
@ -261,6 +272,7 @@ static void gfx_ctx_vivante_set_flags(void *data, uint32_t flags)
const gfx_ctx_driver_t gfx_ctx_vivante_fbdev = {
gfx_ctx_vivante_init,
gfx_ctx_vivante_destroy,
gfx_ctx_vivante_get_api,
gfx_ctx_vivante_bind_api,
gfx_ctx_vivante_set_swap_interval,
gfx_ctx_vivante_set_video_mode,

View File

@ -1198,6 +1198,11 @@ static bool gfx_ctx_wl_has_windowed(void *data)
return true;
}
static enum gfx_ctx_api gfx_ctx_wl_get_api(void *data)
{
return wl_api;
}
static bool gfx_ctx_wl_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -1205,6 +1210,7 @@ static bool gfx_ctx_wl_bind_api(void *video_driver,
g_egl_major = major;
g_egl_minor = minor;
#endif
wl_api = api;
switch (api)
{
@ -1214,7 +1220,6 @@ static bool gfx_ctx_wl_bind_api(void *video_driver,
if ((major * 1000 + minor) >= 3001)
return false;
#endif
wl_api = api;
return eglBindAPI(EGL_OPENGL_API);
#else
break;
@ -1225,21 +1230,18 @@ static bool gfx_ctx_wl_bind_api(void *video_driver,
if (major >= 3)
return false;
#endif
wl_api = api;
return eglBindAPI(EGL_OPENGL_ES_API);
#else
break;
#endif
case GFX_CTX_OPENVG_API:
#ifdef HAVE_VG
wl_api = api;
return eglBindAPI(EGL_OPENVG_API);
#else
break;
#endif
case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
wl_api = api;
return true;
#else
break;
@ -1370,6 +1372,7 @@ static void gfx_ctx_wl_show_mouse(void *data, bool state)
const gfx_ctx_driver_t gfx_ctx_wayland = {
gfx_ctx_wl_init,
gfx_ctx_wl_destroy,
gfx_ctx_wl_get_api,
gfx_ctx_wl_bind_api,
gfx_ctx_wl_set_swap_interval,
gfx_ctx_wl_set_video_mode,

View File

@ -104,6 +104,11 @@ static enum gfx_ctx_api win32_api = GFX_CTX_NONE;
static dylib_t dll_handle = NULL; /* Handle to OpenGL32.dll */
#endif
typedef struct gfx_ctx_cgl_data
{
void *empty;
} gfx_ctx_wgl_data_t;
static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol)
{
switch (win32_api)
@ -460,12 +465,14 @@ static void gfx_ctx_wgl_get_video_size(void *data,
static void *gfx_ctx_wgl_init(video_frame_info_t *video_info, void *video_driver)
{
WNDCLASSEX wndclass = {0};
WNDCLASSEX wndclass = {0};
gfx_ctx_wgl_data_t *wgl = (gfx_ctx_wgl_data_t*)calloc(1, sizeof(*wgl));
(void)video_driver;
if (!wgl)
return NULL;
if (g_inited)
return NULL;
goto error;
#ifdef HAVE_DYNAMIC
dll_handle = dylib_load("OpenGL32.dll");
@ -476,14 +483,14 @@ static void *gfx_ctx_wgl_init(video_frame_info_t *video_info, void *video_driver
wndclass.lpfnWndProc = WndProcGL;
if (!win32_window_init(&wndclass, true, NULL))
return NULL;
goto error;
switch (win32_api)
{
case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
if (!vulkan_context_init(&win32_vk, VULKAN_WSI_WIN32))
return NULL;
goto error;
#endif
break;
case GFX_CTX_NONE:
@ -491,14 +498,18 @@ static void *gfx_ctx_wgl_init(video_frame_info_t *video_info, void *video_driver
break;
}
return (void*)"wgl";
return wgl;
error:
if (wgl)
free(wgl);
return NULL;
}
static void gfx_ctx_wgl_destroy(void *data)
{
HWND window = win32_get_window();
(void)data;
HWND window = win32_get_window();
gfx_ctx_wgl_data_t *wgl = (gfx_ctx_wgl_data_t*)data;
switch (win32_api)
{
@ -557,6 +568,9 @@ static void gfx_ctx_wgl_destroy(void *data)
dylib_close(dll_handle);
#endif
if (wgl)
free(wgl);
win32_core_hw_context_enable = false;
g_inited = false;
win32_major = 0;
@ -643,6 +657,11 @@ static bool gfx_ctx_wgl_get_metrics(void *data,
return win32_get_metrics(data, type, value);
}
static enum gfx_ctx_api gfx_ctx_wgl_get_api(void *data)
{
return win32_api;
}
static bool gfx_ctx_wgl_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
@ -734,6 +753,7 @@ static void gfx_ctx_wgl_get_video_output_next(void *data)
const gfx_ctx_driver_t gfx_ctx_wgl = {
gfx_ctx_wgl_init,
gfx_ctx_wgl_destroy,
gfx_ctx_wgl_get_api,
gfx_ctx_wgl_bind_api,
gfx_ctx_wgl_swap_interval,
gfx_ctx_wgl_set_video_mode,

View File

@ -1043,6 +1043,11 @@ static gfx_ctx_proc_t gfx_ctx_x_get_proc_address(const char *symbol)
return NULL;
}
static enum gfx_ctx_api gfx_ctx_x_get_api(void *data)
{
return x_api;
}
static bool gfx_ctx_x_bind_api(void *data, enum gfx_ctx_api api,
unsigned major, unsigned minor)
{
@ -1187,6 +1192,7 @@ static void gfx_ctx_x_make_current(bool release)
const gfx_ctx_driver_t gfx_ctx_x = {
gfx_ctx_x_init,
gfx_ctx_x_destroy,
gfx_ctx_x_get_api,
gfx_ctx_x_bind_api,
gfx_ctx_x_swap_interval,
gfx_ctx_x_set_video_mode,

View File

@ -49,7 +49,7 @@ typedef struct
bool should_reset_mode;
} xegl_ctx_data_t;
static enum gfx_ctx_api x_api = GFX_CTX_NONE;
static enum gfx_ctx_api xegl_api = GFX_CTX_NONE;
static int x_nul_handler(Display *dpy, XErrorEvent *event)
{
@ -144,7 +144,7 @@ static void *gfx_ctx_xegl_init(video_frame_info_t *video_info, void *video_drive
if (!xegl)
return NULL;
switch (x_api)
switch (xegl_api)
{
case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl;
@ -190,7 +190,7 @@ error:
static EGLint *xegl_fill_attribs(xegl_ctx_data_t *xegl, EGLint *attr)
{
switch (x_api)
switch (xegl_api)
{
#ifdef EGL_KHR_create_context
case GFX_CTX_OPENGL_API:
@ -452,12 +452,17 @@ static bool gfx_ctx_xegl_has_windowed(void *data)
return true;
}
static enum gfx_ctx_api gfx_ctx_xegl_get_api(void *data)
{
return xegl_api;
}
static bool gfx_ctx_xegl_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
g_egl_major = major;
g_egl_minor = minor;
x_api = api;
xegl_api = api;
switch (api)
{
@ -494,7 +499,7 @@ static void gfx_ctx_xegl_swap_buffers(void *data, void *data2)
{
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
switch (x_api)
switch (xegl_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
@ -512,7 +517,7 @@ static void gfx_ctx_xegl_bind_hw_render(void *data, bool enable)
{
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
switch (x_api)
switch (xegl_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
@ -531,7 +536,7 @@ static void gfx_ctx_xegl_set_swap_interval(void *data, unsigned swap_interval)
{
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
switch (x_api)
switch (xegl_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
@ -547,7 +552,7 @@ static void gfx_ctx_xegl_set_swap_interval(void *data, unsigned swap_interval)
static gfx_ctx_proc_t gfx_ctx_xegl_get_proc_address(const char *symbol)
{
switch (x_api)
switch (xegl_api)
{
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
@ -582,6 +587,7 @@ const gfx_ctx_driver_t gfx_ctx_x_egl =
{
gfx_ctx_xegl_init,
gfx_ctx_xegl_destroy,
gfx_ctx_xegl_get_api,
gfx_ctx_xegl_bind_api,
gfx_ctx_xegl_set_swap_interval,
gfx_ctx_xegl_set_video_mode,

View File

@ -223,8 +223,6 @@ static void *video_context_data = NULL;
static bool deferred_video_context_driver_set_flags = false;
static gfx_ctx_flags_t deferred_flag_data = {0};
static enum gfx_ctx_api current_video_context_api = GFX_CTX_NONE;
static shader_backend_t *current_shader = NULL;
static void *current_shader_data = NULL;
@ -627,8 +625,6 @@ void video_context_driver_destroy(void)
current_video_context.bind_hw_render = NULL;
current_video_context.get_context_data = NULL;
current_video_context.make_current = NULL;
current_video_context_api = GFX_CTX_NONE;
}
/**
@ -2890,8 +2886,6 @@ static const gfx_ctx_driver_t *video_context_driver_init(
video_context_driver_set_data(ctx_data);
current_video_context_api = api;
return ctx;
}
@ -3202,27 +3196,31 @@ bool video_context_driver_set_flags(gfx_ctx_flags_t *flags)
enum gfx_ctx_api video_context_driver_get_api(void)
{
if (current_video_context_api == GFX_CTX_NONE)
enum gfx_ctx_api ctx_api = video_context_data ?
current_video_context.get_api(video_context_data) : GFX_CTX_NONE;
if (ctx_api == GFX_CTX_NONE)
{
const char *video_driver = video_driver_get_ident();
if (string_is_equal(video_driver, "d3d9"))
current_video_context_api = GFX_CTX_DIRECT3D9_API;
return GFX_CTX_DIRECT3D9_API;
else if (string_is_equal(video_driver, "d3d10"))
current_video_context_api = GFX_CTX_DIRECT3D10_API;
return GFX_CTX_DIRECT3D10_API;
else if (string_is_equal(video_driver, "d3d11"))
current_video_context_api = GFX_CTX_DIRECT3D11_API;
return GFX_CTX_DIRECT3D11_API;
else if (string_is_equal(video_driver, "d3d12"))
current_video_context_api = GFX_CTX_DIRECT3D12_API;
return GFX_CTX_DIRECT3D12_API;
else if (string_is_equal(video_driver, "gx2"))
current_video_context_api = GFX_CTX_GX2_API;
return GFX_CTX_GX2_API;
else if (string_is_equal(video_driver, "gl"))
current_video_context_api = GFX_CTX_OPENGL_API;
return GFX_CTX_OPENGL_API;
else if (string_is_equal(video_driver, "vulkan"))
current_video_context_api = GFX_CTX_VULKAN_API;
return GFX_CTX_VULKAN_API;
return GFX_CTX_NONE;
}
return current_video_context_api;
return ctx_api;
}
bool video_driver_has_windowed(void)

View File

@ -480,6 +480,8 @@ typedef struct gfx_ctx_driver
void* (*init)(video_frame_info_t *video_info, void *video_driver);
void (*destroy)(void *data);
enum gfx_ctx_api (*get_api)(void *data);
/* Which API to bind to. */
bool (*bind_api)(void *video_driver, enum gfx_ctx_api,
unsigned major, unsigned minor);