From: Paul Gofman Subject: [PATCH 1/3] wined3d: Factor out wined3d_texture_gl_upload_bo() function. Message-Id: <20191003203655.25307-1-gofmanp@gmail.com> Date: Thu, 3 Oct 2019 23:36:53 +0300 Signed-off-by: Paul Gofman --- dlls/wined3d/texture.c | 231 +++++++++++++++++++++-------------------- 1 file changed, 120 insertions(+), 111 deletions(-) diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index c4ef184484..dd61ac8ae1 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1845,6 +1845,124 @@ HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, return WINED3D_OK; } +static void wined3d_texture_gl_upload_bo(const struct wined3d_format *src_format, GLenum target, + unsigned int level, unsigned int src_row_pitch, unsigned int dst_x, unsigned int dst_y, + unsigned int dst_z, unsigned int update_w, unsigned int update_h, unsigned int update_d, + const BYTE *addr, BOOL srgb, struct wined3d_texture *dst_texture, + const struct wined3d_gl_info *gl_info) +{ + const struct wined3d_format_gl *format_gl = wined3d_format_gl(src_format); + + if (src_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED) + { + unsigned int dst_row_pitch, dst_slice_pitch; + GLenum internal; + + if (srgb) + internal = format_gl->srgb_internal; + else if (dst_texture->resource.bind_flags & WINED3D_BIND_RENDER_TARGET + && wined3d_resource_is_offscreen(&dst_texture->resource)) + internal = format_gl->rt_internal; + else + internal = format_gl->internal; + + wined3d_format_calculate_pitch(src_format, 1, update_w, update_h, &dst_row_pitch, &dst_slice_pitch); + + TRACE("Uploading compressed data, target %#x, level %u, x %u, y %u, z %u, " + "w %u, h %u, d %u, format %#x, image_size %#x, addr %p.\n", + target, level, dst_x, dst_y, dst_z, update_w, update_h, + update_d, internal, dst_slice_pitch, addr); + + if (target == GL_TEXTURE_1D) + { + GL_EXTCALL(glCompressedTexSubImage1D(target, level, dst_x, + update_w, internal, dst_row_pitch, addr)); + } + else if (dst_row_pitch == src_row_pitch) + { + if (target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D) + { + GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, dst_y, dst_z, + update_w, update_h, update_d, internal, dst_slice_pitch * update_d, addr)); + } + else + { + GL_EXTCALL(glCompressedTexSubImage2D(target, level, dst_x, dst_y, + update_w, update_h, internal, dst_slice_pitch, addr)); + } + } + else + { + unsigned int row_count = (update_h + src_format->block_height - 1) / src_format->block_height; + unsigned int row, y, z; + + /* glCompressedTexSubImage2D() ignores pixel store state, so we + * can't use the unpack row length like for glTexSubImage2D. */ + for (z = dst_z; z < dst_z + update_d; ++z) + { + for (row = 0, y = dst_y; row < row_count; ++row) + { + if (target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D) + { + GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, y, z, + update_w, src_format->block_height, 1, internal, dst_row_pitch, addr)); + } + else + { + GL_EXTCALL(glCompressedTexSubImage2D(target, level, dst_x, y, + update_w, src_format->block_height, internal, dst_row_pitch, addr)); + } + + y += src_format->block_height; + addr += src_row_pitch; + } + } + } + checkGLcall("Upload compressed texture data"); + } + else + { + unsigned int y, y_count; + + TRACE("Uploading data, target %#x, level %u, x %u, y %u, z %u, " + "w %u, h %u, d %u, format %#x, type %#x, addr %p.\n", + target, level, dst_x, dst_y, dst_z, update_w, update_h, + update_d, format_gl->format, format_gl->type, addr); + + if (src_row_pitch) + { + gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_row_pitch / src_format->byte_count); + y_count = 1; + } + else + { + y_count = update_h; + update_h = 1; + } + + for (y = 0; y < y_count; ++y) + { + if (target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D) + { + GL_EXTCALL(glTexSubImage3D(target, level, dst_x, dst_y + y, dst_z, + update_w, update_h, update_d, format_gl->format, format_gl->type, addr)); + } + else if (target == GL_TEXTURE_1D) + { + gl_info->gl_ops.gl.p_glTexSubImage1D(target, level, dst_x, + update_w, format_gl->format, format_gl->type, addr); + } + else + { + gl_info->gl_ops.gl.p_glTexSubImage2D(target, level, dst_x, dst_y + y, + update_w, update_h, format_gl->format, format_gl->type, addr); + } + } + gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + checkGLcall("Upload texture data"); + } +} + static void wined3d_texture_gl_upload_data(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, @@ -1856,7 +1974,6 @@ static void wined3d_texture_gl_upload_data(struct wined3d_context *context, unsigned int update_w = src_box->right - src_box->left; unsigned int update_h = src_box->bottom - src_box->top; unsigned int update_d = src_box->back - src_box->front; - const struct wined3d_format_gl *format_gl; struct wined3d_bo_address bo; void *converted_mem = NULL; struct wined3d_format_gl f; @@ -1981,116 +2098,8 @@ static void wined3d_texture_gl_upload_data(struct wined3d_context *context, checkGLcall("glBindBuffer"); } - format_gl = wined3d_format_gl(src_format); - if (src_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED) - { - unsigned int dst_row_pitch, dst_slice_pitch; - const BYTE *addr = bo.addr; - GLenum internal; - - if (srgb) - internal = format_gl->srgb_internal; - else if (dst_texture->resource.bind_flags & WINED3D_BIND_RENDER_TARGET - && wined3d_resource_is_offscreen(&dst_texture->resource)) - internal = format_gl->rt_internal; - else - internal = format_gl->internal; - - wined3d_format_calculate_pitch(src_format, 1, update_w, update_h, &dst_row_pitch, &dst_slice_pitch); - - TRACE("Uploading compressed data, target %#x, level %u, x %u, y %u, z %u, " - "w %u, h %u, d %u, format %#x, image_size %#x, addr %p.\n", - target, level, dst_x, dst_y, dst_z, update_w, update_h, - update_d, internal, dst_slice_pitch, addr); - - if (target == GL_TEXTURE_1D) - { - GL_EXTCALL(glCompressedTexSubImage1D(target, level, dst_x, - update_w, internal, dst_row_pitch, addr)); - } - else if (dst_row_pitch == src_row_pitch) - { - if (target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D) - { - GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, dst_y, dst_z, - update_w, update_h, update_d, internal, dst_slice_pitch * update_d, addr)); - } - else - { - GL_EXTCALL(glCompressedTexSubImage2D(target, level, dst_x, dst_y, - update_w, update_h, internal, dst_slice_pitch, addr)); - } - } - else - { - unsigned int row_count = (update_h + src_format->block_height - 1) / src_format->block_height; - unsigned int row, y, z; - - /* glCompressedTexSubImage2D() ignores pixel store state, so we - * can't use the unpack row length like for glTexSubImage2D. */ - for (z = dst_z; z < dst_z + update_d; ++z) - { - for (row = 0, y = dst_y; row < row_count; ++row) - { - if (target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D) - { - GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, y, z, - update_w, src_format->block_height, 1, internal, dst_row_pitch, addr)); - } - else - { - GL_EXTCALL(glCompressedTexSubImage2D(target, level, dst_x, y, - update_w, src_format->block_height, internal, dst_row_pitch, addr)); - } - - y += src_format->block_height; - addr += src_row_pitch; - } - } - } - checkGLcall("Upload compressed texture data"); - } - else - { - unsigned int y, y_count; - - TRACE("Uploading data, target %#x, level %u, x %u, y %u, z %u, " - "w %u, h %u, d %u, format %#x, type %#x, addr %p.\n", - target, level, dst_x, dst_y, dst_z, update_w, update_h, - update_d, format_gl->format, format_gl->type, bo.addr); - - if (src_row_pitch) - { - gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_row_pitch / src_format->byte_count); - y_count = 1; - } - else - { - y_count = update_h; - update_h = 1; - } - - for (y = 0; y < y_count; ++y) - { - if (target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D) - { - GL_EXTCALL(glTexSubImage3D(target, level, dst_x, dst_y + y, dst_z, - update_w, update_h, update_d, format_gl->format, format_gl->type, bo.addr)); - } - else if (target == GL_TEXTURE_1D) - { - gl_info->gl_ops.gl.p_glTexSubImage1D(target, level, dst_x, - update_w, format_gl->format, format_gl->type, bo.addr); - } - else - { - gl_info->gl_ops.gl.p_glTexSubImage2D(target, level, dst_x, dst_y + y, - update_w, update_h, format_gl->format, format_gl->type, bo.addr); - } - } - gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - checkGLcall("Upload texture data"); - } + wined3d_texture_gl_upload_bo(src_format, target, level, src_row_pitch, dst_x, dst_y, + dst_z, update_w, update_h, update_d, bo.addr, srgb, dst_texture, gl_info); if (bo.buffer_object) { -- 2.21.0