diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index c05c833f4b3..9495ea38b1a 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -54,7 +54,7 @@ void wined3d_context_cleanup(struct wined3d_context *context) * A to avoid breaking caller code. */ void context_restore(struct wined3d_context *context, struct wined3d_texture *texture, unsigned int sub_resource_idx) { - if (context->current_rt.texture != texture || context->current_rt.sub_resource_idx != sub_resource_idx) + if (texture && (context->current_rt.texture != texture || context->current_rt.sub_resource_idx != sub_resource_idx)) { context_release(context); context = context_acquire(texture->resource.device, texture, sub_resource_idx); diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index 5f3e9d3c0d7..46bb3f9f365 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -4356,7 +4356,6 @@ struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device * if (!texture) { if (current_context - && current_context->c.current_rt.texture && current_context->c.device == device) { texture = current_context->c.current_rt.texture; diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index b37a84b0086..6cc00833d56 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -352,6 +352,7 @@ void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned i unsigned int row_pitch, slice_pitch; unsigned int width, height, level; struct wined3d_bo_address data; + bool restore_context = false; unsigned int restore_idx; BYTE *row, *top, *bottom; BOOL src_is_upside_down; @@ -369,9 +370,10 @@ void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned i restore_texture = context->current_rt.texture; restore_idx = context->current_rt.sub_resource_idx; if (!wined3d_resource_is_offscreen(resource) && (restore_texture != texture || restore_idx != sub_resource_idx)) + { context = context_acquire(device, texture, sub_resource_idx); - else - restore_texture = NULL; + restore_context = true; + } context_gl = wined3d_context_gl(context); gl_info = context_gl->gl_info; @@ -473,7 +475,7 @@ error: checkGLcall("glBindBuffer"); } - if (restore_texture) + if (restore_context) context_restore(context, restore_texture, restore_idx); } diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 2efdaf91438..27fedf4db67 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -340,12 +340,12 @@ static void texture2d_blt_fbo(struct wined3d_device *device, struct wined3d_cont struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_format *resolve_format) { - struct wined3d_texture *required_texture, *restore_texture = NULL, *dst_save_texture = dst_texture; + struct wined3d_texture *required_texture, *restore_texture, *dst_save_texture = dst_texture; unsigned int restore_idx, dst_save_sub_resource_idx = dst_sub_resource_idx; + bool resolve, scaled_resolve, restore_context = false; struct wined3d_texture *src_staging_texture = NULL; const struct wined3d_gl_info *gl_info; struct wined3d_context_gl *context_gl; - bool resolve, scaled_resolve; GLenum gl_filter; GLenum buffer; RECT s, d; @@ -490,16 +490,17 @@ static void texture2d_blt_fbo(struct wined3d_device *device, struct wined3d_cont restore_texture = context->current_rt.texture; restore_idx = context->current_rt.sub_resource_idx; if (restore_texture != required_texture) + { context = context_acquire(device, required_texture, 0); - else - restore_texture = NULL; + restore_context = true; + } context_gl = wined3d_context_gl(context); if (!context_gl->valid) { context_release(context); WARN("Invalid context, skipping blit.\n"); - restore_texture = NULL; + restore_context = false; goto done; } @@ -565,7 +566,7 @@ done: if (src_staging_texture) wined3d_texture_decref(src_staging_texture); - if (restore_texture) + if (restore_context) context_restore(context, restore_texture, restore_idx); }