Commit a9cf391b authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Merge wined3d_surface_upload_data() into texture2d_upload_data().

parent 17c7f8e3
......@@ -1753,13 +1753,156 @@ void wined3d_texture_upload_data(struct wined3d_texture *texture, unsigned int s
format, src_box, data, row_pitch, slice_pitch, dst_x, dst_y, dst_z, srgb);
}
/* This call just uploads data, the caller is responsible for binding the
* correct texture. */
/* Context activation is done by the caller. */
static void texture2d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
const struct wined3d_context *context, const struct wined3d_format *format, const struct wined3d_box *src_box,
const struct wined3d_const_bo_address *data, unsigned int row_pitch, unsigned int slice_pitch,
const struct wined3d_const_bo_address *data, unsigned int src_row_pitch, unsigned int src_slice_pitch,
unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, BOOL srgb)
{
wined3d_surface_upload_data(texture, sub_resource_idx, context->gl_info,
format, src_box, row_pitch, dst_x, dst_y, srgb, data);
const struct wined3d_gl_info *gl_info = context->gl_info;
unsigned int update_w = src_box->right - src_box->left;
unsigned int update_h = src_box->bottom - src_box->top;
unsigned int level, layer;
GLenum target;
TRACE("texture %p, sub_resource_idx %u, context %p, format %s, src_box %s, data {%#x:%p}, "
"src_row_pitch %#x, src_slice_pitch %#x, dst_x %u, dst_y %u, dst_z %u, srgb %#x.\n",
texture, sub_resource_idx, context, debug_d3dformat(format->id), debug_box(src_box),
data->buffer_object, data->addr, src_row_pitch, src_slice_pitch, dst_x, dst_y, dst_z, srgb);
if (texture->sub_resources[sub_resource_idx].map_count)
{
WARN("Uploading a texture that is currently mapped, setting WINED3D_TEXTURE_PIN_SYSMEM.\n");
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM;
}
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_HEIGHT_SCALE)
{
update_h *= format->height_scale.numerator;
update_h /= format->height_scale.denominator;
}
if (data->buffer_object)
{
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object));
checkGLcall("glBindBuffer");
}
target = wined3d_texture_get_sub_resource_target(texture, sub_resource_idx);
level = sub_resource_idx % texture->level_count;
layer = sub_resource_idx / texture->level_count;
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED)
{
unsigned int dst_row_pitch, dst_slice_pitch;
const BYTE *addr = data->addr;
GLenum internal;
addr += (src_box->top / format->block_height) * src_row_pitch;
addr += (src_box->left / format->block_width) * format->block_byte_count;
if (srgb)
internal = format->glGammaInternal;
else if (texture->resource.usage & WINED3DUSAGE_RENDERTARGET
&& wined3d_resource_is_offscreen(&texture->resource))
internal = format->rtInternal;
else
internal = format->glInternal;
wined3d_format_calculate_pitch(format, 1, update_w, update_h, &dst_row_pitch, &dst_slice_pitch);
TRACE("Uploading compressed data, target %#x, level %u, layer %u, x %d, y %d, w %u, h %u, "
"format %#x, image_size %#x, addr %p.\n",
target, level, layer, dst_x, dst_y,
update_w, update_h, internal, dst_slice_pitch, addr);
if (dst_row_pitch == src_row_pitch)
{
if (target == GL_TEXTURE_2D_ARRAY)
{
GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, dst_y,
layer, update_w, update_h, 1, internal, dst_slice_pitch, addr));
}
else
{
GL_EXTCALL(glCompressedTexSubImage2D(target, level, dst_x, dst_y,
update_w, update_h, internal, dst_slice_pitch, addr));
}
}
else
{
UINT row_count = (update_h + format->block_height - 1) / format->block_height;
UINT row, y;
/* glCompressedTexSubImage2D() ignores pixel store state, so we
* can't use the unpack row length like for glTexSubImage2D. */
for (row = 0, y = dst_y; row < row_count; ++row)
{
if (target == GL_TEXTURE_2D_ARRAY)
{
GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, y,
layer, update_w, format->block_height, 1, internal, dst_row_pitch, addr));
}
else
{
GL_EXTCALL(glCompressedTexSubImage2D(target, level, dst_x, y,
update_w, format->block_height, internal, dst_row_pitch, addr));
}
y += format->block_height;
addr += src_row_pitch;
}
}
checkGLcall("Upload compressed texture data");
}
else
{
const BYTE *addr = data->addr;
addr += src_box->top * src_row_pitch;
addr += src_box->left * format->byte_count;
TRACE("Uploading data, target %#x, level %u, layer %u, x %d, y %d, w %u, h %u, "
"format %#x, type %#x, addr %p.\n",
target, level, layer, dst_x, dst_y,
update_w, update_h, format->glFormat, format->glType, addr);
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_row_pitch / format->byte_count);
if (target == GL_TEXTURE_2D_ARRAY)
{
GL_EXTCALL(glTexSubImage3D(target, level, dst_x, dst_y,
layer, update_w, update_h, 1, format->glFormat, format->glType, addr));
}
else
{
gl_info->gl_ops.gl.p_glTexSubImage2D(target, level, dst_x, dst_y,
update_w, update_h, format->glFormat, format->glType, addr);
}
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
checkGLcall("Upload texture data");
}
if (data->buffer_object)
{
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
checkGLcall("glBindBuffer");
}
if (wined3d_settings.strict_draw_ordering)
gl_info->gl_ops.gl.p_glFlush();
if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE)
{
struct wined3d_device *device = texture->resource.device;
unsigned int i;
for (i = 0; i < device->context_count; ++i)
{
context_texture_update(device->contexts[i], texture);
}
}
}
/* Context activation is done by the caller. Context may be NULL in ddraw-only mode. */
......
......@@ -3335,11 +3335,6 @@ struct fbo_entry
} key;
};
void wined3d_surface_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
const struct wined3d_gl_info *gl_info, const struct wined3d_format *format,
const struct wined3d_box *src_box, unsigned int src_pitch, unsigned int dst_x, unsigned int dst_y,
BOOL srgb, const struct wined3d_const_bo_address *data) DECLSPEC_HIDDEN;
void draw_textured_quad(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect,
enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment