Move readback function to renderchain

This commit is contained in:
twinaphex 2017-11-08 18:45:28 +01:00
parent c825f849f5
commit 5f7527df08
3 changed files with 31 additions and 22 deletions

View File

@ -919,7 +919,6 @@ static struct video_shader *gl_get_current_shader(void *data)
return shader_info.data;
}
#ifdef HAVE_GL_ASYNC_READBACK
static void gl_pbo_async_readback(gl_t *gl)
{
#ifdef HAVE_OPENGLES3
@ -938,18 +937,13 @@ static void gl_pbo_async_readback(gl_t *gl)
/* 4 frames back, we can readback. */
gl->pbo_readback_valid[gl->pbo_readback_index] = true;
glPixelStorei(GL_PACK_ALIGNMENT,
video_pixel_get_alignment(gl->vp.width * sizeof(uint32_t)));
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glReadBuffer(GL_BACK);
glReadPixels(gl->vp.x, gl->vp.y,
gl->vp.width, gl->vp.height,
fmt, type, NULL);
if (gl->renderchain_driver->readback)
gl->renderchain_driver->readback(gl,
video_pixel_get_alignment(gl->vp.width * sizeof(uint32_t)),
fmt, type, NULL);
if (gl->renderchain_driver->unbind_pbo)
gl->renderchain_driver->unbind_pbo();
}
#endif
static INLINE void gl_draw_texture(gl_t *gl, video_frame_info_t *video_info)
{
@ -1226,17 +1220,12 @@ static bool gl_frame(void *data, const void *frame,
/* Screenshots. */
if (gl->readback_buffer_screenshot)
{
glPixelStorei(GL_PACK_ALIGNMENT, 4);
#ifndef HAVE_OPENGLES
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glReadBuffer(GL_BACK);
#endif
glReadPixels(gl->vp.x, gl->vp.y,
gl->vp.width, gl->vp.height,
GL_RGBA, GL_UNSIGNED_BYTE, gl->readback_buffer_screenshot);
if (gl->renderchain_driver->readback)
gl->renderchain_driver->readback(gl,
4, GL_RGBA, GL_UNSIGNED_BYTE,
gl->readback_buffer_screenshot);
}
#ifdef HAVE_GL_ASYNC_READBACK
/* Don't readback if we're in menu mode. */
else if (gl->pbo_readback_enable)
#ifdef HAVE_MENU
@ -1244,7 +1233,6 @@ static bool gl_frame(void *data, const void *frame,
if (!gl->menu_texture_enable)
#endif
gl_pbo_async_readback(gl);
#endif
/* Disable BFI during fast forward, slow-motion,
* and pause to prevent flicker. */
@ -1543,7 +1531,6 @@ static INLINE void gl_set_texture_fmts(gl_t *gl, bool rgb32)
#endif
}
#ifdef HAVE_GL_ASYNC_READBACK
static bool gl_init_pbo_readback(gl_t *gl)
{
unsigned i;
@ -1585,7 +1572,6 @@ static bool gl_init_pbo_readback(gl_t *gl)
return true;
}
#endif
static const gfx_ctx_driver_t *gl_get_context(gl_t *gl)
{

View File

@ -1365,7 +1365,26 @@ static void gl2_renderchain_init_pbo(unsigned size,
#endif
}
static void gl2_renderchain_readback(void *data,
unsigned alignment,
unsigned fmt, unsigned type,
void *src)
{
gl_t *gl = (gl_t*)data;
glPixelStorei(GL_PACK_ALIGNMENT, alignment);
#ifndef HAVE_OPENGLES
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glReadBuffer(GL_BACK);
#endif
glReadPixels(gl->vp.x, gl->vp.y,
gl->vp.width, gl->vp.height,
(GLenum)fmt, (GLenum)type, (GLvoid*)src);
}
gl_renderchain_driver_t gl2_renderchain = {
gl2_renderchain_readback,
gl2_renderchain_init_pbo,
gl2_renderchain_bind_pbo,
gl2_renderchain_unbind_pbo,

View File

@ -827,6 +827,10 @@ typedef struct d3d_renderchain_driver
typedef struct gl_renderchain_driver
{
void (*readback)(void *data,
unsigned alignment,
unsigned fmt, unsigned type,
void *src);
void (*init_pbo)(unsigned size, const void *data);
void (*bind_pbo)(unsigned idx);
void (*unbind_pbo)(void);