vo_opengl: move GL state resetting to vo_opengl_cb

This code is pretty much for the sake of vo_opengl_cb API users. It
resets certain state that either the user or our code doesn't reset
correctly. This is somewhat outdated. With GL implicit state being
so awfully large, it seems more reasonable require that any code
restores the default state when returning to the caller. Some
exceptions are defined in opengl_cb.h.
This commit is contained in:
wm4 2017-08-05 15:17:18 +02:00
parent 333cae74ef
commit dddda6e4a5
4 changed files with 16 additions and 23 deletions

View File

@ -69,6 +69,9 @@ extern "C" {
* standard defaults. The following state is excluded from this:
*
* - the current viewport (can have/is set to an arbitrary value)
* - the glScissor state (but GL_SCISSOR_TEST is expected disabled)
* - glBlendFuncSeparate() state (but GL_BLEND is expected disabled)
* - mpv always disables GL_DITHER at init
*
* Messing with the state could be avoided by creating shared OpenGL contexts,
* but this is avoided for the sake of compatibility and interoperability.

View File

@ -3492,8 +3492,6 @@ static void init_gl(struct gl_video *p)
debug_check_gl(p, "before init_gl");
gl_video_set_gl_state(p);
p->upload_timer = gl_timer_create(gl);
p->blit_timer = gl_timer_create(gl);
@ -3540,22 +3538,6 @@ void gl_video_uninit(struct gl_video *p)
talloc_free(p);
}
void gl_video_set_gl_state(struct gl_video *p)
{
// This resets certain important state to defaults.
gl_video_unset_gl_state(p);
}
void gl_video_unset_gl_state(struct gl_video *p)
{
GL *gl = p->gl;
gl->ActiveTexture(GL_TEXTURE0);
if (gl->mpgl_caps & MPGL_CAP_ROW_LENGTH)
gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4);
}
void gl_video_reset(struct gl_video *p)
{
gl_video_reset_surfaces(p);

View File

@ -176,8 +176,6 @@ bool gl_video_icc_auto_enabled(struct gl_video *p);
bool gl_video_gamma_auto_enabled(struct gl_video *p);
struct mp_colorspace gl_video_get_output_colorspace(struct gl_video *p);
void gl_video_set_gl_state(struct gl_video *p);
void gl_video_unset_gl_state(struct gl_video *p);
void gl_video_reset(struct gl_video *p);
bool gl_video_showing_interpolated_frame(struct gl_video *p);

View File

@ -144,6 +144,16 @@ void mpv_opengl_cb_set_update_callback(struct mpv_opengl_cb_context *ctx,
pthread_mutex_unlock(&ctx->lock);
}
// Reset some GL attributes the user might clobber. For mid-term compatibility
// only - we expect both user code and our code to do this correctly.
static void reset_gl_state(GL *gl)
{
gl->ActiveTexture(GL_TEXTURE0);
if (gl->mpgl_caps & MPGL_CAP_ROW_LENGTH)
gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4);
}
int mpv_opengl_cb_init_gl(struct mpv_opengl_cb_context *ctx, const char *exts,
mpv_opengl_cb_get_proc_address_fn get_proc_address,
void *get_proc_address_ctx)
@ -184,7 +194,7 @@ int mpv_opengl_cb_init_gl(struct mpv_opengl_cb_context *ctx, const char *exts,
ctx->initialized = true;
pthread_mutex_unlock(&ctx->lock);
gl_video_unset_gl_state(ctx->renderer);
reset_gl_state(ctx->gl);
return 0;
}
@ -222,7 +232,7 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h)
{
assert(ctx->renderer);
gl_video_set_gl_state(ctx->renderer);
reset_gl_state(ctx->gl);
pthread_mutex_lock(&ctx->lock);
@ -307,7 +317,7 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h)
MP_STATS(ctx, "glcb-render");
gl_video_render_frame(ctx->renderer, frame, fbo);
gl_video_unset_gl_state(ctx->renderer);
reset_gl_state(ctx->gl);
if (frame != &dummy)
talloc_free(frame);