From 1a79cb485dfe71652ed6715ff41900e9bbeb2bd0 Mon Sep 17 00:00:00 2001 From: Lepton Wu Date: Thu, 1 Oct 2020 11:44:46 -0700 Subject: [PATCH] vrend: Recover texture binding after transfer In the past, we only transfer texture data in "zero" context, changing the texture binding was fine. Now the transfer could happen in the rendering context, so we need to recover the bindings. This fixes unitTest_WritePixelsNonTexture_Gpu in SkQP. Signed-off-by: Lepton Wu Reviewed-by: Gert Wollny --- src/vrend_renderer.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index e6baa8f..5fa67f9 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -7187,6 +7187,28 @@ static bool check_iov_bounds(struct vrend_resource *res, return true; } +static void get_current_texture(GLenum target, GLint* tex) { + switch (target) { +#define GET_TEXTURE(a) \ + case GL_TEXTURE_ ## a: \ + glGetIntegerv(GL_TEXTURE_BINDING_ ## a, tex); return + GET_TEXTURE(1D); + GET_TEXTURE(2D); + GET_TEXTURE(3D); + GET_TEXTURE(1D_ARRAY); + GET_TEXTURE(2D_ARRAY); + GET_TEXTURE(RECTANGLE); + GET_TEXTURE(CUBE_MAP); + GET_TEXTURE(CUBE_MAP_ARRAY); + GET_TEXTURE(BUFFER); + GET_TEXTURE(2D_MULTISAMPLE); + GET_TEXTURE(2D_MULTISAMPLE_ARRAY); +#undef GET_TEXTURE + default: + vrend_printf("Unknown texture target %x\n", target); + } +} + static int vrend_renderer_transfer_write_iov(struct vrend_context *ctx, struct vrend_resource *res, const struct iovec *iov, int num_iovs, @@ -7347,6 +7369,8 @@ static int vrend_renderer_transfer_write_iov(struct vrend_context *ctx, data); } else { uint32_t comp_size; + GLint old_tex = 0; + get_current_texture(res->target, &old_tex); glBindTexture(res->target, res->id); if (compressed) { @@ -7434,7 +7458,7 @@ static int vrend_renderer_transfer_write_iov(struct vrend_context *ctx, if (!vrend_state.use_core_profile) glPixelTransferf(GL_DEPTH_SCALE, 1.0); } - glBindTexture(res->target, 0); + glBindTexture(res->target, old_tex); } if (stride && !need_temp) { @@ -7506,6 +7530,8 @@ static int vrend_transfer_send_getteximage(struct vrend_resource *res, break; } + GLint old_tex = 0; + get_current_texture(res->target, &old_tex); glBindTexture(res->target, res->id); if (res->target == GL_TEXTURE_CUBE_MAP) { target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info->box->z; @@ -7536,7 +7562,7 @@ static int vrend_transfer_send_getteximage(struct vrend_resource *res, info->stride, info->box, info->level, info->offset, false); free(data); - glBindTexture(res->target, 0); + glBindTexture(res->target, old_tex); return 0; }