diff --git a/driver.h b/driver.h index 8de16dae14..cde7f6f649 100644 --- a/driver.h +++ b/driver.h @@ -272,14 +272,6 @@ typedef struct driver uintptr_t video_window; enum rarch_display_type display_type; - /* Graphics driver requires RGBA byte order data (ABGR on little-endian) - * for 32-bit. - * This takes effect for overlay and shader cores that wants to load - * data into graphics driver. Kinda hackish to place it here, it is only - * used for GLES. - * TODO: Refactor this better. */ - bool gfx_use_rgba; - /* Last message given to the video driver */ char current_msg[PATH_MAX_LENGTH]; } driver_t; diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index be9666a3f4..90a9cc9596 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -1410,12 +1410,12 @@ static INLINE void gl_copy_frame(gl_t *gl, const void *frame, else #endif { - driver_t *driver = driver_get_ptr(); + bool use_rgba = video_driver_ctl(VIDEO_DISPLAY_CTL_SUPPORTS_RGBA, NULL); glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(width * gl->base_size)); /* Fallback for GLES devices without GL_BGRA_EXT. */ - if (gl->base_size == 4 && driver->gfx_use_rgba) + if (gl->base_size == 4 && use_rgba) { gl_convert_frame_argb8888_abgr8888(gl, gl->conv_buffer, frame, width, height, pitch); @@ -2009,7 +2009,6 @@ static void gl_set_nonblock_state(void *data, bool state) static bool resolve_extensions(gl_t *gl, const char *context_ident) { - driver_t *driver = driver_get_ptr(); const char *vendor = (const char*)glGetString(GL_VENDOR); const char *renderer = (const char*)glGetString(GL_RENDERER); const char *version = (const char*)glGetString(GL_VERSION); @@ -2057,7 +2056,7 @@ static bool resolve_extensions(gl_t *gl, const char *context_ident) RARCH_LOG("[GL]: Using ARB_sync to reduce latency.\n"); #endif - driver->gfx_use_rgba = false; + video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_RGBA, NULL); #ifdef HAVE_OPENGLES2 bool gles3 = false; unsigned gles_major = 0, gles_minor = 0; @@ -2069,13 +2068,11 @@ static bool resolve_extensions(gl_t *gl, const char *context_ident) RARCH_LOG("[GL]: BGRA8888 extension found for GLES.\n"); else { - driver->gfx_use_rgba = true; + video_driver_ctl(RARCH_DISPLAY_CTL_SET_RGBA, NULL); RARCH_WARN("[GL]: GLES implementation does not have BGRA8888 extension.\n" "32-bit path will require conversion.\n"); } - - /* This format is mandated by GLES. */ if (version && sscanf(version, "OpenGL ES %u.%u", &gles_major, &gles_minor) == 2 && gles_major >= 3) @@ -2148,8 +2145,6 @@ static bool resolve_extensions(gl_t *gl, const char *context_ident) static INLINE void gl_set_texture_fmts(gl_t *gl, bool rgb32) { - driver_t *driver = driver_get_ptr(); - gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT16; gl->texture_type = RARCH_GL_TEXTURE_TYPE16; gl->texture_fmt = RARCH_GL_FORMAT16; @@ -2157,12 +2152,14 @@ static INLINE void gl_set_texture_fmts(gl_t *gl, bool rgb32) if (rgb32) { + bool use_rgba = video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RGBA, NULL); + gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT32; gl->texture_type = RARCH_GL_TEXTURE_TYPE32; gl->texture_fmt = RARCH_GL_FORMAT32; gl->base_size = sizeof(uint32_t); - if (driver->gfx_use_rgba) + if (use_rgba) { gl->internal_fmt = GL_RGBA; gl->texture_type = GL_RGBA; diff --git a/gfx/image/image.c b/gfx/image/image.c index 11af97fabc..39324307fc 100644 --- a/gfx/image/image.c +++ b/gfx/image/image.c @@ -39,9 +39,7 @@ bool texture_image_set_color_shifts(unsigned *r_shift, unsigned *g_shift, unsigned *b_shift, unsigned *a_shift) { - driver_t *driver = driver_get_ptr(); - /* This interface "leak" is very ugly. FIXME: Fix this properly ... */ - bool use_rgba = driver ? driver->gfx_use_rgba : false; + bool use_rgba = video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RGBA, NULL); *a_shift = 24; *r_shift = use_rgba ? 0 : 16; *g_shift = 8; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 00adf46dc0..595ca654cd 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -69,6 +69,14 @@ typedef struct video_driver_state } filter; } video_driver_state_t; +/* Graphics driver requires RGBA byte order data (ABGR on little-endian) + * for 32-bit. + * This takes effect for overlay and shader cores that wants to load + * data into graphics driver. Kinda hackish to place it here, it is only + * used for GLES. + * TODO: Refactor this better. */ +static bool gfx_use_rgba; + static void *video_data; static const video_driver_t *current_video; @@ -532,6 +540,7 @@ static bool uninit_video_input(void) if (hw_render->context_destroy && !driver->video_cache_context) hw_render->context_destroy(); + video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_RGBA, NULL); current_video = NULL; if (!driver->video_data_own) @@ -1442,6 +1451,14 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) custom_vp->y = 0; } return true; + case RARCH_DISPLAY_CTL_SET_RGBA: + gfx_use_rgba = true; + break; + case RARCH_DISPLAY_CTL_UNSET_RGBA: + gfx_use_rgba = false; + break; + case RARCH_DISPLAY_CTL_SUPPORTS_RGBA: + return gfx_use_rgba; case RARCH_DISPLAY_CTL_GET_NEXT_VIDEO_OUT: if (video_poke && video_poke->get_video_output_next) { diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 56cc4aaf96..ed3e211a47 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -287,6 +287,9 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_NONE = 0, RARCH_DISPLAY_CTL_INIT, RARCH_DISPLAY_CTL_DEINIT, + RARCH_DISPLAY_CTL_SUPPORTS_RGBA, + RARCH_DISPLAY_CTL_SET_RGBA, + RARCH_DISPLAY_CTL_UNSET_RGBA, RARCH_DISPLAY_CTL_DEFAULT_SETTINGS, RARCH_DISPLAY_CTL_LOAD_SETTINGS, RARCH_DISPLAY_CTL_SAVE_SETTINGS, diff --git a/gfx/video_texture_c.c b/gfx/video_texture_c.c index 96920296af..8c6ee7f85e 100644 --- a/gfx/video_texture_c.c +++ b/gfx/video_texture_c.c @@ -36,8 +36,8 @@ void gl_load_texture_data(GLuint id, { GLint mag_filter, min_filter; bool want_mipmap = false; + bool use_rgba = video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RGBA, NULL); bool rgb32 = (base_size == (sizeof(uint32_t))); - driver_t *driver = driver_get_ptr(); GLenum wrap = gl_wrap_type_to_enum(wrap_type); glBindTexture(GL_TEXTURE_2D, id); @@ -80,9 +80,9 @@ void gl_load_texture_data(GLuint id, glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); glTexImage2D(GL_TEXTURE_2D, 0, - (driver->gfx_use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, + (use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, width, height, 0, - (driver->gfx_use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, + (use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, (rgb32) ? RARCH_GL_FORMAT32 : GL_UNSIGNED_SHORT_4_4_4_4, frame); if (want_mipmap)