mirror of
https://github.com/libretro/RetroArch
synced 2025-02-08 06:40:14 +00:00
Merge pull request #3478 from bparker06/gl_thread_current
make GLX context current when managing font textures with threaded video
This commit is contained in:
commit
d678273b0b
@ -625,4 +625,5 @@ const gfx_ctx_driver_t gfx_ctx_android = {
|
|||||||
#else
|
#else
|
||||||
NULL
|
NULL
|
||||||
#endif
|
#endif
|
||||||
|
,NULL
|
||||||
};
|
};
|
||||||
|
@ -258,5 +258,6 @@ const gfx_ctx_driver_t gfx_ctx_khr_display = {
|
|||||||
gfx_ctx_khr_display_set_flags,
|
gfx_ctx_khr_display_set_flags,
|
||||||
NULL,
|
NULL,
|
||||||
gfx_ctx_khr_display_get_context_data,
|
gfx_ctx_khr_display_get_context_data,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1177,4 +1177,5 @@ const gfx_ctx_driver_t gfx_ctx_wayland = {
|
|||||||
#else
|
#else
|
||||||
NULL
|
NULL
|
||||||
#endif
|
#endif
|
||||||
|
,NULL
|
||||||
};
|
};
|
||||||
|
@ -705,5 +705,6 @@ const gfx_ctx_driver_t gfx_ctx_wgl = {
|
|||||||
#else
|
#else
|
||||||
NULL,
|
NULL,
|
||||||
#endif
|
#endif
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,6 +69,8 @@ static enum gfx_ctx_api x_api;
|
|||||||
static PFNGLXCREATECONTEXTATTRIBSARBPROC glx_create_context_attribs;
|
static PFNGLXCREATECONTEXTATTRIBSARBPROC glx_create_context_attribs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static gfx_ctx_x_data_t *current_context_data = NULL;
|
||||||
|
|
||||||
static int x_nul_handler(Display *dpy, XErrorEvent *event)
|
static int x_nul_handler(Display *dpy, XErrorEvent *event)
|
||||||
{
|
{
|
||||||
(void)dpy;
|
(void)dpy;
|
||||||
@ -341,6 +343,8 @@ static void *gfx_ctx_x_init(void *data)
|
|||||||
if (!x)
|
if (!x)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
current_context_data = x;
|
||||||
|
|
||||||
XInitThreads();
|
XInitThreads();
|
||||||
|
|
||||||
if (!x11_connect())
|
if (!x11_connect())
|
||||||
@ -913,6 +917,22 @@ static void gfx_ctx_x_set_flags(void *data, uint32_t flags)
|
|||||||
x->core_hw_context_enable = true;
|
x->core_hw_context_enable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gfx_ctx_x_make_current(bool release)
|
||||||
|
{
|
||||||
|
if (!current_context_data)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (release)
|
||||||
|
{
|
||||||
|
glXMakeContextCurrent(g_x11_dpy, None, None, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glXMakeContextCurrent(g_x11_dpy,
|
||||||
|
current_context_data->g_glx_win, current_context_data->g_glx_win, current_context_data->g_ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const gfx_ctx_driver_t gfx_ctx_x = {
|
const gfx_ctx_driver_t gfx_ctx_x = {
|
||||||
gfx_ctx_x_init,
|
gfx_ctx_x_init,
|
||||||
gfx_ctx_x_destroy,
|
gfx_ctx_x_destroy,
|
||||||
@ -947,5 +967,10 @@ const gfx_ctx_driver_t gfx_ctx_x = {
|
|||||||
#else
|
#else
|
||||||
NULL
|
NULL
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OPENGL
|
||||||
|
,gfx_ctx_x_make_current
|
||||||
|
#else
|
||||||
|
,NULL
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "../common/gl_common.h"
|
#include "../common/gl_common.h"
|
||||||
#include "../font_driver.h"
|
#include "../font_driver.h"
|
||||||
#include "../video_shader_driver.h"
|
#include "../video_shader_driver.h"
|
||||||
|
#include "../video_context_driver.h"
|
||||||
#include <encodings/utf.h>
|
#include <encodings/utf.h>
|
||||||
|
|
||||||
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
|
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
|
||||||
@ -142,6 +143,7 @@ static void *gl_raster_font_init_font(void *data,
|
|||||||
{
|
{
|
||||||
const struct font_atlas *atlas = NULL;
|
const struct font_atlas *atlas = NULL;
|
||||||
gl_raster_t *font = (gl_raster_t*)calloc(1, sizeof(*font));
|
gl_raster_t *font = (gl_raster_t*)calloc(1, sizeof(*font));
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
if (!font)
|
if (!font)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -156,6 +158,9 @@ static void *gl_raster_font_init_font(void *data,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings->video.threaded)
|
||||||
|
video_context_driver_make_current(false);
|
||||||
|
|
||||||
glGenTextures(1, &font->tex);
|
glGenTextures(1, &font->tex);
|
||||||
glBindTexture(GL_TEXTURE_2D, font->tex);
|
glBindTexture(GL_TEXTURE_2D, font->tex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
@ -185,12 +190,16 @@ error:
|
|||||||
static void gl_raster_font_free_font(void *data)
|
static void gl_raster_font_free_font(void *data)
|
||||||
{
|
{
|
||||||
gl_raster_t *font = (gl_raster_t*)data;
|
gl_raster_t *font = (gl_raster_t*)data;
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (font->font_driver && font->font_data)
|
if (font->font_driver && font->font_data)
|
||||||
font->font_driver->free(font->font_data);
|
font->font_driver->free(font->font_data);
|
||||||
|
|
||||||
|
if (settings->video.threaded)
|
||||||
|
video_context_driver_make_current(false);
|
||||||
|
|
||||||
glDeleteTextures(1, &font->tex);
|
glDeleteTextures(1, &font->tex);
|
||||||
free(font);
|
free(font);
|
||||||
}
|
}
|
||||||
|
@ -328,6 +328,14 @@ bool video_context_driver_bind_hw_render(bool *enable)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void video_context_driver_make_current(bool release)
|
||||||
|
{
|
||||||
|
if (!current_video_context || !current_video_context->make_current)
|
||||||
|
return;
|
||||||
|
|
||||||
|
current_video_context->make_current(release);
|
||||||
|
}
|
||||||
|
|
||||||
bool video_context_driver_set(const gfx_ctx_driver_t *data)
|
bool video_context_driver_set(const gfx_ctx_driver_t *data)
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data)
|
||||||
|
@ -163,6 +163,10 @@ typedef struct gfx_ctx_driver
|
|||||||
* This is mostly relevant for graphics APIs such as Vulkan
|
* This is mostly relevant for graphics APIs such as Vulkan
|
||||||
* which do not have global context state. */
|
* which do not have global context state. */
|
||||||
void *(*get_context_data)(void *data);
|
void *(*get_context_data)(void *data);
|
||||||
|
|
||||||
|
/* Optional. Makes driver context (only GLX right now)
|
||||||
|
* active for this thread. */
|
||||||
|
void (*make_current)(bool release);
|
||||||
} gfx_ctx_driver_t;
|
} gfx_ctx_driver_t;
|
||||||
|
|
||||||
typedef struct gfx_ctx_flags
|
typedef struct gfx_ctx_flags
|
||||||
@ -280,6 +284,8 @@ bool video_context_driver_get_video_output_next(void);
|
|||||||
|
|
||||||
bool video_context_driver_bind_hw_render(bool *enable);
|
bool video_context_driver_bind_hw_render(bool *enable);
|
||||||
|
|
||||||
|
void video_context_driver_make_current(bool restore);
|
||||||
|
|
||||||
bool video_context_driver_set(const gfx_ctx_driver_t *data);
|
bool video_context_driver_set(const gfx_ctx_driver_t *data);
|
||||||
|
|
||||||
void video_context_driver_destroy(void);
|
void video_context_driver_destroy(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user