Move use_rgba to gfx/video_driver.c - get rid of driver_t dependencies

This commit is contained in:
twinaphex 2015-11-23 23:58:40 +01:00
parent f358962e40
commit deae90e0bb
6 changed files with 31 additions and 24 deletions

View File

@ -272,14 +272,6 @@ typedef struct driver
uintptr_t video_window; uintptr_t video_window;
enum rarch_display_type display_type; 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 */ /* Last message given to the video driver */
char current_msg[PATH_MAX_LENGTH]; char current_msg[PATH_MAX_LENGTH];
} driver_t; } driver_t;

View File

@ -1410,12 +1410,12 @@ static INLINE void gl_copy_frame(gl_t *gl, const void *frame,
else else
#endif #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)); glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(width * gl->base_size));
/* Fallback for GLES devices without GL_BGRA_EXT. */ /* 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, gl_convert_frame_argb8888_abgr8888(gl, gl->conv_buffer,
frame, width, height, pitch); 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) 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 *vendor = (const char*)glGetString(GL_VENDOR);
const char *renderer = (const char*)glGetString(GL_RENDERER); const char *renderer = (const char*)glGetString(GL_RENDERER);
const char *version = (const char*)glGetString(GL_VERSION); 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"); RARCH_LOG("[GL]: Using ARB_sync to reduce latency.\n");
#endif #endif
driver->gfx_use_rgba = false; video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_RGBA, NULL);
#ifdef HAVE_OPENGLES2 #ifdef HAVE_OPENGLES2
bool gles3 = false; bool gles3 = false;
unsigned gles_major = 0, gles_minor = 0; 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"); RARCH_LOG("[GL]: BGRA8888 extension found for GLES.\n");
else 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" RARCH_WARN("[GL]: GLES implementation does not have BGRA8888 extension.\n"
"32-bit path will require conversion.\n"); "32-bit path will require conversion.\n");
} }
/* This format is mandated by GLES. */ /* This format is mandated by GLES. */
if (version && sscanf(version, "OpenGL ES %u.%u", if (version && sscanf(version, "OpenGL ES %u.%u",
&gles_major, &gles_minor) == 2 && gles_major >= 3) &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) 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->internal_fmt = RARCH_GL_INTERNAL_FORMAT16;
gl->texture_type = RARCH_GL_TEXTURE_TYPE16; gl->texture_type = RARCH_GL_TEXTURE_TYPE16;
gl->texture_fmt = RARCH_GL_FORMAT16; gl->texture_fmt = RARCH_GL_FORMAT16;
@ -2157,12 +2152,14 @@ static INLINE void gl_set_texture_fmts(gl_t *gl, bool rgb32)
if (rgb32) if (rgb32)
{ {
bool use_rgba = video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RGBA, NULL);
gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT32; gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT32;
gl->texture_type = RARCH_GL_TEXTURE_TYPE32; gl->texture_type = RARCH_GL_TEXTURE_TYPE32;
gl->texture_fmt = RARCH_GL_FORMAT32; gl->texture_fmt = RARCH_GL_FORMAT32;
gl->base_size = sizeof(uint32_t); gl->base_size = sizeof(uint32_t);
if (driver->gfx_use_rgba) if (use_rgba)
{ {
gl->internal_fmt = GL_RGBA; gl->internal_fmt = GL_RGBA;
gl->texture_type = GL_RGBA; gl->texture_type = GL_RGBA;

View File

@ -39,9 +39,7 @@
bool texture_image_set_color_shifts(unsigned *r_shift, unsigned *g_shift, bool texture_image_set_color_shifts(unsigned *r_shift, unsigned *g_shift,
unsigned *b_shift, unsigned *a_shift) unsigned *b_shift, unsigned *a_shift)
{ {
driver_t *driver = driver_get_ptr(); bool use_rgba = video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RGBA, NULL);
/* This interface "leak" is very ugly. FIXME: Fix this properly ... */
bool use_rgba = driver ? driver->gfx_use_rgba : false;
*a_shift = 24; *a_shift = 24;
*r_shift = use_rgba ? 0 : 16; *r_shift = use_rgba ? 0 : 16;
*g_shift = 8; *g_shift = 8;

View File

@ -69,6 +69,14 @@ typedef struct video_driver_state
} filter; } filter;
} video_driver_state_t; } 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 void *video_data;
static const video_driver_t *current_video; 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) if (hw_render->context_destroy && !driver->video_cache_context)
hw_render->context_destroy(); hw_render->context_destroy();
video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_RGBA, NULL);
current_video = NULL; current_video = NULL;
if (!driver->video_data_own) 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; custom_vp->y = 0;
} }
return true; 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: case RARCH_DISPLAY_CTL_GET_NEXT_VIDEO_OUT:
if (video_poke && video_poke->get_video_output_next) if (video_poke && video_poke->get_video_output_next)
{ {

View File

@ -287,6 +287,9 @@ enum rarch_display_ctl_state
RARCH_DISPLAY_CTL_NONE = 0, RARCH_DISPLAY_CTL_NONE = 0,
RARCH_DISPLAY_CTL_INIT, RARCH_DISPLAY_CTL_INIT,
RARCH_DISPLAY_CTL_DEINIT, 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_DEFAULT_SETTINGS,
RARCH_DISPLAY_CTL_LOAD_SETTINGS, RARCH_DISPLAY_CTL_LOAD_SETTINGS,
RARCH_DISPLAY_CTL_SAVE_SETTINGS, RARCH_DISPLAY_CTL_SAVE_SETTINGS,

View File

@ -36,8 +36,8 @@ void gl_load_texture_data(GLuint id,
{ {
GLint mag_filter, min_filter; GLint mag_filter, min_filter;
bool want_mipmap = false; bool want_mipmap = false;
bool use_rgba = video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RGBA, NULL);
bool rgb32 = (base_size == (sizeof(uint32_t))); bool rgb32 = (base_size == (sizeof(uint32_t)));
driver_t *driver = driver_get_ptr();
GLenum wrap = gl_wrap_type_to_enum(wrap_type); GLenum wrap = gl_wrap_type_to_enum(wrap_type);
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
@ -80,9 +80,9 @@ void gl_load_texture_data(GLuint id,
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
(driver->gfx_use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, (use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
width, height, 0, 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); (rgb32) ? RARCH_GL_FORMAT32 : GL_UNSIGNED_SHORT_4_4_4_4, frame);
if (want_mipmap) if (want_mipmap)