mpv
mpv copied to clipboard
Window screenshot does not work with dxinterop backend
mpv version and platform
mpv git- 22c76e8, Windows 10
Reproduction steps
- Run
mpv --idle --force-window --no-config --vo=opengl:backend=dxinterop - Press
Ctrl+sto take a window screenshot
Expected behavior
Screenshot works.
Actual behavior
Screenshot is just black with the occasional noise.
Log files
http://sprunge.us/BhWf
Possible fix
I suspect that this bug is due to the gl->main_fb changes.
Changing gl_read_window_contents to bind gl->main_fb fixes the problem for me.
mp_image_t *gl_read_window_contents(GL *gl)
{
if (gl->es)
return NULL; // ES can't read from front buffer
gl->BindFramebuffer(GL_FRAMEBUFFER, gl->main_fb);
GLenum obj = gl->main_fb ? GL_COLOR_ATTACHMENT0 : GL_FRONT;
GLint vp[4]; //x, y, w, h
gl->GetIntegerv(GL_VIEWPORT, vp);
mp_image_t *image = mp_image_alloc(IMGFMT_RGB24, vp[2], vp[3]);
if (!image)
return NULL;
gl->PixelStorei(GL_PACK_ALIGNMENT, 1);
gl->ReadBuffer(obj);
//flip image while reading (and also avoid stride-related trouble)
for (int y = 0; y < vp[3]; y++) {
gl->ReadPixels(vp[0], vp[1] + vp[3] - y - 1, vp[2], 1,
GL_RGB, GL_UNSIGNED_BYTE,
image->planes[0] + y * image->stride[0]);
}
gl->PixelStorei(GL_PACK_ALIGNMENT, 4);
gl->BindFramebuffer(GL_FRAMEBUFFER, 0);
return image;
}
Not sure if this breaks anything else. I only tested it on the win and dxinterop backend.
Can you send a PR for this? Move down the first BindFramebuffer call, so the binding won't be left if the image allocation fails.