2005-01-09 18:37:02 +01:00
|
|
|
/*
|
2011-04-15 18:33:39 +02:00
|
|
|
* Copyright 1997-2000 Marcus Meissner
|
|
|
|
* Copyright 1998-2000 Lionel Ulmer
|
2006-05-06 18:08:33 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2005-01-09 18:37:02 +01:00
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-13 16:15:54 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2014-01-07 22:12:15 +01:00
|
|
|
* Copyright 2006-2011, 2013-2014 Stefan Dösinger for CodeWeavers
|
2008-08-19 17:49:07 +02:00
|
|
|
* Copyright 2007-2008 Henri Verbeet
|
2008-02-10 22:20:15 +01:00
|
|
|
* Copyright 2006-2008 Roderick Colenbrander
|
2011-04-05 19:01:29 +02:00
|
|
|
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
|
2005-01-09 18:37:02 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-01-09 18:37:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 23:17:08 +02:00
|
|
|
#include "wine/port.h"
|
2005-01-09 18:37:02 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2016-03-29 16:45:35 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2013-04-17 08:47:59 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
static const DWORD surface_simple_locations = WINED3D_LOCATION_SYSMEM
|
|
|
|
| WINED3D_LOCATION_USER_MEMORY | WINED3D_LOCATION_BUFFER;
|
2014-01-15 14:54:09 +01:00
|
|
|
|
2014-08-04 12:17:26 +02:00
|
|
|
void surface_get_drawable_size(const struct wined3d_surface *surface, const struct wined3d_context *context,
|
|
|
|
unsigned int *width, unsigned int *height)
|
2010-08-16 20:00:23 +02:00
|
|
|
{
|
2014-08-20 13:20:00 +02:00
|
|
|
if (surface->container->swapchain)
|
2010-08-16 20:00:23 +02:00
|
|
|
{
|
2014-08-04 12:17:26 +02:00
|
|
|
/* The drawable size of an onscreen drawable is the surface size.
|
|
|
|
* (Actually: The window size, but the surface is created in window
|
|
|
|
* size.) */
|
2016-03-29 16:45:32 +02:00
|
|
|
*width = context->current_rt.texture->resource.width;
|
|
|
|
*height = context->current_rt.texture->resource.height;
|
2010-08-16 20:00:23 +02:00
|
|
|
}
|
2014-08-04 12:17:26 +02:00
|
|
|
else if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
|
2010-08-16 20:00:23 +02:00
|
|
|
{
|
2014-08-04 12:17:26 +02:00
|
|
|
const struct wined3d_swapchain *swapchain = context->swapchain;
|
2010-08-16 20:00:23 +02:00
|
|
|
|
2014-08-04 12:17:26 +02:00
|
|
|
/* The drawable size of a backbuffer / aux buffer offscreen target is
|
|
|
|
* the size of the current context's drawable, which is the size of
|
|
|
|
* the back buffer of the swapchain the active context belongs to. */
|
|
|
|
*width = swapchain->desc.backbuffer_width;
|
|
|
|
*height = swapchain->desc.backbuffer_height;
|
2010-08-16 20:00:23 +02:00
|
|
|
}
|
2014-08-04 12:17:26 +02:00
|
|
|
else
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
struct wined3d_surface *rt;
|
|
|
|
|
2014-08-04 12:17:26 +02:00
|
|
|
/* The drawable size of an FBO target is the OpenGL texture size,
|
|
|
|
* which is the power of two size. */
|
2016-03-29 16:45:32 +02:00
|
|
|
rt = context->current_rt.texture->sub_resources[context->current_rt.sub_resource_idx].u.surface;
|
2016-04-17 19:07:51 +02:00
|
|
|
*width = wined3d_texture_get_level_pow2_width(rt->container, rt->texture_level);
|
|
|
|
*height = wined3d_texture_get_level_pow2_height(rt->container, rt->texture_level);
|
2014-08-04 12:17:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 19:52:01 +01:00
|
|
|
struct blt_info
|
|
|
|
{
|
|
|
|
GLenum binding;
|
|
|
|
GLenum bind_target;
|
2015-04-02 00:30:49 +02:00
|
|
|
enum wined3d_gl_resource_type tex_type;
|
2010-03-05 19:52:01 +01:00
|
|
|
GLfloat coords[4][3];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct float_rect
|
|
|
|
{
|
|
|
|
float l;
|
|
|
|
float t;
|
|
|
|
float r;
|
|
|
|
float b;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void cube_coords_float(const RECT *r, UINT w, UINT h, struct float_rect *f)
|
|
|
|
{
|
|
|
|
f->l = ((r->left * 2.0f) / w) - 1.0f;
|
|
|
|
f->t = ((r->top * 2.0f) / h) - 1.0f;
|
|
|
|
f->r = ((r->right * 2.0f) / w) - 1.0f;
|
|
|
|
f->b = ((r->bottom * 2.0f) / h) - 1.0f;
|
|
|
|
}
|
|
|
|
|
2010-10-19 12:00:00 +02:00
|
|
|
static void surface_get_blt_info(GLenum target, const RECT *rect, GLsizei w, GLsizei h, struct blt_info *info)
|
2010-03-05 19:52:01 +01:00
|
|
|
{
|
|
|
|
GLfloat (*coords)[3] = info->coords;
|
|
|
|
struct float_rect f;
|
|
|
|
|
|
|
|
switch (target)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported texture target %#x\n", target);
|
|
|
|
/* Fall back to GL_TEXTURE_2D */
|
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_2D;
|
|
|
|
info->bind_target = GL_TEXTURE_2D;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_2D;
|
2010-10-19 12:00:00 +02:00
|
|
|
coords[0][0] = (float)rect->left / w;
|
|
|
|
coords[0][1] = (float)rect->top / h;
|
2010-03-05 19:52:01 +01:00
|
|
|
coords[0][2] = 0.0f;
|
|
|
|
|
2010-10-19 12:00:00 +02:00
|
|
|
coords[1][0] = (float)rect->right / w;
|
|
|
|
coords[1][1] = (float)rect->top / h;
|
2010-03-05 19:52:01 +01:00
|
|
|
coords[1][2] = 0.0f;
|
|
|
|
|
2010-10-19 12:00:00 +02:00
|
|
|
coords[2][0] = (float)rect->left / w;
|
|
|
|
coords[2][1] = (float)rect->bottom / h;
|
2010-03-05 19:52:01 +01:00
|
|
|
coords[2][2] = 0.0f;
|
|
|
|
|
2010-10-19 12:00:00 +02:00
|
|
|
coords[3][0] = (float)rect->right / w;
|
|
|
|
coords[3][1] = (float)rect->bottom / h;
|
2010-03-05 19:52:01 +01:00
|
|
|
coords[3][2] = 0.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_RECTANGLE_ARB:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_RECTANGLE_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_RECTANGLE_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_RECT;
|
2010-10-19 12:00:00 +02:00
|
|
|
coords[0][0] = rect->left; coords[0][1] = rect->top; coords[0][2] = 0.0f;
|
|
|
|
coords[1][0] = rect->right; coords[1][1] = rect->top; coords[1][2] = 0.0f;
|
|
|
|
coords[2][0] = rect->left; coords[2][1] = rect->bottom; coords[2][2] = 0.0f;
|
|
|
|
coords[3][0] = rect->right; coords[3][1] = rect->bottom; coords[3][2] = 0.0f;
|
2010-03-05 19:52:01 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
|
2010-10-19 12:00:00 +02:00
|
|
|
cube_coords_float(rect, w, h, &f);
|
2010-03-05 19:52:01 +01:00
|
|
|
|
|
|
|
coords[0][0] = 1.0f; coords[0][1] = -f.t; coords[0][2] = -f.l;
|
|
|
|
coords[1][0] = 1.0f; coords[1][1] = -f.t; coords[1][2] = -f.r;
|
|
|
|
coords[2][0] = 1.0f; coords[2][1] = -f.b; coords[2][2] = -f.l;
|
|
|
|
coords[3][0] = 1.0f; coords[3][1] = -f.b; coords[3][2] = -f.r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
|
2010-10-19 12:00:00 +02:00
|
|
|
cube_coords_float(rect, w, h, &f);
|
2010-03-05 19:52:01 +01:00
|
|
|
|
|
|
|
coords[0][0] = -1.0f; coords[0][1] = -f.t; coords[0][2] = f.l;
|
|
|
|
coords[1][0] = -1.0f; coords[1][1] = -f.t; coords[1][2] = f.r;
|
|
|
|
coords[2][0] = -1.0f; coords[2][1] = -f.b; coords[2][2] = f.l;
|
|
|
|
coords[3][0] = -1.0f; coords[3][1] = -f.b; coords[3][2] = f.r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
|
2010-10-19 12:00:00 +02:00
|
|
|
cube_coords_float(rect, w, h, &f);
|
2010-03-05 19:52:01 +01:00
|
|
|
|
|
|
|
coords[0][0] = f.l; coords[0][1] = 1.0f; coords[0][2] = f.t;
|
|
|
|
coords[1][0] = f.r; coords[1][1] = 1.0f; coords[1][2] = f.t;
|
|
|
|
coords[2][0] = f.l; coords[2][1] = 1.0f; coords[2][2] = f.b;
|
|
|
|
coords[3][0] = f.r; coords[3][1] = 1.0f; coords[3][2] = f.b;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
|
2010-10-19 12:00:00 +02:00
|
|
|
cube_coords_float(rect, w, h, &f);
|
2010-03-05 19:52:01 +01:00
|
|
|
|
|
|
|
coords[0][0] = f.l; coords[0][1] = -1.0f; coords[0][2] = -f.t;
|
|
|
|
coords[1][0] = f.r; coords[1][1] = -1.0f; coords[1][2] = -f.t;
|
|
|
|
coords[2][0] = f.l; coords[2][1] = -1.0f; coords[2][2] = -f.b;
|
|
|
|
coords[3][0] = f.r; coords[3][1] = -1.0f; coords[3][2] = -f.b;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
|
2010-10-19 12:00:00 +02:00
|
|
|
cube_coords_float(rect, w, h, &f);
|
2010-03-05 19:52:01 +01:00
|
|
|
|
|
|
|
coords[0][0] = f.l; coords[0][1] = -f.t; coords[0][2] = 1.0f;
|
|
|
|
coords[1][0] = f.r; coords[1][1] = -f.t; coords[1][2] = 1.0f;
|
|
|
|
coords[2][0] = f.l; coords[2][1] = -f.b; coords[2][2] = 1.0f;
|
|
|
|
coords[3][0] = f.r; coords[3][1] = -f.b; coords[3][2] = 1.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
|
|
|
|
info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
2015-04-02 00:30:49 +02:00
|
|
|
info->tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
|
2010-10-19 12:00:00 +02:00
|
|
|
cube_coords_float(rect, w, h, &f);
|
2010-03-05 19:52:01 +01:00
|
|
|
|
|
|
|
coords[0][0] = -f.l; coords[0][1] = -f.t; coords[0][2] = -1.0f;
|
|
|
|
coords[1][0] = -f.r; coords[1][1] = -f.t; coords[1][2] = -1.0f;
|
|
|
|
coords[2][0] = -f.l; coords[2][1] = -f.b; coords[2][2] = -1.0f;
|
|
|
|
coords[3][0] = -f.r; coords[3][1] = -f.b; coords[3][2] = -1.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 22:29:03 +02:00
|
|
|
static void surface_get_rect(const struct wined3d_surface *surface, const RECT *rect_in, RECT *rect_out)
|
2010-03-25 23:00:42 +01:00
|
|
|
{
|
|
|
|
if (rect_in)
|
|
|
|
*rect_out = *rect_in;
|
|
|
|
else
|
|
|
|
{
|
2016-04-03 15:30:55 +02:00
|
|
|
const struct wined3d_texture *texture = surface->container;
|
|
|
|
|
2016-07-30 22:00:33 +02:00
|
|
|
SetRect(rect_out, 0, 0, wined3d_texture_get_level_width(texture, surface->texture_level),
|
|
|
|
wined3d_texture_get_level_height(texture, surface->texture_level));
|
2010-03-25 23:00:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-08-26 01:12:26 +02:00
|
|
|
void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3d_context *context,
|
2012-01-12 21:43:12 +01:00
|
|
|
const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter)
|
2010-03-17 13:56:18 +01:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2013-11-18 10:46:18 +01:00
|
|
|
struct wined3d_texture *texture = src_surface->container;
|
2010-03-17 13:56:18 +01:00
|
|
|
struct blt_info info;
|
|
|
|
|
2016-04-17 19:07:52 +02:00
|
|
|
surface_get_blt_info(src_surface->texture_target, src_rect,
|
|
|
|
wined3d_texture_get_level_pow2_width(texture, src_surface->texture_level),
|
|
|
|
wined3d_texture_get_level_pow2_height(texture, src_surface->texture_level), &info);
|
2010-03-17 13:56:18 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnable(info.bind_target);
|
2010-03-17 13:56:18 +01:00
|
|
|
checkGLcall("glEnable(bind_target)");
|
|
|
|
|
2013-11-20 10:04:32 +01:00
|
|
|
context_bind_texture(context, info.bind_target, texture->texture_rgb.name);
|
2010-03-17 13:56:18 +01:00
|
|
|
|
|
|
|
/* Filtering for StretchRect */
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(filter));
|
2010-03-17 13:56:18 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MIN_FILTER,
|
2015-01-15 17:19:05 +01:00
|
|
|
wined3d_gl_min_mip_filter(filter, WINED3D_TEXF_NONE));
|
2010-03-17 13:56:18 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
2015-02-09 21:19:50 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2011-09-08 23:50:35 +02:00
|
|
|
if (context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
|
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2010-03-17 13:56:18 +01:00
|
|
|
checkGLcall("glTexEnvi");
|
|
|
|
|
|
|
|
/* Draw a quad */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[0]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->left, dst_rect->top);
|
2010-03-17 13:56:18 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[1]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->right, dst_rect->top);
|
2010-03-17 13:56:18 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[2]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->left, dst_rect->bottom);
|
2010-03-17 13:56:18 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[3]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->right, dst_rect->bottom);
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2010-03-17 13:56:18 +01:00
|
|
|
|
|
|
|
/* Unbind the texture */
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, info.bind_target, 0);
|
2010-03-17 13:56:18 +01:00
|
|
|
|
|
|
|
/* We changed the filtering settings on the texture. Inform the
|
|
|
|
* container about this to get the filters reset properly next draw. */
|
2015-01-15 17:19:04 +01:00
|
|
|
texture->texture_rgb.sampler_desc.mag_filter = WINED3D_TEXF_POINT;
|
|
|
|
texture->texture_rgb.sampler_desc.min_filter = WINED3D_TEXF_POINT;
|
|
|
|
texture->texture_rgb.sampler_desc.mip_filter = WINED3D_TEXF_NONE;
|
|
|
|
texture->texture_rgb.sampler_desc.srgb_decode = FALSE;
|
2010-03-17 13:56:18 +01:00
|
|
|
}
|
2010-03-05 19:52:01 +01:00
|
|
|
|
2012-08-15 00:38:25 +02:00
|
|
|
/* Works correctly only for <= 4 bpp formats. */
|
|
|
|
static void get_color_masks(const struct wined3d_format *format, DWORD *masks)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
masks[0] = ((1u << format->red_size) - 1) << format->red_offset;
|
|
|
|
masks[1] = ((1u << format->green_size) - 1) << format->green_offset;
|
|
|
|
masks[2] = ((1u << format->blue_size) - 1) << format->blue_offset;
|
2012-08-15 00:38:25 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
void wined3d_surface_destroy_dc(struct wined3d_surface *surface)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-04-14 19:32:46 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2016-03-14 17:02:12 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2016-04-14 19:32:46 +02:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
|
|
|
const struct wined3d_gl_info *gl_info = NULL;
|
|
|
|
D3DKMT_DESTROYDCFROMMEMORY destroy_desc;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
struct wined3d_bo_address data;
|
|
|
|
NTSTATUS status;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (!surface->dc)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-04-14 19:32:46 +02:00
|
|
|
ERR("Surface %p has no DC.\n", surface);
|
|
|
|
return;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
TRACE("dc %p, bitmap %p.\n", surface->dc, surface->bitmap);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
destroy_desc.hDc = surface->dc;
|
|
|
|
destroy_desc.hBitmap = surface->bitmap;
|
|
|
|
if ((status = D3DKMTDestroyDCFromMemory(&destroy_desc)))
|
|
|
|
ERR("Failed to destroy dc, status %#x.\n", status);
|
|
|
|
surface->dc = NULL;
|
|
|
|
surface->bitmap = NULL;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
|
2016-04-14 19:32:46 +02:00
|
|
|
wined3d_texture_unmap_bo_address(&data, gl_info, GL_PIXEL_UNPACK_BUFFER);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (context)
|
|
|
|
context_release(context);
|
|
|
|
}
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
HRESULT wined3d_surface_create_dc(struct wined3d_surface *surface)
|
|
|
|
{
|
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
|
|
|
const struct wined3d_gl_info *gl_info = NULL;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
unsigned int row_pitch, slice_pitch;
|
|
|
|
struct wined3d_bo_address data;
|
|
|
|
D3DKMT_CREATEDCFROMMEMORY desc;
|
|
|
|
NTSTATUS status;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
TRACE("surface %p.\n", surface);
|
|
|
|
|
|
|
|
if (!format->ddi_format)
|
|
|
|
{
|
|
|
|
WARN("Cannot create a DC for format %s.\n", debug_d3dformat(format->id));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
wined3d_texture_get_pitch(texture, surface->texture_level, &row_pitch, &slice_pitch);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (device->d3d_initialized)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-04-14 19:32:46 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
|
2016-04-20 19:29:12 +02:00
|
|
|
desc.pMemory = wined3d_texture_map_bo_address(&data, texture->sub_resources[sub_resource_idx].size,
|
2016-04-14 19:32:46 +02:00
|
|
|
gl_info, GL_PIXEL_UNPACK_BUFFER, 0);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (context)
|
|
|
|
context_release(context);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
desc.Format = format->ddi_format;
|
|
|
|
desc.Width = wined3d_texture_get_level_width(texture, surface->texture_level);
|
|
|
|
desc.Height = wined3d_texture_get_level_height(texture, surface->texture_level);
|
|
|
|
desc.Pitch = row_pitch;
|
|
|
|
desc.hDeviceDc = CreateCompatibleDC(NULL);
|
|
|
|
desc.pColorTable = NULL;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
status = D3DKMTCreateDCFromMemory(&desc);
|
|
|
|
DeleteDC(desc.hDeviceDc);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
WARN("Failed to create DC, status %#x.\n", status);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->dc = desc.hDc;
|
|
|
|
surface->bitmap = desc.hBitmap;
|
|
|
|
|
|
|
|
TRACE("Created DC %p, bitmap %p for surface %p.\n", surface->dc, surface->bitmap, surface);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-17 22:29:04 +02:00
|
|
|
static BOOL surface_is_full_rect(const struct wined3d_surface *surface, const RECT *r)
|
2011-04-29 13:03:39 +02:00
|
|
|
{
|
2016-04-03 15:30:57 +02:00
|
|
|
unsigned int t;
|
|
|
|
|
|
|
|
t = wined3d_texture_get_level_width(surface->container, surface->texture_level);
|
|
|
|
if ((r->left && r->right) || abs(r->right - r->left) != t)
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
2016-04-03 15:30:57 +02:00
|
|
|
t = wined3d_texture_get_level_height(surface->container, surface->texture_level);
|
|
|
|
if ((r->top && r->bottom) || abs(r->bottom - r->top) != t)
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
static void surface_depth_blt_fbo(const struct wined3d_device *device,
|
|
|
|
struct wined3d_surface *src_surface, DWORD src_location, const RECT *src_rect,
|
|
|
|
struct wined3d_surface *dst_surface, DWORD dst_location, const RECT *dst_rect)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-04-22 17:11:53 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
2016-08-02 12:26:33 +02:00
|
|
|
unsigned int src_sub_resource_idx = surface_get_sub_resource_idx(src_surface);
|
2016-04-22 17:11:53 +02:00
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
2011-04-29 13:03:40 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
DWORD src_mask, dst_mask;
|
|
|
|
GLbitfield gl_mask;
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
TRACE("device %p\n", device);
|
|
|
|
TRACE("src_surface %p, src_location %s, src_rect %s,\n",
|
2014-01-17 13:27:16 +01:00
|
|
|
src_surface, wined3d_debug_location(src_location), wine_dbgstr_rect(src_rect));
|
2013-02-18 13:56:22 +01:00
|
|
|
TRACE("dst_surface %p, dst_location %s, dst_rect %s.\n",
|
2014-01-17 13:27:16 +01:00
|
|
|
dst_surface, wined3d_debug_location(dst_location), wine_dbgstr_rect(dst_rect));
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2016-04-22 17:11:53 +02:00
|
|
|
src_mask = src_texture->resource.format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
|
|
|
|
dst_mask = dst_texture->resource.format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
if (src_mask != dst_mask)
|
2011-04-29 13:03:39 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
ERR("Incompatible formats %s and %s.\n",
|
2016-04-22 17:11:53 +02:00
|
|
|
debug_d3dformat(src_texture->resource.format->id),
|
|
|
|
debug_d3dformat(dst_texture->resource.format->id));
|
2011-04-29 13:03:40 +02:00
|
|
|
return;
|
2011-04-29 13:03:39 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
if (!src_mask)
|
2011-04-29 13:03:39 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
ERR("Not a depth / stencil format: %s.\n",
|
2016-04-22 17:11:53 +02:00
|
|
|
debug_d3dformat(src_texture->resource.format->id));
|
2011-04-29 13:03:40 +02:00
|
|
|
return;
|
2011-04-29 13:03:39 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
gl_mask = 0;
|
|
|
|
if (src_mask & WINED3DFMT_FLAG_DEPTH)
|
|
|
|
gl_mask |= GL_DEPTH_BUFFER_BIT;
|
|
|
|
if (src_mask & WINED3DFMT_FLAG_STENCIL)
|
|
|
|
gl_mask |= GL_STENCIL_BUFFER_BIT;
|
|
|
|
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
if (!context->valid)
|
2011-04-29 13:03:39 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping blit.\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2015-10-15 22:41:12 +02:00
|
|
|
/* Make sure the locations are up-to-date. Loading the destination
|
|
|
|
* surface isn't required if the entire surface is overwritten. */
|
2016-08-02 12:26:33 +02:00
|
|
|
wined3d_texture_load_location(src_texture, src_sub_resource_idx, context, src_location);
|
2015-10-15 22:41:12 +02:00
|
|
|
if (!surface_is_full_rect(dst_surface, dst_rect))
|
2016-08-02 12:26:33 +02:00
|
|
|
wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location);
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
2016-04-22 17:11:53 +02:00
|
|
|
wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, dst_location);
|
2015-10-15 22:41:12 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
gl_info = context->gl_info;
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, NULL, src_surface, src_location);
|
2011-04-29 13:03:40 +02:00
|
|
|
context_check_fbo_status(context, GL_READ_FRAMEBUFFER);
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, NULL, dst_surface, dst_location);
|
2011-04-29 13:03:40 +02:00
|
|
|
context_set_draw_buffer(context, GL_NONE);
|
|
|
|
context_check_fbo_status(context, GL_DRAW_FRAMEBUFFER);
|
2012-01-18 23:41:32 +01:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
if (gl_mask & GL_DEPTH_BUFFER_BIT)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE));
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
if (gl_mask & GL_STENCIL_BUFFER_BIT)
|
|
|
|
{
|
|
|
|
if (context->gl_info->supported[EXT_STENCIL_TWO_SIDE])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE));
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glStencilMask(~0U);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
|
2011-04-29 13:03:39 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE));
|
2011-04-29 13:03:39 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
|
|
|
|
dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, gl_mask, GL_NEAREST);
|
|
|
|
checkGLcall("glBlitFramebuffer()");
|
2011-04-27 20:21:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2011-04-27 20:21:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
context_release(context);
|
|
|
|
}
|
2011-04-27 20:21:42 +02:00
|
|
|
|
2011-08-21 21:35:00 +02:00
|
|
|
/* Blit between surface locations. Onscreen on different swapchains is not supported.
|
2015-10-12 22:34:42 +02:00
|
|
|
* Depth / stencil is not supported. Context activation is done by the caller. */
|
|
|
|
static void surface_blt_fbo(const struct wined3d_device *device,
|
|
|
|
struct wined3d_context *old_ctx, enum wined3d_texture_filter_type filter,
|
2011-08-21 21:35:00 +02:00
|
|
|
struct wined3d_surface *src_surface, DWORD src_location, const RECT *src_rect_in,
|
|
|
|
struct wined3d_surface *dst_surface, DWORD dst_location, const RECT *dst_rect_in)
|
|
|
|
{
|
2016-04-22 17:11:54 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
2011-08-21 21:35:00 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2015-10-12 22:34:42 +02:00
|
|
|
struct wined3d_context *context = old_ctx;
|
|
|
|
struct wined3d_surface *required_rt, *restore_rt = NULL;
|
2011-08-21 21:35:00 +02:00
|
|
|
RECT src_rect, dst_rect;
|
|
|
|
GLenum gl_filter;
|
|
|
|
GLenum buffer;
|
|
|
|
|
|
|
|
TRACE("device %p, filter %s,\n", device, debug_d3dtexturefiltertype(filter));
|
|
|
|
TRACE("src_surface %p, src_location %s, src_rect %s,\n",
|
2014-01-17 13:27:16 +01:00
|
|
|
src_surface, wined3d_debug_location(src_location), wine_dbgstr_rect(src_rect_in));
|
2011-08-21 21:35:00 +02:00
|
|
|
TRACE("dst_surface %p, dst_location %s, dst_rect %s.\n",
|
2014-01-17 13:27:16 +01:00
|
|
|
dst_surface, wined3d_debug_location(dst_location), wine_dbgstr_rect(dst_rect_in));
|
2011-08-21 21:35:00 +02:00
|
|
|
|
|
|
|
src_rect = *src_rect_in;
|
|
|
|
dst_rect = *dst_rect_in;
|
|
|
|
|
|
|
|
switch (filter)
|
|
|
|
{
|
2012-01-12 21:43:12 +01:00
|
|
|
case WINED3D_TEXF_LINEAR:
|
2011-08-21 21:35:00 +02:00
|
|
|
gl_filter = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported filter mode %s (%#x).\n", debug_d3dtexturefiltertype(filter), filter);
|
2012-01-12 21:43:12 +01:00
|
|
|
case WINED3D_TEXF_NONE:
|
|
|
|
case WINED3D_TEXF_POINT:
|
2011-08-21 21:35:00 +02:00
|
|
|
gl_filter = GL_NEAREST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-25 21:05:03 +02:00
|
|
|
/* Resolve the source surface first if needed. */
|
2014-01-17 13:27:16 +01:00
|
|
|
if (src_location == WINED3D_LOCATION_RB_MULTISAMPLE
|
2016-04-22 17:11:54 +02:00
|
|
|
&& (src_texture->resource.format->id != dst_texture->resource.format->id
|
2011-08-25 21:05:03 +02:00
|
|
|
|| abs(src_rect.bottom - src_rect.top) != abs(dst_rect.bottom - dst_rect.top)
|
|
|
|
|| abs(src_rect.right - src_rect.left) != abs(dst_rect.right - dst_rect.left)))
|
2014-01-17 13:27:16 +01:00
|
|
|
src_location = WINED3D_LOCATION_RB_RESOLVED;
|
2011-08-25 21:05:03 +02:00
|
|
|
|
2011-08-21 21:35:00 +02:00
|
|
|
/* Make sure the locations are up-to-date. Loading the destination
|
|
|
|
* surface isn't required if the entire surface is overwritten. (And is
|
|
|
|
* in fact harmful if we're being called by surface_load_location() with
|
|
|
|
* the purpose of loading the destination surface.) */
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(src_surface, old_ctx, src_location);
|
2011-08-21 21:35:00 +02:00
|
|
|
if (!surface_is_full_rect(dst_surface, &dst_rect))
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(dst_surface, old_ctx, dst_location);
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
2016-04-22 17:11:54 +02:00
|
|
|
wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, old_ctx, dst_location);
|
2015-10-28 15:29:17 +01:00
|
|
|
|
2011-08-21 21:35:00 +02:00
|
|
|
|
2015-10-12 22:34:42 +02:00
|
|
|
if (src_location == WINED3D_LOCATION_DRAWABLE) required_rt = src_surface;
|
|
|
|
else if (dst_location == WINED3D_LOCATION_DRAWABLE) required_rt = dst_surface;
|
|
|
|
else required_rt = NULL;
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
restore_rt = context_get_rt_surface(old_ctx);
|
|
|
|
if (restore_rt != required_rt)
|
2015-10-12 22:34:42 +02:00
|
|
|
context = context_acquire(device, required_rt);
|
2016-03-29 16:45:32 +02:00
|
|
|
else
|
|
|
|
restore_rt = NULL;
|
2011-08-21 21:35:00 +02:00
|
|
|
|
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping blit.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
if (src_location == WINED3D_LOCATION_DRAWABLE)
|
2011-08-21 21:35:00 +02:00
|
|
|
{
|
|
|
|
TRACE("Source surface %p is onscreen.\n", src_surface);
|
2016-04-22 17:11:54 +02:00
|
|
|
buffer = wined3d_texture_get_gl_buffer(src_texture);
|
2011-08-21 21:35:00 +02:00
|
|
|
surface_translate_drawable_coords(src_surface, context->win_handle, &src_rect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Source surface %p is offscreen.\n", src_surface);
|
|
|
|
buffer = GL_COLOR_ATTACHMENT0;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, src_surface, NULL, src_location);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(buffer);
|
2011-08-21 21:35:00 +02:00
|
|
|
checkGLcall("glReadBuffer()");
|
|
|
|
context_check_fbo_status(context, GL_READ_FRAMEBUFFER);
|
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
if (dst_location == WINED3D_LOCATION_DRAWABLE)
|
2011-08-21 21:35:00 +02:00
|
|
|
{
|
|
|
|
TRACE("Destination surface %p is onscreen.\n", dst_surface);
|
2016-04-22 17:11:54 +02:00
|
|
|
buffer = wined3d_texture_get_gl_buffer(dst_texture);
|
2011-08-21 21:35:00 +02:00
|
|
|
surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Destination surface %p is offscreen.\n", dst_surface);
|
|
|
|
buffer = GL_COLOR_ATTACHMENT0;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, dst_surface, NULL, dst_location);
|
|
|
|
context_set_draw_buffer(context, buffer);
|
|
|
|
context_check_fbo_status(context, GL_DRAW_FRAMEBUFFER);
|
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3));
|
2011-08-21 21:35:00 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE));
|
2011-08-21 21:35:00 +02:00
|
|
|
|
|
|
|
gl_info->fbo_ops.glBlitFramebuffer(src_rect.left, src_rect.top, src_rect.right, src_rect.bottom,
|
|
|
|
dst_rect.left, dst_rect.top, dst_rect.right, dst_rect.bottom, GL_COLOR_BUFFER_BIT, gl_filter);
|
|
|
|
checkGLcall("glBlitFramebuffer()");
|
|
|
|
|
2016-04-22 17:11:54 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering || (dst_location == WINED3D_LOCATION_DRAWABLE
|
|
|
|
&& dst_texture->swapchain->front_buffer == dst_texture))
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush();
|
2011-08-21 21:35:00 +02:00
|
|
|
|
2015-10-12 22:34:42 +02:00
|
|
|
if (restore_rt)
|
|
|
|
context_restore(context, restore_rt);
|
2011-08-21 21:35:00 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op,
|
2012-01-17 21:13:37 +01:00
|
|
|
const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
if ((wined3d_settings.offscreen_rendering_mode != ORM_FBO) || !gl_info->fbo_ops.glBlitFramebuffer)
|
|
|
|
return FALSE;
|
2011-04-27 20:21:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Source and/or destination need to be on the GL side */
|
2012-01-17 21:13:37 +01:00
|
|
|
if (src_pool == WINED3D_POOL_SYSTEM_MEM || dst_pool == WINED3D_POOL_SYSTEM_MEM)
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (blit_op)
|
2011-04-27 20:21:42 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT:
|
2015-04-24 10:33:47 +02:00
|
|
|
if (!((src_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FBO_ATTACHABLE)
|
|
|
|
|| (src_usage & WINED3DUSAGE_RENDERTARGET)))
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
2015-04-24 10:33:47 +02:00
|
|
|
if (!((dst_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FBO_ATTACHABLE)
|
|
|
|
|| (dst_usage & WINED3DUSAGE_RENDERTARGET)))
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
2015-10-22 00:20:56 +02:00
|
|
|
if (!(src_format->id == dst_format->id
|
|
|
|
|| (is_identity_fixup(src_format->color_fixup)
|
|
|
|
&& is_identity_fixup(dst_format->color_fixup))))
|
|
|
|
return FALSE;
|
2011-04-29 13:03:40 +02:00
|
|
|
break;
|
2011-04-27 20:21:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3D_BLIT_OP_DEPTH_BLIT:
|
2015-04-24 10:33:47 +02:00
|
|
|
if (!(src_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
2015-04-24 10:33:47 +02:00
|
|
|
if (!(dst_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
2015-10-22 00:20:56 +02:00
|
|
|
/* Accept pure swizzle fixups for depth formats. In general we
|
|
|
|
* ignore the stencil component (if present) at the moment and the
|
|
|
|
* swizzle is not relevant with just the depth component. */
|
|
|
|
if (is_complex_fixup(src_format->color_fixup) || is_complex_fixup(dst_format->color_fixup)
|
|
|
|
|| is_scaling_fixup(src_format->color_fixup) || is_scaling_fixup(dst_format->color_fixup))
|
|
|
|
return FALSE;
|
2011-04-29 13:03:40 +02:00
|
|
|
break;
|
2011-04-27 20:21:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
default:
|
|
|
|
return FALSE;
|
2011-04-27 20:21:42 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
return TRUE;
|
2011-04-27 20:21:42 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 22:29:05 +02:00
|
|
|
static BOOL surface_convert_depth_to_float(const struct wined3d_surface *surface, DWORD depth, float *float_depth)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2016-03-14 17:02:16 +01:00
|
|
|
const struct wined3d_format *format = surface->container->resource.format;
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
switch (format->id)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3DFMT_S1_UINT_D15_UNORM:
|
|
|
|
*float_depth = depth / (float)0x00007fff;
|
|
|
|
break;
|
2011-02-28 08:05:39 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3DFMT_D16_UNORM:
|
|
|
|
*float_depth = depth / (float)0x0000ffff;
|
|
|
|
break;
|
2011-02-28 08:05:39 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3DFMT_D24_UNORM_S8_UINT:
|
|
|
|
case WINED3DFMT_X8D24_UNORM:
|
|
|
|
*float_depth = depth / (float)0x00ffffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_D32_UNORM:
|
|
|
|
*float_depth = depth / (float)0xffffffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format->id));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2011-02-28 08:05:39 +01:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
static HRESULT wined3d_surface_depth_fill(struct wined3d_surface *surface, const RECT *rect, float depth)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2016-02-03 22:22:57 +01:00
|
|
|
struct wined3d_resource *resource = &surface->container->resource;
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = resource->device;
|
2016-02-03 22:22:57 +01:00
|
|
|
struct wined3d_rendertarget_view_desc view_desc;
|
|
|
|
struct wined3d_rendertarget_view *view;
|
2011-04-29 13:03:40 +02:00
|
|
|
const struct blit_shader *blitter;
|
2016-02-03 22:22:57 +01:00
|
|
|
HRESULT hr;
|
2011-02-28 08:05:39 +01:00
|
|
|
|
2016-02-03 22:22:57 +01:00
|
|
|
if (!(blitter = wined3d_select_blitter(&device->adapter->gl_info, &device->adapter->d3d_info,
|
|
|
|
WINED3D_BLIT_OP_DEPTH_FILL, NULL, 0, 0, NULL, rect, resource->usage, resource->pool, resource->format)))
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
FIXME("No blitter is capable of performing the requested depth fill operation.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:22:57 +01:00
|
|
|
view_desc.format_id = resource->format->id;
|
|
|
|
view_desc.u.texture.level_idx = surface->texture_level;
|
|
|
|
view_desc.u.texture.layer_idx = surface->texture_layer;
|
|
|
|
view_desc.u.texture.layer_count = 1;
|
|
|
|
if (FAILED(hr = wined3d_rendertarget_view_create(&view_desc,
|
|
|
|
resource, NULL, &wined3d_null_parent_ops, &view)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-03-15 10:52:49 +01:00
|
|
|
hr = blitter->depth_fill(device, view, rect, WINED3DCLEAR_ZBUFFER, depth, 0);
|
2016-02-03 22:22:57 +01:00
|
|
|
wined3d_rendertarget_view_decref(view);
|
|
|
|
|
|
|
|
return hr;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
static HRESULT wined3d_surface_depth_blt(struct wined3d_surface *src_surface, DWORD src_location, const RECT *src_rect,
|
|
|
|
struct wined3d_surface *dst_surface, DWORD dst_location, const RECT *dst_rect)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-16 18:16:55 +01:00
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_device *device = src_texture->resource.device;
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
if (!fbo_blit_supported(&device->adapter->gl_info, WINED3D_BLIT_OP_DEPTH_BLIT,
|
2016-03-16 18:16:55 +01:00
|
|
|
src_rect, src_texture->resource.usage, src_texture->resource.pool, src_texture->resource.format,
|
|
|
|
dst_rect, dst_texture->resource.usage, dst_texture->resource.pool, dst_texture->resource.format))
|
2011-04-29 13:03:40 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
surface_depth_blt_fbo(device, src_surface, src_location, src_rect, dst_surface, dst_location, dst_rect);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2013-02-18 13:56:22 +01:00
|
|
|
surface_modify_ds_location(dst_surface, dst_location,
|
2011-04-29 13:03:40 +02:00
|
|
|
dst_surface->ds_current_size.cx, dst_surface->ds_current_size.cy);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-02 09:45:42 +02:00
|
|
|
/* This call just downloads data, the caller is responsible for binding the
|
|
|
|
* correct texture. */
|
|
|
|
/* Context activation is done by the caller. */
|
2014-01-10 12:40:47 +01:00
|
|
|
static void surface_download_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info,
|
|
|
|
DWORD dst_location)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-04-22 11:18:46 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2016-03-16 18:16:56 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
2016-04-22 11:18:46 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-04-19 00:01:27 +02:00
|
|
|
unsigned int dst_row_pitch, dst_slice_pitch;
|
|
|
|
unsigned int src_row_pitch, src_slice_pitch;
|
2013-12-11 12:22:19 +01:00
|
|
|
struct wined3d_bo_address data;
|
2016-04-22 11:18:46 +02:00
|
|
|
BYTE *temporary_mem = NULL;
|
2016-04-19 00:01:27 +02:00
|
|
|
void *mem;
|
2011-02-28 08:05:39 +01:00
|
|
|
|
2013-09-02 09:45:42 +02:00
|
|
|
/* Only support read back of converted P8 surfaces. */
|
2016-03-16 18:16:56 +01:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_CONVERTED && format->id != WINED3DFMT_P8_UINT)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2013-09-02 09:45:42 +02:00
|
|
|
ERR("Trying to read back converted surface %p with format %s.\n", surface, debug_d3dformat(format->id));
|
|
|
|
return;
|
2011-02-28 08:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-04-22 11:18:46 +02:00
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
|
|
|
|
|
|
|
if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
2016-05-22 18:23:08 +02:00
|
|
|
/* NP2 emulation is not allowed on array textures. */
|
2016-04-22 11:18:46 +02:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
|
2016-05-22 18:23:08 +02:00
|
|
|
ERR("Array texture %p uses NP2 emulation.\n", texture);
|
2016-04-22 11:18:46 +02:00
|
|
|
|
|
|
|
WARN_(d3d_perf)("Downloading all miplevel layers to get the surface data for a single sub-resource.\n");
|
|
|
|
|
2016-05-23 18:06:27 +02:00
|
|
|
if (!(temporary_mem = wined3d_calloc(texture->layer_count, sub_resource->size)))
|
2016-04-22 11:18:46 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, dst_location);
|
2013-12-11 12:22:19 +01:00
|
|
|
|
2016-04-19 00:01:27 +02:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
|
2011-08-25 21:05:03 +02:00
|
|
|
{
|
2016-04-19 00:01:27 +02:00
|
|
|
wined3d_texture_get_pitch(texture, surface->texture_level, &dst_row_pitch, &dst_slice_pitch);
|
|
|
|
wined3d_format_calculate_pitch(format, texture->resource.device->surface_alignment,
|
|
|
|
wined3d_texture_get_level_pow2_width(texture, surface->texture_level),
|
|
|
|
wined3d_texture_get_level_pow2_height(texture, surface->texture_level),
|
|
|
|
&src_row_pitch, &src_slice_pitch);
|
2016-04-22 11:18:46 +02:00
|
|
|
if (!(temporary_mem = HeapAlloc(GetProcessHeap(), 0, src_slice_pitch)))
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-04-25 22:54:12 +02:00
|
|
|
|
2013-12-11 12:22:19 +01:00
|
|
|
if (data.buffer_object)
|
2016-04-19 00:01:27 +02:00
|
|
|
ERR("NP2 emulated texture uses PBO unexpectedly.\n");
|
|
|
|
if (texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
|
|
|
|
ERR("Unexpected compressed format for NP2 emulated texture.\n");
|
2011-04-25 22:54:12 +02:00
|
|
|
}
|
2016-04-22 11:18:46 +02:00
|
|
|
|
|
|
|
if (temporary_mem)
|
2011-04-25 22:54:12 +02:00
|
|
|
{
|
2016-04-22 11:18:46 +02:00
|
|
|
mem = temporary_mem;
|
2016-04-19 00:01:27 +02:00
|
|
|
}
|
2016-04-22 11:18:46 +02:00
|
|
|
else if (data.buffer_object)
|
2016-04-19 00:01:27 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
2016-04-22 11:18:46 +02:00
|
|
|
mem = data.addr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mem = data.addr;
|
2016-04-19 00:01:27 +02:00
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2016-04-19 00:01:27 +02:00
|
|
|
if (texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
|
|
|
|
{
|
|
|
|
TRACE("Downloading compressed surface %p, level %u, format %#x, type %#x, data %p.\n",
|
|
|
|
surface, surface->texture_level, format->glFormat, format->glType, mem);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2016-04-19 00:01:27 +02:00
|
|
|
GL_EXTCALL(glGetCompressedTexImage(surface->texture_target, surface->texture_level, mem));
|
|
|
|
checkGLcall("glGetCompressedTexImage");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Downloading surface %p, level %u, format %#x, type %#x, data %p.\n",
|
|
|
|
surface, surface->texture_level, format->glFormat, format->glType, mem);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2016-04-19 00:01:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetTexImage(surface->texture_target, surface->texture_level,
|
|
|
|
format->glFormat, format->glType, mem);
|
|
|
|
checkGLcall("glGetTexImage");
|
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2016-04-19 00:01:27 +02:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
|
|
|
|
{
|
|
|
|
const BYTE *src_data;
|
|
|
|
unsigned int h, y;
|
|
|
|
BYTE *dst_data;
|
|
|
|
/*
|
|
|
|
* Some games (e.g. warhammer 40k) don't work properly with the odd pitches, preventing
|
|
|
|
* the surface pitch from being used to box non-power2 textures. Instead we have to use a hack to
|
|
|
|
* repack the texture so that the bpp * width pitch can be used instead of bpp * pow2width.
|
|
|
|
*
|
|
|
|
* We're doing this...
|
|
|
|
*
|
|
|
|
* instead of boxing the texture :
|
|
|
|
* |<-texture width ->| -->pow2width| /\
|
|
|
|
* |111111111111111111| | |
|
|
|
|
* |222 Texture 222222| boxed empty | texture height
|
|
|
|
* |3333 Data 33333333| | |
|
|
|
|
* |444444444444444444| | \/
|
|
|
|
* ----------------------------------- |
|
|
|
|
* | boxed empty | boxed empty | pow2height
|
|
|
|
* | | | \/
|
|
|
|
* -----------------------------------
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* we're repacking the data to the expected texture width
|
|
|
|
*
|
|
|
|
* |<-texture width ->| -->pow2width| /\
|
|
|
|
* |111111111111111111222222222222222| |
|
|
|
|
* |222333333333333333333444444444444| texture height
|
|
|
|
* |444444 | |
|
|
|
|
* | | \/
|
|
|
|
* | | |
|
|
|
|
* | empty | pow2height
|
|
|
|
* | | \/
|
|
|
|
* -----------------------------------
|
|
|
|
*
|
|
|
|
* == is the same as
|
|
|
|
*
|
|
|
|
* |<-texture width ->| /\
|
|
|
|
* |111111111111111111|
|
|
|
|
* |222222222222222222|texture height
|
|
|
|
* |333333333333333333|
|
|
|
|
* |444444444444444444| \/
|
|
|
|
* --------------------
|
|
|
|
*
|
|
|
|
* This also means that any references to surface memory should work with the data as if it were a
|
|
|
|
* standard texture with a non-power2 width instead of a texture boxed up to be a power2 texture.
|
|
|
|
*
|
|
|
|
* internally the texture is still stored in a boxed format so any references to textureName will
|
|
|
|
* get a boxed texture with width pow2width and not a texture of width resource.width. */
|
|
|
|
src_data = mem;
|
|
|
|
dst_data = data.addr;
|
|
|
|
TRACE("Repacking the surface data from pitch %u to pitch %u.\n", src_row_pitch, dst_row_pitch);
|
|
|
|
h = wined3d_texture_get_level_height(texture, surface->texture_level);
|
|
|
|
for (y = 0; y < h; ++y)
|
2010-11-12 13:12:04 +01:00
|
|
|
{
|
2016-04-19 00:01:27 +02:00
|
|
|
memcpy(dst_data, src_data, dst_row_pitch);
|
|
|
|
src_data += src_row_pitch;
|
|
|
|
dst_data += dst_row_pitch;
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
2016-04-22 11:18:46 +02:00
|
|
|
}
|
|
|
|
else if (temporary_mem)
|
|
|
|
{
|
|
|
|
void *src_data = temporary_mem + surface->texture_layer * sub_resource->size;
|
|
|
|
if (data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
GL_EXTCALL(glBufferSubData(GL_PIXEL_PACK_BUFFER, 0, sub_resource->size, src_data));
|
|
|
|
checkGLcall("glBufferSubData");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(data.addr, src_data, sub_resource->size);
|
|
|
|
}
|
|
|
|
}
|
2016-04-19 00:01:27 +02:00
|
|
|
|
2016-04-22 11:18:46 +02:00
|
|
|
if (data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
2016-04-22 11:18:46 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, temporary_mem);
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* This call just uploads data, the caller is responsible for binding the
|
|
|
|
* correct texture. */
|
|
|
|
/* Context activation is done by the caller. */
|
2015-01-05 13:24:58 +01:00
|
|
|
void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info,
|
2011-10-27 17:06:23 +02:00
|
|
|
const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point,
|
2015-01-05 13:24:58 +01:00
|
|
|
BOOL srgb, const struct wined3d_const_bo_address *data)
|
2010-03-17 21:59:50 +01:00
|
|
|
{
|
2016-04-10 18:09:27 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2016-03-16 18:16:57 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2011-06-14 20:28:08 +02:00
|
|
|
UINT update_w = src_rect->right - src_rect->left;
|
|
|
|
UINT update_h = src_rect->bottom - src_rect->top;
|
2010-04-08 22:49:46 +02:00
|
|
|
|
2011-10-27 17:06:23 +02:00
|
|
|
TRACE("surface %p, gl_info %p, format %s, src_rect %s, src_pitch %u, dst_point %s, srgb %#x, data {%#x:%p}.\n",
|
|
|
|
surface, gl_info, debug_d3dformat(format->id), wine_dbgstr_rect(src_rect), src_pitch,
|
2011-06-14 20:28:08 +02:00
|
|
|
wine_dbgstr_point(dst_point), srgb, data->buffer_object, data->addr);
|
2008-08-26 21:36:30 +02:00
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
if (texture->sub_resources[sub_resource_idx].map_count)
|
2012-01-10 20:36:58 +01:00
|
|
|
{
|
2014-10-09 11:50:45 +02:00
|
|
|
WARN("Uploading a surface that is currently mapped, setting WINED3D_TEXTURE_PIN_SYSMEM.\n");
|
2016-03-16 18:16:57 +01:00
|
|
|
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM;
|
2012-01-10 20:36:58 +01:00
|
|
|
}
|
|
|
|
|
2015-04-24 10:33:47 +02:00
|
|
|
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_HEIGHT_SCALE)
|
2012-03-07 18:38:52 +01:00
|
|
|
{
|
|
|
|
update_h *= format->height_scale.numerator;
|
|
|
|
update_h /= format->height_scale.denominator;
|
|
|
|
}
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2011-06-09 20:40:49 +02:00
|
|
|
if (data->buffer_object)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
2009-08-03 08:06:52 +02:00
|
|
|
}
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2015-04-24 10:33:47 +02:00
|
|
|
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
2013-08-21 15:15:47 +02:00
|
|
|
UINT row_length = wined3d_format_calculate_size(format, 1, update_w, 1, 1);
|
2011-06-14 20:28:08 +02:00
|
|
|
UINT row_count = (update_h + format->block_height - 1) / format->block_height;
|
|
|
|
const BYTE *addr = data->addr;
|
|
|
|
GLenum internal;
|
|
|
|
|
|
|
|
addr += (src_rect->top / format->block_height) * src_pitch;
|
|
|
|
addr += (src_rect->left / format->block_width) * format->block_byte_count;
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2011-06-14 20:28:08 +02:00
|
|
|
if (srgb)
|
|
|
|
internal = format->glGammaInternal;
|
2016-03-16 18:16:57 +01:00
|
|
|
else if (texture->resource.usage & WINED3DUSAGE_RENDERTARGET
|
|
|
|
&& wined3d_resource_is_offscreen(&texture->resource))
|
2011-06-14 20:28:08 +02:00
|
|
|
internal = format->rtInternal;
|
|
|
|
else
|
|
|
|
internal = format->glInternal;
|
|
|
|
|
2016-04-25 12:25:30 +02:00
|
|
|
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",
|
|
|
|
surface->texture_target, surface->texture_level, surface->texture_layer,
|
2011-06-14 20:28:08 +02:00
|
|
|
dst_point->x, dst_point->y, update_w, update_h, internal, row_count * row_length, addr);
|
|
|
|
|
|
|
|
if (row_length == src_pitch)
|
|
|
|
{
|
2016-04-25 12:25:30 +02:00
|
|
|
if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glCompressedTexSubImage3D(surface->texture_target, surface->texture_level,
|
|
|
|
dst_point->x, dst_point->y, surface->texture_layer, update_w, update_h, 1,
|
|
|
|
internal, row_count * row_length, addr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glCompressedTexSubImage2D(surface->texture_target, surface->texture_level,
|
|
|
|
dst_point->x, dst_point->y, update_w, update_h,
|
|
|
|
internal, row_count * row_length, addr));
|
|
|
|
}
|
2011-06-14 20:28:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT row, y;
|
|
|
|
|
2015-01-20 15:47:05 +01:00
|
|
|
/* glCompressedTexSubImage2D() ignores pixel store state, so we
|
|
|
|
* can't use the unpack row length like for glTexSubImage2D. */
|
2011-06-14 20:28:08 +02:00
|
|
|
for (row = 0, y = dst_point->y; row < row_count; ++row)
|
|
|
|
{
|
2016-04-25 12:25:30 +02:00
|
|
|
if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glCompressedTexSubImage3D(surface->texture_target, surface->texture_level,
|
|
|
|
dst_point->x, y, surface->texture_layer, update_w, format->block_height, 1,
|
|
|
|
internal, row_length, addr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glCompressedTexSubImage2D(surface->texture_target, surface->texture_level,
|
|
|
|
dst_point->x, y, update_w, format->block_height, internal, row_length, addr));
|
|
|
|
}
|
|
|
|
|
2011-06-14 20:28:08 +02:00
|
|
|
y += format->block_height;
|
|
|
|
addr += src_pitch;
|
|
|
|
}
|
|
|
|
}
|
2016-04-25 12:25:30 +02:00
|
|
|
checkGLcall("Upload compressed surface data");
|
2009-06-11 10:24:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-14 20:28:08 +02:00
|
|
|
const BYTE *addr = data->addr;
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2011-10-27 17:06:23 +02:00
|
|
|
addr += src_rect->top * src_pitch;
|
2011-06-14 20:28:08 +02:00
|
|
|
addr += src_rect->left * format->byte_count;
|
|
|
|
|
2016-04-25 12:25:30 +02:00
|
|
|
TRACE("Uploading data, target %#x, level %u, layer %u, x %d, y %d, w %u, h %u, "
|
|
|
|
"format %#x, type %#x, addr %p.\n",
|
|
|
|
surface->texture_target, surface->texture_level, surface->texture_layer,
|
|
|
|
dst_point->x, dst_point->y, update_w, update_h, format->glFormat, format->glType, addr);
|
2011-06-14 20:28:08 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_pitch / format->byte_count);
|
2016-04-25 12:25:30 +02:00
|
|
|
if (surface->texture_target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTexSubImage3D(surface->texture_target, surface->texture_level,
|
|
|
|
dst_point->x, dst_point->y, surface->texture_layer, update_w, update_h, 1,
|
|
|
|
format->glFormat, format->glType, addr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glTexSubImage2D(surface->texture_target, surface->texture_level,
|
|
|
|
dst_point->x, dst_point->y, update_w, update_h, format->glFormat, format->glType, addr);
|
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2016-04-25 12:25:30 +02:00
|
|
|
checkGLcall("Upload surface data");
|
2009-08-03 08:06:52 +02:00
|
|
|
}
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2011-06-09 20:40:49 +02:00
|
|
|
if (data->buffer_object)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
2009-08-03 08:06:52 +02:00
|
|
|
|
2011-09-14 20:17:30 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush();
|
2011-09-14 20:17:30 +02:00
|
|
|
|
2010-03-17 21:59:51 +01:00
|
|
|
if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE)
|
|
|
|
{
|
2016-03-16 18:16:57 +01:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2010-03-17 21:59:51 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
context_surface_update(device->contexts[i], surface);
|
2010-03-17 21:59:51 +01:00
|
|
|
}
|
|
|
|
}
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 10:36:47 +02:00
|
|
|
static BOOL surface_check_block_align_rect(struct wined3d_surface *surface, const RECT *rect)
|
|
|
|
{
|
|
|
|
struct wined3d_box box = {rect->left, rect->top, rect->right, rect->bottom, 0, 1};
|
|
|
|
|
2016-02-17 18:35:35 +01:00
|
|
|
return wined3d_texture_check_block_align(surface->container, surface->texture_level, &box);
|
2015-10-06 10:36:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-24 20:45:42 +02:00
|
|
|
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
|
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect)
|
|
|
|
{
|
2016-03-31 22:48:54 +02:00
|
|
|
unsigned int src_sub_resource_idx = surface_get_sub_resource_idx(src_surface);
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
2016-03-16 18:16:58 +01:00
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
2016-02-10 19:29:59 +01:00
|
|
|
unsigned int src_row_pitch, src_slice_pitch;
|
2011-10-24 20:45:42 +02:00
|
|
|
const struct wined3d_format *src_format;
|
|
|
|
const struct wined3d_format *dst_format;
|
2015-04-22 11:30:15 +02:00
|
|
|
unsigned int src_fmt_flags, dst_fmt_flags;
|
2011-10-24 20:45:42 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
struct wined3d_bo_address data;
|
|
|
|
UINT update_w, update_h;
|
|
|
|
UINT dst_w, dst_h;
|
2012-07-11 12:19:01 +02:00
|
|
|
RECT r, dst_rect;
|
2011-10-24 20:45:42 +02:00
|
|
|
POINT p;
|
|
|
|
|
|
|
|
TRACE("dst_surface %p, dst_point %s, src_surface %p, src_rect %s.\n",
|
|
|
|
dst_surface, wine_dbgstr_point(dst_point),
|
|
|
|
src_surface, wine_dbgstr_rect(src_rect));
|
|
|
|
|
2016-03-16 18:16:58 +01:00
|
|
|
src_format = src_texture->resource.format;
|
|
|
|
dst_format = dst_texture->resource.format;
|
|
|
|
src_fmt_flags = src_texture->resource.format_flags;
|
|
|
|
dst_fmt_flags = dst_texture->resource.format_flags;
|
2011-10-24 20:45:42 +02:00
|
|
|
|
|
|
|
if (src_format->id != dst_format->id)
|
|
|
|
{
|
|
|
|
WARN("Source and destination surfaces should have the same format.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dst_point)
|
|
|
|
{
|
|
|
|
p.x = 0;
|
|
|
|
p.y = 0;
|
|
|
|
dst_point = &p;
|
|
|
|
}
|
|
|
|
else if (dst_point->x < 0 || dst_point->y < 0)
|
|
|
|
{
|
|
|
|
WARN("Invalid destination point.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!src_rect)
|
|
|
|
{
|
2016-04-05 18:24:21 +02:00
|
|
|
SetRect(&r, 0, 0, wined3d_texture_get_level_width(src_texture, src_surface->texture_level),
|
|
|
|
wined3d_texture_get_level_height(src_texture, src_surface->texture_level));
|
2011-10-24 20:45:42 +02:00
|
|
|
src_rect = &r;
|
|
|
|
}
|
2016-05-03 21:48:05 +02:00
|
|
|
else if (src_rect->left < 0 || src_rect->top < 0 || IsRectEmpty(src_rect))
|
2011-10-24 20:45:42 +02:00
|
|
|
{
|
|
|
|
WARN("Invalid source rectangle.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:24:21 +02:00
|
|
|
dst_w = wined3d_texture_get_level_width(dst_texture, dst_surface->texture_level);
|
|
|
|
dst_h = wined3d_texture_get_level_height(dst_texture, dst_surface->texture_level);
|
2011-10-24 20:45:42 +02:00
|
|
|
|
|
|
|
update_w = src_rect->right - src_rect->left;
|
|
|
|
update_h = src_rect->bottom - src_rect->top;
|
|
|
|
|
|
|
|
if (update_w > dst_w || dst_point->x > dst_w - update_w
|
|
|
|
|| update_h > dst_h || dst_point->y > dst_h - update_h)
|
|
|
|
{
|
|
|
|
WARN("Destination out of bounds.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:36:47 +02:00
|
|
|
if ((src_fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !surface_check_block_align_rect(src_surface, src_rect))
|
2012-07-11 12:19:01 +02:00
|
|
|
{
|
|
|
|
WARN("Source rectangle not block-aligned.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRect(&dst_rect, dst_point->x, dst_point->y, dst_point->x + update_w, dst_point->y + update_h);
|
2015-10-06 10:36:47 +02:00
|
|
|
if ((dst_fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !surface_check_block_align_rect(dst_surface, &dst_rect))
|
2011-10-24 20:45:42 +02:00
|
|
|
{
|
2012-07-11 12:19:01 +02:00
|
|
|
WARN("Destination rectangle not block-aligned.\n");
|
2011-10-24 20:45:42 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-11-02 22:46:52 +01:00
|
|
|
/* Use wined3d_surface_blt() instead of uploading directly if we need conversion. */
|
2016-03-16 18:16:58 +01:00
|
|
|
if (dst_format->convert || wined3d_format_get_color_key_conversion(dst_texture, FALSE))
|
2012-01-12 21:43:12 +01:00
|
|
|
return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, src_rect, 0, NULL, WINED3D_TEXF_POINT);
|
2011-10-24 20:45:42 +02:00
|
|
|
|
2016-03-16 18:16:58 +01:00
|
|
|
context = context_acquire(dst_texture->resource.device, NULL);
|
2011-10-24 20:45:42 +02:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
/* Only load the surface for partial updates. For newly allocated texture
|
|
|
|
* the texture wouldn't be the current location, and we'd upload zeroes
|
|
|
|
* just to overwrite them again. */
|
|
|
|
if (update_w == dst_w && update_h == dst_h)
|
2016-03-16 18:16:58 +01:00
|
|
|
wined3d_texture_prepare_texture(dst_texture, context, FALSE);
|
2011-10-24 20:45:42 +02:00
|
|
|
else
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(dst_surface, context, WINED3D_LOCATION_TEXTURE_RGB);
|
2016-03-16 18:16:58 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(dst_texture, context, FALSE);
|
2011-10-24 20:45:42 +02:00
|
|
|
|
2016-03-31 22:48:54 +02:00
|
|
|
wined3d_texture_get_memory(src_texture, src_sub_resource_idx, &data,
|
|
|
|
src_texture->sub_resources[src_sub_resource_idx].locations);
|
2016-03-16 18:16:58 +01:00
|
|
|
wined3d_texture_get_pitch(src_texture, src_surface->texture_level, &src_row_pitch, &src_slice_pitch);
|
2011-10-24 20:45:42 +02:00
|
|
|
|
2015-01-05 13:24:58 +01:00
|
|
|
wined3d_surface_upload_data(dst_surface, gl_info, src_format, src_rect,
|
2016-02-10 19:29:59 +01:00
|
|
|
src_row_pitch, dst_point, FALSE, wined3d_const_bo_address(&data));
|
2011-10-24 20:45:42 +02:00
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~WINED3D_LOCATION_TEXTURE_RGB);
|
2013-09-10 09:32:34 +02:00
|
|
|
|
2011-10-24 20:45:42 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-09 01:53:32 +02:00
|
|
|
/* In D3D the depth stencil dimensions have to be greater than or equal to the
|
|
|
|
* render target dimensions. With FBOs, the dimensions have to be an exact match. */
|
|
|
|
/* TODO: We should synchronize the renderbuffer's content with the texture's content. */
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-07 21:01:35 +02:00
|
|
|
void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, const struct wined3d_surface *rt)
|
2010-04-18 22:50:46 +02:00
|
|
|
{
|
2016-03-16 18:16:59 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &surface->container->resource.device->adapter->gl_info;
|
2011-05-16 23:01:24 +02:00
|
|
|
struct wined3d_renderbuffer_entry *entry;
|
2007-04-09 01:53:32 +02:00
|
|
|
GLuint renderbuffer = 0;
|
|
|
|
unsigned int src_width, src_height;
|
2011-04-04 17:46:01 +02:00
|
|
|
unsigned int width, height;
|
|
|
|
|
2016-03-16 18:16:59 +01:00
|
|
|
if (rt && rt->container->resource.format->id != WINED3DFMT_NULL)
|
2011-04-04 17:46:01 +02:00
|
|
|
{
|
2016-04-19 18:34:02 +02:00
|
|
|
width = wined3d_texture_get_level_pow2_width(rt->container, rt->texture_level);
|
|
|
|
height = wined3d_texture_get_level_pow2_height(rt->container, rt->texture_level);
|
2011-04-04 17:46:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-19 18:34:02 +02:00
|
|
|
width = wined3d_texture_get_level_pow2_width(surface->container, surface->texture_level);
|
|
|
|
height = wined3d_texture_get_level_pow2_height(surface->container, surface->texture_level);
|
2011-04-04 17:46:01 +02:00
|
|
|
}
|
2007-04-09 01:53:32 +02:00
|
|
|
|
2016-04-19 18:34:02 +02:00
|
|
|
src_width = wined3d_texture_get_level_pow2_width(surface->container, surface->texture_level);
|
|
|
|
src_height = wined3d_texture_get_level_pow2_height(surface->container, surface->texture_level);
|
2007-04-09 01:53:32 +02:00
|
|
|
|
|
|
|
/* A depth stencil smaller than the render target is not valid */
|
|
|
|
if (width > src_width || height > src_height) return;
|
|
|
|
|
|
|
|
/* Remove any renderbuffer set if the sizes match */
|
2009-09-23 10:05:56 +02:00
|
|
|
if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
|
|
|
|
|| (width == src_width && height == src_height))
|
|
|
|
{
|
2010-04-18 22:50:46 +02:00
|
|
|
surface->current_renderbuffer = NULL;
|
2007-04-09 01:53:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look if we've already got a renderbuffer of the correct dimensions */
|
2011-05-16 23:01:24 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(entry, &surface->renderbuffers, struct wined3d_renderbuffer_entry, entry)
|
2010-04-18 22:50:46 +02:00
|
|
|
{
|
|
|
|
if (entry->width == width && entry->height == height)
|
|
|
|
{
|
2007-04-09 01:53:32 +02:00
|
|
|
renderbuffer = entry->id;
|
2010-04-18 22:50:46 +02:00
|
|
|
surface->current_renderbuffer = entry;
|
2007-04-09 01:53:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-18 22:50:46 +02:00
|
|
|
if (!renderbuffer)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glGenRenderbuffers(1, &renderbuffer);
|
|
|
|
gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
|
|
|
gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER,
|
2016-03-16 18:16:59 +01:00
|
|
|
surface->container->resource.format->glInternal, width, height);
|
2007-04-09 01:53:32 +02:00
|
|
|
|
2011-05-16 23:01:24 +02:00
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
|
2007-04-09 01:53:32 +02:00
|
|
|
entry->width = width;
|
|
|
|
entry->height = height;
|
|
|
|
entry->id = renderbuffer;
|
2010-04-18 22:50:46 +02:00
|
|
|
list_add_head(&surface->renderbuffers, &entry->entry);
|
2007-04-09 01:53:32 +02:00
|
|
|
|
2010-04-18 22:50:46 +02:00
|
|
|
surface->current_renderbuffer = entry;
|
2007-04-09 01:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkGLcall("set_compatible_renderbuffer");
|
|
|
|
}
|
|
|
|
|
2011-04-25 22:54:13 +02:00
|
|
|
/* See also float_16_to_32() in wined3d_private.h */
|
|
|
|
static inline unsigned short float_32_to_16(const float *in)
|
|
|
|
{
|
|
|
|
int exp = 0;
|
2011-05-12 18:05:27 +02:00
|
|
|
float tmp = fabsf(*in);
|
2011-04-25 22:54:13 +02:00
|
|
|
unsigned int mantissa;
|
|
|
|
unsigned short ret;
|
|
|
|
|
|
|
|
/* Deal with special numbers */
|
|
|
|
if (*in == 0.0f)
|
|
|
|
return 0x0000;
|
|
|
|
if (isnan(*in))
|
|
|
|
return 0x7c01;
|
|
|
|
if (isinf(*in))
|
|
|
|
return (*in < 0.0f ? 0xfc00 : 0x7c00);
|
|
|
|
|
2015-08-26 12:46:46 +02:00
|
|
|
if (tmp < (float)(1u << 10))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tmp = tmp * 2.0f;
|
|
|
|
exp--;
|
2015-08-26 12:46:46 +02:00
|
|
|
} while (tmp < (float)(1u << 10));
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
2015-08-26 12:46:46 +02:00
|
|
|
else if (tmp >= (float)(1u << 11))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tmp /= 2.0f;
|
|
|
|
exp++;
|
2015-08-26 12:46:46 +02:00
|
|
|
} while (tmp >= (float)(1u << 11));
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mantissa = (unsigned int)tmp;
|
|
|
|
if (tmp - mantissa >= 0.5f)
|
|
|
|
++mantissa; /* Round to nearest, away from zero. */
|
|
|
|
|
|
|
|
exp += 10; /* Normalize the mantissa. */
|
|
|
|
exp += 15; /* Exponent is encoded with excess 15. */
|
|
|
|
|
|
|
|
if (exp > 30) /* too big */
|
|
|
|
{
|
|
|
|
ret = 0x7c00; /* INF */
|
|
|
|
}
|
|
|
|
else if (exp <= 0)
|
|
|
|
{
|
|
|
|
/* exp == 0: Non-normalized mantissa. Returns 0x0000 (=0.0) for too small numbers. */
|
|
|
|
while (exp <= 0)
|
|
|
|
{
|
|
|
|
mantissa = mantissa >> 1;
|
|
|
|
++exp;
|
|
|
|
}
|
|
|
|
ret = mantissa & 0x3ff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = (exp << 10) | (mantissa & 0x3ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret |= ((*in < 0.0f ? 1 : 0) << 15); /* Add the sign */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_r32_float_r16_float(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
unsigned short *dst_s;
|
|
|
|
const float *src_f;
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
src_f = (const float *)(src + y * pitch_in);
|
|
|
|
dst_s = (unsigned short *) (dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
dst_s[x] = float_32_to_16(src_f + x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_r5g6b5_x8r8g8b8(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
static const unsigned char convert_5to8[] =
|
|
|
|
{
|
|
|
|
0x00, 0x08, 0x10, 0x19, 0x21, 0x29, 0x31, 0x3a,
|
|
|
|
0x42, 0x4a, 0x52, 0x5a, 0x63, 0x6b, 0x73, 0x7b,
|
|
|
|
0x84, 0x8c, 0x94, 0x9c, 0xa5, 0xad, 0xb5, 0xbd,
|
|
|
|
0xc5, 0xce, 0xd6, 0xde, 0xe6, 0xef, 0xf7, 0xff,
|
|
|
|
};
|
|
|
|
static const unsigned char convert_6to8[] =
|
|
|
|
{
|
|
|
|
0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c,
|
|
|
|
0x20, 0x24, 0x28, 0x2d, 0x31, 0x35, 0x39, 0x3d,
|
|
|
|
0x41, 0x45, 0x49, 0x4d, 0x51, 0x55, 0x59, 0x5d,
|
|
|
|
0x61, 0x65, 0x69, 0x6d, 0x71, 0x75, 0x79, 0x7d,
|
|
|
|
0x82, 0x86, 0x8a, 0x8e, 0x92, 0x96, 0x9a, 0x9e,
|
|
|
|
0xa2, 0xa6, 0xaa, 0xae, 0xb2, 0xb6, 0xba, 0xbe,
|
|
|
|
0xc2, 0xc6, 0xca, 0xce, 0xd2, 0xd7, 0xdb, 0xdf,
|
|
|
|
0xe3, 0xe7, 0xeb, 0xef, 0xf3, 0xf7, 0xfb, 0xff,
|
|
|
|
};
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const WORD *src_line = (const WORD *)(src + y * pitch_in);
|
|
|
|
DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
WORD pixel = src_line[x];
|
2015-08-26 12:46:47 +02:00
|
|
|
dst_line[x] = 0xff000000u
|
|
|
|
| convert_5to8[(pixel & 0xf800u) >> 11] << 16
|
|
|
|
| convert_6to8[(pixel & 0x07e0u) >> 5] << 8
|
|
|
|
| convert_5to8[(pixel & 0x001fu)];
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-21 21:34:52 +02:00
|
|
|
/* We use this for both B8G8R8A8 -> B8G8R8X8 and B8G8R8X8 -> B8G8R8A8, since
|
|
|
|
* in both cases we're just setting the X / Alpha channel to 0xff. */
|
2011-04-25 22:54:13 +02:00
|
|
|
static void convert_a8r8g8b8_x8r8g8b8(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const DWORD *src_line = (const DWORD *)(src + y * pitch_in);
|
|
|
|
DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
|
|
|
|
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
dst_line[x] = 0xff000000 | (src_line[x] & 0xffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BYTE cliptobyte(int x)
|
|
|
|
{
|
|
|
|
return (BYTE)((x < 0) ? 0 : ((x > 255) ? 255 : x));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_yuy2_x8r8g8b8(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
int c2, d, e, r2 = 0, g2 = 0, b2 = 0;
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const BYTE *src_line = src + y * pitch_in;
|
|
|
|
DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
/* YUV to RGB conversion formulas from http://en.wikipedia.org/wiki/YUV:
|
|
|
|
* C = Y - 16; D = U - 128; E = V - 128;
|
|
|
|
* R = cliptobyte((298 * C + 409 * E + 128) >> 8);
|
|
|
|
* G = cliptobyte((298 * C - 100 * D - 208 * E + 128) >> 8);
|
|
|
|
* B = cliptobyte((298 * C + 516 * D + 128) >> 8);
|
|
|
|
* Two adjacent YUY2 pixels are stored as four bytes: Y0 U Y1 V .
|
|
|
|
* U and V are shared between the pixels. */
|
|
|
|
if (!(x & 1)) /* For every even pixel, read new U and V. */
|
|
|
|
{
|
|
|
|
d = (int) src_line[1] - 128;
|
|
|
|
e = (int) src_line[3] - 128;
|
|
|
|
r2 = 409 * e + 128;
|
|
|
|
g2 = - 100 * d - 208 * e + 128;
|
|
|
|
b2 = 516 * d + 128;
|
|
|
|
}
|
|
|
|
c2 = 298 * ((int) src_line[0] - 16);
|
|
|
|
dst_line[x] = 0xff000000
|
|
|
|
| cliptobyte((c2 + r2) >> 8) << 16 /* red */
|
|
|
|
| cliptobyte((c2 + g2) >> 8) << 8 /* green */
|
|
|
|
| cliptobyte((c2 + b2) >> 8); /* blue */
|
|
|
|
/* Scale RGB values to 0..255 range,
|
|
|
|
* then clip them if still not in range (may be negative),
|
|
|
|
* then shift them within DWORD if necessary. */
|
|
|
|
src_line += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_yuy2_r5g6b5(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
unsigned int x, y;
|
|
|
|
int c2, d, e, r2 = 0, g2 = 0, b2 = 0;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const BYTE *src_line = src + y * pitch_in;
|
|
|
|
WORD *dst_line = (WORD *)(dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
/* YUV to RGB conversion formulas from http://en.wikipedia.org/wiki/YUV:
|
|
|
|
* C = Y - 16; D = U - 128; E = V - 128;
|
|
|
|
* R = cliptobyte((298 * C + 409 * E + 128) >> 8);
|
|
|
|
* G = cliptobyte((298 * C - 100 * D - 208 * E + 128) >> 8);
|
|
|
|
* B = cliptobyte((298 * C + 516 * D + 128) >> 8);
|
|
|
|
* Two adjacent YUY2 pixels are stored as four bytes: Y0 U Y1 V .
|
|
|
|
* U and V are shared between the pixels. */
|
|
|
|
if (!(x & 1)) /* For every even pixel, read new U and V. */
|
|
|
|
{
|
|
|
|
d = (int) src_line[1] - 128;
|
|
|
|
e = (int) src_line[3] - 128;
|
|
|
|
r2 = 409 * e + 128;
|
|
|
|
g2 = - 100 * d - 208 * e + 128;
|
|
|
|
b2 = 516 * d + 128;
|
|
|
|
}
|
|
|
|
c2 = 298 * ((int) src_line[0] - 16);
|
|
|
|
dst_line[x] = (cliptobyte((c2 + r2) >> 8) >> 3) << 11 /* red */
|
|
|
|
| (cliptobyte((c2 + g2) >> 8) >> 2) << 5 /* green */
|
|
|
|
| (cliptobyte((c2 + b2) >> 8) >> 3); /* blue */
|
|
|
|
/* Scale RGB values to 0..255 range,
|
|
|
|
* then clip them if still not in range (may be negative),
|
|
|
|
* then shift them within DWORD if necessary. */
|
|
|
|
src_line += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
struct d3dfmt_converter_desc
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
enum wined3d_format_id from, to;
|
|
|
|
void (*convert)(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h);
|
|
|
|
};
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
static const struct d3dfmt_converter_desc converters[] =
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
{WINED3DFMT_R32_FLOAT, WINED3DFMT_R16_FLOAT, convert_r32_float_r16_float},
|
|
|
|
{WINED3DFMT_B5G6R5_UNORM, WINED3DFMT_B8G8R8X8_UNORM, convert_r5g6b5_x8r8g8b8},
|
|
|
|
{WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_B8G8R8X8_UNORM, convert_a8r8g8b8_x8r8g8b8},
|
2011-08-21 21:34:52 +02:00
|
|
|
{WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_B8G8R8A8_UNORM, convert_a8r8g8b8_x8r8g8b8},
|
2011-04-25 22:54:13 +02:00
|
|
|
{WINED3DFMT_YUY2, WINED3DFMT_B8G8R8X8_UNORM, convert_yuy2_x8r8g8b8},
|
|
|
|
{WINED3DFMT_YUY2, WINED3DFMT_B5G6R5_UNORM, convert_yuy2_r5g6b5},
|
|
|
|
};
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
static inline const struct d3dfmt_converter_desc *find_converter(enum wined3d_format_id from,
|
2011-04-25 22:54:13 +02:00
|
|
|
enum wined3d_format_id to)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
for (i = 0; i < (sizeof(converters) / sizeof(*converters)); ++i)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2012-08-16 12:58:54 +02:00
|
|
|
if (converters[i].from == from && converters[i].to == to)
|
|
|
|
return &converters[i];
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:53 +01:00
|
|
|
static struct wined3d_texture *surface_convert_format(struct wined3d_texture *src_texture,
|
2016-04-04 18:42:58 +02:00
|
|
|
unsigned int sub_resource_idx, const struct wined3d_format *dst_format)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-04-20 19:29:09 +02:00
|
|
|
unsigned int texture_level = sub_resource_idx % src_texture->level_count;
|
2016-04-04 18:42:58 +02:00
|
|
|
const struct wined3d_format *src_format = src_texture->resource.format;
|
|
|
|
struct wined3d_device *device = src_texture->resource.device;
|
|
|
|
const struct d3dfmt_converter_desc *conv = NULL;
|
2016-03-07 17:05:53 +01:00
|
|
|
struct wined3d_texture *dst_texture;
|
2013-11-13 10:12:09 +01:00
|
|
|
struct wined3d_resource_desc desc;
|
2016-04-04 18:42:58 +02:00
|
|
|
struct wined3d_map_desc src_map;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-04 18:42:58 +02:00
|
|
|
if (!(conv = find_converter(src_format->id, dst_format->id)) && (!device->d3d_initialized
|
|
|
|
|| !is_identity_fixup(src_format->color_fixup) || src_format->convert
|
|
|
|
|| !is_identity_fixup(dst_format->color_fixup) || dst_format->convert))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
FIXME("Cannot find a conversion function from format %s to %s.\n",
|
2016-04-04 18:42:58 +02:00
|
|
|
debug_d3dformat(src_format->id), debug_d3dformat(dst_format->id));
|
2011-04-25 22:54:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-23 21:01:05 +02:00
|
|
|
/* FIXME: Multisampled conversion? */
|
2016-01-27 00:06:23 +01:00
|
|
|
desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2016-04-04 18:42:58 +02:00
|
|
|
desc.format = dst_format->id;
|
2016-04-20 19:29:09 +02:00
|
|
|
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
|
|
|
|
desc.multisample_quality = 0;
|
2013-11-13 10:12:09 +01:00
|
|
|
desc.usage = 0;
|
|
|
|
desc.pool = WINED3D_POOL_SCRATCH;
|
2016-04-20 19:29:09 +02:00
|
|
|
desc.width = wined3d_texture_get_level_width(src_texture, texture_level);
|
|
|
|
desc.height = wined3d_texture_get_level_height(src_texture, texture_level);
|
|
|
|
desc.depth = 1;
|
|
|
|
desc.size = 0;
|
2016-04-25 12:25:29 +02:00
|
|
|
if (FAILED(wined3d_texture_create(device, &desc, 1, 1,
|
2016-01-27 00:06:25 +01:00
|
|
|
WINED3D_TEXTURE_CREATE_MAPPABLE | WINED3D_TEXTURE_CREATE_DISCARD,
|
2016-03-07 17:05:53 +01:00
|
|
|
NULL, NULL, &wined3d_null_parent_ops, &dst_texture)))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-03-07 17:05:53 +01:00
|
|
|
ERR("Failed to create a destination texture for conversion.\n");
|
2011-04-25 22:54:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-05 22:06:56 +01:00
|
|
|
memset(&src_map, 0, sizeof(src_map));
|
2016-03-07 17:05:53 +01:00
|
|
|
if (FAILED(wined3d_resource_map(&src_texture->resource, sub_resource_idx,
|
|
|
|
&src_map, NULL, WINED3D_MAP_READONLY)))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-03-07 17:05:53 +01:00
|
|
|
ERR("Failed to map the source texture.\n");
|
|
|
|
wined3d_texture_decref(dst_texture);
|
2011-04-25 22:54:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-04-04 18:42:58 +02:00
|
|
|
if (conv)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-04-04 18:42:58 +02:00
|
|
|
struct wined3d_map_desc dst_map;
|
|
|
|
|
|
|
|
memset(&dst_map, 0, sizeof(dst_map));
|
|
|
|
if (FAILED(wined3d_resource_map(&dst_texture->resource, 0, &dst_map, NULL, 0)))
|
|
|
|
{
|
|
|
|
ERR("Failed to map the destination texture.\n");
|
|
|
|
wined3d_resource_unmap(&src_texture->resource, sub_resource_idx);
|
|
|
|
wined3d_texture_decref(dst_texture);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
conv->convert(src_map.data, dst_map.data, src_map.row_pitch, dst_map.row_pitch, desc.width, desc.height);
|
|
|
|
|
|
|
|
wined3d_resource_unmap(&dst_texture->resource, 0);
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
2016-04-04 18:42:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_bo_address data = {0, src_map.data};
|
|
|
|
RECT src_rect = {0, 0, desc.width, desc.height};
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
POINT dst_point = {0, 0};
|
|
|
|
|
|
|
|
TRACE("Using upload conversion.\n");
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-04 18:42:58 +02:00
|
|
|
wined3d_texture_prepare_texture(dst_texture, context, FALSE);
|
|
|
|
wined3d_texture_bind_and_dirtify(dst_texture, context, FALSE);
|
|
|
|
wined3d_surface_upload_data(dst_texture->sub_resources[0].u.surface, gl_info, src_format,
|
|
|
|
&src_rect, src_map.row_pitch, &dst_point, FALSE, wined3d_const_bo_address(&data));
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-04-04 18:42:58 +02:00
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
wined3d_texture_validate_location(dst_texture, 0, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, 0, ~WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
}
|
2016-03-07 17:05:53 +01:00
|
|
|
wined3d_resource_unmap(&src_texture->resource, sub_resource_idx);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-03-07 17:05:53 +01:00
|
|
|
return dst_texture;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT _Blt_ColorFill(BYTE *buf, unsigned int width, unsigned int height,
|
|
|
|
unsigned int bpp, UINT pitch, DWORD color)
|
|
|
|
{
|
|
|
|
BYTE *first;
|
2013-03-05 00:01:12 +01:00
|
|
|
unsigned int x, y;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
|
|
|
/* Do first row */
|
|
|
|
|
|
|
|
#define COLORFILL_ROW(type) \
|
|
|
|
do { \
|
|
|
|
type *d = (type *)buf; \
|
|
|
|
for (x = 0; x < width; ++x) \
|
|
|
|
d[x] = (type)color; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
switch (bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
COLORFILL_ROW(BYTE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
COLORFILL_ROW(WORD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
BYTE *d = buf;
|
|
|
|
for (x = 0; x < width; ++x, d += 3)
|
|
|
|
{
|
2012-07-20 00:24:27 +02:00
|
|
|
d[0] = (color ) & 0xff;
|
|
|
|
d[1] = (color >> 8) & 0xff;
|
|
|
|
d[2] = (color >> 16) & 0xff;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
COLORFILL_ROW(DWORD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Color fill not implemented for bpp %u!\n", bpp * 8);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef COLORFILL_ROW
|
|
|
|
|
|
|
|
/* Now copy first row. */
|
|
|
|
first = buf;
|
|
|
|
for (y = 1; y < height; ++y)
|
|
|
|
{
|
|
|
|
buf += pitch;
|
|
|
|
memcpy(buf, first, width * bpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-12 22:34:39 +02:00
|
|
|
static void read_from_framebuffer(struct wined3d_surface *surface,
|
|
|
|
struct wined3d_context *old_ctx, DWORD dst_location)
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2016-03-31 22:48:54 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2016-03-19 10:35:46 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2010-03-17 21:59:50 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2015-10-12 22:34:39 +02:00
|
|
|
struct wined3d_context *context = old_ctx;
|
|
|
|
struct wined3d_surface *restore_rt = NULL;
|
2016-02-12 11:06:05 +01:00
|
|
|
unsigned int row_pitch, slice_pitch;
|
2016-04-05 18:24:22 +02:00
|
|
|
unsigned int width, height;
|
2007-02-13 20:24:00 +01:00
|
|
|
BYTE *mem;
|
|
|
|
BYTE *row, *top, *bottom;
|
|
|
|
int i;
|
2007-11-02 22:23:22 +01:00
|
|
|
BOOL srcIsUpsideDown;
|
2013-11-29 12:59:13 +01:00
|
|
|
struct wined3d_bo_address data;
|
|
|
|
|
2016-03-31 22:48:54 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, dst_location);
|
2007-11-02 22:23:22 +01:00
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
restore_rt = context_get_rt_surface(old_ctx);
|
|
|
|
if (restore_rt != surface)
|
2015-10-12 22:34:39 +02:00
|
|
|
context = context_acquire(device, surface);
|
2016-03-29 16:45:32 +02:00
|
|
|
else
|
|
|
|
restore_rt = NULL;
|
2015-10-12 22:34:39 +02:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context_apply_blit_state(context, device);
|
2010-03-17 21:59:50 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2007-11-02 22:23:22 +01:00
|
|
|
/* Select the correct read buffer, and give some debug output.
|
|
|
|
* There is no need to keep track of the current read buffer or reset it, every part of the code
|
|
|
|
* that reads sets the read buffer as desired.
|
|
|
|
*/
|
2016-03-19 10:35:46 +01:00
|
|
|
if (wined3d_resource_is_offscreen(&texture->resource))
|
2008-10-16 11:52:54 +02:00
|
|
|
{
|
2010-10-14 13:04:02 +02:00
|
|
|
/* Mapping the primary render target which is not on a swapchain.
|
|
|
|
* Read from the back buffer. */
|
|
|
|
TRACE("Mapping offscreen render target.\n");
|
2016-02-29 18:19:30 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(context_get_offscreen_gl_buffer(context));
|
2008-10-16 11:52:54 +02:00
|
|
|
srcIsUpsideDown = TRUE;
|
2007-11-02 22:23:22 +01:00
|
|
|
}
|
2009-12-06 15:45:46 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Onscreen surfaces are always part of a swapchain */
|
2016-03-23 17:58:23 +01:00
|
|
|
GLenum buffer = wined3d_texture_get_gl_buffer(texture);
|
2010-10-14 13:04:02 +02:00
|
|
|
TRACE("Mapping %#x buffer.\n", buffer);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(buffer);
|
2009-12-06 15:45:46 +01:00
|
|
|
checkGLcall("glReadBuffer");
|
|
|
|
srcIsUpsideDown = FALSE;
|
|
|
|
}
|
2007-11-02 22:23:22 +01:00
|
|
|
|
2013-11-29 12:59:13 +01:00
|
|
|
if (data.buffer_object)
|
2010-11-12 13:12:04 +01:00
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
2007-09-11 10:31:54 +02:00
|
|
|
}
|
|
|
|
|
2016-03-19 10:35:46 +01:00
|
|
|
wined3d_texture_get_pitch(texture, surface->texture_level, &row_pitch, &slice_pitch);
|
2016-02-12 11:06:05 +01:00
|
|
|
|
2008-12-22 15:08:10 +01:00
|
|
|
/* Setup pixel store pack state -- to glReadPixels into the correct place */
|
2016-03-19 10:35:46 +01:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ROW_LENGTH, row_pitch / texture->resource.format->byte_count);
|
2008-12-22 15:08:10 +01:00
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
|
2016-04-05 18:24:22 +02:00
|
|
|
width = wined3d_texture_get_level_width(texture, surface->texture_level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, surface->texture_level);
|
|
|
|
gl_info->gl_ops.gl.p_glReadPixels(0, 0, width, height,
|
2016-03-19 10:35:46 +01:00
|
|
|
texture->resource.format->glFormat,
|
|
|
|
texture->resource.format->glType, data.addr);
|
2008-12-03 14:53:44 +01:00
|
|
|
checkGLcall("glReadPixels");
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2008-12-22 15:08:10 +01:00
|
|
|
/* Reset previous pixel store pack state */
|
2013-11-29 12:59:14 +01:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
2008-12-22 15:08:10 +01:00
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
|
2013-11-20 12:33:31 +01:00
|
|
|
if (!srcIsUpsideDown)
|
|
|
|
{
|
2016-02-12 11:06:05 +01:00
|
|
|
/* glReadPixels returns the image upside down, and there is no way to
|
|
|
|
* prevent this. Flip the lines in software. */
|
2014-05-13 16:21:49 +02:00
|
|
|
|
2016-02-12 11:06:05 +01:00
|
|
|
if (!(row = HeapAlloc(GetProcessHeap(), 0, row_pitch)))
|
2014-05-13 16:21:49 +02:00
|
|
|
goto error;
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2014-05-13 16:21:49 +02:00
|
|
|
if (data.buffer_object)
|
2013-11-20 12:33:31 +01:00
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
mem = GL_EXTCALL(glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_WRITE));
|
|
|
|
checkGLcall("glMapBuffer");
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
2014-05-13 16:21:49 +02:00
|
|
|
else
|
|
|
|
mem = data.addr;
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2013-11-20 12:33:31 +01:00
|
|
|
top = mem;
|
2016-04-05 18:24:22 +02:00
|
|
|
bottom = mem + row_pitch * (height - 1);
|
|
|
|
for (i = 0; i < height / 2; i++)
|
2013-11-20 12:33:31 +01:00
|
|
|
{
|
2016-02-12 11:06:05 +01:00
|
|
|
memcpy(row, top, row_pitch);
|
|
|
|
memcpy(top, bottom, row_pitch);
|
|
|
|
memcpy(bottom, row, row_pitch);
|
|
|
|
top += row_pitch;
|
|
|
|
bottom -= row_pitch;
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, row);
|
2014-05-13 16:21:49 +02:00
|
|
|
|
|
|
|
if (data.buffer_object)
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glUnmapBuffer(GL_PIXEL_PACK_BUFFER));
|
2013-11-29 12:59:13 +01:00
|
|
|
}
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2014-05-13 16:21:49 +02:00
|
|
|
error:
|
2013-11-29 12:59:13 +01:00
|
|
|
if (data.buffer_object)
|
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2015-10-12 22:34:39 +02:00
|
|
|
if (restore_rt)
|
|
|
|
context_restore(context, restore_rt);
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2011-11-03 19:37:24 +01:00
|
|
|
/* Read the framebuffer contents into a texture. Note that this function
|
|
|
|
* doesn't do any kind of flipping. Using this on an onscreen surface will
|
2015-10-15 22:41:11 +02:00
|
|
|
* result in a flipped D3D texture.
|
|
|
|
*
|
|
|
|
* Context activation is done by the caller. This function may temporarily
|
|
|
|
* switch to a different context and restore the original one before return. */
|
|
|
|
void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb, struct wined3d_context *old_ctx)
|
2008-02-10 22:20:15 +01:00
|
|
|
{
|
2016-03-19 10:35:47 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2015-10-15 22:41:11 +02:00
|
|
|
struct wined3d_context *context = old_ctx;
|
|
|
|
struct wined3d_surface *restore_rt = NULL;
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
restore_rt = context_get_rt_surface(old_ctx);
|
|
|
|
if (restore_rt != surface)
|
2015-10-15 22:41:11 +02:00
|
|
|
context = context_acquire(device, surface);
|
2016-03-29 16:45:32 +02:00
|
|
|
else
|
|
|
|
restore_rt = NULL;
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info = context->gl_info;
|
2011-06-08 00:27:15 +02:00
|
|
|
device_invalidate_state(device, STATE_FRAMEBUFFER);
|
2010-03-17 21:59:50 +01:00
|
|
|
|
2016-03-19 10:35:47 +01:00
|
|
|
wined3d_texture_prepare_texture(texture, context, srgb);
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, srgb);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
TRACE("Reading back offscreen render target %p.\n", surface);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2016-03-19 10:35:47 +01:00
|
|
|
if (wined3d_resource_is_offscreen(&texture->resource))
|
2016-02-29 18:19:30 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(context_get_offscreen_gl_buffer(context));
|
2011-11-03 19:37:24 +01:00
|
|
|
else
|
2016-03-23 17:58:23 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(wined3d_texture_get_gl_buffer(texture));
|
2010-06-22 12:49:07 +02:00
|
|
|
checkGLcall("glReadBuffer");
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(surface->texture_target, surface->texture_level,
|
2016-04-05 18:24:23 +02:00
|
|
|
0, 0, 0, 0, wined3d_texture_get_level_width(texture, surface->texture_level),
|
|
|
|
wined3d_texture_get_level_height(texture, surface->texture_level));
|
2008-02-10 22:20:15 +01:00
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
2015-10-15 22:41:11 +02:00
|
|
|
if (restore_rt)
|
|
|
|
context_restore(context, restore_rt);
|
2008-02-10 22:20:15 +01:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
/* Does a direct frame buffer -> texture copy. Stretching is done with single
|
|
|
|
* pixel copy calls. */
|
|
|
|
static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struct wined3d_surface *src_surface,
|
2012-01-12 21:43:12 +01:00
|
|
|
const RECT *src_rect, const RECT *dst_rect_in, enum wined3d_texture_filter_type filter)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
2016-03-19 10:35:49 +01:00
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_device *device = dst_texture->resource.device;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2007-02-12 19:18:46 +01:00
|
|
|
float xrel, yrel;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2010-04-01 23:58:49 +02:00
|
|
|
BOOL upsidedown = FALSE;
|
|
|
|
RECT dst_rect = *dst_rect_in;
|
2016-04-05 18:24:24 +02:00
|
|
|
unsigned int src_height;
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-04-01 23:58:49 +02:00
|
|
|
/* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
|
|
|
|
* glCopyTexSubImage is a bit picky about the parameters we pass to it
|
|
|
|
*/
|
|
|
|
if(dst_rect.top > dst_rect.bottom) {
|
|
|
|
UINT tmp = dst_rect.bottom;
|
|
|
|
dst_rect.bottom = dst_rect.top;
|
|
|
|
dst_rect.top = tmp;
|
|
|
|
upsidedown = TRUE;
|
|
|
|
}
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, src_surface);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info = context->gl_info;
|
2010-05-03 22:03:28 +02:00
|
|
|
context_apply_blit_state(context, device);
|
2016-03-19 10:35:49 +01:00
|
|
|
wined3d_texture_load(dst_texture, context, FALSE);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* Bind the target texture */
|
2016-03-19 10:35:49 +01:00
|
|
|
context_bind_texture(context, dst_texture->target, dst_texture->texture_rgb.name);
|
|
|
|
if (wined3d_resource_is_offscreen(&src_texture->resource))
|
2010-04-18 22:50:45 +02:00
|
|
|
{
|
2008-06-29 22:49:05 +02:00
|
|
|
TRACE("Reading from an offscreen target\n");
|
|
|
|
upsidedown = !upsidedown;
|
2016-02-29 18:19:30 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(context_get_offscreen_gl_buffer(context));
|
2009-12-15 17:51:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-23 17:58:23 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(wined3d_texture_get_gl_buffer(src_texture));
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
checkGLcall("glReadBuffer");
|
|
|
|
|
2010-04-01 23:58:49 +02:00
|
|
|
xrel = (float) (src_rect->right - src_rect->left) / (float) (dst_rect.right - dst_rect.left);
|
|
|
|
yrel = (float) (src_rect->bottom - src_rect->top) / (float) (dst_rect.bottom - dst_rect.top);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2009-07-07 11:08:01 +02:00
|
|
|
if ((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
|
|
|
|
{
|
2016-05-18 00:04:35 +02:00
|
|
|
FIXME_(d3d_perf)("Doing a pixel by pixel copy from the framebuffer to a texture.\n");
|
2007-04-03 12:00:15 +02:00
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
if (filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT)
|
|
|
|
ERR("Texture filtering not supported in direct blit.\n");
|
2009-07-07 11:08:01 +02:00
|
|
|
}
|
2012-01-12 21:43:12 +01:00
|
|
|
else if ((filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT)
|
2009-07-07 11:08:01 +02:00
|
|
|
&& ((yrel - 1.0f < -eps) || (yrel - 1.0f > eps)))
|
|
|
|
{
|
2007-04-03 12:00:15 +02:00
|
|
|
ERR("Texture filtering not supported in direct blit\n");
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:24:24 +02:00
|
|
|
src_height = wined3d_texture_get_level_height(src_texture, src_surface->texture_level);
|
2009-07-07 11:08:01 +02:00
|
|
|
if (upsidedown
|
|
|
|
&& !((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
|
|
|
|
&& !((yrel - 1.0f < -eps) || (yrel - 1.0f > eps)))
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
/* Upside down copy without stretching is nice, one glCopyTexSubImage call will do. */
|
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level,
|
2010-04-01 23:58:49 +02:00
|
|
|
dst_rect.left /*xoffset */, dst_rect.top /* y offset */,
|
2016-04-05 18:24:24 +02:00
|
|
|
src_rect->left, src_height - src_rect->bottom,
|
2010-04-01 23:58:49 +02:00
|
|
|
dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top);
|
2011-03-08 19:41:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-05 00:01:12 +01:00
|
|
|
LONG row;
|
2016-04-05 18:24:24 +02:00
|
|
|
UINT yoffset = src_height - src_rect->top + dst_rect.top - 1;
|
2007-02-12 19:18:46 +01:00
|
|
|
/* I have to process this row by row to swap the image,
|
2007-06-06 00:21:08 +02:00
|
|
|
* otherwise it would be upside down, so stretching in y direction
|
2007-02-12 19:18:46 +01:00
|
|
|
* doesn't cost extra time
|
|
|
|
*
|
2007-06-06 00:21:08 +02:00
|
|
|
* However, stretching in x direction can be avoided if not necessary
|
2007-02-12 19:18:46 +01:00
|
|
|
*/
|
2010-04-01 23:58:49 +02:00
|
|
|
for(row = dst_rect.top; row < dst_rect.bottom; row++) {
|
2009-07-07 11:08:01 +02:00
|
|
|
if ((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
|
|
|
|
{
|
2007-02-12 19:18:46 +01:00
|
|
|
/* Well, that stuff works, but it's very slow.
|
|
|
|
* find a better way instead
|
|
|
|
*/
|
2013-03-05 00:01:12 +01:00
|
|
|
LONG col;
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-04-22 18:56:00 +02:00
|
|
|
for (col = dst_rect.left; col < dst_rect.right; ++col)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level,
|
2010-04-01 23:58:49 +02:00
|
|
|
dst_rect.left + col /* x offset */, row /* y offset */,
|
2010-03-30 22:18:59 +02:00
|
|
|
src_rect->left + col * xrel, yoffset - (int) (row * yrel), 1, 1);
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
2010-04-22 18:56:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level,
|
2010-04-01 23:58:49 +02:00
|
|
|
dst_rect.left /* x offset */, row /* y offset */,
|
|
|
|
src_rect->left, yoffset - (int) (row * yrel), dst_rect.right - dst_rect.left, 1);
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-03 14:53:44 +01:00
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
2007-11-26 21:43:08 +01:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2009-09-05 22:32:51 +02:00
|
|
|
|
2013-09-10 09:32:34 +02:00
|
|
|
/* The texture is now most up to date - If the surface is a render target
|
|
|
|
* and has a drawable, this path is never entered. */
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~WINED3D_LOCATION_TEXTURE_RGB);
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Uses the hardware to stretch and flip the image */
|
2011-04-29 13:03:42 +02:00
|
|
|
static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, struct wined3d_surface *src_surface,
|
2012-01-12 21:43:12 +01:00
|
|
|
const RECT *src_rect, const RECT *dst_rect_in, enum wined3d_texture_filter_type filter)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
2016-04-19 18:34:03 +02:00
|
|
|
unsigned int src_width, src_height, src_pow2_width, src_pow2_height;
|
2016-03-19 10:35:50 +01:00
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_device *device = dst_texture->resource.device;
|
2007-03-01 01:42:50 +01:00
|
|
|
GLuint src, backup = 0;
|
2007-02-12 19:18:46 +01:00
|
|
|
float left, right, top, bottom; /* Texture coordinates */
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2007-03-04 23:47:57 +01:00
|
|
|
GLenum drawBuffer = GL_BACK;
|
2016-02-29 18:19:30 +01:00
|
|
|
GLenum offscreen_buffer;
|
2007-11-26 21:28:20 +01:00
|
|
|
GLenum texture_target;
|
2008-04-06 23:06:27 +02:00
|
|
|
BOOL noBackBufferBackup;
|
2009-12-15 17:51:33 +01:00
|
|
|
BOOL src_offscreen;
|
2010-04-01 23:58:49 +02:00
|
|
|
BOOL upsidedown = FALSE;
|
|
|
|
RECT dst_rect = *dst_rect_in;
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
TRACE("Using hwstretch blit\n");
|
|
|
|
/* Activate the Proper context for reading from the source surface, set it up for blitting */
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, src_surface);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info = context->gl_info;
|
2010-05-03 22:03:28 +02:00
|
|
|
context_apply_blit_state(context, device);
|
2016-03-19 10:35:50 +01:00
|
|
|
wined3d_texture_load(dst_texture, context, FALSE);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2016-02-29 18:19:30 +01:00
|
|
|
offscreen_buffer = context_get_offscreen_gl_buffer(context);
|
2016-04-07 19:37:57 +02:00
|
|
|
src_width = wined3d_texture_get_level_width(src_texture, src_surface->texture_level);
|
|
|
|
src_height = wined3d_texture_get_level_height(src_texture, src_surface->texture_level);
|
2016-04-19 18:34:03 +02:00
|
|
|
src_pow2_width = wined3d_texture_get_level_pow2_width(src_texture, src_surface->texture_level);
|
|
|
|
src_pow2_height = wined3d_texture_get_level_pow2_height(src_texture, src_surface->texture_level);
|
2016-02-29 18:19:30 +01:00
|
|
|
|
2016-03-19 10:35:50 +01:00
|
|
|
src_offscreen = wined3d_resource_is_offscreen(&src_texture->resource);
|
2009-12-15 17:51:33 +01:00
|
|
|
noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
|
2016-03-19 10:35:50 +01:00
|
|
|
if (!noBackBufferBackup && !src_texture->texture_rgb.name)
|
2009-07-10 10:20:13 +02:00
|
|
|
{
|
2008-04-06 23:06:27 +02:00
|
|
|
/* Get it a description */
|
2016-03-19 10:35:50 +01:00
|
|
|
wined3d_texture_load(src_texture, context, FALSE);
|
2008-04-06 23:06:27 +02:00
|
|
|
}
|
|
|
|
|
2007-03-04 23:47:57 +01:00
|
|
|
/* Try to use an aux buffer for drawing the rectangle. This way it doesn't need restoring.
|
|
|
|
* This way we don't have to wait for the 2nd readback to finish to leave this function.
|
|
|
|
*/
|
2009-07-24 10:44:17 +02:00
|
|
|
if (context->aux_buffers >= 2)
|
|
|
|
{
|
2007-03-04 23:47:57 +01:00
|
|
|
/* Got more than one aux buffer? Use the 2nd aux buffer */
|
|
|
|
drawBuffer = GL_AUX1;
|
2009-07-24 10:44:17 +02:00
|
|
|
}
|
2016-02-29 18:19:30 +01:00
|
|
|
else if ((!src_offscreen || offscreen_buffer == GL_BACK) && context->aux_buffers >= 1)
|
2009-07-24 10:44:17 +02:00
|
|
|
{
|
2007-03-04 23:47:57 +01:00
|
|
|
/* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
|
|
|
|
drawBuffer = GL_AUX0;
|
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (noBackBufferBackup)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &backup);
|
2009-07-07 11:08:02 +02:00
|
|
|
checkGLcall("glGenTextures");
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, GL_TEXTURE_2D, backup);
|
2007-11-26 21:28:20 +01:00
|
|
|
texture_target = GL_TEXTURE_2D;
|
2012-07-24 11:32:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-01 01:42:50 +01:00
|
|
|
/* Backup the back buffer and copy the source buffer into a texture to draw an upside down stretched quad. If
|
|
|
|
* we are reading from the back buffer, the backup can be used as source texture
|
|
|
|
*/
|
2010-04-22 18:56:01 +02:00
|
|
|
texture_target = src_surface->texture_target;
|
2016-03-19 10:35:50 +01:00
|
|
|
context_bind_texture(context, texture_target, src_texture->texture_rgb.name);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnable(texture_target);
|
2007-11-26 21:28:20 +01:00
|
|
|
checkGLcall("glEnable(texture_target)");
|
2007-03-06 21:47:45 +01:00
|
|
|
|
|
|
|
/* For now invalidate the texture copy of the back buffer. Drawable and sysmem copy are untouched */
|
2016-03-28 18:58:01 +02:00
|
|
|
surface_get_sub_resource(src_surface)->locations &= ~WINED3D_LOCATION_TEXTURE_RGB;
|
2007-03-01 01:42:50 +01:00
|
|
|
}
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-04-01 23:58:49 +02:00
|
|
|
/* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
|
|
|
|
* glCopyTexSubImage is a bit picky about the parameters we pass to it
|
|
|
|
*/
|
|
|
|
if(dst_rect.top > dst_rect.bottom) {
|
|
|
|
UINT tmp = dst_rect.bottom;
|
|
|
|
dst_rect.bottom = dst_rect.top;
|
|
|
|
dst_rect.top = tmp;
|
|
|
|
upsidedown = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-15 17:51:33 +01:00
|
|
|
if (src_offscreen)
|
|
|
|
{
|
2008-06-29 22:49:05 +02:00
|
|
|
TRACE("Reading from an offscreen target\n");
|
|
|
|
upsidedown = !upsidedown;
|
2016-02-29 18:19:30 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(offscreen_buffer);
|
2009-12-15 17:51:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-23 17:58:23 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(wined3d_texture_get_gl_buffer(src_texture));
|
2008-04-23 16:19:19 +02:00
|
|
|
}
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* TODO: Only back up the part that will be overwritten */
|
2016-04-07 19:37:57 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(texture_target, 0, 0, 0, 0, 0, src_width, src_height);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
2007-03-01 01:42:50 +01:00
|
|
|
/* No issue with overriding these - the sampler is dirty due to blit usage */
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(filter));
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER,
|
2015-01-15 17:19:05 +01:00
|
|
|
wined3d_gl_min_mip_filter(filter, WINED3D_TEXF_NONE));
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
2016-03-19 10:35:50 +01:00
|
|
|
if (!src_texture->swapchain || src_texture == src_texture->swapchain->back_buffers[0])
|
2010-04-22 18:56:01 +02:00
|
|
|
{
|
2016-03-19 10:35:50 +01:00
|
|
|
src = backup ? backup : src_texture->texture_rgb.name;
|
2010-04-22 18:56:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(GL_FRONT);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glReadBuffer(GL_FRONT)");
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &src);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glGenTextures(1, &src)");
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, GL_TEXTURE_2D, src);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2016-04-19 18:34:03 +02:00
|
|
|
/* TODO: Only copy the part that will be read. Use src_rect->left,
|
|
|
|
* src_rect->bottom as origin, but with the width watch out for power
|
|
|
|
* of 2 sizes. */
|
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_pow2_width,
|
|
|
|
src_pow2_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexImage2D");
|
2016-04-07 19:37:57 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, src_width, src_height);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(GL_BACK);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glReadBuffer(GL_BACK)");
|
2007-11-26 21:28:20 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (texture_target != GL_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(texture_target);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
|
2007-11-26 21:28:20 +01:00
|
|
|
texture_target = GL_TEXTURE_2D;
|
|
|
|
}
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
checkGLcall("glEnd and previous");
|
|
|
|
|
2010-03-30 22:19:00 +02:00
|
|
|
left = src_rect->left;
|
|
|
|
right = src_rect->right;
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-10-29 12:25:18 +02:00
|
|
|
if (!upsidedown)
|
2010-04-22 18:56:01 +02:00
|
|
|
{
|
2016-04-07 19:37:57 +02:00
|
|
|
top = src_height - src_rect->top;
|
|
|
|
bottom = src_height - src_rect->bottom;
|
2010-04-22 18:56:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-07 19:37:57 +02:00
|
|
|
top = src_height - src_rect->bottom;
|
|
|
|
bottom = src_height - src_rect->top;
|
2008-04-23 02:48:55 +02:00
|
|
|
}
|
|
|
|
|
2016-03-19 10:35:50 +01:00
|
|
|
if (src_texture->flags & WINED3D_TEXTURE_NORMALIZED_COORDS)
|
2010-04-22 18:56:01 +02:00
|
|
|
{
|
2016-04-19 18:34:03 +02:00
|
|
|
left /= src_pow2_width;
|
|
|
|
right /= src_pow2_width;
|
|
|
|
top /= src_pow2_height;
|
|
|
|
bottom /= src_pow2_height;
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the source texture stretched and upside down. The correct surface is bound already */
|
2015-02-09 21:19:50 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2009-12-13 22:04:00 +01:00
|
|
|
context_set_draw_buffer(context, drawBuffer);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(drawBuffer);
|
2007-03-04 23:47:57 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_QUADS);
|
2007-02-12 19:18:46 +01:00
|
|
|
/* bottom left */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(left, bottom);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(0, 0);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* top left */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(left, top);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(0, dst_rect.bottom - dst_rect.top);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* top right */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(right, top);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* bottom right */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(right, bottom);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect.right - dst_rect.left, 0);
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glEnd and previous");
|
|
|
|
|
2010-04-22 18:56:01 +02:00
|
|
|
if (texture_target != dst_surface->texture_target)
|
2009-07-10 10:20:13 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(texture_target);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(dst_surface->texture_target);
|
2010-04-22 18:56:01 +02:00
|
|
|
texture_target = dst_surface->texture_target;
|
2007-11-26 21:28:20 +01:00
|
|
|
}
|
|
|
|
|
2007-02-12 19:18:46 +01:00
|
|
|
/* Now read the stretched and upside down image into the destination texture */
|
2016-03-19 10:35:50 +01:00
|
|
|
context_bind_texture(context, texture_target, dst_texture->texture_rgb.name);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(texture_target,
|
2007-02-12 19:18:46 +01:00
|
|
|
0,
|
2010-04-01 23:58:49 +02:00
|
|
|
dst_rect.left, dst_rect.top, /* xoffset, yoffset */
|
2007-02-12 19:18:46 +01:00
|
|
|
0, 0, /* We blitted the image to the origin */
|
2010-04-01 23:58:49 +02:00
|
|
|
dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (drawBuffer == GL_BACK)
|
|
|
|
{
|
|
|
|
/* Write the back buffer backup back. */
|
|
|
|
if (backup)
|
|
|
|
{
|
|
|
|
if (texture_target != GL_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(texture_target);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
|
2007-11-26 21:28:20 +01:00
|
|
|
texture_target = GL_TEXTURE_2D;
|
|
|
|
}
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, GL_TEXTURE_2D, backup);
|
2010-04-22 18:56:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (texture_target != src_surface->texture_target)
|
2009-07-10 10:20:13 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(texture_target);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(src_surface->texture_target);
|
2010-04-22 18:56:01 +02:00
|
|
|
texture_target = src_surface->texture_target;
|
2007-11-26 21:28:20 +01:00
|
|
|
}
|
2016-03-19 10:35:50 +01:00
|
|
|
context_bind_texture(context, src_surface->texture_target, src_texture->texture_rgb.name);
|
2007-11-26 21:28:20 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_QUADS);
|
2007-03-04 23:47:57 +01:00
|
|
|
/* top left */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(0.0f, 0.0f);
|
2016-04-07 19:37:57 +02:00
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(0, src_height);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-10-29 12:25:18 +02:00
|
|
|
/* bottom left */
|
2016-04-19 18:34:03 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(0.0f, (float)src_height / (float)src_pow2_height);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(0, 0);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-10-29 12:25:18 +02:00
|
|
|
/* bottom right */
|
2016-04-19 18:34:03 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f((float)src_width / (float)src_pow2_width,
|
|
|
|
(float)src_height / (float)src_pow2_height);
|
2016-04-07 19:37:57 +02:00
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(src_width, 0);
|
2010-10-29 12:25:18 +02:00
|
|
|
|
|
|
|
/* top right */
|
2016-04-19 18:34:03 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f((float)src_width / (float)src_pow2_width, 0.0f);
|
2016-04-07 19:37:57 +02:00
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(src_width, src_height);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2007-03-04 23:47:57 +01:00
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(texture_target);
|
2007-11-26 21:28:20 +01:00
|
|
|
checkGLcall("glDisable(texture_target)");
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* Cleanup */
|
2016-03-19 10:35:50 +01:00
|
|
|
if (src != src_texture->texture_rgb.name && src != backup)
|
2009-07-10 10:20:13 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &src);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glDeleteTextures(1, &src)");
|
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
if (backup)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &backup);
|
2007-03-01 01:42:50 +01:00
|
|
|
checkGLcall("glDeleteTextures(1, &backup)");
|
|
|
|
}
|
2007-11-26 21:43:08 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2010-01-27 20:19:40 +01:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2009-09-05 22:32:51 +02:00
|
|
|
|
2013-09-10 09:32:34 +02:00
|
|
|
/* The texture is now most up to date - If the surface is a render target
|
|
|
|
* and has a drawable, this path is never entered. */
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~WINED3D_LOCATION_TEXTURE_RGB);
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
2010-05-21 09:35:21 +02:00
|
|
|
/* Front buffer coordinates are always full screen coordinates, but our GL
|
|
|
|
* drawable is limited to the window's client area. The sysmem and texture
|
|
|
|
* copies do have the full screen size. Note that GL has a bottom-left
|
|
|
|
* origin, while D3D has a top-left origin. */
|
2011-07-07 21:01:36 +02:00
|
|
|
void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect)
|
2010-05-21 09:35:21 +02:00
|
|
|
{
|
2016-04-07 19:37:58 +02:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2010-11-01 11:57:57 +01:00
|
|
|
UINT drawable_height;
|
2010-05-21 09:35:21 +02:00
|
|
|
|
2016-04-07 19:37:58 +02:00
|
|
|
if (texture->swapchain && texture == texture->swapchain->front_buffer)
|
2010-11-01 11:57:57 +01:00
|
|
|
{
|
|
|
|
POINT offset = {0, 0};
|
|
|
|
RECT windowsize;
|
|
|
|
|
|
|
|
ScreenToClient(window, &offset);
|
|
|
|
OffsetRect(rect, offset.x, offset.y);
|
|
|
|
|
|
|
|
GetClientRect(window, &windowsize);
|
|
|
|
drawable_height = windowsize.bottom - windowsize.top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-07 19:37:58 +02:00
|
|
|
drawable_height = wined3d_texture_get_level_height(texture, surface->texture_level);
|
2010-11-01 11:57:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rect->top = drawable_height - rect->top;
|
|
|
|
rect->bottom = drawable_height - rect->bottom;
|
2010-05-21 09:35:21 +02:00
|
|
|
}
|
|
|
|
|
2015-10-12 22:34:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-10-27 17:06:26 +02:00
|
|
|
static void surface_blt_to_drawable(const struct wined3d_device *device,
|
2015-10-12 22:34:40 +02:00
|
|
|
struct wined3d_context *old_ctx,
|
2014-01-10 10:43:04 +01:00
|
|
|
enum wined3d_texture_filter_type filter, BOOL alpha_test,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect_in,
|
|
|
|
struct wined3d_surface *dst_surface, const RECT *dst_rect_in)
|
2010-10-21 12:40:45 +02:00
|
|
|
{
|
2016-03-22 17:46:10 +01:00
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2015-10-12 22:34:40 +02:00
|
|
|
struct wined3d_context *context = old_ctx;
|
|
|
|
struct wined3d_surface *restore_rt = NULL;
|
2010-10-21 12:40:45 +02:00
|
|
|
RECT src_rect, dst_rect;
|
|
|
|
|
|
|
|
src_rect = *src_rect_in;
|
|
|
|
dst_rect = *dst_rect_in;
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
restore_rt = context_get_rt_surface(old_ctx);
|
|
|
|
if (restore_rt != dst_surface)
|
2015-10-12 22:34:40 +02:00
|
|
|
context = context_acquire(device, dst_surface);
|
2016-03-29 16:45:32 +02:00
|
|
|
else
|
|
|
|
restore_rt = NULL;
|
2015-10-12 22:34:40 +02:00
|
|
|
|
2013-09-16 12:43:17 +02:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2010-10-21 12:40:45 +02:00
|
|
|
/* Make sure the surface is up-to-date. This should probably use
|
|
|
|
* surface_load_location() and worry about the destination surface too,
|
|
|
|
* unless we're overwriting it completely. */
|
2016-03-22 17:46:10 +01:00
|
|
|
wined3d_texture_load(src_texture, context, FALSE);
|
2010-10-21 12:40:45 +02:00
|
|
|
|
|
|
|
/* Activate the destination context, set it up for blitting */
|
|
|
|
context_apply_blit_state(context, device);
|
|
|
|
|
2016-03-22 17:46:10 +01:00
|
|
|
if (!wined3d_resource_is_offscreen(&dst_texture->resource))
|
2010-11-01 11:57:57 +01:00
|
|
|
surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect);
|
2010-10-21 12:40:45 +02:00
|
|
|
|
2015-04-10 12:05:53 +02:00
|
|
|
device->blitter->set_shader(device->blit_priv, context, src_surface, NULL);
|
2010-10-21 12:40:45 +02:00
|
|
|
|
2014-01-10 10:43:04 +01:00
|
|
|
if (alpha_test)
|
2010-10-21 12:40:45 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_ALPHA_TEST);
|
2010-10-21 12:40:45 +02:00
|
|
|
checkGLcall("glEnable(GL_ALPHA_TEST)");
|
|
|
|
|
2014-05-13 16:21:49 +02:00
|
|
|
/* For P8 surfaces, the alpha component contains the palette index.
|
|
|
|
* Which means that the colorkey is one of the palette entries. In
|
|
|
|
* other cases pixels that should be masked away have alpha set to 0. */
|
2016-03-22 17:46:10 +01:00
|
|
|
if (src_texture->resource.format->id == WINED3DFMT_P8_UINT)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glAlphaFunc(GL_NOTEQUAL,
|
2016-03-22 17:46:10 +01:00
|
|
|
(float)src_texture->async.src_blt_color_key.color_space_low_value / 255.0f);
|
2010-10-21 12:40:45 +02:00
|
|
|
else
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glAlphaFunc(GL_NOTEQUAL, 0.0f);
|
2010-10-21 12:40:45 +02:00
|
|
|
checkGLcall("glAlphaFunc");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
|
2010-10-21 12:40:45 +02:00
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:12:26 +02:00
|
|
|
draw_textured_quad(src_surface, context, &src_rect, &dst_rect, filter);
|
2010-10-21 12:40:45 +02:00
|
|
|
|
2014-01-10 10:43:04 +01:00
|
|
|
if (alpha_test)
|
2010-10-21 12:40:45 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
|
2010-10-21 12:40:45 +02:00
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Leave the opengl state valid for blitting */
|
2010-12-09 23:41:19 +01:00
|
|
|
device->blitter->unset_shader(context->gl_info);
|
2010-10-21 12:40:45 +02:00
|
|
|
|
2011-04-14 22:41:49 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering
|
2016-03-22 17:46:10 +01:00
|
|
|
|| (dst_texture->swapchain && dst_texture->swapchain->front_buffer == dst_texture))
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2010-10-21 12:40:45 +02:00
|
|
|
|
2015-10-12 22:34:40 +02:00
|
|
|
if (restore_rt)
|
|
|
|
context_restore(context, restore_rt);
|
2010-10-21 12:40:45 +02:00
|
|
|
}
|
|
|
|
|
2011-11-15 21:18:27 +01:00
|
|
|
HRESULT surface_color_fill(struct wined3d_surface *s, const RECT *rect, const struct wined3d_color *color)
|
2010-08-29 21:57:42 +02:00
|
|
|
{
|
2016-02-03 22:22:56 +01:00
|
|
|
struct wined3d_resource *resource = &s->container->resource;
|
|
|
|
struct wined3d_device *device = resource->device;
|
|
|
|
struct wined3d_rendertarget_view_desc view_desc;
|
|
|
|
struct wined3d_rendertarget_view *view;
|
2010-08-29 21:57:42 +02:00
|
|
|
const struct blit_shader *blitter;
|
2016-02-03 22:22:56 +01:00
|
|
|
HRESULT hr;
|
2010-08-29 21:57:42 +02:00
|
|
|
|
2016-02-03 22:22:56 +01:00
|
|
|
if (!(blitter = wined3d_select_blitter(&device->adapter->gl_info, &device->adapter->d3d_info,
|
|
|
|
WINED3D_BLIT_OP_COLOR_FILL, NULL, 0, 0, NULL, rect, resource->usage, resource->pool, resource->format)))
|
2010-08-29 21:57:42 +02:00
|
|
|
{
|
|
|
|
FIXME("No blitter is capable of performing the requested color fill operation.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:22:56 +01:00
|
|
|
view_desc.format_id = resource->format->id;
|
|
|
|
view_desc.u.texture.level_idx = s->texture_level;
|
|
|
|
view_desc.u.texture.layer_idx = s->texture_layer;
|
|
|
|
view_desc.u.texture.layer_count = 1;
|
|
|
|
if (FAILED(hr = wined3d_rendertarget_view_create(&view_desc,
|
|
|
|
resource, NULL, &wined3d_null_parent_ops, &view)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = blitter->color_fill(device, view, rect, color);
|
|
|
|
wined3d_rendertarget_view_decref(view);
|
|
|
|
|
|
|
|
return hr;
|
2010-08-29 21:57:42 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 09:47:21 +02:00
|
|
|
static HRESULT surface_blt_special(struct wined3d_surface *dst_surface, const RECT *dst_rect,
|
2016-02-15 18:18:03 +01:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags,
|
|
|
|
const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
|
2008-11-25 11:57:39 +01:00
|
|
|
{
|
2016-03-22 17:46:11 +01:00
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_device *device = dst_texture->resource.device;
|
2014-08-21 09:55:55 +02:00
|
|
|
const struct wined3d_surface *rt = wined3d_rendertarget_view_get_surface(device->fb.render_targets[0]);
|
2013-06-03 09:19:35 +02:00
|
|
|
struct wined3d_swapchain *src_swapchain, *dst_swapchain;
|
2016-03-22 17:46:11 +01:00
|
|
|
struct wined3d_texture *src_texture;
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p, filter %s.\n",
|
2011-08-01 21:35:42 +02:00
|
|
|
dst_surface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect),
|
2016-02-15 18:18:03 +01:00
|
|
|
flags, fx, debug_d3dtexturefiltertype(filter));
|
2006-05-23 00:48:54 +02:00
|
|
|
|
|
|
|
/* Get the swapchain. One of the surfaces has to be a primary surface */
|
2016-03-22 17:46:11 +01:00
|
|
|
if (dst_texture->resource.pool == WINED3D_POOL_SYSTEM_MEM)
|
2010-04-26 11:02:35 +02:00
|
|
|
{
|
2007-08-21 23:24:16 +02:00
|
|
|
WARN("Destination is in sysmem, rejecting gl blt\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2010-08-16 20:00:27 +02:00
|
|
|
|
2016-03-22 17:46:11 +01:00
|
|
|
dst_swapchain = dst_texture->swapchain;
|
2010-08-16 20:00:27 +02:00
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
if (src_surface)
|
|
|
|
{
|
2016-03-22 17:46:11 +01:00
|
|
|
src_texture = src_surface->container;
|
|
|
|
if (src_texture->resource.pool == WINED3D_POOL_SYSTEM_MEM)
|
2010-04-26 11:02:35 +02:00
|
|
|
{
|
2007-08-21 23:24:16 +02:00
|
|
|
WARN("Src is in sysmem, rejecting gl blt\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2010-08-16 20:00:27 +02:00
|
|
|
|
2016-03-22 17:46:11 +01:00
|
|
|
src_swapchain = src_texture->swapchain;
|
2013-06-03 09:19:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-22 17:46:11 +01:00
|
|
|
src_texture = NULL;
|
2013-06-03 09:19:35 +02:00
|
|
|
src_swapchain = NULL;
|
2007-02-15 03:02:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Early sort out of cases where no render target is used */
|
2014-08-21 09:55:55 +02:00
|
|
|
if (!dst_swapchain && !src_swapchain && src_surface != rt && dst_surface != rt)
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
2010-04-26 11:02:35 +02:00
|
|
|
TRACE("No surface is render target, not using hardware blit.\n");
|
2007-02-15 03:02:39 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
2007-02-15 03:03:05 +01:00
|
|
|
/* No destination color keying supported */
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & (WINED3D_BLT_DST_CKEY | WINED3D_BLT_DST_CKEY_OVERRIDE))
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2007-02-15 03:03:05 +01:00
|
|
|
/* Can we support that with glBlendFunc if blitting to the frame buffer? */
|
|
|
|
TRACE("Destination color key not supported in accelerated Blit, falling back to software\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-06-03 09:19:35 +02:00
|
|
|
if (dst_swapchain && dst_swapchain == src_swapchain)
|
2011-09-01 20:20:55 +02:00
|
|
|
{
|
2007-12-16 00:18:20 +01:00
|
|
|
FIXME("Implement hardware blit between two surfaces on the same swapchain\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-09-01 20:20:55 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 09:19:35 +02:00
|
|
|
if (dst_swapchain && src_swapchain)
|
2011-09-01 20:20:55 +02:00
|
|
|
{
|
2007-12-16 00:18:20 +01:00
|
|
|
FIXME("Implement hardware blit between two different swapchains\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2010-04-18 22:50:42 +02:00
|
|
|
}
|
2011-09-01 20:20:55 +02:00
|
|
|
|
2013-06-03 09:19:35 +02:00
|
|
|
if (dst_swapchain)
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
2010-04-19 20:46:59 +02:00
|
|
|
/* Handled with regular texture -> swapchain blit */
|
2014-08-21 09:55:55 +02:00
|
|
|
if (src_surface == rt)
|
2007-12-31 03:04:27 +01:00
|
|
|
TRACE("Blit from active render target to a swapchain\n");
|
2010-04-18 22:50:42 +02:00
|
|
|
}
|
2014-08-21 09:55:55 +02:00
|
|
|
else if (src_swapchain && dst_surface == rt)
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
2007-12-16 00:18:20 +01:00
|
|
|
FIXME("Implement blit from a swapchain to the active render target\n");
|
2007-02-15 03:02:39 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
if ((src_swapchain || src_surface == rt) && !dst_swapchain)
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
2016-04-07 19:37:59 +02:00
|
|
|
unsigned int src_width, src_height;
|
2007-02-15 03:02:39 +01:00
|
|
|
/* Blit from render target to texture */
|
2010-04-01 23:58:49 +02:00
|
|
|
BOOL stretchx;
|
2010-04-05 20:05:16 +02:00
|
|
|
|
|
|
|
/* P8 read back is not implemented */
|
2016-03-22 17:46:11 +01:00
|
|
|
if (src_texture->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| dst_texture->resource.format->id == WINED3DFMT_P8_UINT)
|
2010-04-05 20:05:16 +02:00
|
|
|
{
|
|
|
|
TRACE("P8 read back not supported by frame buffer to texture blit\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & (WINED3D_BLT_SRC_CKEY | WINED3D_BLT_SRC_CKEY_OVERRIDE))
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2007-02-15 03:03:05 +01:00
|
|
|
TRACE("Color keying not supported by frame buffer to texture blit\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
/* Destination color key is checked above */
|
|
|
|
}
|
|
|
|
|
2011-08-01 21:35:42 +02:00
|
|
|
if (dst_rect->right - dst_rect->left != src_rect->right - src_rect->left)
|
2007-02-15 03:02:39 +01:00
|
|
|
stretchx = TRUE;
|
2011-08-01 21:35:42 +02:00
|
|
|
else
|
2007-02-15 03:02:39 +01:00
|
|
|
stretchx = FALSE;
|
2006-07-26 23:19:04 +02:00
|
|
|
|
2007-02-15 03:02:39 +01:00
|
|
|
/* Blt is a pretty powerful call, while glCopyTexSubImage2D is not. glCopyTexSubImage cannot
|
2007-04-09 01:54:07 +02:00
|
|
|
* flip the image nor scale it.
|
2007-02-15 03:02:39 +01:00
|
|
|
*
|
2013-12-03 14:25:04 +01:00
|
|
|
* -> If the app asks for an unscaled, upside down copy, just perform one glCopyTexSubImage2D call
|
|
|
|
* -> If the app wants an image width an unscaled width, copy it line per line
|
|
|
|
* -> If the app wants an image that is scaled on the x axis, and the destination rectangle is smaller
|
2007-02-15 03:02:39 +01:00
|
|
|
* than the frame buffer, draw an upside down scaled image onto the fb, read it back and restore the
|
|
|
|
* back buffer. This is slower than reading line per line, thus not used for flipping
|
|
|
|
* -> If the app wants a scaled image with a dest rect that is bigger than the fb, it has to be copied
|
2011-08-21 21:35:00 +02:00
|
|
|
* pixel by pixel. */
|
2016-04-07 19:37:59 +02:00
|
|
|
src_width = wined3d_texture_get_level_width(src_texture, src_surface->texture_level);
|
|
|
|
src_height = wined3d_texture_get_level_height(src_texture, src_surface->texture_level);
|
|
|
|
if (!stretchx || dst_rect->right - dst_rect->left > src_width
|
|
|
|
|| dst_rect->bottom - dst_rect->top > src_height)
|
2010-04-20 22:38:43 +02:00
|
|
|
{
|
2012-01-12 21:43:12 +01:00
|
|
|
TRACE("No stretching in x direction, using direct framebuffer -> texture copy.\n");
|
|
|
|
fb_copy_to_texture_direct(dst_surface, src_surface, src_rect, dst_rect, filter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Using hardware stretching to flip / stretch the texture.\n");
|
|
|
|
fb_copy_to_texture_hwstretch(dst_surface, src_surface, src_rect, dst_rect, filter);
|
2007-02-15 03:02:39 +01:00
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default: Fall back to the generic blt. Not an error, a TRACE is enough */
|
|
|
|
TRACE("Didn't find any usable render target setup for hw blit, falling back to software\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-27 23:21:25 +02:00
|
|
|
static void surface_depth_blt(const struct wined3d_surface *surface, struct wined3d_context *context,
|
2011-06-16 00:40:31 +02:00
|
|
|
GLuint texture, GLint x, GLint y, GLsizei w, GLsizei h, GLenum target)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-22 17:46:12 +01:00
|
|
|
struct wined3d_device *device = surface->container->resource.device;
|
2011-07-27 23:21:25 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-04-29 13:03:40 +02:00
|
|
|
GLint compare_mode = GL_NONE;
|
|
|
|
struct blt_info info;
|
|
|
|
GLint old_binding = 0;
|
|
|
|
RECT rect;
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
|
|
|
|
gl_info->gl_ops.gl.p_glDepthFunc(GL_ALWAYS);
|
|
|
|
gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
|
|
|
|
gl_info->gl_ops.gl.p_glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
|
|
|
gl_info->gl_ops.gl.p_glViewport(x, y, w, h);
|
|
|
|
gl_info->gl_ops.gl.p_glDepthRange(0.0, 1.0);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
SetRect(&rect, 0, h, w, 0);
|
2016-04-19 18:34:04 +02:00
|
|
|
surface_get_blt_info(target, &rect,
|
|
|
|
wined3d_texture_get_level_pow2_width(surface->container, surface->texture_level),
|
|
|
|
wined3d_texture_get_level_pow2_height(surface->container, surface->texture_level), &info);
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(context, context->gl_info, 0);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(info.binding, &old_binding);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(info.bind_target, texture);
|
2011-04-29 13:03:40 +02:00
|
|
|
if (gl_info->supported[ARB_SHADOW])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetTexParameteriv(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, &compare_mode);
|
|
|
|
if (compare_mode != GL_NONE)
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
device->shader_backend->shader_select_depth_blt(device->shader_priv,
|
2011-04-29 13:03:42 +02:00
|
|
|
gl_info, info.tex_type, &surface->ds_current_size);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[0]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2f(-1.0f, -1.0f);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[1]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2f(1.0f, -1.0f);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[2]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2f(-1.0f, 1.0f);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(info.coords[3]);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2f(1.0f, 1.0f);
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (compare_mode != GL_NONE)
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, compare_mode);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(info.bind_target, old_binding);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPopAttrib();
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
device->shader_backend->shader_deselect_depth_blt(device->shader_priv, gl_info);
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
void surface_modify_ds_location(struct wined3d_surface *surface,
|
2011-04-29 13:03:40 +02:00
|
|
|
DWORD location, UINT w, UINT h)
|
|
|
|
{
|
2016-04-20 19:29:10 +02:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
unsigned int sub_resource_idx;
|
2016-03-28 18:58:01 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
TRACE("surface %p, new location %#x, w %u, h %u.\n", surface, location, w, h);
|
|
|
|
|
2016-04-20 19:29:10 +02:00
|
|
|
sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2011-04-29 13:03:40 +02:00
|
|
|
surface->ds_current_size.cx = w;
|
|
|
|
surface->ds_current_size.cy = h;
|
2016-04-20 19:29:10 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~location);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2016-03-09 16:21:55 +01:00
|
|
|
static void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-04-25 17:19:34 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2016-03-24 18:24:26 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-04-29 13:03:40 +02:00
|
|
|
GLsizei w, h;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("surface %p, context %p, new location %#x.\n", surface, context, location);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
/* TODO: Make this work for modes other than FBO */
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return;
|
|
|
|
|
2016-04-25 17:19:34 +02:00
|
|
|
if (!(texture->sub_resources[sub_resource_idx].locations & location))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
w = surface->ds_current_size.cx;
|
|
|
|
h = surface->ds_current_size.cy;
|
|
|
|
surface->ds_current_size.cx = 0;
|
|
|
|
surface->ds_current_size.cy = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-19 18:34:05 +02:00
|
|
|
w = wined3d_texture_get_level_width(texture, surface->texture_level);
|
|
|
|
h = wined3d_texture_get_level_height(texture, surface->texture_level);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (surface->current_renderbuffer)
|
|
|
|
{
|
|
|
|
FIXME("Not supported with fixed up depth stencil.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-25 17:19:34 +02:00
|
|
|
wined3d_texture_prepare_location(texture, sub_resource_idx, context, location);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
if (location == WINED3D_LOCATION_TEXTURE_RGB)
|
2010-04-26 11:02:35 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
GLint old_binding = 0;
|
|
|
|
GLenum bind_target;
|
2007-02-15 03:02:39 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* The render target is allowed to be smaller than the depth/stencil
|
|
|
|
* buffer, so the onscreen depth/stencil buffer is potentially smaller
|
|
|
|
* than the offscreen surface. Don't overwrite the offscreen surface
|
|
|
|
* with undefined data. */
|
2011-12-02 08:15:52 +01:00
|
|
|
w = min(w, context->swapchain->desc.backbuffer_width);
|
|
|
|
h = min(h, context->swapchain->desc.backbuffer_height);
|
2007-02-15 03:02:39 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
TRACE("Copying onscreen depth buffer to depth texture.\n");
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
if (!device->depth_blt_texture)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &device->depth_blt_texture);
|
2010-04-08 22:49:51 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Note that we use depth_blt here as well, rather than glCopyTexImage2D
|
|
|
|
* directly on the FBO texture. That's because we need to flip. */
|
2011-07-31 17:33:43 +02:00
|
|
|
context_apply_fbo_state_blit(context, GL_FRAMEBUFFER,
|
2016-04-13 19:09:53 +02:00
|
|
|
context->swapchain->front_buffer->sub_resources[0].u.surface,
|
2014-08-20 13:20:02 +02:00
|
|
|
NULL, WINED3D_LOCATION_DRAWABLE);
|
2011-04-29 13:03:40 +02:00
|
|
|
if (surface->texture_target == GL_TEXTURE_RECTANGLE_ARB)
|
2010-10-21 12:40:44 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
|
2011-04-29 13:03:40 +02:00
|
|
|
bind_target = GL_TEXTURE_RECTANGLE_ARB;
|
2010-10-21 12:40:44 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
else
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
|
2011-04-29 13:03:40 +02:00
|
|
|
bind_target = GL_TEXTURE_2D;
|
2010-11-18 20:50:40 +01:00
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(bind_target, device->depth_blt_texture);
|
2011-06-07 11:06:26 +02:00
|
|
|
/* We use GL_DEPTH_COMPONENT instead of the surface's specific
|
|
|
|
* internal format, because the internal format might include stencil
|
|
|
|
* data. In principle we should copy stencil data as well, but unless
|
|
|
|
* the driver supports stencil export it's hard to do, and doesn't
|
|
|
|
* seem to be needed in practice. If the hardware doesn't support
|
|
|
|
* writing stencil data, the glCopyTexImage2D() call might trigger
|
|
|
|
* software fallbacks. */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexImage2D(bind_target, 0, GL_DEPTH_COMPONENT, 0, 0, w, h, 0);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(bind_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(bind_target, old_binding);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2011-07-31 17:33:43 +02:00
|
|
|
context_apply_fbo_state_blit(context, GL_FRAMEBUFFER,
|
2014-01-17 13:27:16 +01:00
|
|
|
NULL, surface, WINED3D_LOCATION_TEXTURE_RGB);
|
2011-07-31 17:33:43 +02:00
|
|
|
context_set_draw_buffer(context, GL_NONE);
|
2007-02-15 03:04:40 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Do the actual blit */
|
2011-07-27 23:21:25 +02:00
|
|
|
surface_depth_blt(surface, context, device->depth_blt_texture, 0, 0, w, h, bind_target);
|
2011-04-29 13:03:40 +02:00
|
|
|
checkGLcall("depth_blt");
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2011-07-31 17:33:42 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2010-08-23 18:28:08 +02:00
|
|
|
}
|
2014-01-17 13:27:16 +01:00
|
|
|
else if (location == WINED3D_LOCATION_DRAWABLE)
|
2010-08-23 18:28:08 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
TRACE("Copying depth texture to onscreen depth buffer.\n");
|
2007-02-15 03:02:39 +01:00
|
|
|
|
2011-07-31 17:33:43 +02:00
|
|
|
context_apply_fbo_state_blit(context, GL_FRAMEBUFFER,
|
2016-04-13 19:09:53 +02:00
|
|
|
context->swapchain->front_buffer->sub_resources[0].u.surface,
|
2014-08-20 13:20:02 +02:00
|
|
|
NULL, WINED3D_LOCATION_DRAWABLE);
|
2016-04-19 18:34:05 +02:00
|
|
|
surface_depth_blt(surface, context, texture->texture_rgb.name, 0,
|
|
|
|
wined3d_texture_get_level_pow2_height(texture, surface->texture_level) - h,
|
|
|
|
w, h, surface->texture_target);
|
2011-04-29 13:03:40 +02:00
|
|
|
checkGLcall("depth_blt");
|
2007-02-15 03:02:39 +01:00
|
|
|
|
2011-07-31 17:33:42 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Invalid location (%#x) specified.\n", location);
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
2006-04-14 19:15:46 +02:00
|
|
|
}
|
|
|
|
|
2011-05-05 20:56:07 +02:00
|
|
|
static DWORD resource_access_from_location(DWORD location)
|
|
|
|
{
|
|
|
|
switch (location)
|
|
|
|
{
|
2014-01-17 13:27:16 +01:00
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
|
|
|
case WINED3D_LOCATION_USER_MEMORY:
|
|
|
|
case WINED3D_LOCATION_BUFFER:
|
2011-05-05 20:56:07 +02:00
|
|
|
return WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
case WINED3D_LOCATION_DRAWABLE:
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
|
|
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
|
|
|
case WINED3D_LOCATION_RB_RESOLVED:
|
2011-05-05 20:56:07 +02:00
|
|
|
return WINED3D_RESOURCE_ACCESS_GPU;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled location %#x.\n", location);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-14 13:59:23 +01:00
|
|
|
static void surface_copy_simple_location(struct wined3d_surface *surface, DWORD location)
|
|
|
|
{
|
2016-03-31 22:48:54 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2016-04-20 19:29:12 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2014-01-14 13:59:23 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_bo_address dst, src;
|
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
2016-03-31 22:48:54 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &dst, location);
|
2016-04-20 19:29:12 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &src, sub_resource->locations);
|
2014-01-14 13:59:23 +01:00
|
|
|
|
|
|
|
if (dst.buffer_object)
|
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, dst.buffer_object));
|
2016-04-20 19:29:12 +02:00
|
|
|
GL_EXTCALL(glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, sub_resource->size, src.addr));
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
|
2014-01-14 13:59:23 +01:00
|
|
|
checkGLcall("Upload PBO");
|
|
|
|
context_release(context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (src.buffer_object)
|
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, src.buffer_object));
|
2016-04-20 19:29:12 +02:00
|
|
|
GL_EXTCALL(glGetBufferSubData(GL_PIXEL_PACK_BUFFER, 0, sub_resource->size, dst.addr));
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
|
2014-01-14 13:59:23 +01:00
|
|
|
checkGLcall("Download PBO");
|
|
|
|
context_release(context);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-20 19:29:12 +02:00
|
|
|
memcpy(dst.addr, src.addr, sub_resource->size);
|
2014-01-14 13:59:23 +01:00
|
|
|
}
|
|
|
|
|
2015-10-12 22:34:38 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-04 21:39:36 +02:00
|
|
|
static void surface_load_sysmem(struct wined3d_surface *surface,
|
2015-10-12 22:34:38 +02:00
|
|
|
struct wined3d_context *context, DWORD dst_location)
|
2011-07-04 21:39:36 +02:00
|
|
|
{
|
2016-04-26 17:56:02 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2015-10-12 22:34:38 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2016-04-26 17:56:02 +02:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2015-10-12 22:34:38 +02:00
|
|
|
|
2016-04-26 17:56:02 +02:00
|
|
|
wined3d_texture_prepare_location(texture, sub_resource_idx, context, dst_location);
|
2016-03-07 17:05:55 +01:00
|
|
|
|
2016-04-26 17:56:02 +02:00
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & surface_simple_locations)
|
2014-01-14 13:59:23 +01:00
|
|
|
{
|
|
|
|
surface_copy_simple_location(surface, dst_location);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_RB_MULTISAMPLE | WINED3D_LOCATION_RB_RESOLVED))
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(surface, context, WINED3D_LOCATION_TEXTURE_RGB);
|
2011-10-19 22:03:10 +02:00
|
|
|
|
2011-07-04 21:39:36 +02:00
|
|
|
/* Download the surface to system memory. */
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
2011-07-04 21:39:36 +02:00
|
|
|
{
|
2016-03-09 16:21:53 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context,
|
2016-03-28 18:58:01 +02:00
|
|
|
!(sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB));
|
2014-01-10 12:40:47 +01:00
|
|
|
surface_download_data(surface, gl_info, dst_location);
|
2016-03-09 16:21:53 +01:00
|
|
|
++texture->download_count;
|
2011-07-04 21:39:36 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_DRAWABLE)
|
2011-10-23 18:23:57 +02:00
|
|
|
{
|
2015-10-12 22:34:39 +02:00
|
|
|
read_from_framebuffer(surface, context, dst_location);
|
2011-10-23 18:23:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-17 13:27:15 +01:00
|
|
|
FIXME("Can't load surface %p with location flags %s into sysmem.\n",
|
2016-03-28 18:58:01 +02:00
|
|
|
surface, wined3d_debug_location(sub_resource->locations));
|
2011-07-04 21:39:36 +02:00
|
|
|
}
|
|
|
|
|
2015-10-12 22:34:41 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-04 21:39:37 +02:00
|
|
|
static HRESULT surface_load_drawable(struct wined3d_surface *surface,
|
2015-10-12 22:34:41 +02:00
|
|
|
struct wined3d_context *context)
|
2011-07-04 21:39:37 +02:00
|
|
|
{
|
2016-03-24 18:24:28 +01:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2013-08-28 10:09:58 +02:00
|
|
|
RECT r;
|
2011-07-04 21:39:37 +02:00
|
|
|
|
2014-08-19 09:22:29 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
|
2016-03-24 18:24:28 +01:00
|
|
|
&& wined3d_resource_is_offscreen(&texture->resource))
|
2011-08-25 21:04:56 +02:00
|
|
|
{
|
2014-01-17 13:27:16 +01:00
|
|
|
ERR("Trying to load offscreen surface into WINED3D_LOCATION_DRAWABLE.\n");
|
2011-08-25 21:04:56 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-11-20 12:33:31 +01:00
|
|
|
surface_get_rect(surface, NULL, &r);
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(surface, context, WINED3D_LOCATION_TEXTURE_RGB);
|
2016-03-24 18:24:28 +01:00
|
|
|
surface_blt_to_drawable(texture->resource.device, context,
|
2013-08-28 10:09:58 +02:00
|
|
|
WINED3D_TEXF_POINT, FALSE, surface, &r, surface, &r);
|
2011-07-04 21:39:37 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-04 21:39:38 +02:00
|
|
|
static HRESULT surface_load_texture(struct wined3d_surface *surface,
|
2015-10-15 22:41:10 +02:00
|
|
|
struct wined3d_context *context, BOOL srgb)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-04-07 19:38:01 +02:00
|
|
|
unsigned int width, height, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch;
|
2016-03-31 22:48:54 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2015-10-15 22:41:10 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2014-10-07 08:41:14 +02:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2016-03-24 18:24:29 +01:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
|
|
|
const struct wined3d_color_key_conversion *conversion;
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2011-07-04 21:39:38 +02:00
|
|
|
struct wined3d_bo_address data;
|
2016-04-18 19:06:27 +02:00
|
|
|
BYTE *src_mem, *dst_mem = NULL;
|
2011-04-29 13:03:40 +02:00
|
|
|
struct wined3d_format format;
|
2011-07-04 21:39:38 +02:00
|
|
|
POINT dst_point = {0, 0};
|
2016-04-07 19:38:01 +02:00
|
|
|
RECT src_rect;
|
2011-07-04 21:39:38 +02:00
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
sub_resource = surface_get_sub_resource(surface);
|
2011-07-04 21:39:38 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
|
2014-10-07 08:41:14 +02:00
|
|
|
&& wined3d_resource_is_offscreen(&texture->resource)
|
2016-03-28 18:58:01 +02:00
|
|
|
&& (sub_resource->locations & WINED3D_LOCATION_DRAWABLE))
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2015-10-15 22:41:11 +02:00
|
|
|
surface_load_fb_texture(surface, srgb, context);
|
2011-07-04 21:39:38 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-07 19:38:01 +02:00
|
|
|
width = wined3d_texture_get_level_width(texture, surface->texture_level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, surface->texture_level);
|
|
|
|
SetRect(&src_rect, 0, 0, width, height);
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_SRGB | WINED3D_LOCATION_TEXTURE_RGB)
|
2016-03-24 18:24:29 +01:00
|
|
|
&& (texture->resource.format_flags & WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB)
|
2011-07-04 21:39:38 +02:00
|
|
|
&& fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT,
|
2016-03-24 18:24:29 +01:00
|
|
|
NULL, texture->resource.usage, texture->resource.pool, texture->resource.format,
|
|
|
|
NULL, texture->resource.usage, texture->resource.pool, texture->resource.format))
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
|
|
|
if (srgb)
|
2015-10-12 22:34:42 +02:00
|
|
|
surface_blt_fbo(device, context, WINED3D_TEXF_POINT, surface, WINED3D_LOCATION_TEXTURE_RGB,
|
2014-01-17 13:27:16 +01:00
|
|
|
&src_rect, surface, WINED3D_LOCATION_TEXTURE_SRGB, &src_rect);
|
2011-07-04 21:39:38 +02:00
|
|
|
else
|
2015-10-12 22:34:42 +02:00
|
|
|
surface_blt_fbo(device, context, WINED3D_TEXF_POINT, surface, WINED3D_LOCATION_TEXTURE_SRGB,
|
2014-01-17 13:27:16 +01:00
|
|
|
&src_rect, surface, WINED3D_LOCATION_TEXTURE_RGB, &src_rect);
|
2011-07-04 21:39:38 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_RB_MULTISAMPLE | WINED3D_LOCATION_RB_RESOLVED)
|
2016-03-24 18:24:29 +01:00
|
|
|
&& (!srgb || (texture->resource.format_flags & WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB))
|
2011-10-19 22:03:10 +02:00
|
|
|
&& fbo_blit_supported(gl_info, WINED3D_BLIT_OP_COLOR_BLIT,
|
2016-03-24 18:24:29 +01:00
|
|
|
NULL, texture->resource.usage, texture->resource.pool, texture->resource.format,
|
|
|
|
NULL, texture->resource.usage, texture->resource.pool, texture->resource.format))
|
2011-10-19 22:03:10 +02:00
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
DWORD src_location = sub_resource->locations & WINED3D_LOCATION_RB_RESOLVED ?
|
2014-01-17 13:27:16 +01:00
|
|
|
WINED3D_LOCATION_RB_RESOLVED : WINED3D_LOCATION_RB_MULTISAMPLE;
|
|
|
|
DWORD dst_location = srgb ? WINED3D_LOCATION_TEXTURE_SRGB : WINED3D_LOCATION_TEXTURE_RGB;
|
2011-10-19 22:03:10 +02:00
|
|
|
|
2015-10-12 22:34:42 +02:00
|
|
|
surface_blt_fbo(device, context, WINED3D_TEXF_POINT, surface, src_location,
|
2016-04-07 19:38:01 +02:00
|
|
|
&src_rect, surface, dst_location, &src_rect);
|
2011-10-19 22:03:10 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-04 21:39:38 +02:00
|
|
|
/* Upload from system memory */
|
|
|
|
|
|
|
|
if (srgb)
|
|
|
|
{
|
2016-04-18 19:06:27 +02:00
|
|
|
if ((sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | texture->resource.map_binding))
|
2014-01-17 13:27:16 +01:00
|
|
|
== WINED3D_LOCATION_TEXTURE_RGB)
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2016-05-18 00:04:35 +02:00
|
|
|
FIXME_(d3d_perf)("Downloading RGB surface %p to reload it as sRGB.\n", surface);
|
2016-04-18 19:06:27 +02:00
|
|
|
surface_load_location(surface, context, texture->resource.map_binding);
|
2011-07-04 21:39:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-18 19:06:27 +02:00
|
|
|
if ((sub_resource->locations & (WINED3D_LOCATION_TEXTURE_SRGB | texture->resource.map_binding))
|
2014-01-17 13:27:16 +01:00
|
|
|
== WINED3D_LOCATION_TEXTURE_SRGB)
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2016-05-18 00:04:35 +02:00
|
|
|
FIXME_(d3d_perf)("Downloading sRGB surface %p to reload it as RGB.\n", surface);
|
2016-04-18 19:06:27 +02:00
|
|
|
surface_load_location(surface, context, texture->resource.map_binding);
|
2011-07-04 21:39:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (!(sub_resource->locations & surface_simple_locations))
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2014-01-15 14:54:09 +01:00
|
|
|
WARN("Trying to load a texture from sysmem, but no simple location is valid.\n");
|
2011-07-04 21:39:38 +02:00
|
|
|
/* Lets hope we get it from somewhere... */
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(surface, context, WINED3D_LOCATION_SYSMEM);
|
2011-07-04 21:39:38 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 08:47:19 +02:00
|
|
|
wined3d_texture_prepare_texture(texture, context, srgb);
|
2014-10-07 08:41:14 +02:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, srgb);
|
2016-02-12 11:06:06 +01:00
|
|
|
wined3d_texture_get_pitch(texture, surface->texture_level, &src_row_pitch, &src_slice_pitch);
|
2011-07-04 21:39:38 +02:00
|
|
|
|
2014-10-07 08:41:14 +02:00
|
|
|
format = *texture->resource.format;
|
2014-10-08 08:47:18 +02:00
|
|
|
if ((conversion = wined3d_format_get_color_key_conversion(texture, TRUE)))
|
2014-10-07 08:41:15 +02:00
|
|
|
format = *wined3d_get_format(gl_info, conversion->dst_format);
|
2014-10-07 08:41:14 +02:00
|
|
|
|
2011-07-04 21:39:38 +02:00
|
|
|
/* Don't use PBOs for converted surfaces. During PBO conversion we look at
|
2014-10-08 08:47:22 +02:00
|
|
|
* WINED3D_TEXTURE_CONVERTED but it isn't set (yet) in all cases it is
|
|
|
|
* getting called. */
|
2016-03-31 22:48:54 +02:00
|
|
|
if ((format.convert || conversion) && texture->sub_resources[sub_resource_idx].buffer_object)
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
|
|
|
TRACE("Removing the pbo attached to surface %p.\n", surface);
|
2014-01-15 14:54:12 +01:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
surface_load_location(surface, context, WINED3D_LOCATION_SYSMEM);
|
|
|
|
wined3d_texture_set_map_binding(texture, WINED3D_LOCATION_SYSMEM);
|
2011-07-04 21:39:38 +02:00
|
|
|
}
|
|
|
|
|
2016-03-31 22:48:54 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, sub_resource->locations);
|
2011-07-04 21:39:38 +02:00
|
|
|
if (format.convert)
|
|
|
|
{
|
|
|
|
/* This code is entered for texture formats which need a fixup. */
|
2014-10-06 08:24:19 +02:00
|
|
|
format.byte_count = format.conv_byte_count;
|
2016-02-09 21:29:56 +01:00
|
|
|
wined3d_format_calculate_pitch(&format, 1, width, height, &dst_row_pitch, &dst_slice_pitch);
|
2011-07-04 21:39:38 +02:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
src_mem = wined3d_texture_map_bo_address(&data, src_slice_pitch,
|
|
|
|
gl_info, GL_PIXEL_UNPACK_BUFFER, WINED3D_MAP_READONLY);
|
|
|
|
if (!(dst_mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch)))
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2016-02-09 21:29:56 +01:00
|
|
|
ERR("Out of memory (%u).\n", dst_slice_pitch);
|
2011-07-27 23:14:34 +02:00
|
|
|
context_release(context);
|
2011-07-04 21:39:38 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2016-04-18 19:06:27 +02:00
|
|
|
format.convert(src_mem, dst_mem, src_row_pitch, src_slice_pitch,
|
2016-02-09 21:29:56 +01:00
|
|
|
dst_row_pitch, dst_slice_pitch, width, height, 1);
|
2016-02-12 11:06:06 +01:00
|
|
|
src_row_pitch = dst_row_pitch;
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_unmap_bo_address(&data, gl_info, GL_PIXEL_UNPACK_BUFFER);
|
|
|
|
|
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = dst_mem;
|
2011-07-04 21:39:38 +02:00
|
|
|
}
|
2014-10-07 08:41:15 +02:00
|
|
|
else if (conversion)
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
|
|
|
/* This code is only entered for color keying fixups */
|
2014-10-07 08:41:15 +02:00
|
|
|
struct wined3d_palette *palette = NULL;
|
2011-07-04 21:39:38 +02:00
|
|
|
|
2016-02-09 21:29:56 +01:00
|
|
|
wined3d_format_calculate_pitch(&format, device->surface_alignment,
|
|
|
|
width, height, &dst_row_pitch, &dst_slice_pitch);
|
2011-07-04 21:39:38 +02:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
src_mem = wined3d_texture_map_bo_address(&data, src_slice_pitch,
|
|
|
|
gl_info, GL_PIXEL_UNPACK_BUFFER, WINED3D_MAP_READONLY);
|
|
|
|
if (!(dst_mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch)))
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2016-02-09 21:29:56 +01:00
|
|
|
ERR("Out of memory (%u).\n", dst_slice_pitch);
|
2011-07-27 23:14:34 +02:00
|
|
|
context_release(context);
|
2011-07-04 21:39:38 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2014-10-07 08:41:15 +02:00
|
|
|
if (texture->swapchain && texture->swapchain->palette)
|
|
|
|
palette = texture->swapchain->palette;
|
2016-04-18 19:06:27 +02:00
|
|
|
conversion->convert(src_mem, src_row_pitch, dst_mem, dst_row_pitch,
|
2015-04-09 22:48:11 +02:00
|
|
|
width, height, palette, &texture->async.gl_color_key);
|
2016-02-12 11:06:06 +01:00
|
|
|
src_row_pitch = dst_row_pitch;
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_unmap_bo_address(&data, gl_info, GL_PIXEL_UNPACK_BUFFER);
|
|
|
|
|
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = dst_mem;
|
2011-07-04 21:39:38 +02:00
|
|
|
}
|
|
|
|
|
2015-01-05 13:24:58 +01:00
|
|
|
wined3d_surface_upload_data(surface, gl_info, &format, &src_rect,
|
2016-02-12 11:06:06 +01:00
|
|
|
src_row_pitch, &dst_point, srgb, wined3d_const_bo_address(&data));
|
2011-07-04 21:39:38 +02:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, dst_mem);
|
2011-07-04 21:39:38 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-15 22:41:09 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2015-11-22 01:00:58 +01:00
|
|
|
static void surface_load_renderbuffer(struct wined3d_surface *surface, struct wined3d_context *context,
|
|
|
|
DWORD dst_location)
|
2011-08-25 21:05:03 +02:00
|
|
|
{
|
2016-04-11 18:34:39 +02:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
|
|
|
const RECT rect = {0, 0,
|
|
|
|
wined3d_texture_get_level_width(texture, surface->texture_level),
|
|
|
|
wined3d_texture_get_level_height(texture, surface->texture_level)};
|
2016-03-28 18:58:01 +02:00
|
|
|
DWORD locations = surface_get_sub_resource(surface)->locations;
|
2015-11-22 01:00:58 +01:00
|
|
|
DWORD src_location;
|
2011-08-25 21:05:03 +02:00
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (locations & WINED3D_LOCATION_RB_MULTISAMPLE)
|
2015-11-22 01:00:58 +01:00
|
|
|
src_location = WINED3D_LOCATION_RB_MULTISAMPLE;
|
2016-03-28 18:58:01 +02:00
|
|
|
else if (locations & WINED3D_LOCATION_RB_RESOLVED)
|
2015-11-22 01:00:58 +01:00
|
|
|
src_location = WINED3D_LOCATION_RB_RESOLVED;
|
2016-03-28 18:58:01 +02:00
|
|
|
else if (locations & WINED3D_LOCATION_TEXTURE_SRGB)
|
2015-11-22 01:00:58 +01:00
|
|
|
src_location = WINED3D_LOCATION_TEXTURE_SRGB;
|
|
|
|
else /* surface_blt_fbo will load the source location if necessary. */
|
|
|
|
src_location = WINED3D_LOCATION_TEXTURE_RGB;
|
2011-08-25 21:05:03 +02:00
|
|
|
|
2016-04-11 18:34:39 +02:00
|
|
|
surface_blt_fbo(texture->resource.device, context, WINED3D_TEXF_POINT,
|
2015-11-22 01:00:58 +01:00
|
|
|
surface, src_location, &rect, surface, dst_location, &rect);
|
2011-08-25 21:05:03 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 22:41:12 +02:00
|
|
|
/* Context activation is done by the caller. Context may be NULL in ddraw-only mode. */
|
|
|
|
HRESULT surface_load_location(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location)
|
2011-07-04 21:39:38 +02:00
|
|
|
{
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
2016-03-28 18:57:56 +02:00
|
|
|
struct wined3d_texture *texture = surface->container;
|
2016-03-29 16:45:36 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-04-11 18:34:40 +02:00
|
|
|
unsigned int surface_w, surface_h;
|
2011-07-04 21:39:37 +02:00
|
|
|
HRESULT hr;
|
2011-04-06 19:17:49 +02:00
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
TRACE("surface %p, location %s.\n", surface, wined3d_debug_location(location));
|
2011-04-06 19:17:49 +02:00
|
|
|
|
2016-04-11 18:34:40 +02:00
|
|
|
surface_w = wined3d_texture_get_level_width(texture, surface->texture_level);
|
|
|
|
surface_h = wined3d_texture_get_level_height(texture, surface->texture_level);
|
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & location && (!(texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
2016-04-11 18:34:40 +02:00
|
|
|
|| (surface->ds_current_size.cx == surface_w && surface->ds_current_size.cy == surface_h)))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-09 16:21:56 +01:00
|
|
|
TRACE("Location (%#x) is already up to date.\n", location);
|
2011-04-29 13:03:40 +02:00
|
|
|
return WINED3D_OK;
|
2008-02-15 23:55:36 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:35 +02:00
|
|
|
if (WARN_ON(d3d))
|
2011-05-05 20:56:07 +02:00
|
|
|
{
|
2011-07-05 22:30:54 +02:00
|
|
|
DWORD required_access = resource_access_from_location(location);
|
2016-03-28 18:57:56 +02:00
|
|
|
if ((texture->resource.access_flags & required_access) != required_access)
|
2011-05-05 20:56:07 +02:00
|
|
|
WARN("Operation requires %#x access, but surface only has %#x.\n",
|
2016-03-28 18:57:56 +02:00
|
|
|
required_access, texture->resource.access_flags);
|
2011-05-05 20:56:07 +02:00
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_DISCARDED)
|
2016-03-09 16:21:56 +01:00
|
|
|
{
|
|
|
|
TRACE("Surface previously discarded, nothing to do.\n");
|
2016-04-26 17:56:03 +02:00
|
|
|
wined3d_texture_prepare_location(texture, sub_resource_idx, context, location);
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
2016-03-09 16:21:56 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (!sub_resource->locations)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
ERR("Surface %p does not have any up to date location.\n", surface);
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
2016-03-09 16:21:56 +01:00
|
|
|
return surface_load_location(surface, context, location);
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:57:56 +02:00
|
|
|
if (texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
2016-03-09 16:21:56 +01:00
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
if ((location == WINED3D_LOCATION_TEXTURE_RGB && sub_resource->locations & WINED3D_LOCATION_DRAWABLE)
|
|
|
|
|| (location == WINED3D_LOCATION_DRAWABLE && sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB))
|
2016-03-09 16:21:56 +01:00
|
|
|
{
|
|
|
|
surface_load_ds_location(surface, context, location);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unimplemented copy from %s to %s for depth/stencil buffers.\n",
|
2016-03-28 18:58:01 +02:00
|
|
|
wined3d_debug_location(sub_resource->locations), wined3d_debug_location(location));
|
2015-12-04 11:30:14 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2011-04-06 19:17:49 +02:00
|
|
|
|
2011-07-05 22:30:54 +02:00
|
|
|
switch (location)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2014-01-17 13:27:16 +01:00
|
|
|
case WINED3D_LOCATION_USER_MEMORY:
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
|
|
|
case WINED3D_LOCATION_BUFFER:
|
2015-10-12 22:34:38 +02:00
|
|
|
surface_load_sysmem(surface, context, location);
|
2011-07-04 21:39:39 +02:00
|
|
|
break;
|
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
case WINED3D_LOCATION_DRAWABLE:
|
2015-10-15 22:41:12 +02:00
|
|
|
if (FAILED(hr = surface_load_drawable(surface, context)))
|
2011-07-04 21:39:39 +02:00
|
|
|
return hr;
|
|
|
|
break;
|
2011-08-25 21:05:03 +02:00
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
case WINED3D_LOCATION_RB_RESOLVED:
|
2015-11-22 01:00:58 +01:00
|
|
|
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
|
|
|
surface_load_renderbuffer(surface, context, location);
|
2011-08-25 21:05:03 +02:00
|
|
|
break;
|
2011-07-04 21:39:39 +02:00
|
|
|
|
2014-01-17 13:27:16 +01:00
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
2015-10-15 22:41:12 +02:00
|
|
|
if (FAILED(hr = surface_load_texture(surface, context,
|
|
|
|
location == WINED3D_LOCATION_TEXTURE_SRGB)))
|
2011-07-04 21:39:39 +02:00
|
|
|
return hr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-07-05 22:30:54 +02:00
|
|
|
ERR("Don't know how to handle location %#x.\n", location);
|
2011-07-04 21:39:39 +02:00
|
|
|
break;
|
2011-04-04 17:46:02 +02:00
|
|
|
}
|
2010-04-29 00:08:59 +02:00
|
|
|
|
2016-03-09 16:21:56 +01:00
|
|
|
done:
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2016-03-28 18:57:56 +02:00
|
|
|
if (texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
2016-03-09 16:21:56 +01:00
|
|
|
{
|
2016-04-11 18:34:40 +02:00
|
|
|
surface->ds_current_size.cx = surface_w;
|
|
|
|
surface->ds_current_size.cy = surface_h;
|
2016-03-09 16:21:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2010-04-28 00:08:52 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT ffp_blit_alloc(struct wined3d_device *device) { return WINED3D_OK; }
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-05-16 23:01:23 +02:00
|
|
|
static void ffp_blit_free(struct wined3d_device *device) { }
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2015-04-10 12:05:53 +02:00
|
|
|
static HRESULT ffp_blit_set(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface,
|
|
|
|
const struct wined3d_color_key *color_key)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2012-07-17 11:40:35 +02:00
|
|
|
|
2013-11-20 10:04:30 +01:00
|
|
|
gl_info->gl_ops.gl.p_glEnable(surface->container->target);
|
2012-07-17 11:40:35 +02:00
|
|
|
checkGLcall("glEnable(target)");
|
2012-12-10 21:54:36 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
return WINED3D_OK;
|
2008-07-02 23:00:41 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void ffp_blit_unset(const struct wined3d_gl_info *gl_info)
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
|
2011-04-29 13:03:40 +02:00
|
|
|
checkGLcall("glDisable(GL_TEXTURE_2D)");
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
2010-04-18 22:50:45 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
2011-04-29 13:03:40 +02:00
|
|
|
checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
|
2008-01-02 19:53:13 +01:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
2011-03-03 09:24:10 +01:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
2011-04-29 13:03:40 +02:00
|
|
|
checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
|
2011-03-03 09:24:10 +01:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2011-03-03 09:24:10 +01:00
|
|
|
|
2015-04-09 22:48:15 +02:00
|
|
|
static BOOL ffp_blit_supported(const struct wined3d_gl_info *gl_info,
|
|
|
|
const struct wined3d_d3d_info *d3d_info, enum wined3d_blit_op blit_op,
|
2012-01-17 21:13:37 +01:00
|
|
|
const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2015-04-14 11:16:25 +02:00
|
|
|
if (src_pool == WINED3D_POOL_SYSTEM_MEM || dst_pool == WINED3D_POOL_SYSTEM_MEM)
|
|
|
|
{
|
|
|
|
TRACE("Source or destination is in system memory.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
switch (blit_op)
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2015-04-10 12:05:53 +02:00
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT_CKEY:
|
2015-04-09 22:48:15 +02:00
|
|
|
if (d3d_info->shader_color_key)
|
|
|
|
{
|
|
|
|
TRACE("Color keying requires converted textures.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT:
|
2015-12-10 21:02:34 +01:00
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST:
|
2016-03-29 16:45:35 +02:00
|
|
|
if (TRACE_ON(d3d))
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
TRACE("Checking support for fixup:\n");
|
|
|
|
dump_color_fixup_desc(src_format->color_fixup);
|
2007-11-03 16:41:13 +01:00
|
|
|
}
|
2008-08-20 17:48:14 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* We only support identity conversions. */
|
2013-08-28 10:09:57 +02:00
|
|
|
if (!is_identity_fixup(src_format->color_fixup)
|
|
|
|
|| !is_identity_fixup(dst_format->color_fixup))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2013-08-28 10:09:57 +02:00
|
|
|
TRACE("Fixups are not supported.\n");
|
|
|
|
return FALSE;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2010-07-21 18:48:22 +02:00
|
|
|
|
2015-04-14 11:16:25 +02:00
|
|
|
if (!(dst_usage & WINED3DUSAGE_RENDERTARGET))
|
|
|
|
{
|
|
|
|
TRACE("Can only blit to render targets.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-08-28 10:09:57 +02:00
|
|
|
return TRUE;
|
2010-05-17 11:14:45 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3D_BLIT_OP_COLOR_FILL:
|
2011-08-21 21:34:56 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2015-04-24 10:33:47 +02:00
|
|
|
if (!((dst_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FBO_ATTACHABLE)
|
|
|
|
|| (dst_usage & WINED3DUSAGE_RENDERTARGET)))
|
2011-08-21 21:34:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (!(dst_usage & WINED3DUSAGE_RENDERTARGET))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
TRACE("Color fill not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-01-02 19:53:13 +01:00
|
|
|
|
2011-08-21 21:34:56 +02:00
|
|
|
/* FIXME: We should reject color fills on formats with fixups,
|
|
|
|
* but this would break P8 color fills for example. */
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
return TRUE;
|
2011-03-03 09:24:10 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
case WINED3D_BLIT_OP_DEPTH_FILL:
|
|
|
|
return TRUE;
|
2007-09-25 00:02:14 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
default:
|
|
|
|
TRACE("Unsupported blit_op=%d\n", blit_op);
|
|
|
|
return FALSE;
|
2007-09-25 00:02:14 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2007-09-25 00:02:14 +02:00
|
|
|
|
2016-02-03 22:22:56 +01:00
|
|
|
static HRESULT ffp_blit_color_fill(struct wined3d_device *device, struct wined3d_rendertarget_view *view,
|
|
|
|
const RECT *rect, const struct wined3d_color *color)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-02-03 22:22:56 +01:00
|
|
|
const RECT draw_rect = {0, 0, view->width, view->height};
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_fb_state fb = {&view, NULL};
|
|
|
|
|
2016-02-03 22:22:56 +01:00
|
|
|
device_clear_render_targets(device, 1, &fb, 1, rect, &draw_rect, WINED3DCLEAR_TARGET, color, 0.0f, 0);
|
2012-04-15 18:57:14 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2016-02-03 22:22:57 +01:00
|
|
|
static HRESULT ffp_blit_depth_fill(struct wined3d_device *device,
|
2016-03-15 10:52:49 +01:00
|
|
|
struct wined3d_rendertarget_view *view, const RECT *rect, DWORD clear_flags,
|
|
|
|
float depth, DWORD stencil)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-02-03 22:22:57 +01:00
|
|
|
const RECT draw_rect = {0, 0, view->width, view->height};
|
|
|
|
struct wined3d_fb_state fb = {NULL, view};
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2016-03-15 10:52:49 +01:00
|
|
|
device_clear_render_targets(device, 0, &fb, 1, rect, &draw_rect, clear_flags, NULL, depth, stencil);
|
2012-04-15 18:57:14 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2010-11-11 12:39:18 +01:00
|
|
|
|
2015-12-10 21:02:34 +01:00
|
|
|
static void ffp_blit_blit_surface(struct wined3d_device *device, enum wined3d_blit_op op, DWORD filter,
|
2015-04-14 11:16:25 +02:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect,
|
|
|
|
struct wined3d_surface *dst_surface, const RECT *dst_rect,
|
|
|
|
const struct wined3d_color_key *color_key)
|
|
|
|
{
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_texture *src_texture = src_surface->container;
|
2015-10-12 22:34:40 +02:00
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2015-04-14 11:16:25 +02:00
|
|
|
/* Blit from offscreen surface to render target */
|
2016-03-29 16:45:36 +02:00
|
|
|
struct wined3d_color_key old_blt_key = src_texture->async.src_blt_color_key;
|
|
|
|
DWORD old_color_key_flags = src_texture->async.color_key_flags;
|
2015-04-14 11:16:25 +02:00
|
|
|
|
|
|
|
TRACE("Blt from surface %p to rendertarget %p\n", src_surface, dst_surface);
|
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_set_color_key(src_texture, WINED3D_CKEY_SRC_BLT, color_key);
|
2015-04-14 11:16:25 +02:00
|
|
|
|
2015-10-12 22:34:40 +02:00
|
|
|
context = context_acquire(device, dst_surface);
|
2015-12-10 21:02:34 +01:00
|
|
|
|
|
|
|
if (op == WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST)
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
|
2015-10-12 22:34:40 +02:00
|
|
|
surface_blt_to_drawable(device, context, filter,
|
2015-04-14 11:16:25 +02:00
|
|
|
!!color_key, src_surface, src_rect, dst_surface, dst_rect);
|
2015-12-10 21:02:34 +01:00
|
|
|
|
|
|
|
if (op == WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST)
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
|
2015-10-12 22:34:40 +02:00
|
|
|
context_release(context);
|
2015-04-14 11:16:25 +02:00
|
|
|
|
|
|
|
/* Restore the color key parameters */
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_set_color_key(src_texture, WINED3D_CKEY_SRC_BLT,
|
2015-04-14 11:16:25 +02:00
|
|
|
(old_color_key_flags & WINED3D_CKEY_SRC_BLT) ? &old_blt_key : NULL);
|
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, dst_texture->resource.draw_binding);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~dst_texture->resource.draw_binding);
|
2015-04-14 11:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
const struct blit_shader ffp_blit = {
|
|
|
|
ffp_blit_alloc,
|
|
|
|
ffp_blit_free,
|
|
|
|
ffp_blit_set,
|
|
|
|
ffp_blit_unset,
|
|
|
|
ffp_blit_supported,
|
|
|
|
ffp_blit_color_fill,
|
|
|
|
ffp_blit_depth_fill,
|
2015-04-14 11:16:26 +02:00
|
|
|
ffp_blit_blit_surface,
|
2011-04-29 13:03:40 +02:00
|
|
|
};
|
2010-10-21 12:40:45 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT cpu_blit_alloc(struct wined3d_device *device)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2009-01-16 16:22:09 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-05-16 23:01:23 +02:00
|
|
|
static void cpu_blit_free(struct wined3d_device *device)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
}
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2015-04-10 12:05:53 +02:00
|
|
|
static HRESULT cpu_blit_set(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface,
|
|
|
|
const struct wined3d_color_key *color_key)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void cpu_blit_unset(const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2015-04-09 22:48:15 +02:00
|
|
|
static BOOL cpu_blit_supported(const struct wined3d_gl_info *gl_info,
|
|
|
|
const struct wined3d_d3d_info *d3d_info, enum wined3d_blit_op blit_op,
|
2012-01-17 21:13:37 +01:00
|
|
|
const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
if (blit_op == WINED3D_BLIT_OP_COLOR_FILL)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-06 01:54:26 +02:00
|
|
|
|
2011-09-08 23:50:37 +02:00
|
|
|
static HRESULT surface_cpu_blt_compressed(const BYTE *src_data, BYTE *dst_data,
|
|
|
|
UINT src_pitch, UINT dst_pitch, UINT update_w, UINT update_h,
|
2016-02-15 18:18:03 +01:00
|
|
|
const struct wined3d_format *format, DWORD flags, const struct wined3d_blt_fx *fx)
|
2011-09-08 23:50:37 +02:00
|
|
|
{
|
|
|
|
UINT row_block_count;
|
|
|
|
const BYTE *src_row;
|
|
|
|
BYTE *dst_row;
|
|
|
|
UINT x, y;
|
|
|
|
|
|
|
|
src_row = src_data;
|
|
|
|
dst_row = dst_data;
|
|
|
|
|
|
|
|
row_block_count = (update_w + format->block_width - 1) / format->block_width;
|
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
{
|
|
|
|
for (y = 0; y < update_h; y += format->block_height)
|
|
|
|
{
|
|
|
|
memcpy(dst_row, src_row, row_block_count * format->block_byte_count);
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
if (flags == WINED3D_BLT_FX && fx->fx == WINEDDBLTFX_MIRRORUPDOWN)
|
2011-09-08 23:50:37 +02:00
|
|
|
{
|
|
|
|
src_row += (((update_h / format->block_height) - 1) * src_pitch);
|
|
|
|
|
|
|
|
switch (format->id)
|
|
|
|
{
|
|
|
|
case WINED3DFMT_DXT1:
|
|
|
|
for (y = 0; y < update_h; y += format->block_height)
|
|
|
|
{
|
|
|
|
struct block
|
|
|
|
{
|
|
|
|
WORD color[2];
|
|
|
|
BYTE control_row[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct block *s = (const struct block *)src_row;
|
|
|
|
struct block *d = (struct block *)dst_row;
|
|
|
|
|
|
|
|
for (x = 0; x < row_block_count; ++x)
|
|
|
|
{
|
|
|
|
d[x].color[0] = s[x].color[0];
|
|
|
|
d[x].color[1] = s[x].color[1];
|
|
|
|
d[x].control_row[0] = s[x].control_row[3];
|
|
|
|
d[x].control_row[1] = s[x].control_row[2];
|
|
|
|
d[x].control_row[2] = s[x].control_row[1];
|
|
|
|
d[x].control_row[3] = s[x].control_row[0];
|
|
|
|
}
|
|
|
|
src_row -= src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
2014-05-12 15:12:41 +02:00
|
|
|
case WINED3DFMT_DXT2:
|
2011-09-08 23:50:37 +02:00
|
|
|
case WINED3DFMT_DXT3:
|
|
|
|
for (y = 0; y < update_h; y += format->block_height)
|
|
|
|
{
|
|
|
|
struct block
|
|
|
|
{
|
|
|
|
WORD alpha_row[4];
|
|
|
|
WORD color[2];
|
|
|
|
BYTE control_row[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct block *s = (const struct block *)src_row;
|
|
|
|
struct block *d = (struct block *)dst_row;
|
|
|
|
|
|
|
|
for (x = 0; x < row_block_count; ++x)
|
|
|
|
{
|
|
|
|
d[x].alpha_row[0] = s[x].alpha_row[3];
|
|
|
|
d[x].alpha_row[1] = s[x].alpha_row[2];
|
|
|
|
d[x].alpha_row[2] = s[x].alpha_row[1];
|
|
|
|
d[x].alpha_row[3] = s[x].alpha_row[0];
|
|
|
|
d[x].color[0] = s[x].color[0];
|
|
|
|
d[x].color[1] = s[x].color[1];
|
|
|
|
d[x].control_row[0] = s[x].control_row[3];
|
|
|
|
d[x].control_row[1] = s[x].control_row[2];
|
|
|
|
d[x].control_row[2] = s[x].control_row[1];
|
|
|
|
d[x].control_row[3] = s[x].control_row[0];
|
|
|
|
}
|
|
|
|
src_row -= src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Compressed flip not implemented for format %s.\n",
|
|
|
|
debug_d3dformat(format->id));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unsupported blit on compressed surface (format %s, flags %#x, DDFX %#x).\n",
|
2016-02-15 18:18:03 +01:00
|
|
|
debug_d3dformat(format->id), flags, flags & WINED3D_BLT_FX ? fx->fx : 0);
|
2011-09-08 23:50:37 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
static HRESULT surface_cpu_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
|
|
|
|
const struct wined3d_box *dst_box, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx,
|
|
|
|
const struct wined3d_box *src_box, DWORD flags, const struct wined3d_blt_fx *fx,
|
|
|
|
enum wined3d_texture_filter_type filter)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
unsigned int bpp, src_height, src_width, dst_height, dst_width, row_byte_count;
|
2011-04-29 13:03:40 +02:00
|
|
|
const struct wined3d_format *src_format, *dst_format;
|
2016-03-07 17:05:54 +01:00
|
|
|
struct wined3d_texture *converted_texture = NULL;
|
2015-04-22 11:30:15 +02:00
|
|
|
unsigned int src_fmt_flags, dst_fmt_flags;
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc dst_map, src_map;
|
2012-03-11 22:03:08 +01:00
|
|
|
const BYTE *sbase = NULL;
|
2011-04-29 13:03:40 +02:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2016-03-07 17:05:54 +01:00
|
|
|
BOOL same_sub_resource;
|
2011-04-29 13:03:40 +02:00
|
|
|
const BYTE *sbuf;
|
|
|
|
BYTE *dbuf;
|
|
|
|
int x, y;
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_box %s, src_texture %p, "
|
|
|
|
"src_sub_resource_idx %u, src_box %s, flags %#x, fx %p, filter %s.\n",
|
|
|
|
dst_texture, dst_sub_resource_idx, debug_box(dst_box), src_texture,
|
|
|
|
src_sub_resource_idx, debug_box(src_box), flags, fx, debug_d3dtexturefiltertype(filter));
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (src_texture == dst_texture && src_sub_resource_idx == dst_sub_resource_idx)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
same_sub_resource = TRUE;
|
|
|
|
wined3d_resource_map(&dst_texture->resource, dst_sub_resource_idx, &dst_map, NULL, 0);
|
2011-12-05 22:06:56 +01:00
|
|
|
src_map = dst_map;
|
2016-03-07 17:05:54 +01:00
|
|
|
src_format = dst_texture->resource.format;
|
2011-04-29 13:03:40 +02:00
|
|
|
dst_format = src_format;
|
2016-03-07 17:05:54 +01:00
|
|
|
dst_fmt_flags = dst_texture->resource.format_flags;
|
2015-04-22 11:30:15 +02:00
|
|
|
src_fmt_flags = dst_fmt_flags;
|
2007-09-25 00:21:34 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
else
|
2011-03-03 09:24:10 +01:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
same_sub_resource = FALSE;
|
|
|
|
dst_format = dst_texture->resource.format;
|
|
|
|
dst_fmt_flags = dst_texture->resource.format_flags;
|
|
|
|
if (src_texture)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
if (dst_texture->resource.format->id != src_texture->resource.format->id)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-04-04 18:42:58 +02:00
|
|
|
if (!(converted_texture = surface_convert_format(src_texture, src_sub_resource_idx, dst_format)))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-04-21 17:05:06 +02:00
|
|
|
FIXME("Cannot convert %s to %s.\n", debug_d3dformat(src_texture->resource.format->id),
|
|
|
|
debug_d3dformat(dst_texture->resource.format->id));
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-03-07 17:05:54 +01:00
|
|
|
src_texture = converted_texture;
|
|
|
|
src_sub_resource_idx = 0;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-03-07 17:05:54 +01:00
|
|
|
wined3d_resource_map(&src_texture->resource, src_sub_resource_idx, &src_map, NULL, WINED3D_MAP_READONLY);
|
|
|
|
src_format = src_texture->resource.format;
|
|
|
|
src_fmt_flags = src_texture->resource.format_flags;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src_format = dst_format;
|
2015-04-22 11:30:15 +02:00
|
|
|
src_fmt_flags = dst_fmt_flags;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2012-03-11 22:03:09 +01:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
wined3d_resource_map(&dst_texture->resource, dst_sub_resource_idx, &dst_map, dst_box, 0);
|
2011-03-03 09:24:10 +01:00
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
bpp = dst_format->byte_count;
|
|
|
|
src_height = src_box->bottom - src_box->top;
|
|
|
|
src_width = src_box->right - src_box->left;
|
|
|
|
dst_height = dst_box->bottom - dst_box->top;
|
|
|
|
dst_width = dst_box->right - dst_box->left;
|
|
|
|
row_byte_count = dst_width * bpp;
|
2010-04-05 20:05:14 +02:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (src_texture)
|
2012-03-11 22:03:08 +01:00
|
|
|
sbase = (BYTE *)src_map.data
|
2016-03-07 17:05:54 +01:00
|
|
|
+ ((src_box->top / src_format->block_height) * src_map.row_pitch)
|
|
|
|
+ ((src_box->left / src_format->block_width) * src_format->block_byte_count);
|
|
|
|
if (same_sub_resource)
|
2012-03-11 22:03:08 +01:00
|
|
|
dbuf = (BYTE *)dst_map.data
|
2016-03-07 17:05:54 +01:00
|
|
|
+ ((dst_box->top / dst_format->block_height) * dst_map.row_pitch)
|
|
|
|
+ ((dst_box->left / dst_format->block_width) * dst_format->block_byte_count);
|
|
|
|
else
|
|
|
|
dbuf = dst_map.data;
|
2012-03-11 22:03:08 +01:00
|
|
|
|
2015-04-22 11:30:15 +02:00
|
|
|
if (src_fmt_flags & dst_fmt_flags & WINED3DFMT_FLAG_BLOCKS)
|
2011-08-21 21:34:51 +02:00
|
|
|
{
|
2011-09-08 23:50:37 +02:00
|
|
|
TRACE("%s -> %s copy.\n", debug_d3dformat(src_format->id), debug_d3dformat(dst_format->id));
|
2011-08-21 21:34:51 +02:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (same_sub_resource)
|
2011-08-21 21:34:51 +02:00
|
|
|
{
|
|
|
|
FIXME("Only plain blits supported on compressed surfaces.\n");
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (src_height != dst_height || src_width != dst_width)
|
2011-08-21 21:34:51 +02:00
|
|
|
{
|
|
|
|
WARN("Stretching not supported on compressed surfaces.\n");
|
|
|
|
hr = WINED3DERR_INVALIDCALL;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (!wined3d_texture_check_block_align(src_texture,
|
|
|
|
src_sub_resource_idx % src_texture->level_count, src_box))
|
2011-08-21 21:34:51 +02:00
|
|
|
{
|
2012-07-11 12:19:02 +02:00
|
|
|
WARN("Source rectangle not block-aligned.\n");
|
|
|
|
hr = WINED3DERR_INVALIDCALL;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (!wined3d_texture_check_block_align(dst_texture,
|
|
|
|
dst_sub_resource_idx % dst_texture->level_count, dst_box))
|
2012-07-11 12:19:02 +02:00
|
|
|
{
|
|
|
|
WARN("Destination rectangle not block-aligned.\n");
|
2011-09-08 23:50:37 +02:00
|
|
|
hr = WINED3DERR_INVALIDCALL;
|
|
|
|
goto release;
|
2011-08-21 21:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-03-11 22:03:08 +01:00
|
|
|
hr = surface_cpu_blt_compressed(sbase, dbuf,
|
2016-03-07 17:05:54 +01:00
|
|
|
src_map.row_pitch, dst_map.row_pitch, dst_width, dst_height,
|
2011-09-08 23:50:37 +02:00
|
|
|
src_format, flags, fx);
|
2011-08-21 21:34:51 +02:00
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* First, all the 'source-less' blits */
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_COLOR_FILL)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
hr = _Blt_ColorFill(dbuf, dst_width, dst_height, bpp, dst_map.row_pitch, fx->fill_color);
|
2016-02-15 18:18:02 +01:00
|
|
|
flags &= ~WINED3D_BLT_COLOR_FILL;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2008-08-01 20:21:10 +02:00
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_DEPTH_FILL)
|
|
|
|
FIXME("WINED3D_BLT_DEPTH_FILL needs to be implemented!\n");
|
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
/* Now the 'with source' blits. */
|
2016-03-07 17:05:54 +01:00
|
|
|
if (src_texture)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
int sx, xinc, sy, yinc;
|
2008-08-01 20:21:10 +02:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (!dst_width || !dst_height) /* Hmm... stupid program? */
|
2011-04-29 13:03:40 +02:00
|
|
|
goto release;
|
2010-03-18 23:11:55 +01:00
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
if (filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT
|
2016-03-07 17:05:54 +01:00
|
|
|
&& (src_width != dst_width || src_height != dst_height))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* Can happen when d3d9 apps do a StretchRect() call which isn't handled in GL. */
|
|
|
|
FIXME("Filter %s not supported in software blit.\n", debug_d3dtexturefiltertype(filter));
|
|
|
|
}
|
2010-04-12 12:17:09 +02:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
xinc = (src_width << 16) / dst_width;
|
|
|
|
yinc = (src_height << 16) / dst_height;
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
{
|
|
|
|
/* No effects, we can cheat here. */
|
2016-03-07 17:05:54 +01:00
|
|
|
if (dst_width == src_width)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
if (dst_height == src_height)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* No stretching in either direction. This needs to be as
|
|
|
|
* fast as possible. */
|
|
|
|
sbuf = sbase;
|
|
|
|
|
|
|
|
/* Check for overlapping surfaces. */
|
2016-03-07 17:05:54 +01:00
|
|
|
if (!same_sub_resource || dst_box->top < src_box->top
|
|
|
|
|| dst_box->right <= src_box->left || src_box->right <= dst_box->left)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* No overlap, or dst above src, so copy from top downwards. */
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = 0; y < dst_height; ++y)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
memcpy(dbuf, sbuf, row_byte_count);
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf += src_map.row_pitch;
|
|
|
|
dbuf += dst_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-07 17:05:54 +01:00
|
|
|
else if (dst_box->top > src_box->top)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* Copy from bottom upwards. */
|
2016-03-07 17:05:54 +01:00
|
|
|
sbuf += src_map.row_pitch * dst_height;
|
|
|
|
dbuf += dst_map.row_pitch * dst_height;
|
|
|
|
for (y = 0; y < dst_height; ++y)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf -= src_map.row_pitch;
|
|
|
|
dbuf -= dst_map.row_pitch;
|
2016-03-07 17:05:54 +01:00
|
|
|
memcpy(dbuf, sbuf, row_byte_count);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Src and dst overlapping on the same line, use memmove. */
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = 0; y < dst_height; ++y)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
memmove(dbuf, sbuf, row_byte_count);
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf += src_map.row_pitch;
|
|
|
|
dbuf += dst_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Stretching in y direction only. */
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf = sbase + (sy >> 16) * src_map.row_pitch;
|
2016-03-07 17:05:54 +01:00
|
|
|
memcpy(dbuf, sbuf, row_byte_count);
|
2011-12-05 22:06:56 +01:00
|
|
|
dbuf += dst_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Stretching in X direction. */
|
|
|
|
int last_sy = -1;
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf = sbase + (sy >> 16) * src_map.row_pitch;
|
2010-04-12 12:17:09 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
if ((sy >> 16) == (last_sy >> 16))
|
|
|
|
{
|
|
|
|
/* This source row is the same as last source row -
|
|
|
|
* Copy the already stretched row. */
|
2016-03-07 17:05:54 +01:00
|
|
|
memcpy(dbuf, dbuf - dst_map.row_pitch, row_byte_count);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#define STRETCH_ROW(type) \
|
|
|
|
do { \
|
|
|
|
const type *s = (const type *)sbuf; \
|
|
|
|
type *d = (type *)dbuf; \
|
2016-03-07 17:05:54 +01:00
|
|
|
for (x = sx = 0; x < dst_width; ++x, sx += xinc) \
|
2011-04-29 13:03:40 +02:00
|
|
|
d[x] = s[sx >> 16]; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
switch(bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
STRETCH_ROW(BYTE);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
STRETCH_ROW(WORD);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
STRETCH_ROW(DWORD);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
const BYTE *s;
|
|
|
|
BYTE *d = dbuf;
|
2016-03-07 17:05:54 +01:00
|
|
|
for (x = sx = 0; x < dst_width; x++, sx+= xinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
DWORD pixel;
|
|
|
|
|
|
|
|
s = sbuf + 3 * (sx >> 16);
|
|
|
|
pixel = s[0] | (s[1] << 8) | (s[2] << 16);
|
|
|
|
d[0] = (pixel ) & 0xff;
|
|
|
|
d[1] = (pixel >> 8) & 0xff;
|
|
|
|
d[2] = (pixel >> 16) & 0xff;
|
|
|
|
d += 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("Stretched blit not implemented for bpp %u!\n", bpp * 8);
|
|
|
|
hr = WINED3DERR_NOTAVAILABLE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#undef STRETCH_ROW
|
|
|
|
}
|
2011-12-05 22:06:56 +01:00
|
|
|
dbuf += dst_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
last_sy = sy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-05 22:06:56 +01:00
|
|
|
LONG dstyinc = dst_map.row_pitch, dstxinc = bpp;
|
2012-07-20 00:24:27 +02:00
|
|
|
DWORD keylow = 0xffffffff, keyhigh = 0, keymask = 0xffffffff;
|
|
|
|
DWORD destkeylow = 0x0, destkeyhigh = 0xffffffff, destkeymask = 0xffffffff;
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & (WINED3D_BLT_SRC_CKEY | WINED3D_BLT_DST_CKEY
|
|
|
|
| WINED3D_BLT_SRC_CKEY_OVERRIDE | WINED3D_BLT_DST_CKEY_OVERRIDE))
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
/* The color keying flags are checked for correctness in ddraw */
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_SRC_CKEY)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
keylow = src_texture->async.src_blt_color_key.color_space_low_value;
|
|
|
|
keyhigh = src_texture->async.src_blt_color_key.color_space_high_value;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-02-15 18:18:02 +01:00
|
|
|
else if (flags & WINED3D_BLT_SRC_CKEY_OVERRIDE)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-02-15 18:18:03 +01:00
|
|
|
keylow = fx->src_color_key.color_space_low_value;
|
|
|
|
keyhigh = fx->src_color_key.color_space_high_value;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_DST_CKEY)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* Destination color keys are taken from the source surface! */
|
2016-03-07 17:05:54 +01:00
|
|
|
destkeylow = src_texture->async.dst_blt_color_key.color_space_low_value;
|
|
|
|
destkeyhigh = src_texture->async.dst_blt_color_key.color_space_high_value;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-02-15 18:18:02 +01:00
|
|
|
else if (flags & WINED3D_BLT_DST_CKEY_OVERRIDE)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-02-15 18:18:03 +01:00
|
|
|
destkeylow = fx->dst_color_key.color_space_low_value;
|
|
|
|
destkeyhigh = fx->dst_color_key.color_space_high_value;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bpp == 1)
|
|
|
|
{
|
|
|
|
keymask = 0xff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-15 00:38:25 +02:00
|
|
|
DWORD masks[3];
|
|
|
|
get_color_masks(src_format, masks);
|
|
|
|
keymask = masks[0]
|
|
|
|
| masks[1]
|
|
|
|
| masks[2];
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-02-15 18:18:02 +01:00
|
|
|
flags &= ~(WINED3D_BLT_SRC_CKEY | WINED3D_BLT_DST_CKEY
|
|
|
|
| WINED3D_BLT_SRC_CKEY_OVERRIDE | WINED3D_BLT_DST_CKEY_OVERRIDE);
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2008-12-03 14:53:43 +01:00
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_FX)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
BYTE *dTopLeft, *dTopRight, *dBottomLeft, *dBottomRight, *tmp;
|
|
|
|
LONG tmpxy;
|
|
|
|
dTopLeft = dbuf;
|
2016-03-07 17:05:54 +01:00
|
|
|
dTopRight = dbuf + ((dst_width - 1) * bpp);
|
|
|
|
dBottomLeft = dTopLeft + ((dst_height - 1) * dst_map.row_pitch);
|
|
|
|
dBottomRight = dBottomLeft + ((dst_width - 1) * bpp);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_ARITHSTRETCHY)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* I don't think we need to do anything about this flag */
|
2016-02-15 18:18:02 +01:00
|
|
|
WARN("Nothing done for WINEDDBLTFX_ARITHSTRETCHY.\n");
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_MIRRORLEFTRIGHT)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
tmp = dTopRight;
|
|
|
|
dTopRight = dTopLeft;
|
|
|
|
dTopLeft = tmp;
|
|
|
|
tmp = dBottomRight;
|
|
|
|
dBottomRight = dBottomLeft;
|
|
|
|
dBottomLeft = tmp;
|
|
|
|
dstxinc = dstxinc * -1;
|
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_MIRRORUPDOWN)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
tmp = dTopLeft;
|
|
|
|
dTopLeft = dBottomLeft;
|
|
|
|
dBottomLeft = tmp;
|
|
|
|
tmp = dTopRight;
|
|
|
|
dTopRight = dBottomRight;
|
|
|
|
dBottomRight = tmp;
|
|
|
|
dstyinc = dstyinc * -1;
|
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_NOTEARING)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* I don't think we need to do anything about this flag */
|
2016-02-15 18:18:02 +01:00
|
|
|
WARN("Nothing done for WINEDDBLTFX_NOTEARING.\n");
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_ROTATE180)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
tmp = dBottomRight;
|
|
|
|
dBottomRight = dTopLeft;
|
|
|
|
dTopLeft = tmp;
|
|
|
|
tmp = dBottomLeft;
|
|
|
|
dBottomLeft = dTopRight;
|
|
|
|
dTopRight = tmp;
|
|
|
|
dstxinc = dstxinc * -1;
|
|
|
|
dstyinc = dstyinc * -1;
|
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_ROTATE270)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
tmp = dTopLeft;
|
|
|
|
dTopLeft = dBottomLeft;
|
|
|
|
dBottomLeft = dBottomRight;
|
|
|
|
dBottomRight = dTopRight;
|
|
|
|
dTopRight = tmp;
|
|
|
|
tmpxy = dstxinc;
|
|
|
|
dstxinc = dstyinc;
|
|
|
|
dstyinc = tmpxy;
|
|
|
|
dstxinc = dstxinc * -1;
|
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_ROTATE90)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
tmp = dTopLeft;
|
|
|
|
dTopLeft = dTopRight;
|
|
|
|
dTopRight = dBottomRight;
|
|
|
|
dBottomRight = dBottomLeft;
|
|
|
|
dBottomLeft = tmp;
|
|
|
|
tmpxy = dstxinc;
|
|
|
|
dstxinc = dstyinc;
|
|
|
|
dstyinc = tmpxy;
|
|
|
|
dstyinc = dstyinc * -1;
|
|
|
|
}
|
2016-02-15 18:18:03 +01:00
|
|
|
if (fx->fx & WINEDDBLTFX_ZBUFFERBASEDEST)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
/* I don't think we need to do anything about this flag */
|
2016-02-15 18:18:02 +01:00
|
|
|
WARN("Nothing done for WINEDDBLTFX_ZBUFFERBASEDEST.\n");
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
dbuf = dTopLeft;
|
2016-02-15 18:18:02 +01:00
|
|
|
flags &= ~(WINED3D_BLT_FX);
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2010-04-06 22:20:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
#define COPY_COLORKEY_FX(type) \
|
|
|
|
do { \
|
|
|
|
const type *s; \
|
|
|
|
type *d = (type *)dbuf, *dx, tmp; \
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc) \
|
2011-04-29 13:03:40 +02:00
|
|
|
{ \
|
2011-12-05 22:06:56 +01:00
|
|
|
s = (const type *)(sbase + (sy >> 16) * src_map.row_pitch); \
|
2011-04-29 13:03:40 +02:00
|
|
|
dx = d; \
|
2016-03-07 17:05:54 +01:00
|
|
|
for (x = sx = 0; x < dst_width; ++x, sx += xinc) \
|
2011-04-29 13:03:40 +02:00
|
|
|
{ \
|
|
|
|
tmp = s[sx >> 16]; \
|
|
|
|
if (((tmp & keymask) < keylow || (tmp & keymask) > keyhigh) \
|
|
|
|
&& ((dx[0] & destkeymask) >= destkeylow && (dx[0] & destkeymask) <= destkeyhigh)) \
|
|
|
|
{ \
|
|
|
|
dx[0] = tmp; \
|
|
|
|
} \
|
|
|
|
dx = (type *)(((BYTE *)dx) + dstxinc); \
|
|
|
|
} \
|
|
|
|
d = (type *)(((BYTE *)d) + dstyinc); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2008-12-03 14:53:43 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
switch (bpp)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
case 1:
|
|
|
|
COPY_COLORKEY_FX(BYTE);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
COPY_COLORKEY_FX(WORD);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
COPY_COLORKEY_FX(DWORD);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
const BYTE *s;
|
|
|
|
BYTE *d = dbuf, *dx;
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf = sbase + (sy >> 16) * src_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
dx = d;
|
2016-03-07 17:05:54 +01:00
|
|
|
for (x = sx = 0; x < dst_width; ++x, sx+= xinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
|
|
|
DWORD pixel, dpixel = 0;
|
|
|
|
s = sbuf + 3 * (sx>>16);
|
|
|
|
pixel = s[0] | (s[1] << 8) | (s[2] << 16);
|
|
|
|
dpixel = dx[0] | (dx[1] << 8 ) | (dx[2] << 16);
|
|
|
|
if (((pixel & keymask) < keylow || (pixel & keymask) > keyhigh)
|
|
|
|
&& ((dpixel & keymask) >= destkeylow || (dpixel & keymask) <= keyhigh))
|
|
|
|
{
|
|
|
|
dx[0] = (pixel ) & 0xff;
|
|
|
|
dx[1] = (pixel >> 8) & 0xff;
|
|
|
|
dx[2] = (pixel >> 16) & 0xff;
|
|
|
|
}
|
|
|
|
dx += dstxinc;
|
|
|
|
}
|
|
|
|
d += dstyinc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("%s color-keyed blit not implemented for bpp %u!\n",
|
2016-02-15 18:18:02 +01:00
|
|
|
(flags & WINED3D_BLT_SRC_CKEY) ? "Source" : "Destination", bpp * 8);
|
2011-04-29 13:03:40 +02:00
|
|
|
hr = WINED3DERR_NOTAVAILABLE;
|
|
|
|
goto error;
|
|
|
|
#undef COPY_COLORKEY_FX
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2010-03-25 17:01:33 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
error:
|
2016-03-29 16:45:35 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME(" Unsupported flags %#x.\n", flags);
|
2010-04-12 12:17:09 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
release:
|
2016-03-07 17:05:54 +01:00
|
|
|
wined3d_resource_unmap(&dst_texture->resource, dst_sub_resource_idx);
|
|
|
|
if (src_texture && !same_sub_resource)
|
|
|
|
wined3d_resource_unmap(&src_texture->resource, src_sub_resource_idx);
|
|
|
|
if (converted_texture)
|
|
|
|
wined3d_texture_decref(converted_texture);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
return hr;
|
2010-03-25 17:01:33 +01:00
|
|
|
}
|
|
|
|
|
2016-02-03 22:22:56 +01:00
|
|
|
static HRESULT cpu_blit_color_fill(struct wined3d_device *device, struct wined3d_rendertarget_view *view,
|
|
|
|
const RECT *rect, const struct wined3d_color *color)
|
2010-03-25 17:01:33 +01:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
const struct wined3d_box box = {rect->left, rect->top, rect->right, rect->bottom, 0, 1};
|
|
|
|
static const struct wined3d_box src_box;
|
2016-02-15 18:18:03 +01:00
|
|
|
struct wined3d_blt_fx fx;
|
2010-08-23 18:28:07 +02:00
|
|
|
|
2016-02-19 17:28:43 +01:00
|
|
|
fx.fill_color = wined3d_format_convert_from_float(view->format, color);
|
2016-04-20 19:29:13 +02:00
|
|
|
return surface_cpu_blt(texture_from_resource(view->resource), view->sub_resource_idx,
|
2016-03-07 17:05:54 +01:00
|
|
|
&box, NULL, 0, &src_box, WINED3D_BLT_COLOR_FILL, &fx, WINED3D_TEXF_POINT);
|
2010-03-25 17:01:33 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT cpu_blit_depth_fill(struct wined3d_device *device,
|
2016-03-15 10:52:49 +01:00
|
|
|
struct wined3d_rendertarget_view *view, const RECT *rect, DWORD clear_flags,
|
|
|
|
float depth, DWORD stencil)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2016-03-15 10:52:49 +01:00
|
|
|
FIXME("Depth/stencil filling not implemented by cpu_blit.\n");
|
2011-04-05 19:01:31 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2015-12-10 21:02:34 +01:00
|
|
|
static void cpu_blit_blit_surface(struct wined3d_device *device, enum wined3d_blit_op op, DWORD filter,
|
2015-04-14 11:16:26 +02:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect,
|
|
|
|
struct wined3d_surface *dst_surface, const RECT *dst_rect,
|
|
|
|
const struct wined3d_color_key *color_key)
|
|
|
|
{
|
|
|
|
/* FIXME: Remove error returns from surface_blt_cpu. */
|
|
|
|
ERR("Blit method not implemented by cpu_blit.\n");
|
|
|
|
}
|
|
|
|
|
2010-03-25 17:01:33 +01:00
|
|
|
const struct blit_shader cpu_blit = {
|
|
|
|
cpu_blit_alloc,
|
|
|
|
cpu_blit_free,
|
|
|
|
cpu_blit_set,
|
|
|
|
cpu_blit_unset,
|
2010-04-06 22:20:42 +02:00
|
|
|
cpu_blit_supported,
|
2011-04-05 19:01:31 +02:00
|
|
|
cpu_blit_color_fill,
|
|
|
|
cpu_blit_depth_fill,
|
2015-04-14 11:16:26 +02:00
|
|
|
cpu_blit_blit_surface,
|
2008-08-01 20:21:10 +02:00
|
|
|
};
|
2010-03-31 13:54:57 +02:00
|
|
|
|
2016-01-29 18:48:55 +01:00
|
|
|
HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect,
|
2016-01-27 20:44:38 +01:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags,
|
2016-02-15 18:18:03 +01:00
|
|
|
const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
struct wined3d_box dst_box = {dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, 0, 1};
|
|
|
|
struct wined3d_box src_box = {src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, 0, 1};
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int dst_sub_resource_idx = surface_get_sub_resource_idx(dst_surface);
|
2016-03-06 20:59:49 +01:00
|
|
|
struct wined3d_texture *dst_texture = dst_surface->container;
|
|
|
|
struct wined3d_device *device = dst_texture->resource.device;
|
2013-09-02 09:45:42 +02:00
|
|
|
struct wined3d_swapchain *src_swapchain, *dst_swapchain;
|
2016-03-06 20:59:49 +01:00
|
|
|
struct wined3d_texture *src_texture = NULL;
|
2016-04-11 18:34:41 +02:00
|
|
|
unsigned int dst_w, dst_h, src_w, src_h;
|
2016-04-10 18:09:27 +02:00
|
|
|
unsigned int src_sub_resource_idx = 0;
|
2013-09-02 09:45:42 +02:00
|
|
|
DWORD src_ds_flags, dst_ds_flags;
|
|
|
|
BOOL scale, convert;
|
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
static const DWORD simple_blit = WINED3D_BLT_ASYNC
|
|
|
|
| WINED3D_BLT_COLOR_FILL
|
|
|
|
| WINED3D_BLT_SRC_CKEY
|
|
|
|
| WINED3D_BLT_SRC_CKEY_OVERRIDE
|
|
|
|
| WINED3D_BLT_WAIT
|
|
|
|
| WINED3D_BLT_DEPTH_FILL
|
|
|
|
| WINED3D_BLT_DO_NOT_WAIT
|
|
|
|
| WINED3D_BLT_ALPHA_TEST;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2016-01-27 20:44:38 +01:00
|
|
|
TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p, filter %s.\n",
|
|
|
|
dst_surface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect),
|
2013-09-02 09:45:42 +02:00
|
|
|
flags, fx, debug_d3dtexturefiltertype(filter));
|
2016-03-06 20:59:49 +01:00
|
|
|
TRACE("Usage is %s.\n", debug_d3dusage(dst_texture->resource.usage));
|
2013-09-02 09:45:42 +02:00
|
|
|
|
|
|
|
if (fx)
|
|
|
|
{
|
2016-02-15 18:18:03 +01:00
|
|
|
TRACE("fx %#x.\n", fx->fx);
|
|
|
|
TRACE("fill_color 0x%08x.\n", fx->fill_color);
|
|
|
|
TRACE("dst_color_key {0x%08x, 0x%08x}.\n",
|
|
|
|
fx->dst_color_key.color_space_low_value,
|
|
|
|
fx->dst_color_key.color_space_high_value);
|
|
|
|
TRACE("src_color_key {0x%08x, 0x%08x}.\n",
|
|
|
|
fx->src_color_key.color_space_low_value,
|
|
|
|
fx->src_color_key.color_space_high_value);
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
if (src_surface)
|
|
|
|
{
|
|
|
|
src_texture = src_surface->container;
|
|
|
|
src_sub_resource_idx = surface_get_sub_resource_idx(src_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst_texture->sub_resources[dst_sub_resource_idx].map_count
|
|
|
|
|| (src_texture && src_texture->sub_resources[src_sub_resource_idx].map_count))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
WARN("Surface is busy, returning WINEDDERR_SURFACEBUSY.\n");
|
|
|
|
return WINEDDERR_SURFACEBUSY;
|
|
|
|
}
|
|
|
|
|
2016-04-11 18:34:41 +02:00
|
|
|
dst_w = wined3d_texture_get_level_width(dst_texture, dst_surface->texture_level);
|
|
|
|
dst_h = wined3d_texture_get_level_height(dst_texture, dst_surface->texture_level);
|
2016-05-03 21:48:05 +02:00
|
|
|
if (IsRectEmpty(dst_rect) || dst_rect->left > dst_w || dst_rect->left < 0
|
2016-04-11 18:34:41 +02:00
|
|
|
|| dst_rect->top > dst_h || dst_rect->top < 0
|
|
|
|
|| dst_rect->right > dst_w || dst_rect->right < 0
|
|
|
|
|| dst_rect->bottom > dst_h || dst_rect->bottom < 0)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
WARN("The application gave us a bad destination rectangle.\n");
|
|
|
|
return WINEDDERR_INVALIDRECT;
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
if (src_texture)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2016-04-11 18:34:41 +02:00
|
|
|
src_w = wined3d_texture_get_level_width(src_texture, src_surface->texture_level);
|
|
|
|
src_h = wined3d_texture_get_level_height(src_texture, src_surface->texture_level);
|
2016-05-03 21:48:05 +02:00
|
|
|
if (IsRectEmpty(src_rect) || src_rect->left > src_w || src_rect->left < 0
|
2016-04-11 18:34:41 +02:00
|
|
|
|| src_rect->top > src_h || src_rect->top < 0
|
|
|
|
|| src_rect->right > src_w || src_rect->right < 0
|
|
|
|
|| src_rect->bottom > src_h || src_rect->bottom < 0)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2016-01-27 20:44:38 +01:00
|
|
|
WARN("The application gave us a bad source rectangle.\n");
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINEDDERR_INVALIDRECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
if (!fx || !(fx->fx))
|
2016-02-15 18:18:02 +01:00
|
|
|
flags &= ~WINED3D_BLT_FX;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_WAIT)
|
|
|
|
flags &= ~WINED3D_BLT_WAIT;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_ASYNC)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (!once++)
|
2016-02-15 18:18:02 +01:00
|
|
|
FIXME("Can't handle WINED3D_BLT_ASYNC flag.\n");
|
|
|
|
flags &= ~WINED3D_BLT_ASYNC;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
/* WINED3D_BLT_DO_NOT_WAIT appeared in DX7. */
|
|
|
|
if (flags & WINED3D_BLT_DO_NOT_WAIT)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (!once++)
|
2016-02-15 18:18:02 +01:00
|
|
|
FIXME("Can't handle WINED3D_BLT_DO_NOT_WAIT flag.\n");
|
|
|
|
flags &= ~WINED3D_BLT_DO_NOT_WAIT;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!device->d3d_initialized)
|
|
|
|
{
|
|
|
|
WARN("D3D not initialized, using fallback.\n");
|
|
|
|
goto cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to avoid invalidating the sysmem location for converted
|
|
|
|
* surfaces, since otherwise we'd have to convert the data back when
|
|
|
|
* locking them. */
|
2016-03-06 20:59:49 +01:00
|
|
|
if (dst_texture->flags & WINED3D_TEXTURE_CONVERTED || dst_texture->resource.format->convert
|
|
|
|
|| wined3d_format_get_color_key_conversion(dst_texture, TRUE))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
WARN_(d3d_perf)("Converted surface, using CPU blit.\n");
|
2013-10-08 00:27:06 +02:00
|
|
|
goto cpu;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & ~simple_blit)
|
|
|
|
{
|
|
|
|
WARN_(d3d_perf)("Using fallback for complex blit (%#x).\n", flags);
|
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
if (src_texture)
|
2016-03-06 20:59:49 +01:00
|
|
|
src_swapchain = src_texture->swapchain;
|
2013-09-02 09:45:42 +02:00
|
|
|
else
|
|
|
|
src_swapchain = NULL;
|
|
|
|
|
2016-03-06 20:59:49 +01:00
|
|
|
dst_swapchain = dst_texture->swapchain;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
|
|
|
/* This isn't strictly needed. FBO blits for example could deal with
|
|
|
|
* cross-swapchain blits by first downloading the source to a texture
|
|
|
|
* before switching to the destination context. We just have this here to
|
|
|
|
* not have to deal with the issue, since cross-swapchain blits should be
|
|
|
|
* rare. */
|
|
|
|
if (src_swapchain && dst_swapchain && src_swapchain != dst_swapchain)
|
|
|
|
{
|
|
|
|
FIXME("Using fallback for cross-swapchain blit.\n");
|
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
scale = src_texture
|
2016-01-27 20:44:38 +01:00
|
|
|
&& (src_rect->right - src_rect->left != dst_rect->right - dst_rect->left
|
|
|
|
|| src_rect->bottom - src_rect->top != dst_rect->bottom - dst_rect->top);
|
2016-04-10 18:09:27 +02:00
|
|
|
convert = src_texture && src_texture->resource.format->id != dst_texture->resource.format->id;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2016-03-06 20:59:49 +01:00
|
|
|
dst_ds_flags = dst_texture->resource.format_flags
|
2015-06-06 17:53:52 +02:00
|
|
|
& (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
|
2016-04-10 18:09:27 +02:00
|
|
|
if (src_texture)
|
2016-03-06 20:59:49 +01:00
|
|
|
src_ds_flags = src_texture->resource.format_flags
|
2015-06-06 17:53:52 +02:00
|
|
|
& (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
|
2013-09-02 09:45:42 +02:00
|
|
|
else
|
|
|
|
src_ds_flags = 0;
|
|
|
|
|
|
|
|
if (src_ds_flags || dst_ds_flags)
|
|
|
|
{
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_DEPTH_FILL)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
float depth;
|
|
|
|
|
|
|
|
TRACE("Depth fill.\n");
|
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
if (!surface_convert_depth_to_float(dst_surface, fx->fill_color, &depth))
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-01-27 20:44:38 +01:00
|
|
|
if (SUCCEEDED(wined3d_surface_depth_fill(dst_surface, dst_rect, depth)))
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (src_ds_flags != dst_ds_flags)
|
|
|
|
{
|
|
|
|
WARN("Rejecting depth / stencil blit between incompatible formats.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-03-06 20:59:49 +01:00
|
|
|
if (SUCCEEDED(wined3d_surface_depth_blt(src_surface, src_texture->resource.draw_binding,
|
|
|
|
src_rect, dst_surface, dst_texture->resource.draw_binding, dst_rect)))
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_texture_sub_resource *src_sub_resource, *dst_sub_resource;
|
2015-04-14 11:16:26 +02:00
|
|
|
const struct blit_shader *blitter;
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
dst_sub_resource = surface_get_sub_resource(dst_surface);
|
2016-04-10 18:09:27 +02:00
|
|
|
src_sub_resource = src_texture ? &src_texture->sub_resources[src_sub_resource_idx] : NULL;
|
2016-03-28 18:58:01 +02:00
|
|
|
|
2013-09-02 09:45:42 +02:00
|
|
|
/* In principle this would apply to depth blits as well, but we don't
|
|
|
|
* implement those in the CPU blitter at the moment. */
|
2016-04-18 19:06:27 +02:00
|
|
|
if ((dst_sub_resource->locations & dst_texture->resource.map_binding)
|
|
|
|
&& (!src_texture || (src_sub_resource->locations & src_texture->resource.map_binding)))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
if (scale)
|
|
|
|
TRACE("Not doing sysmem blit because of scaling.\n");
|
|
|
|
else if (convert)
|
|
|
|
TRACE("Not doing sysmem blit because of format conversion.\n");
|
|
|
|
else
|
2013-10-08 00:27:06 +02:00
|
|
|
goto cpu;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_COLOR_FILL)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
struct wined3d_color color;
|
2015-04-06 00:28:53 +02:00
|
|
|
const struct wined3d_palette *palette = dst_swapchain ? dst_swapchain->palette : NULL;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
|
|
|
TRACE("Color fill.\n");
|
|
|
|
|
2016-03-06 20:59:49 +01:00
|
|
|
if (!wined3d_format_convert_color_to_float(dst_texture->resource.format,
|
2016-02-15 18:18:03 +01:00
|
|
|
palette, fx->fill_color, &color))
|
2013-09-02 09:45:42 +02:00
|
|
|
goto fallback;
|
|
|
|
|
2016-01-27 20:44:38 +01:00
|
|
|
if (SUCCEEDED(surface_color_fill(dst_surface, dst_rect, &color)))
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-10 12:05:53 +02:00
|
|
|
enum wined3d_blit_op blit_op = WINED3D_BLIT_OP_COLOR_BLIT;
|
|
|
|
const struct wined3d_color_key *color_key = NULL;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2015-04-10 12:05:53 +02:00
|
|
|
TRACE("Color blit.\n");
|
2016-02-15 18:18:02 +01:00
|
|
|
if (flags & WINED3D_BLT_SRC_CKEY_OVERRIDE)
|
2015-04-10 12:05:53 +02:00
|
|
|
{
|
2016-02-15 18:18:03 +01:00
|
|
|
color_key = &fx->src_color_key;
|
2015-04-10 12:05:53 +02:00
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT_CKEY;
|
|
|
|
}
|
2016-02-15 18:18:02 +01:00
|
|
|
else if (flags & WINED3D_BLT_SRC_CKEY)
|
2015-04-10 12:05:53 +02:00
|
|
|
{
|
2016-03-06 20:59:49 +01:00
|
|
|
color_key = &src_texture->async.src_blt_color_key;
|
2015-04-10 12:05:53 +02:00
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT_CKEY;
|
|
|
|
}
|
2016-02-15 18:18:02 +01:00
|
|
|
else if (flags & WINED3D_BLT_ALPHA_TEST)
|
2015-12-10 21:02:34 +01:00
|
|
|
{
|
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST;
|
|
|
|
}
|
2016-03-28 18:58:01 +02:00
|
|
|
else if ((src_sub_resource->locations & WINED3D_LOCATION_SYSMEM)
|
|
|
|
&& !(dst_sub_resource->locations & WINED3D_LOCATION_SYSMEM))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2015-04-10 12:05:53 +02:00
|
|
|
/* Upload */
|
2013-09-02 09:45:42 +02:00
|
|
|
if (scale)
|
|
|
|
TRACE("Not doing upload because of scaling.\n");
|
|
|
|
else if (convert)
|
|
|
|
TRACE("Not doing upload because of format conversion.\n");
|
|
|
|
else
|
|
|
|
{
|
2016-01-27 20:44:38 +01:00
|
|
|
POINT dst_point = {dst_rect->left, dst_rect->top};
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2016-01-27 20:44:38 +01:00
|
|
|
if (SUCCEEDED(surface_upload_from_surface(dst_surface, &dst_point, src_surface, src_rect)))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2016-03-06 20:59:49 +01:00
|
|
|
if (!wined3d_resource_is_offscreen(&dst_texture->resource))
|
2015-10-15 22:41:12 +02:00
|
|
|
{
|
|
|
|
struct wined3d_context *context = context_acquire(device, dst_surface);
|
2016-03-06 20:59:49 +01:00
|
|
|
surface_load_location(dst_surface, context, dst_texture->resource.draw_binding);
|
2015-10-15 22:41:12 +02:00
|
|
|
context_release(context);
|
|
|
|
}
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-10 12:05:53 +02:00
|
|
|
else if (dst_swapchain && dst_swapchain->back_buffers
|
2016-03-06 20:59:49 +01:00
|
|
|
&& dst_texture == dst_swapchain->front_buffer
|
|
|
|
&& src_texture == dst_swapchain->back_buffers[0])
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2015-04-10 12:05:53 +02:00
|
|
|
/* Use present for back -> front blits. The idea behind this is
|
|
|
|
* that present is potentially faster than a blit, in particular
|
|
|
|
* when FBO blits aren't available. Some ddraw applications like
|
|
|
|
* Half-Life and Prince of Persia 3D use Blt() from the backbuffer
|
|
|
|
* to the frontbuffer instead of doing a Flip(). D3D8 and D3D9
|
|
|
|
* applications can't blit directly to the frontbuffer. */
|
2013-09-02 09:45:42 +02:00
|
|
|
enum wined3d_swap_effect swap_effect = dst_swapchain->desc.swap_effect;
|
|
|
|
|
|
|
|
TRACE("Using present for backbuffer -> frontbuffer blit.\n");
|
|
|
|
|
|
|
|
/* Set the swap effect to COPY, we don't want the backbuffer
|
|
|
|
* to become undefined. */
|
|
|
|
dst_swapchain->desc.swap_effect = WINED3D_SWAP_EFFECT_COPY;
|
2016-03-17 16:30:03 +01:00
|
|
|
wined3d_swapchain_present(dst_swapchain, NULL, NULL, dst_swapchain->win_handle, 0);
|
2013-09-02 09:45:42 +02:00
|
|
|
dst_swapchain->desc.swap_effect = swap_effect;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-10 12:05:53 +02:00
|
|
|
if (fbo_blit_supported(&device->adapter->gl_info, blit_op,
|
2016-03-06 20:59:49 +01:00
|
|
|
src_rect, src_texture->resource.usage, src_texture->resource.pool, src_texture->resource.format,
|
|
|
|
dst_rect, dst_texture->resource.usage, dst_texture->resource.pool, dst_texture->resource.format))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2015-10-12 22:34:42 +02:00
|
|
|
struct wined3d_context *context;
|
2013-09-02 09:45:42 +02:00
|
|
|
TRACE("Using FBO blit.\n");
|
|
|
|
|
2015-10-12 22:34:42 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
surface_blt_fbo(device, context, filter,
|
2016-03-06 20:59:49 +01:00
|
|
|
src_surface, src_texture->resource.draw_binding, src_rect,
|
|
|
|
dst_surface, dst_texture->resource.draw_binding, dst_rect);
|
2015-10-12 22:34:42 +02:00
|
|
|
context_release(context);
|
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx,
|
|
|
|
dst_texture->resource.draw_binding);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx,
|
|
|
|
~dst_texture->resource.draw_binding);
|
2013-09-10 09:32:34 +02:00
|
|
|
|
2013-09-02 09:45:42 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:16:26 +02:00
|
|
|
blitter = wined3d_select_blitter(&device->adapter->gl_info, &device->adapter->d3d_info, blit_op,
|
2016-03-06 20:59:49 +01:00
|
|
|
src_rect, src_texture->resource.usage, src_texture->resource.pool, src_texture->resource.format,
|
|
|
|
dst_rect, dst_texture->resource.usage, dst_texture->resource.pool, dst_texture->resource.format);
|
2015-04-14 11:16:26 +02:00
|
|
|
if (blitter)
|
2015-04-14 11:16:25 +02:00
|
|
|
{
|
2015-12-10 21:02:34 +01:00
|
|
|
blitter->blit_surface(device, blit_op, filter, src_surface,
|
2016-01-27 20:44:38 +01:00
|
|
|
src_rect, dst_surface, dst_rect, color_key);
|
2015-04-14 11:16:25 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback:
|
|
|
|
/* Special cases for render targets. */
|
2016-01-27 20:44:38 +01:00
|
|
|
if (SUCCEEDED(surface_blt_special(dst_surface, dst_rect, src_surface, src_rect, flags, fx, filter)))
|
2013-09-24 09:48:45 +02:00
|
|
|
return WINED3D_OK;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
|
|
|
cpu:
|
2016-04-10 18:09:27 +02:00
|
|
|
return surface_cpu_blt(dst_texture, dst_sub_resource_idx, &dst_box,
|
|
|
|
src_texture, src_sub_resource_idx, &src_box, flags, fx, filter);
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|