2005-01-09 18:37:02 +01:00
|
|
|
/*
|
|
|
|
* IWineD3DSurface Implementation
|
|
|
|
*
|
2006-05-22 23:49:09 +02:00
|
|
|
* Copyright 1998 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
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2006-2008 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
|
2010-11-12 13:12:02 +01:00
|
|
|
* Copyright 2009-2010 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"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
|
2008-12-03 14:53:43 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
static void surface_cleanup(IWineD3DSurfaceImpl *This)
|
|
|
|
{
|
|
|
|
TRACE("(%p) : Cleaning up.\n", This);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->texture_name || (This->flags & SFLAG_PBO) || !list_empty(&This->renderbuffers))
|
2009-06-15 09:06:49 +02:00
|
|
|
{
|
2010-08-04 11:10:26 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
renderbuffer_entry_t *entry, *entry2;
|
|
|
|
struct wined3d_context *context;
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2010-08-04 11:10:26 +02:00
|
|
|
context = context_acquire(This->resource.device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2010-08-04 11:10:26 +02:00
|
|
|
ENTER_GL();
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2010-08-04 11:10:26 +02:00
|
|
|
if (This->texture_name)
|
|
|
|
{
|
|
|
|
TRACE("Deleting texture %u.\n", This->texture_name);
|
|
|
|
glDeleteTextures(1, &This->texture_name);
|
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2010-08-04 11:10:26 +02:00
|
|
|
{
|
|
|
|
TRACE("Deleting PBO %u.\n", This->pbo);
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry)
|
|
|
|
{
|
|
|
|
TRACE("Deleting renderbuffer %u.\n", entry->id);
|
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2010-08-04 11:10:26 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DIBSECTION)
|
2009-06-15 09:06:49 +02:00
|
|
|
{
|
|
|
|
/* Release the DC. */
|
|
|
|
SelectObject(This->hDC, This->dib.holdbitmap);
|
|
|
|
DeleteDC(This->hDC);
|
|
|
|
/* Release the DIB section. */
|
|
|
|
DeleteObject(This->dib.DIBsection);
|
|
|
|
This->dib.bitmap_data = NULL;
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
|
2009-06-15 09:06:49 +02:00
|
|
|
if (This->overlay_dest) list_remove(&This->overlay_entry);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->palette9);
|
|
|
|
|
|
|
|
resource_cleanup((IWineD3DResource *)This);
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
void surface_set_container(IWineD3DSurfaceImpl *surface, enum wined3d_container_type type, IWineD3DBase *container)
|
2010-08-16 20:00:23 +02:00
|
|
|
{
|
|
|
|
TRACE("surface %p, container %p.\n", surface, container);
|
|
|
|
|
2010-08-25 20:46:49 +02:00
|
|
|
if (!container && type != WINED3D_CONTAINER_NONE)
|
|
|
|
ERR("Setting NULL container of type %#x.\n", type);
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
if (type == WINED3D_CONTAINER_SWAPCHAIN)
|
2010-08-16 20:00:23 +02:00
|
|
|
{
|
|
|
|
surface->get_drawable_size = get_drawable_size_swapchain;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (wined3d_settings.offscreen_rendering_mode)
|
|
|
|
{
|
|
|
|
case ORM_FBO:
|
|
|
|
surface->get_drawable_size = get_drawable_size_fbo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ORM_BACKBUFFER:
|
|
|
|
surface->get_drawable_size = get_drawable_size_backbuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Unhandled offscreen rendering mode %#x.\n", wined3d_settings.offscreen_rendering_mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
surface->container.type = type;
|
|
|
|
surface->container.u.base = container;
|
2010-08-16 20:00:23 +02:00
|
|
|
}
|
|
|
|
|
2010-03-05 19:52:01 +01:00
|
|
|
struct blt_info
|
|
|
|
{
|
|
|
|
GLenum binding;
|
|
|
|
GLenum bind_target;
|
|
|
|
enum tex_types tex_type;
|
|
|
|
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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
info->tex_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-25 23:00:42 +01:00
|
|
|
static inline void surface_get_rect(IWineD3DSurfaceImpl *This, const RECT *rect_in, RECT *rect_out)
|
|
|
|
{
|
|
|
|
if (rect_in)
|
|
|
|
*rect_out = *rect_in;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect_out->left = 0;
|
|
|
|
rect_out->top = 0;
|
|
|
|
rect_out->right = This->currentDesc.Width;
|
|
|
|
rect_out->bottom = This->currentDesc.Height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 13:56:18 +01:00
|
|
|
/* GL locking and context activation is done by the caller */
|
2010-04-08 22:49:51 +02:00
|
|
|
void draw_textured_quad(IWineD3DSurfaceImpl *src_surface, const RECT *src_rect, const RECT *dst_rect, WINED3DTEXTUREFILTERTYPE Filter)
|
2010-03-17 13:56:18 +01:00
|
|
|
{
|
|
|
|
struct blt_info info;
|
|
|
|
|
|
|
|
surface_get_blt_info(src_surface->texture_target, src_rect, src_surface->pow2Width, src_surface->pow2Height, &info);
|
|
|
|
|
|
|
|
glEnable(info.bind_target);
|
|
|
|
checkGLcall("glEnable(bind_target)");
|
|
|
|
|
|
|
|
/* Bind the texture */
|
|
|
|
glBindTexture(info.bind_target, src_surface->texture_name);
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
/* Filtering for StretchRect */
|
|
|
|
glTexParameteri(info.bind_target, GL_TEXTURE_MAG_FILTER,
|
|
|
|
wined3d_gl_mag_filter(magLookup, Filter));
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
glTexParameteri(info.bind_target, GL_TEXTURE_MIN_FILTER,
|
|
|
|
wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE));
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
checkGLcall("glTexEnvi");
|
|
|
|
|
|
|
|
/* Draw a quad */
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
glTexCoord3fv(info.coords[0]);
|
|
|
|
glVertex2i(dst_rect->left, dst_rect->top);
|
|
|
|
|
|
|
|
glTexCoord3fv(info.coords[1]);
|
|
|
|
glVertex2i(dst_rect->right, dst_rect->top);
|
|
|
|
|
|
|
|
glTexCoord3fv(info.coords[2]);
|
|
|
|
glVertex2i(dst_rect->left, dst_rect->bottom);
|
|
|
|
|
|
|
|
glTexCoord3fv(info.coords[3]);
|
|
|
|
glVertex2i(dst_rect->right, dst_rect->bottom);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
/* Unbind the texture */
|
|
|
|
glBindTexture(info.bind_target, 0);
|
|
|
|
checkGLcall("glBindTexture(info->bind_target, 0)");
|
|
|
|
|
|
|
|
/* We changed the filtering settings on the texture. Inform the
|
|
|
|
* container about this to get the filters reset properly next draw. */
|
2010-08-16 20:00:27 +02:00
|
|
|
if (src_surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
2010-03-17 13:56:18 +01:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DBaseTextureImpl *texture = src_surface->container.u.texture;
|
2010-03-17 13:56:18 +01:00
|
|
|
texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
|
|
|
|
texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
|
|
|
|
texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
|
|
|
|
}
|
|
|
|
}
|
2010-03-05 19:52:01 +01:00
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type, UINT alignment,
|
|
|
|
UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
|
2010-08-23 18:28:10 +02:00
|
|
|
UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, enum wined3d_format_id format_id,
|
2010-08-31 18:41:40 +02:00
|
|
|
WINED3DPOOL pool, void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-06-15 09:06:49 +02:00
|
|
|
{
|
2009-07-17 10:34:01 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
|
2009-06-15 09:06:49 +02:00
|
|
|
void (*cleanup)(IWineD3DSurfaceImpl *This);
|
|
|
|
unsigned int resource_size;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (multisample_quality > 0)
|
|
|
|
{
|
|
|
|
FIXME("multisample_quality set to %u, substituting 0\n", multisample_quality);
|
|
|
|
multisample_quality = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Check that the format is supported by the device. */
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
resource_size = wined3d_format_calculate_size(format, alignment, width, height);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
|
|
|
/* Look at the implementation and set the correct Vtable. */
|
|
|
|
switch (surface_type)
|
|
|
|
{
|
|
|
|
case SURFACE_OPENGL:
|
|
|
|
surface->lpVtbl = &IWineD3DSurface_Vtbl;
|
|
|
|
cleanup = surface_cleanup;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_GDI:
|
|
|
|
surface->lpVtbl = &IWineGDISurface_Vtbl;
|
|
|
|
cleanup = surface_gdi_cleanup;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Requested unknown surface implementation %#x.\n", surface_type);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = resource_init((IWineD3DResource *)surface, WINED3DRTYPE_SURFACE,
|
2010-08-30 20:29:49 +02:00
|
|
|
device, resource_size, usage, format, pool, parent, parent_ops);
|
2009-06-15 09:06:49 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize resource, returning %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "Standalone" surface. */
|
2010-08-16 20:00:25 +02:00
|
|
|
surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
|
|
|
surface->currentDesc.Width = width;
|
|
|
|
surface->currentDesc.Height = height;
|
|
|
|
surface->currentDesc.MultiSampleType = multisample_type;
|
|
|
|
surface->currentDesc.MultiSampleQuality = multisample_quality;
|
2009-07-10 10:20:13 +02:00
|
|
|
surface->texture_level = level;
|
2009-06-15 09:06:49 +02:00
|
|
|
list_init(&surface->overlays);
|
|
|
|
|
|
|
|
/* Flags */
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags = SFLAG_NORMCOORD; /* Default to normalized coords. */
|
|
|
|
if (discard) surface->flags |= SFLAG_DISCARD;
|
|
|
|
if (lockable || format_id == WINED3DFMT_D16_LOCKABLE) surface->flags |= SFLAG_LOCKABLE;
|
2009-06-15 09:06:49 +02:00
|
|
|
|
|
|
|
/* Quick lockable sanity check.
|
|
|
|
* TODO: remove this after surfaces, usage and lockability have been debugged properly
|
|
|
|
* this function is too deep to need to care about things like this.
|
|
|
|
* Levels need to be checked too, since they all affect what can be done. */
|
|
|
|
switch (pool)
|
|
|
|
{
|
|
|
|
case WINED3DPOOL_SCRATCH:
|
|
|
|
if(!lockable)
|
|
|
|
{
|
|
|
|
FIXME("Called with a pool of SCRATCH and a lockable of FALSE "
|
|
|
|
"which are mutually exclusive, setting lockable to TRUE.\n");
|
|
|
|
lockable = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DPOOL_SYSTEMMEM:
|
|
|
|
if (!lockable)
|
|
|
|
FIXME("Called with a pool of SYSTEMMEM and a lockable of FALSE, this is acceptable but unexpected.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DPOOL_MANAGED:
|
|
|
|
if (usage & WINED3DUSAGE_DYNAMIC)
|
|
|
|
FIXME("Called with a pool of MANAGED and a usage of DYNAMIC which are mutually exclusive.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DPOOL_DEFAULT:
|
|
|
|
if (lockable && !(usage & (WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
|
|
|
|
WARN("Creating a lockable surface with a POOL of DEFAULT, that doesn't specify DYNAMIC usage.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unknown pool %#x.\n", pool);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (usage & WINED3DUSAGE_RENDERTARGET && pool != WINED3DPOOL_DEFAULT)
|
|
|
|
{
|
|
|
|
FIXME("Trying to create a render target that isn't in the default pool.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the texture as dirty so that it gets loaded first time around. */
|
2010-04-26 21:33:04 +02:00
|
|
|
surface_add_dirty_rect(surface, NULL);
|
2009-06-15 09:06:49 +02:00
|
|
|
list_init(&surface->renderbuffers);
|
|
|
|
|
|
|
|
TRACE("surface %p, memory %p, size %u\n", surface, surface->resource.allocatedMemory, surface->resource.size);
|
|
|
|
|
|
|
|
/* Call the private setup routine */
|
|
|
|
hr = IWineD3DSurface_PrivateSetup((IWineD3DSurface *)surface);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Private setup failed, returning %#x\n", hr);
|
|
|
|
cleanup(surface);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-04-26 11:02:36 +02:00
|
|
|
static void surface_force_reload(IWineD3DSurfaceImpl *surface)
|
2008-09-24 15:56:47 +02:00
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
|
2008-09-24 15:56:47 +02:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:02 +02:00
|
|
|
void surface_set_texture_name(IWineD3DSurfaceImpl *surface, GLuint new_name, BOOL srgb)
|
2008-09-24 15:56:47 +02:00
|
|
|
{
|
2009-01-16 16:22:09 +01:00
|
|
|
GLuint *name;
|
|
|
|
DWORD flag;
|
2008-09-24 15:56:47 +02:00
|
|
|
|
2010-04-26 21:33:02 +02:00
|
|
|
TRACE("surface %p, new_name %u, srgb %#x.\n", surface, new_name, srgb);
|
|
|
|
|
2009-01-16 16:22:09 +01:00
|
|
|
if(srgb)
|
|
|
|
{
|
2010-04-26 21:33:02 +02:00
|
|
|
name = &surface->texture_name_srgb;
|
2009-01-16 16:22:09 +01:00
|
|
|
flag = SFLAG_INSRGBTEX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-26 21:33:02 +02:00
|
|
|
name = &surface->texture_name;
|
2009-01-16 16:22:09 +01:00
|
|
|
flag = SFLAG_INTEXTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*name && new_name)
|
2008-09-24 15:56:47 +02:00
|
|
|
{
|
|
|
|
/* FIXME: We shouldn't need to remove SFLAG_INTEXTURE if the
|
|
|
|
* surface has no texture name yet. See if we can get rid of this. */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (surface->flags & flag)
|
2010-08-15 23:21:45 +02:00
|
|
|
ERR("Surface has %s set, but no texture name.\n", debug_surflocation(flag));
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(surface, flag, FALSE);
|
2008-09-24 15:56:47 +02:00
|
|
|
}
|
|
|
|
|
2009-01-16 16:22:09 +01:00
|
|
|
*name = new_name;
|
2010-04-26 21:33:02 +02:00
|
|
|
surface_force_reload(surface);
|
2008-09-24 15:56:47 +02:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:03 +02:00
|
|
|
void surface_set_texture_target(IWineD3DSurfaceImpl *surface, GLenum target)
|
2008-09-24 15:56:47 +02:00
|
|
|
{
|
2010-04-26 21:33:03 +02:00
|
|
|
TRACE("surface %p, target %#x.\n", surface, target);
|
2008-09-24 15:56:47 +02:00
|
|
|
|
2010-04-26 21:33:03 +02:00
|
|
|
if (surface->texture_target != target)
|
2008-09-24 15:56:47 +02:00
|
|
|
{
|
|
|
|
if (target == GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~SFLAG_NORMCOORD;
|
2008-09-24 15:56:47 +02:00
|
|
|
}
|
2010-04-26 21:33:03 +02:00
|
|
|
else if (surface->texture_target == GL_TEXTURE_RECTANGLE_ARB)
|
2008-09-24 15:56:47 +02:00
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= SFLAG_NORMCOORD;
|
2008-09-24 15:56:47 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-26 21:33:03 +02:00
|
|
|
surface->texture_target = target;
|
|
|
|
surface_force_reload(surface);
|
2008-09-24 15:56:47 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2009-01-16 16:22:09 +01:00
|
|
|
static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This, BOOL srgb) {
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD active_sampler;
|
2008-02-11 01:18:06 +01:00
|
|
|
|
|
|
|
/* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
|
|
|
|
* Read the unit back instead of switching to 0, this avoids messing around with the state manager's
|
|
|
|
* gl states. The current texture unit should always be a valid one.
|
|
|
|
*
|
2008-09-17 14:50:49 +02:00
|
|
|
* To be more specific, this is tricky because we can implicitly be called
|
|
|
|
* from sampler() in state.c. This means we can't touch anything other than
|
|
|
|
* whatever happens to be the currently active texture, or we would risk
|
|
|
|
* marking already applied sampler states dirty again.
|
|
|
|
*
|
2008-02-11 01:18:06 +01:00
|
|
|
* TODO: Track the current active texture per GL context instead of using glGet
|
|
|
|
*/
|
2008-12-16 13:18:49 +01:00
|
|
|
GLint active_texture;
|
|
|
|
ENTER_GL();
|
|
|
|
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
|
|
|
|
LEAVE_GL();
|
2009-12-09 20:32:08 +01:00
|
|
|
active_sampler = This->resource.device->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
|
2008-07-15 23:54:44 +02:00
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (active_sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(active_sampler));
|
2008-01-02 19:52:22 +01:00
|
|
|
}
|
2009-01-16 16:22:09 +01:00
|
|
|
IWineD3DSurface_BindTexture((IWineD3DSurface *)This, srgb);
|
2008-01-02 19:52:22 +01:00
|
|
|
}
|
|
|
|
|
2008-02-21 21:41:20 +01:00
|
|
|
/* This function checks if the primary render target uses the 8bit paletted format. */
|
|
|
|
static BOOL primary_render_target_is_p8(IWineD3DDeviceImpl *device)
|
|
|
|
{
|
2010-04-19 20:46:59 +02:00
|
|
|
if (device->render_targets && device->render_targets[0])
|
|
|
|
{
|
|
|
|
IWineD3DSurfaceImpl *render_target = device->render_targets[0];
|
2009-03-13 10:44:18 +01:00
|
|
|
if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET)
|
2010-08-30 20:29:49 +02:00
|
|
|
&& (render_target->resource.format->id == WINED3DFMT_P8_UINT))
|
2008-02-21 21:41:20 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* This call just downloads data, the caller is responsible for binding the
|
|
|
|
* correct texture. */
|
|
|
|
/* Context activation is done by the caller. */
|
2010-03-17 21:59:50 +01:00
|
|
|
static void surface_download_data(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format = This->resource.format;
|
2009-03-13 10:44:17 +01:00
|
|
|
|
2008-02-05 10:15:46 +01:00
|
|
|
/* Only support read back of converted P8 surfaces */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_CONVERTED && format->id != WINED3DFMT_P8_UINT)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
FIXME("Readback conversion not supported for format %s.\n", debug_d3dformat(format->id));
|
2007-12-16 23:00:39 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-11-02 21:28:11 +01:00
|
|
|
|
|
|
|
ENTER_GL();
|
2008-01-02 19:52:22 +01:00
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (format->flags & WINED3DFMT_FLAG_COMPRESSED)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2009-06-11 10:24:30 +02:00
|
|
|
TRACE("(%p) : Calling glGetCompressedTexImageARB level %d, format %#x, type %#x, data %p.\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
This, This->texture_level, format->glFormat, format->glType,
|
2009-06-11 10:24:30 +02:00
|
|
|
This->resource.allocatedMemory);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2009-06-11 10:24:30 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
2009-07-10 10:20:13 +02:00
|
|
|
GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target, This->texture_level, NULL));
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetCompressedTexImageARB");
|
2009-06-11 10:24:30 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
2009-06-11 10:24:30 +02:00
|
|
|
else
|
|
|
|
{
|
2009-07-10 10:20:13 +02:00
|
|
|
GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target,
|
|
|
|
This->texture_level, This->resource.allocatedMemory));
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetCompressedTexImageARB");
|
2009-06-11 10:24:30 +02:00
|
|
|
}
|
|
|
|
|
2007-11-02 21:28:11 +01:00
|
|
|
LEAVE_GL();
|
2006-09-11 18:51:18 +02:00
|
|
|
} else {
|
2007-02-13 20:21:48 +01:00
|
|
|
void *mem;
|
2010-08-30 20:29:49 +02:00
|
|
|
GLenum gl_format = format->glFormat;
|
|
|
|
GLenum gl_type = format->glType;
|
2007-02-13 20:21:48 +01:00
|
|
|
int src_pitch = 0;
|
|
|
|
int dst_pitch = 0;
|
|
|
|
|
2008-02-05 10:15:46 +01:00
|
|
|
/* In case of P8 the index is stored in the alpha component if the primary render target uses P8 */
|
2010-08-30 20:29:49 +02:00
|
|
|
if (format->id == WINED3DFMT_P8_UINT && primary_render_target_is_p8(This->resource.device))
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
gl_format = GL_ALPHA;
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
2008-02-05 10:15:46 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_NONPOW2)
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
unsigned char alignment = This->resource.device->surface_alignment;
|
2010-08-30 20:29:49 +02:00
|
|
|
src_pitch = format->byte_count * This->pow2Width;
|
2007-02-13 20:21:48 +01:00
|
|
|
dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This);
|
2007-06-08 22:28:04 +02:00
|
|
|
src_pitch = (src_pitch + alignment - 1) & ~(alignment - 1);
|
2007-02-13 20:21:48 +01:00
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, src_pitch * This->pow2Height);
|
|
|
|
} else {
|
|
|
|
mem = This->resource.allocatedMemory;
|
|
|
|
}
|
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
TRACE("(%p) : Calling glGetTexImage level %d, format %#x, type %#x, data %p\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
This, This->texture_level, gl_format, gl_type, mem);
|
2006-09-11 18:51:18 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
glGetTexImage(This->texture_target, This->texture_level, gl_format, gl_type, NULL);
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetTexImage");
|
2007-09-11 10:31:54 +02:00
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
} else {
|
2010-08-30 20:29:49 +02:00
|
|
|
glGetTexImage(This->texture_target, This->texture_level, gl_format, gl_type, mem);
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetTexImage");
|
2007-09-11 10:31:54 +02:00
|
|
|
}
|
2007-11-02 21:28:11 +01:00
|
|
|
LEAVE_GL();
|
2006-09-11 18:51:18 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_NONPOW2)
|
|
|
|
{
|
2008-11-25 14:36:09 +01:00
|
|
|
const BYTE *src_data;
|
|
|
|
BYTE *dst_data;
|
2008-12-01 23:19:43 +01:00
|
|
|
UINT y;
|
2006-09-11 18:51:18 +02:00
|
|
|
/*
|
|
|
|
* 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 allocatedMemory should work with the data as if were a
|
|
|
|
* standard texture with a non-power2 width instead of 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 currentDesc.Width.
|
2007-02-13 20:21:48 +01:00
|
|
|
*
|
|
|
|
* Performance should not be an issue, because applications normally do not lock the surfaces when
|
|
|
|
* rendering. If an app does, the SFLAG_DYNLOCK flag will kick in and the memory copy won't be released,
|
|
|
|
* and doesn't have to be re-read.
|
2006-09-11 18:51:18 +02:00
|
|
|
*/
|
2007-02-13 20:21:48 +01:00
|
|
|
src_data = mem;
|
|
|
|
dst_data = This->resource.allocatedMemory;
|
|
|
|
TRACE("(%p) : Repacking the surface data from pitch %d to pitch %d\n", This, src_pitch, dst_pitch);
|
|
|
|
for (y = 1 ; y < This->currentDesc.Height; y++) {
|
|
|
|
/* skip the first row */
|
|
|
|
src_data += src_pitch;
|
|
|
|
dst_data += dst_pitch;
|
|
|
|
memcpy(dst_data, src_data, dst_pitch);
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
2007-02-13 20:21:48 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
|
|
|
}
|
2007-11-02 21:28:11 +01:00
|
|
|
|
2007-06-07 01:08:26 +02:00
|
|
|
/* Surface has now been downloaded */
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_INSYSMEM;
|
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. */
|
2010-03-17 21:59:50 +01:00
|
|
|
static void surface_upload_data(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format, BOOL srgb, const GLvoid *data)
|
2010-03-17 21:59:50 +01:00
|
|
|
{
|
2010-04-15 19:21:23 +02:00
|
|
|
GLsizei width = This->currentDesc.Width;
|
|
|
|
GLsizei height = This->currentDesc.Height;
|
2010-04-08 22:49:46 +02:00
|
|
|
GLenum internal;
|
|
|
|
|
|
|
|
if (srgb)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
internal = format->glGammaInternal;
|
2010-04-08 22:49:46 +02:00
|
|
|
}
|
2010-04-18 22:50:45 +02:00
|
|
|
else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(This))
|
2010-04-08 22:49:46 +02:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
internal = format->rtInternal;
|
2010-04-08 22:49:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
internal = format->glInternal;
|
2010-04-08 22:49:46 +02:00
|
|
|
}
|
2008-08-26 21:36:30 +02:00
|
|
|
|
2009-08-03 08:06:52 +02:00
|
|
|
TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
This, internal, width, height, format->glFormat, format->glType, data);
|
2009-08-03 08:06:52 +02:00
|
|
|
TRACE("target %#x, level %u, resource size %u.\n",
|
|
|
|
This->texture_target, This->texture_level, This->resource.size);
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (format->heightscale != 1.0f && format->heightscale != 0.0f) height *= format->heightscale;
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2009-08-03 08:06:52 +02:00
|
|
|
ENTER_GL();
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2009-08-03 08:06:52 +02:00
|
|
|
TRACE("(%p) pbo: %#x, data: %p.\n", This, This->pbo, data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (format->flags & WINED3DFMT_FLAG_COMPRESSED)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
|
|
|
TRACE("Calling glCompressedTexSubImage2DARB.\n");
|
2009-06-11 10:24:30 +02:00
|
|
|
|
2009-08-03 08:06:52 +02:00
|
|
|
GL_EXTCALL(glCompressedTexSubImage2DARB(This->texture_target, This->texture_level,
|
|
|
|
0, 0, width, height, internal, This->resource.size, data));
|
|
|
|
checkGLcall("glCompressedTexSubImage2DARB");
|
2009-06-11 10:24:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-03 08:06:52 +02:00
|
|
|
TRACE("Calling glTexSubImage2D.\n");
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2009-08-03 08:06:52 +02:00
|
|
|
glTexSubImage2D(This->texture_target, This->texture_level,
|
2010-08-30 20:29:49 +02:00
|
|
|
0, 0, width, height, format->glFormat, format->glType, data);
|
2009-08-03 08:06:52 +02:00
|
|
|
checkGLcall("glTexSubImage2D");
|
|
|
|
}
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
2009-08-03 08:06:52 +02:00
|
|
|
|
|
|
|
LEAVE_GL();
|
2010-03-17 21:59:51 +01:00
|
|
|
|
|
|
|
if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE)
|
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < device->numContexts; ++i)
|
|
|
|
{
|
|
|
|
context_surface_update(device->contexts[i], This);
|
|
|
|
}
|
|
|
|
}
|
2006-09-11 18:51:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* This call just allocates the texture, the caller is responsible for binding
|
|
|
|
* the correct texture. */
|
|
|
|
/* Context activation is done by the caller. */
|
2010-03-17 21:59:50 +01:00
|
|
|
static void surface_allocate_surface(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format, BOOL srgb)
|
2010-03-17 21:59:50 +01:00
|
|
|
{
|
2007-03-31 23:02:37 +02:00
|
|
|
BOOL enable_client_storage = FALSE;
|
2010-04-15 19:21:22 +02:00
|
|
|
GLsizei width = This->pow2Width;
|
|
|
|
GLsizei height = This->pow2Height;
|
2008-11-25 14:36:09 +01:00
|
|
|
const BYTE *mem = NULL;
|
2010-04-08 22:49:46 +02:00
|
|
|
GLenum internal;
|
|
|
|
|
|
|
|
if (srgb)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
internal = format->glGammaInternal;
|
2010-04-08 22:49:46 +02:00
|
|
|
}
|
2010-04-18 22:50:45 +02:00
|
|
|
else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(This))
|
2010-04-08 22:49:46 +02:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
internal = format->rtInternal;
|
2010-04-08 22:49:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
internal = format->glInternal;
|
2010-04-08 22:49:46 +02:00
|
|
|
}
|
2007-03-31 23:02:37 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (format->heightscale != 1.0f && format->heightscale != 0.0f) height *= format->heightscale;
|
2008-08-26 21:36:30 +02:00
|
|
|
|
2009-03-13 10:44:18 +01:00
|
|
|
TRACE("(%p) : Creating surface (target %#x) level %d, d3d format %s, internal format %#x, width %d, height %d, gl format %#x, gl type=%#x\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
This, This->texture_target, This->texture_level, debug_d3dformat(format->id),
|
|
|
|
internal, width, height, format->glFormat, format->glType);
|
2006-09-11 18:51:18 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_CONVERTED)
|
2010-09-14 13:38:39 +02:00
|
|
|
|| !This->resource.allocatedMemory)
|
|
|
|
{
|
2007-03-31 23:02:37 +02:00
|
|
|
/* In some cases we want to disable client storage.
|
|
|
|
* SFLAG_NONPOW2 has a bigger opengl texture than the client memory, and different pitches
|
|
|
|
* SFLAG_DIBSECTION: Dibsections may have read / write protections on the memory. Avoid issues...
|
|
|
|
* SFLAG_CONVERTED: The conversion destination memory is freed after loading the surface
|
|
|
|
* allocatedMemory == NULL: Not defined in the extension. Seems to disable client storage effectively
|
|
|
|
*/
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_CLIENT;
|
2007-03-31 23:02:37 +02:00
|
|
|
enable_client_storage = TRUE;
|
2010-11-12 13:12:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
This->flags |= SFLAG_CLIENT;
|
2007-11-03 16:24:55 +01:00
|
|
|
|
|
|
|
/* Point opengl to our allocated texture memory. Do not use resource.allocatedMemory here because
|
|
|
|
* it might point into a pbo. Instead use heapMemory, but get the alignment right.
|
|
|
|
*/
|
|
|
|
mem = (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
2007-03-31 23:02:37 +02:00
|
|
|
}
|
|
|
|
}
|
2009-08-03 08:06:52 +02:00
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (format->flags & WINED3DFMT_FLAG_COMPRESSED && mem)
|
2009-08-03 08:06:52 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level,
|
|
|
|
internal, width, height, 0, This->resource.size, mem));
|
2010-06-21 22:14:58 +02:00
|
|
|
checkGLcall("glCompressedTexImage2DARB");
|
2009-08-03 08:06:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glTexImage2D(This->texture_target, This->texture_level,
|
2010-08-30 20:29:49 +02:00
|
|
|
internal, width, height, 0, format->glFormat, format->glType, mem);
|
2009-08-03 08:06:52 +02:00
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
2006-09-11 18:51:18 +02:00
|
|
|
|
2007-03-31 23:02:37 +02:00
|
|
|
if(enable_client_storage) {
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
|
|
|
|
}
|
2006-09-11 18:51:18 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
|
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. */
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-04-18 22:50:46 +02:00
|
|
|
void surface_set_compatible_renderbuffer(IWineD3DSurfaceImpl *surface, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &surface->resource.device->adapter->gl_info;
|
2007-04-09 01:53:32 +02:00
|
|
|
renderbuffer_entry_t *entry;
|
|
|
|
GLuint renderbuffer = 0;
|
|
|
|
unsigned int src_width, src_height;
|
|
|
|
|
2010-04-18 22:50:46 +02:00
|
|
|
src_width = surface->pow2Width;
|
|
|
|
src_height = surface->pow2Height;
|
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 */
|
2010-04-18 22:50:46 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(entry, &surface->renderbuffers, renderbuffer_entry_t, entry)
|
|
|
|
{
|
|
|
|
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,
|
2010-08-30 20:29:49 +02:00
|
|
|
surface->resource.format->glInternal, width, height);
|
2007-04-09 01:53:32 +02:00
|
|
|
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(renderbuffer_entry_t));
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2010-04-20 22:38:42 +02:00
|
|
|
GLenum surface_get_gl_buffer(IWineD3DSurfaceImpl *surface)
|
2009-12-15 17:51:36 +01:00
|
|
|
{
|
2010-08-16 20:00:25 +02:00
|
|
|
IWineD3DSwapChainImpl *swapchain = surface->container.u.swapchain;
|
2007-04-16 21:20:25 +02:00
|
|
|
|
2010-04-20 22:38:42 +02:00
|
|
|
TRACE("surface %p.\n", surface);
|
2007-04-16 21:20:25 +02:00
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
if (surface->container.type != WINED3D_CONTAINER_SWAPCHAIN)
|
2009-12-15 17:51:36 +01:00
|
|
|
{
|
2010-04-20 22:38:42 +02:00
|
|
|
ERR("Surface %p is not on a swapchain.\n", surface);
|
2009-12-15 17:51:36 +01:00
|
|
|
return GL_NONE;
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers && swapchain->back_buffers[0] == surface)
|
2009-12-15 17:51:36 +01:00
|
|
|
{
|
|
|
|
if (swapchain->render_to_fbo)
|
|
|
|
{
|
2009-12-06 17:39:47 +01:00
|
|
|
TRACE("Returning GL_COLOR_ATTACHMENT0\n");
|
|
|
|
return GL_COLOR_ATTACHMENT0;
|
|
|
|
}
|
2007-04-16 21:20:25 +02:00
|
|
|
TRACE("Returning GL_BACK\n");
|
|
|
|
return GL_BACK;
|
2009-12-15 17:51:36 +01:00
|
|
|
}
|
2010-04-26 21:33:00 +02:00
|
|
|
else if (surface == swapchain->front_buffer)
|
2009-12-15 17:51:36 +01:00
|
|
|
{
|
2007-04-16 21:20:25 +02:00
|
|
|
TRACE("Returning GL_FRONT\n");
|
|
|
|
return GL_FRONT;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Higher back buffer, returning GL_BACK\n");
|
|
|
|
return GL_BACK;
|
|
|
|
}
|
2007-04-09 01:53:32 +02:00
|
|
|
|
2009-01-14 10:01:11 +01:00
|
|
|
/* Slightly inefficient way to handle multiple dirty rects but it works :) */
|
2010-04-26 21:33:04 +02:00
|
|
|
void surface_add_dirty_rect(IWineD3DSurfaceImpl *surface, const RECT *dirty_rect)
|
2009-01-14 10:01:11 +01:00
|
|
|
{
|
2010-04-26 21:33:04 +02:00
|
|
|
TRACE("surface %p, dirty_rect %s.\n", surface, wine_dbgstr_rect(dirty_rect));
|
2009-01-14 10:01:11 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(surface->flags & SFLAG_INSYSMEM) && (surface->flags & SFLAG_INTEXTURE))
|
2010-04-26 21:33:04 +02:00
|
|
|
/* No partial locking for textures yet. */
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(surface, SFLAG_INSYSMEM, NULL);
|
2010-04-26 21:33:04 +02:00
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(surface, SFLAG_INSYSMEM, TRUE);
|
2009-01-14 10:01:11 +01:00
|
|
|
if (dirty_rect)
|
|
|
|
{
|
2010-04-26 21:33:04 +02:00
|
|
|
surface->dirtyRect.left = min(surface->dirtyRect.left, dirty_rect->left);
|
|
|
|
surface->dirtyRect.top = min(surface->dirtyRect.top, dirty_rect->top);
|
|
|
|
surface->dirtyRect.right = max(surface->dirtyRect.right, dirty_rect->right);
|
|
|
|
surface->dirtyRect.bottom = max(surface->dirtyRect.bottom, dirty_rect->bottom);
|
2009-01-14 10:01:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-26 21:33:04 +02:00
|
|
|
surface->dirtyRect.left = 0;
|
|
|
|
surface->dirtyRect.top = 0;
|
|
|
|
surface->dirtyRect.right = surface->currentDesc.Width;
|
|
|
|
surface->dirtyRect.bottom = surface->currentDesc.Height;
|
2009-01-14 10:01:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the container is a basetexture then mark it dirty. */
|
2010-08-16 20:00:27 +02:00
|
|
|
if (surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
2009-01-14 10:01:11 +01:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
TRACE("Passing to container.\n");
|
|
|
|
IWineD3DBaseTexture_SetDirty((IWineD3DBaseTexture *)surface->container.u.texture, TRUE);
|
2009-01-14 10:01:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:28:08 +02:00
|
|
|
static BOOL surface_convert_color_to_float(IWineD3DSurfaceImpl *surface, DWORD color, WINED3DCOLORVALUE *float_color)
|
2010-03-25 16:42:51 +01:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format = surface->resource.format;
|
2010-08-23 18:28:08 +02:00
|
|
|
IWineD3DDeviceImpl *device = surface->resource.device;
|
2010-03-25 16:42:51 +01:00
|
|
|
|
2010-08-25 20:46:51 +02:00
|
|
|
switch (format->id)
|
2010-03-25 16:42:51 +01:00
|
|
|
{
|
|
|
|
case WINED3DFMT_P8_UINT:
|
2010-08-23 18:28:08 +02:00
|
|
|
if (surface->palette)
|
2010-03-25 16:42:51 +01:00
|
|
|
{
|
2010-08-23 18:28:08 +02:00
|
|
|
float_color->r = surface->palette->palents[color].peRed / 255.0f;
|
|
|
|
float_color->g = surface->palette->palents[color].peGreen / 255.0f;
|
|
|
|
float_color->b = surface->palette->palents[color].peBlue / 255.0f;
|
2010-03-25 16:42:51 +01:00
|
|
|
}
|
2010-08-23 18:28:08 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
float_color->r = 0.0f;
|
|
|
|
float_color->g = 0.0f;
|
|
|
|
float_color->b = 0.0f;
|
|
|
|
}
|
|
|
|
float_color->a = primary_render_target_is_p8(device) ? color / 255.0f : 1.0f;
|
2010-03-25 16:42:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_B5G6R5_UNORM:
|
2010-08-23 18:28:08 +02:00
|
|
|
float_color->r = ((color >> 11) & 0x1f) / 31.0f;
|
|
|
|
float_color->g = ((color >> 5) & 0x3f) / 63.0f;
|
|
|
|
float_color->b = (color & 0x1f) / 31.0f;
|
|
|
|
float_color->a = 1.0f;
|
2010-03-25 16:42:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_B8G8R8_UNORM:
|
|
|
|
case WINED3DFMT_B8G8R8X8_UNORM:
|
2010-08-23 18:28:08 +02:00
|
|
|
float_color->r = D3DCOLOR_R(color);
|
|
|
|
float_color->g = D3DCOLOR_G(color);
|
|
|
|
float_color->b = D3DCOLOR_B(color);
|
|
|
|
float_color->a = 1.0f;
|
2010-03-25 16:42:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
2010-08-23 18:28:08 +02:00
|
|
|
float_color->r = D3DCOLOR_R(color);
|
|
|
|
float_color->g = D3DCOLOR_G(color);
|
|
|
|
float_color->b = D3DCOLOR_B(color);
|
|
|
|
float_color->a = D3DCOLOR_A(color);
|
2010-03-25 16:42:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-08-25 20:46:51 +02:00
|
|
|
ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format->id));
|
2010-03-25 16:42:51 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-23 18:28:08 +02:00
|
|
|
|
2010-03-25 16:42:51 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2008-11-25 11:57:40 +01:00
|
|
|
static ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface)
|
|
|
|
{
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2005-01-19 17:59:01 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->resource.ref);
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : Releasing from %d\n", This, ref + 1);
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
surface_cleanup(This);
|
2009-09-17 23:03:33 +02:00
|
|
|
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
|
2008-07-30 22:28:25 +02:00
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
TRACE("(%p) Released.\n", This);
|
2005-01-09 18:37:02 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2005-01-09 18:37:02 +01:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************************************
|
|
|
|
IWineD3DSurface IWineD3DResource parts follow
|
|
|
|
**************************************************** */
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-04-26 11:02:34 +02:00
|
|
|
void surface_internal_preload(IWineD3DSurfaceImpl *surface, enum WINED3DSRGB srgb)
|
2008-11-25 11:57:40 +01:00
|
|
|
{
|
2010-04-26 11:02:34 +02:00
|
|
|
IWineD3DDeviceImpl *device = surface->resource.device;
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
TRACE("iface %p, srgb %#x.\n", surface, srgb);
|
|
|
|
|
|
|
|
if (surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
|
|
|
{
|
|
|
|
IWineD3DBaseTextureImpl *texture = surface->container.u.texture;
|
|
|
|
|
|
|
|
TRACE("Passing to container.\n");
|
|
|
|
texture->baseTexture.internal_preload((IWineD3DBaseTexture *)texture, srgb);
|
|
|
|
}
|
|
|
|
else
|
2010-04-26 11:02:34 +02:00
|
|
|
{
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
|
2010-04-26 11:02:34 +02:00
|
|
|
TRACE("(%p) : About to load surface\n", surface);
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
if (!device->isInDraw) context = context_acquire(device, NULL);
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (surface->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| surface->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2010-04-26 11:02:34 +02:00
|
|
|
if (palette9_changed(surface))
|
|
|
|
{
|
2008-04-02 23:12:16 +02:00
|
|
|
TRACE("Reloading surface because the d3d8/9 palette was changed\n");
|
|
|
|
/* TODO: This is not necessarily needed with hw palettized texture support */
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(surface, SFLAG_INSYSMEM, NULL);
|
2008-04-02 23:12:16 +02:00
|
|
|
/* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(surface, SFLAG_INTEXTURE, FALSE);
|
2008-04-02 23:12:16 +02:00
|
|
|
}
|
|
|
|
}
|
2008-08-19 17:49:07 +02:00
|
|
|
|
2010-04-26 11:02:34 +02:00
|
|
|
IWineD3DSurface_LoadTexture((IWineD3DSurface *)surface, srgb == SRGB_SRGB ? TRUE : FALSE);
|
2008-08-19 17:49:07 +02:00
|
|
|
|
2010-04-26 11:02:34 +02:00
|
|
|
if (surface->resource.pool == WINED3DPOOL_DEFAULT)
|
|
|
|
{
|
2008-02-18 21:34:29 +01:00
|
|
|
/* Tell opengl to try and keep this texture in video ram (well mostly) */
|
|
|
|
GLclampf tmp;
|
|
|
|
tmp = 0.9f;
|
2008-04-02 23:12:00 +02:00
|
|
|
ENTER_GL();
|
2010-04-26 11:02:34 +02:00
|
|
|
glPrioritizeTextures(1, &surface->texture_name, &tmp);
|
2008-04-02 23:12:00 +02:00
|
|
|
LEAVE_GL();
|
2008-02-18 21:34:29 +01:00
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
if (context) context_release(context);
|
2005-03-14 11:12:52 +01:00
|
|
|
}
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2010-04-26 11:02:34 +02:00
|
|
|
static void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface)
|
|
|
|
{
|
|
|
|
surface_internal_preload((IWineD3DSurfaceImpl *)iface, SRGB_ANY);
|
2009-02-17 00:25:51 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-03-17 21:59:50 +01:00
|
|
|
static void surface_remove_pbo(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
2008-01-12 22:33:04 +01:00
|
|
|
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
|
|
|
|
This->resource.allocatedMemory =
|
|
|
|
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, This->pbo)");
|
2008-01-12 22:33:04 +01:00
|
|
|
GL_EXTCALL(glGetBufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0, This->resource.size, This->resource.allocatedMemory));
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetBufferSubDataARB");
|
2008-01-12 22:33:04 +01:00
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glDeleteBuffersARB");
|
2008-01-12 22:33:04 +01:00
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
This->pbo = 0;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_PBO;
|
2008-01-12 22:33:04 +01:00
|
|
|
}
|
|
|
|
|
2010-04-28 00:08:48 +02:00
|
|
|
BOOL surface_init_sysmem(IWineD3DSurfaceImpl *surface)
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
2010-04-28 00:08:48 +02:00
|
|
|
if (!surface->resource.allocatedMemory)
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
2010-04-28 00:08:48 +02:00
|
|
|
surface->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
surface->resource.size + RESOURCE_ALIGNMENT);
|
|
|
|
if (!surface->resource.heapMemory)
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-28 00:08:48 +02:00
|
|
|
surface->resource.allocatedMemory =
|
|
|
|
(BYTE *)(((ULONG_PTR)surface->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
2009-12-04 13:07:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-28 00:08:48 +02:00
|
|
|
memset(surface->resource.allocatedMemory, 0, surface->resource.size);
|
2009-12-04 13:07:18 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(surface, SFLAG_INSYSMEM, TRUE);
|
|
|
|
|
2009-12-04 13:07:18 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-08-16 20:00:27 +02:00
|
|
|
static void WINAPI IWineD3DSurfaceImpl_UnLoad(IWineD3DSurface *iface)
|
|
|
|
{
|
2008-01-12 22:33:04 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2009-09-23 10:05:55 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2008-01-25 18:10:14 +01:00
|
|
|
renderbuffer_entry_t *entry, *entry2;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2008-01-12 22:33:04 +01:00
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
if(This->resource.pool == WINED3DPOOL_DEFAULT) {
|
2008-01-25 18:10:14 +01:00
|
|
|
/* Default pool resources are supposed to be destroyed before Reset is called.
|
|
|
|
* Implicit resources stay however. So this means we have an implicit render target
|
|
|
|
* or depth stencil. The content may be destroyed, but we still have to tear down
|
|
|
|
* opengl resources, so we cannot leave early.
|
2008-04-07 23:21:33 +02:00
|
|
|
*
|
2009-12-04 13:07:18 +01:00
|
|
|
* Put the surfaces into sysmem, and reset the content. The D3D content is undefined,
|
|
|
|
* but we can't set the sysmem INDRAWABLE because when we're rendering the swapchain
|
|
|
|
* or the depth stencil into an FBO the texture or render buffer will be removed
|
|
|
|
* and all flags get lost
|
2008-01-25 18:10:14 +01:00
|
|
|
*/
|
2010-04-28 00:08:48 +02:00
|
|
|
surface_init_sysmem(This);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-25 18:10:14 +01:00
|
|
|
/* Load the surface into system memory */
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(This, SFLAG_INSYSMEM, NULL);
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INDRAWABLE, FALSE);
|
2008-01-12 22:33:04 +01:00
|
|
|
}
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INTEXTURE, FALSE);
|
|
|
|
surface_modify_location(This, SFLAG_INSRGBTEX, FALSE);
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
|
2008-01-12 22:33:04 +01:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info = context->gl_info;
|
2009-06-26 10:07:09 +02:00
|
|
|
|
2008-01-12 22:33:04 +01:00
|
|
|
/* Destroy PBOs, but load them into real sysmem before */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2010-03-17 21:59:50 +01:00
|
|
|
surface_remove_pbo(This, gl_info);
|
2008-01-12 22:33:04 +01:00
|
|
|
|
2008-01-25 18:10:14 +01:00
|
|
|
/* Destroy fbo render buffers. This is needed for implicit render targets, for
|
|
|
|
* all application-created targets the application has to release the surface
|
|
|
|
* before calling _Reset
|
|
|
|
*/
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry) {
|
|
|
|
ENTER_GL();
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
|
2008-01-25 18:10:14 +01:00
|
|
|
LEAVE_GL();
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
}
|
|
|
|
list_init(&This->renderbuffers);
|
|
|
|
This->current_renderbuffer = NULL;
|
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
/* If we're in a texture, the texture name belongs to the texture.
|
|
|
|
* Otherwise, destroy it. */
|
|
|
|
if (This->container.type != WINED3D_CONTAINER_TEXTURE)
|
|
|
|
{
|
2008-01-12 22:33:04 +01:00
|
|
|
ENTER_GL();
|
2009-07-10 10:20:13 +02:00
|
|
|
glDeleteTextures(1, &This->texture_name);
|
|
|
|
This->texture_name = 0;
|
|
|
|
glDeleteTextures(1, &This->texture_name_srgb);
|
|
|
|
This->texture_name_srgb = 0;
|
2008-01-12 22:33:04 +01:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
2010-08-15 23:21:42 +02:00
|
|
|
|
|
|
|
resource_unload((IWineD3DResourceImpl *)This);
|
2008-01-12 22:56:30 +01:00
|
|
|
}
|
|
|
|
|
2005-01-09 18:37:02 +01:00
|
|
|
/* ******************************************************
|
|
|
|
IWineD3DSurface IWineD3DSurface parts follow
|
|
|
|
****************************************************** */
|
|
|
|
|
2008-02-10 22:20:15 +01:00
|
|
|
/* Read the framebuffer back into the surface */
|
2009-12-09 20:32:08 +01:00
|
|
|
static void read_from_framebuffer(IWineD3DSurfaceImpl *This, const RECT *rect, void *dest, UINT pitch)
|
|
|
|
{
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2010-03-17 21:59:50 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2007-02-13 20:24:00 +01:00
|
|
|
BYTE *mem;
|
2006-07-17 12:39:44 +02:00
|
|
|
GLint fmt;
|
|
|
|
GLint type;
|
2007-02-13 20:24:00 +01:00
|
|
|
BYTE *row, *top, *bottom;
|
|
|
|
int i;
|
|
|
|
BOOL bpp;
|
2007-11-02 22:23:22 +01:00
|
|
|
RECT local_rect;
|
|
|
|
BOOL srcIsUpsideDown;
|
2008-12-22 15:08:10 +01:00
|
|
|
GLint rowLen = 0;
|
|
|
|
GLint skipPix = 0;
|
|
|
|
GLint skipRow = 0;
|
2007-11-02 22:23:22 +01:00
|
|
|
|
|
|
|
if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) {
|
|
|
|
static BOOL warned = FALSE;
|
|
|
|
if(!warned) {
|
|
|
|
ERR("The application tries to lock the render target, but render target locking is disabled\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, This);
|
|
|
|
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
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2010-04-18 22:50:45 +02:00
|
|
|
if (surface_is_offscreen(This))
|
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");
|
2010-04-18 22:50:42 +02:00
|
|
|
glReadBuffer(device->offscreenBuffer);
|
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 */
|
2010-04-20 22:38:42 +02:00
|
|
|
GLenum buffer = surface_get_gl_buffer(This);
|
2010-10-14 13:04:02 +02:00
|
|
|
TRACE("Mapping %#x buffer.\n", buffer);
|
2009-12-06 15:45:46 +01:00
|
|
|
glReadBuffer(buffer);
|
|
|
|
checkGLcall("glReadBuffer");
|
|
|
|
srcIsUpsideDown = FALSE;
|
|
|
|
}
|
2007-11-02 22:23:22 +01:00
|
|
|
|
|
|
|
/* TODO: Get rid of the extra rectangle comparison and construction of a full surface rectangle */
|
|
|
|
if(!rect) {
|
|
|
|
local_rect.left = 0;
|
|
|
|
local_rect.top = 0;
|
|
|
|
local_rect.right = This->currentDesc.Width;
|
|
|
|
local_rect.bottom = This->currentDesc.Height;
|
|
|
|
} else {
|
|
|
|
local_rect = *rect;
|
|
|
|
}
|
|
|
|
/* TODO: Get rid of the extra GetPitch call, LockRect does that too. Cache the pitch */
|
2006-07-17 12:39:44 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
switch (This->resource.format->id)
|
2006-07-17 12:39:44 +02:00
|
|
|
{
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_P8_UINT:
|
2006-07-17 12:39:44 +02:00
|
|
|
{
|
2010-04-18 22:50:42 +02:00
|
|
|
if (primary_render_target_is_p8(device))
|
|
|
|
{
|
2007-10-11 22:04:48 +02:00
|
|
|
/* In case of P8 render targets the index is stored in the alpha component */
|
|
|
|
fmt = GL_ALPHA;
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
mem = dest;
|
2010-08-30 20:29:49 +02:00
|
|
|
bpp = This->resource.format->byte_count;
|
2007-10-11 22:04:48 +02:00
|
|
|
} else {
|
|
|
|
/* GL can't return palettized data, so read ARGB pixels into a
|
|
|
|
* separate block of memory and convert them into palettized format
|
|
|
|
* in software. Slow, but if the app means to use palettized render
|
|
|
|
* targets and locks it...
|
|
|
|
*
|
|
|
|
* Use GL_RGB, GL_UNSIGNED_BYTE to read the surface for performance reasons
|
|
|
|
* Don't use GL_BGR as in the WINED3DFMT_R8G8B8 case, instead watch out
|
|
|
|
* for the color channels when palettizing the colors.
|
|
|
|
*/
|
|
|
|
fmt = GL_RGB;
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
pitch *= 3;
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, This->resource.size * 3);
|
|
|
|
if(!mem) {
|
|
|
|
ERR("Out of memory\n");
|
2007-11-02 22:23:22 +01:00
|
|
|
LEAVE_GL();
|
2007-10-11 22:04:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-08-30 20:29:49 +02:00
|
|
|
bpp = This->resource.format->byte_count * 3;
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mem = dest;
|
2010-08-30 20:29:49 +02:00
|
|
|
fmt = This->resource.format->glFormat;
|
|
|
|
type = This->resource.format->glType;
|
|
|
|
bpp = This->resource.format->byte_count;
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
2010-09-14 13:38:39 +02:00
|
|
|
if (mem)
|
|
|
|
{
|
2008-12-22 15:08:10 +01:00
|
|
|
ERR("mem not null for pbo -- unexpected\n");
|
|
|
|
mem = NULL;
|
|
|
|
}
|
2007-09-11 10:31:54 +02:00
|
|
|
}
|
|
|
|
|
2008-12-22 15:08:10 +01:00
|
|
|
/* Save old pixel store pack state */
|
|
|
|
glGetIntegerv(GL_PACK_ROW_LENGTH, &rowLen);
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetIntegerv");
|
2008-12-22 15:08:10 +01:00
|
|
|
glGetIntegerv(GL_PACK_SKIP_PIXELS, &skipPix);
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetIntegerv");
|
2008-12-22 15:08:10 +01:00
|
|
|
glGetIntegerv(GL_PACK_SKIP_ROWS, &skipRow);
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glGetIntegerv");
|
2008-12-22 15:08:10 +01:00
|
|
|
|
|
|
|
/* Setup pixel store pack state -- to glReadPixels into the correct place */
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, This->currentDesc.Width);
|
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
glPixelStorei(GL_PACK_SKIP_PIXELS, local_rect.left);
|
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
glPixelStorei(GL_PACK_SKIP_ROWS, local_rect.top);
|
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
|
|
|
|
glReadPixels(local_rect.left, (!srcIsUpsideDown) ? (This->currentDesc.Height - local_rect.bottom) : local_rect.top ,
|
2007-11-02 22:23:22 +01:00
|
|
|
local_rect.right - local_rect.left,
|
|
|
|
local_rect.bottom - local_rect.top,
|
2007-02-13 20:24:00 +01:00
|
|
|
fmt, type, mem);
|
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 */
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, rowLen);
|
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
glPixelStorei(GL_PACK_SKIP_PIXELS, skipPix);
|
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
glPixelStorei(GL_PACK_SKIP_ROWS, skipRow);
|
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
/* Check if we need to flip the image. If we need to flip use glMapBufferARB
|
|
|
|
* to get a pointer to it and perform the flipping in software. This is a lot
|
|
|
|
* faster than calling glReadPixels for each line. In case we want more speed
|
|
|
|
* we should rerender it flipped in a FBO and read the data back from the FBO. */
|
2007-11-02 22:23:22 +01:00
|
|
|
if(!srcIsUpsideDown) {
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2007-09-11 10:31:54 +02:00
|
|
|
mem = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_WRITE_ARB));
|
|
|
|
checkGLcall("glMapBufferARB");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Merge this with the palettization loop below for P8 targets */
|
2007-11-02 22:23:22 +01:00
|
|
|
if(!srcIsUpsideDown) {
|
2007-02-13 20:24:00 +01:00
|
|
|
UINT len, off;
|
|
|
|
/* glReadPixels returns the image upside down, and there is no way to prevent this.
|
|
|
|
Flip the lines in software */
|
2007-11-02 22:23:22 +01:00
|
|
|
len = (local_rect.right - local_rect.left) * bpp;
|
|
|
|
off = local_rect.left * bpp;
|
2007-02-13 20:24:00 +01:00
|
|
|
|
|
|
|
row = HeapAlloc(GetProcessHeap(), 0, len);
|
2006-07-17 12:39:44 +02:00
|
|
|
if(!row) {
|
|
|
|
ERR("Out of memory\n");
|
2010-08-30 20:29:49 +02:00
|
|
|
if (This->resource.format->id == WINED3DFMT_P8_UINT) HeapFree(GetProcessHeap(), 0, mem);
|
2007-11-02 22:23:22 +01:00
|
|
|
LEAVE_GL();
|
2006-07-17 12:39:44 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2007-11-02 22:23:22 +01:00
|
|
|
top = mem + pitch * local_rect.top;
|
2008-12-22 15:08:10 +01:00
|
|
|
bottom = mem + pitch * (local_rect.bottom - 1);
|
2007-11-02 22:23:22 +01:00
|
|
|
for(i = 0; i < (local_rect.bottom - local_rect.top) / 2; i++) {
|
2007-02-13 20:24:00 +01:00
|
|
|
memcpy(row, top + off, len);
|
|
|
|
memcpy(top + off, bottom + off, len);
|
|
|
|
memcpy(bottom + off, row, len);
|
2006-07-17 12:39:44 +02:00
|
|
|
top += pitch;
|
|
|
|
bottom -= pitch;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, row);
|
2007-09-11 10:31:54 +02:00
|
|
|
|
|
|
|
/* Unmap the temp PBO buffer */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
}
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 01:03:38 +01:00
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2008-03-25 01:03:38 +01:00
|
|
|
|
2007-10-11 22:04:48 +02:00
|
|
|
/* For P8 textures we need to perform an inverse palette lookup. This is done by searching for a palette
|
|
|
|
* index which matches the RGB value. Note this isn't guaranteed to work when there are multiple entries for
|
|
|
|
* the same color but we have no choice.
|
2008-03-09 15:09:52 +01:00
|
|
|
* In case of P8 render targets, the index is stored in the alpha component so no conversion is needed.
|
2007-10-11 22:04:48 +02:00
|
|
|
*/
|
2010-08-30 20:29:49 +02:00
|
|
|
if (This->resource.format->id == WINED3DFMT_P8_UINT && !primary_render_target_is_p8(device))
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2008-11-25 14:36:09 +01:00
|
|
|
const PALETTEENTRY *pal = NULL;
|
2006-07-17 12:39:44 +02:00
|
|
|
DWORD width = pitch / 3;
|
|
|
|
int x, y, c;
|
2008-03-25 01:03:38 +01:00
|
|
|
|
2006-07-17 12:39:44 +02:00
|
|
|
if(This->palette) {
|
|
|
|
pal = This->palette->palents;
|
|
|
|
} else {
|
2008-03-25 01:03:38 +01:00
|
|
|
ERR("Palette is missing, cannot perform inverse palette lookup\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
return ;
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2007-11-02 22:23:22 +01:00
|
|
|
for(y = local_rect.top; y < local_rect.bottom; y++) {
|
|
|
|
for(x = local_rect.left; x < local_rect.right; x++) {
|
2006-07-17 12:39:44 +02:00
|
|
|
/* start lines pixels */
|
2008-11-25 14:36:09 +01:00
|
|
|
const BYTE *blue = mem + y * pitch + x * (sizeof(BYTE) * 3);
|
|
|
|
const BYTE *green = blue + 1;
|
|
|
|
const BYTE *red = green + 1;
|
2006-07-17 12:39:44 +02:00
|
|
|
|
|
|
|
for(c = 0; c < 256; c++) {
|
|
|
|
if(*red == pal[c].peRed &&
|
|
|
|
*green == pal[c].peGreen &&
|
|
|
|
*blue == pal[c].peBlue)
|
|
|
|
{
|
|
|
|
*((BYTE *) dest + y * width + x) = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-10 22:20:15 +01:00
|
|
|
/* Read the framebuffer contents into a texture */
|
2009-01-16 16:22:09 +01:00
|
|
|
static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This, BOOL srgb)
|
2008-02-10 22:20:15 +01:00
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2010-03-17 21:59:50 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2010-06-22 12:49:07 +02:00
|
|
|
if (!surface_is_offscreen(This))
|
|
|
|
{
|
|
|
|
/* We would need to flip onscreen surfaces, but there's no efficient
|
|
|
|
* way to do that here. It makes more sense for the caller to
|
|
|
|
* explicitly go through sysmem. */
|
|
|
|
ERR("Not supported for onscreen targets.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-17 01:41:02 +02:00
|
|
|
/* Activate the surface to read from. In some situations it isn't the currently active target(e.g. backbuffer
|
|
|
|
* locking during offscreen rendering). RESOURCELOAD is ok because glCopyTexSubImage2D isn't affected by any
|
|
|
|
* states in the stateblock, and no driver was found yet that had bugs in that regard.
|
2008-02-10 22:20:15 +01:00
|
|
|
*/
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, This);
|
2010-03-17 21:59:50 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2010-05-10 15:36:31 +02:00
|
|
|
surface_prepare_texture(This, gl_info, srgb);
|
2009-01-16 16:22:09 +01:00
|
|
|
surface_bind_and_dirtify(This, srgb);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2010-06-22 12:49:07 +02:00
|
|
|
TRACE("Reading back offscreen render target %p.\n", This);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2008-10-19 01:21:46 +02:00
|
|
|
ENTER_GL();
|
2010-06-22 12:49:07 +02:00
|
|
|
|
|
|
|
glReadBuffer(device->offscreenBuffer);
|
|
|
|
checkGLcall("glReadBuffer");
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
glCopyTexSubImage2D(This->texture_target, This->texture_level,
|
|
|
|
0, 0, 0, 0, This->currentDesc.Width, This->currentDesc.Height);
|
2008-02-10 22:20:15 +01:00
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
2008-02-10 22:20:15 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 18:17:57 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2010-04-22 18:55:58 +02:00
|
|
|
static void surface_prepare_texture_internal(IWineD3DSurfaceImpl *surface,
|
|
|
|
const struct wined3d_gl_info *gl_info, BOOL srgb)
|
2010-02-03 18:17:57 +01:00
|
|
|
{
|
|
|
|
DWORD alloc_flag = srgb ? SFLAG_SRGBALLOCATED : SFLAG_ALLOCATED;
|
|
|
|
CONVERT_TYPES convert;
|
2010-08-30 20:29:49 +02:00
|
|
|
struct wined3d_format format;
|
2010-02-03 18:17:57 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (surface->flags & alloc_flag) return;
|
2010-02-03 18:17:57 +01:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
d3dfmt_get_conv(surface, TRUE, TRUE, &format, &convert);
|
2010-11-12 13:12:04 +01:00
|
|
|
if (convert != NO_CONVERSION || format.convert) surface->flags |= SFLAG_CONVERTED;
|
|
|
|
else surface->flags &= ~SFLAG_CONVERTED;
|
2010-02-15 12:30:37 +01:00
|
|
|
|
2010-02-03 18:17:57 +01:00
|
|
|
surface_bind_and_dirtify(surface, srgb);
|
2010-08-30 20:29:49 +02:00
|
|
|
surface_allocate_surface(surface, gl_info, &format, srgb);
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= alloc_flag;
|
2010-02-03 18:17:57 +01:00
|
|
|
}
|
|
|
|
|
2010-04-22 18:55:58 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
void surface_prepare_texture(IWineD3DSurfaceImpl *surface, const struct wined3d_gl_info *gl_info, BOOL srgb)
|
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
if (surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
2010-04-22 18:55:58 +02:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DBaseTextureImpl *texture = surface->container.u.texture;
|
2010-04-22 18:55:58 +02:00
|
|
|
UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("surface %p is a subresource of texture %p.\n", surface, texture);
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
IWineD3DSurfaceImpl *s = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[i];
|
|
|
|
surface_prepare_texture_internal(s, gl_info, srgb);
|
|
|
|
}
|
|
|
|
|
2010-07-26 12:06:34 +02:00
|
|
|
return;
|
2010-04-22 18:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
surface_prepare_texture_internal(surface, gl_info, srgb);
|
|
|
|
}
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This)
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
|
2007-11-01 01:31:01 +01:00
|
|
|
/* Performance optimization: Count how often a surface is locked, if it is locked regularly do not throw away the system memory copy.
|
|
|
|
* This avoids the need to download the surface from opengl all the time. The surface is still downloaded if the opengl texture is
|
|
|
|
* changed
|
2007-09-14 17:46:19 +02:00
|
|
|
*/
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_DYNLOCK))
|
|
|
|
{
|
2007-11-01 01:31:01 +01:00
|
|
|
This->lockCount++;
|
|
|
|
/* MAXLOCKCOUNT is defined in wined3d_private.h */
|
|
|
|
if(This->lockCount > MAXLOCKCOUNT) {
|
|
|
|
TRACE("Surface is locked regularly, not freeing the system memory copy any more\n");
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_DYNLOCK;
|
2007-10-09 22:17:59 +02:00
|
|
|
}
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2007-09-27 18:57:51 +02:00
|
|
|
/* Create a PBO for dynamically locked surfaces but don't do it for converted or non-pow2 surfaces.
|
2007-11-01 01:31:01 +01:00
|
|
|
* Also don't create a PBO for systemmem surfaces.
|
|
|
|
*/
|
2010-11-12 13:12:04 +01:00
|
|
|
if (gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] && (This->flags & SFLAG_DYNLOCK)
|
|
|
|
&& !(This->flags & (SFLAG_PBO | SFLAG_CONVERTED | SFLAG_NONPOW2))
|
2009-10-28 11:00:11 +01:00
|
|
|
&& (This->resource.pool != WINED3DPOOL_SYSTEMMEM))
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GLenum error;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2008-08-15 23:45:51 +02:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2007-09-11 10:31:54 +02:00
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
GL_EXTCALL(glGenBuffersARB(1, &This->pbo));
|
|
|
|
error = glGetError();
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!This->pbo || error != GL_NO_ERROR)
|
2007-09-11 10:31:54 +02:00
|
|
|
ERR("Failed to bind the PBO with error %s (%#x)\n", debug_glerror(error), error);
|
|
|
|
|
|
|
|
TRACE("Attaching pbo=%#x to (%p)\n", This->pbo, This);
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->resource.size + 4, This->resource.allocatedMemory, GL_STREAM_DRAW_ARB));
|
|
|
|
checkGLcall("glBufferDataARB");
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
/* We don't need the system memory anymore and we can't even use it for PBOs */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_CLIENT))
|
|
|
|
{
|
2007-11-03 16:24:55 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
|
|
|
This->resource.heapMemory = NULL;
|
|
|
|
}
|
2007-09-11 10:31:54 +02:00
|
|
|
This->resource.allocatedMemory = NULL;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_PBO;
|
2007-09-11 10:31:54 +02:00
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
else if (!(This->resource.allocatedMemory || This->flags & SFLAG_PBO))
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
2007-11-01 01:31:01 +01:00
|
|
|
/* Whatever surface we have, make sure that there is memory allocated for the downloaded copy,
|
|
|
|
* or a pbo to map
|
|
|
|
*/
|
2007-11-03 16:24:55 +01:00
|
|
|
if(!This->resource.heapMemory) {
|
|
|
|
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
|
|
|
|
}
|
2007-10-22 13:30:14 +02:00
|
|
|
This->resource.allocatedMemory =
|
|
|
|
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_INSYSMEM)
|
|
|
|
{
|
2007-11-01 01:31:01 +01:00
|
|
|
ERR("Surface without memory or pbo has SFLAG_INSYSMEM set!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_Map(IWineD3DSurface *iface,
|
|
|
|
WINED3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
|
|
|
|
{
|
2007-11-01 01:31:01 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2009-06-18 09:04:05 +02:00
|
|
|
const RECT *pass_rect = pRect;
|
2007-11-01 01:31:01 +01:00
|
|
|
|
2010-05-19 11:13:36 +02:00
|
|
|
TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n",
|
|
|
|
iface, pLockedRect, wine_dbgstr_rect(pRect), Flags);
|
2007-11-01 01:31:01 +01:00
|
|
|
|
2007-10-09 22:19:39 +02:00
|
|
|
/* This is also done in the base class, but we have to verify this before loading any data from
|
|
|
|
* gl into the sysmem copy. The PBO may be mapped, a different rectangle locked, the discard flag
|
|
|
|
* may interfere, and all other bad things may happen
|
|
|
|
*/
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_LOCKED)
|
|
|
|
{
|
2007-11-01 01:31:01 +01:00
|
|
|
WARN("Surface is already locked, returning D3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_LOCKED;
|
2007-11-08 22:44:34 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_LOCKABLE))
|
2007-11-08 22:44:34 +01:00
|
|
|
{
|
|
|
|
TRACE("Warning: trying to lock unlockable surf@%p\n", This);
|
|
|
|
}
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-11-11 12:39:19 +01:00
|
|
|
if (Flags & WINED3DLOCK_DISCARD)
|
|
|
|
{
|
|
|
|
TRACE("WINED3DLOCK_DISCARD flag passed, marking SYSMEM as up to date.\n");
|
|
|
|
surface_prepare_system_memory(This);
|
|
|
|
surface_modify_location(This, SFLAG_INSYSMEM, TRUE);
|
2008-03-09 15:08:57 +01:00
|
|
|
goto lock_end;
|
2007-08-01 22:48:42 +02:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
/* surface_load_location() does not check if the rectangle specifies
|
2009-06-18 09:04:05 +02:00
|
|
|
* the full surface. Most callers don't need that, so do it here. */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (pRect && !pRect->top && !pRect->left
|
2009-06-18 09:04:05 +02:00
|
|
|
&& pRect->right == This->currentDesc.Width
|
|
|
|
&& pRect->bottom == This->currentDesc.Height)
|
2009-03-25 10:12:27 +01:00
|
|
|
{
|
2009-06-18 09:04:05 +02:00
|
|
|
pass_rect = NULL;
|
|
|
|
}
|
2006-06-15 12:54:19 +02:00
|
|
|
|
2009-06-18 09:04:05 +02:00
|
|
|
if (!(wined3d_settings.rendertargetlock_mode == RTL_DISABLE
|
2010-08-16 20:00:26 +02:00
|
|
|
&& ((This->container.type == WINED3D_CONTAINER_SWAPCHAIN) || This == device->render_targets[0])))
|
2009-06-18 09:04:05 +02:00
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(This, SFLAG_INSYSMEM, pass_rect);
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2007-02-13 20:21:44 +01:00
|
|
|
lock_end:
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
2010-03-17 21:59:50 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-03-17 21:59:50 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2007-09-11 10:31:54 +02:00
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
/* This shouldn't happen but could occur if some other function didn't handle the PBO properly */
|
|
|
|
if(This->resource.allocatedMemory) {
|
|
|
|
ERR("The surface already has PBO memory allocated!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
This->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_WRITE_ARB));
|
|
|
|
checkGLcall("glMapBufferARB");
|
|
|
|
|
|
|
|
/* Make sure the pbo isn't set anymore in order not to break non-pbo calls */
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2007-09-11 10:31:54 +02:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:28 +01:00
|
|
|
if (Flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY)) {
|
2005-01-09 18:37:02 +01:00
|
|
|
/* Don't dirtify */
|
2010-08-16 20:00:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-26 21:33:04 +02:00
|
|
|
surface_add_dirty_rect(This, pRect);
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
if (This->container.type == WINED3D_CONTAINER_TEXTURE)
|
|
|
|
{
|
|
|
|
TRACE("Making container dirty.\n");
|
|
|
|
IWineD3DBaseTexture_SetDirty((IWineD3DBaseTexture *)This->container.u.texture, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-14 11:12:52 +01:00
|
|
|
TRACE("Surface is standalone, no need to dirty the container\n");
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
return IWineD3DBaseSurfaceImpl_Map(iface, pLockedRect, pRect, Flags);
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2010-10-29 12:25:19 +02:00
|
|
|
static void flush_to_framebuffer_drawpixels(IWineD3DSurfaceImpl *This,
|
|
|
|
GLenum fmt, GLenum type, UINT bpp, const BYTE *mem)
|
|
|
|
{
|
2007-02-13 20:24:00 +01:00
|
|
|
UINT pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This); /* target is argb, 4 byte */
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2010-03-17 21:59:50 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2010-11-02 12:02:48 +01:00
|
|
|
RECT rect;
|
|
|
|
UINT w, h;
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_LOCKED)
|
2010-11-02 12:02:48 +01:00
|
|
|
rect = This->lockedRect;
|
|
|
|
else
|
|
|
|
SetRect(&rect, 0, 0, This->currentDesc.Width, This->currentDesc.Height);
|
|
|
|
|
|
|
|
mem += rect.top * pitch + rect.left * bpp;
|
|
|
|
w = rect.right - rect.left;
|
|
|
|
h = rect.bottom - rect.top;
|
2007-11-02 21:08:20 +01:00
|
|
|
|
|
|
|
/* Activate the correct context for the render target */
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, This);
|
|
|
|
context_apply_blit_state(context, device);
|
2010-03-17 21:59:50 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2007-11-02 21:08:20 +01:00
|
|
|
ENTER_GL();
|
|
|
|
|
2010-04-18 22:50:45 +02:00
|
|
|
if (!surface_is_offscreen(This))
|
2009-12-15 17:51:35 +01:00
|
|
|
{
|
2010-04-20 22:38:42 +02:00
|
|
|
GLenum buffer = surface_get_gl_buffer(This);
|
2009-12-13 22:03:59 +01:00
|
|
|
TRACE("Unlocking %#x buffer.\n", buffer);
|
|
|
|
context_set_draw_buffer(context, buffer);
|
2010-11-02 12:02:49 +01:00
|
|
|
|
|
|
|
surface_translate_drawable_coords(This, context->win_handle, &rect);
|
|
|
|
glPixelZoom(1.0f, -1.0f);
|
2009-12-13 22:03:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-16 11:52:54 +02:00
|
|
|
/* Primary offscreen render target */
|
2009-12-13 22:03:59 +01:00
|
|
|
TRACE("Offscreen render target.\n");
|
2010-04-18 22:50:42 +02:00
|
|
|
context_set_draw_buffer(context, device->offscreenBuffer);
|
2010-11-02 12:02:49 +01:00
|
|
|
|
|
|
|
glPixelZoom(1.0f, 1.0f);
|
2007-11-02 21:08:20 +01:00
|
|
|
}
|
2006-07-17 17:27:19 +02:00
|
|
|
|
2010-11-02 12:02:48 +01:00
|
|
|
glRasterPos3i(rect.left, rect.top, 1);
|
2009-08-15 15:59:55 +02:00
|
|
|
checkGLcall("glRasterPos3i");
|
2006-07-17 17:27:19 +02:00
|
|
|
|
|
|
|
/* Some drivers(radeon dri, others?) don't like exceptions during
|
|
|
|
* glDrawPixels. If the surface is a DIB section, it might be in GDIMode
|
|
|
|
* after ReleaseDC. Reading it will cause an exception, which x11drv will
|
|
|
|
* catch to put the dib section in InSync mode, which leads to a crash
|
|
|
|
* and a blocked x server on my radeon card.
|
|
|
|
*
|
2008-04-22 08:18:14 +02:00
|
|
|
* The following lines read the dib section so it is put in InSync mode
|
2006-07-17 17:27:19 +02:00
|
|
|
* before glDrawPixels is called and the crash is prevented. There won't
|
|
|
|
* be any interfering gdi accesses, because UnlockRect is called from
|
|
|
|
* ReleaseDC, and the app won't use the dc any more afterwards.
|
|
|
|
*/
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((This->flags & SFLAG_DIBSECTION) && !(This->flags & SFLAG_PBO))
|
|
|
|
{
|
2006-07-17 17:27:19 +02:00
|
|
|
volatile BYTE read;
|
|
|
|
read = This->resource.allocatedMemory[0];
|
|
|
|
}
|
|
|
|
|
2010-10-29 12:25:19 +02:00
|
|
|
/* If not fullscreen, we need to skip a number of bytes to find the next row of data */
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, This->currentDesc.Width);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
}
|
|
|
|
|
2010-11-02 12:02:48 +01:00
|
|
|
glDrawPixels(w, h, fmt, type, mem);
|
|
|
|
checkGLcall("glDrawPixels");
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
}
|
|
|
|
|
2010-10-29 12:25:19 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)");
|
2006-07-17 17:27:19 +02:00
|
|
|
|
2007-11-02 21:08:20 +01:00
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2006-07-17 17:27:19 +02:00
|
|
|
}
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_Unmap(IWineD3DSurface *iface)
|
|
|
|
{
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2007-09-21 19:55:06 +02:00
|
|
|
BOOL fullsurface;
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_LOCKED))
|
|
|
|
{
|
2005-07-07 22:35:05 +02:00
|
|
|
WARN("trying to Unlock an unlocked surf@%p\n", This);
|
2008-12-18 16:43:06 +01:00
|
|
|
return WINEDDERR_NOTLOCKED;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
2010-03-17 21:59:50 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2007-09-11 10:31:54 +02:00
|
|
|
TRACE("Freeing PBO memory\n");
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-03-17 21:59:50 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2007-09-11 10:31:54 +02:00
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glUnmapBufferARB");
|
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2007-09-11 10:31:54 +02:00
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
TRACE("(%p) : dirtyfied(%d)\n", This, This->flags & (SFLAG_INDRAWABLE | SFLAG_INTEXTURE) ? 0 : 1);
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & (SFLAG_INDRAWABLE | SFLAG_INTEXTURE))
|
|
|
|
{
|
2005-01-09 18:37:02 +01:00
|
|
|
TRACE("(%p) : Not Dirtified so nothing to do, return now\n", This);
|
|
|
|
goto unlock_end;
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:26 +02:00
|
|
|
if (This->container.type == WINED3D_CONTAINER_SWAPCHAIN
|
|
|
|
|| (device->render_targets && This == device->render_targets[0]))
|
2009-03-25 10:12:27 +01:00
|
|
|
{
|
2007-02-13 20:21:44 +01:00
|
|
|
if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) {
|
|
|
|
static BOOL warned = FALSE;
|
|
|
|
if(!warned) {
|
|
|
|
ERR("The application tries to write to the render target, but render target locking is disabled\n");
|
|
|
|
warned = TRUE;
|
2006-12-19 23:26:39 +01:00
|
|
|
}
|
2007-02-13 20:21:44 +01:00
|
|
|
goto unlock_end;
|
2006-12-19 23:26:39 +01:00
|
|
|
}
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!This->dirtyRect.left && !This->dirtyRect.top
|
|
|
|
&& This->dirtyRect.right == This->currentDesc.Width
|
|
|
|
&& This->dirtyRect.bottom == This->currentDesc.Height)
|
|
|
|
{
|
2007-09-21 19:55:06 +02:00
|
|
|
fullsurface = TRUE;
|
2007-02-13 20:21:44 +01:00
|
|
|
} else {
|
2007-09-21 19:55:06 +02:00
|
|
|
/* TODO: Proper partial rectangle tracking */
|
|
|
|
fullsurface = FALSE;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_INSYSMEM;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2010-11-11 12:39:18 +01:00
|
|
|
surface_load_location(This, SFLAG_INDRAWABLE, fullsurface ? NULL : &This->dirtyRect);
|
2007-09-21 19:55:06 +02:00
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
if (!fullsurface)
|
|
|
|
{
|
|
|
|
/* Partial rectangle tracking is not commonly implemented, it is
|
|
|
|
* only done for render targets. Overwrite the flags to bring
|
|
|
|
* them back into a sane state. INSYSMEM was set before to tell
|
|
|
|
* surface_load_location() where to read the rectangle from.
|
|
|
|
* Indrawable is set because all modifications from the partial
|
|
|
|
* sysmem copy are written back to the drawable, thus the surface
|
|
|
|
* is merged again in the drawable. The sysmem copy is not fully
|
|
|
|
* up to date because only a subrectangle was read in Map(). */
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_INSYSMEM;
|
|
|
|
This->flags |= SFLAG_INDRAWABLE;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 21:47:45 +01:00
|
|
|
This->dirtyRect.left = This->currentDesc.Width;
|
|
|
|
This->dirtyRect.top = This->currentDesc.Height;
|
|
|
|
This->dirtyRect.right = 0;
|
|
|
|
This->dirtyRect.bottom = 0;
|
2010-04-18 22:50:42 +02:00
|
|
|
}
|
2010-11-12 13:12:05 +01:00
|
|
|
else if (This->resource.format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
2007-02-13 20:21:44 +01:00
|
|
|
FIXME("Depth Stencil buffer locking is not implemented\n");
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock_end:
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_LOCKED;
|
2005-01-09 18:37:02 +01:00
|
|
|
memset(&This->lockedRect, 0, sizeof(RECT));
|
2008-08-01 20:12:18 +02:00
|
|
|
|
|
|
|
/* Overlays have to be redrawn manually after changes with the GL implementation */
|
|
|
|
if(This->overlay_dest) {
|
|
|
|
IWineD3DSurface_DrawOverlay(iface);
|
|
|
|
}
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2010-04-28 00:08:49 +02:00
|
|
|
static void surface_release_client_storage(IWineD3DSurfaceImpl *surface)
|
2009-12-15 11:25:14 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(surface->resource.device, NULL);
|
2009-12-15 11:25:14 +01:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
|
2010-04-28 00:08:49 +02:00
|
|
|
if (surface->texture_name)
|
2009-12-15 11:25:14 +01:00
|
|
|
{
|
2010-04-28 00:08:49 +02:00
|
|
|
surface_bind_and_dirtify(surface, FALSE);
|
|
|
|
glTexImage2D(surface->texture_target, surface->texture_level,
|
|
|
|
GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
2009-12-15 11:25:14 +01:00
|
|
|
}
|
2010-04-28 00:08:49 +02:00
|
|
|
if (surface->texture_name_srgb)
|
2009-12-15 11:25:14 +01:00
|
|
|
{
|
2010-04-28 00:08:49 +02:00
|
|
|
surface_bind_and_dirtify(surface, TRUE);
|
|
|
|
glTexImage2D(surface->texture_target, surface->texture_level,
|
|
|
|
GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
2009-12-15 11:25:14 +01:00
|
|
|
}
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
context_release(context);
|
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(surface, SFLAG_INSRGBTEX, FALSE);
|
|
|
|
surface_modify_location(surface, SFLAG_INTEXTURE, FALSE);
|
2010-04-28 00:08:49 +02:00
|
|
|
surface_force_reload(surface);
|
2009-12-15 11:25:14 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 11:57:40 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC)
|
|
|
|
{
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2006-05-06 18:08:33 +02:00
|
|
|
WINED3DLOCKED_RECT lock;
|
|
|
|
HRESULT hr;
|
2006-05-09 21:04:07 +02:00
|
|
|
RGBQUAD col[256];
|
2006-05-06 18:08:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n",This,pHDC);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_USERPTR)
|
|
|
|
{
|
2006-07-25 16:38:02 +02:00
|
|
|
ERR("Not supported on surfaces with an application-provided surfaces\n");
|
2007-04-14 22:44:55 +02:00
|
|
|
return WINEDDERR_NODC;
|
2006-07-25 16:38:02 +02:00
|
|
|
}
|
|
|
|
|
2006-05-06 18:08:33 +02:00
|
|
|
/* Give more detailed info for ddraw */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DCINUSE)
|
2007-04-14 22:44:55 +02:00
|
|
|
return WINEDDERR_DCALREADYCREATED;
|
2006-05-06 18:08:33 +02:00
|
|
|
|
|
|
|
/* Can't GetDC if the surface is locked */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_LOCKED)
|
2006-05-06 18:08:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
memset(&lock, 0, sizeof(lock)); /* To be sure */
|
|
|
|
|
|
|
|
/* Create a DIB section if there isn't a hdc yet */
|
2010-07-21 18:48:22 +02:00
|
|
|
if (!This->hDC)
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_CLIENT)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
|
|
|
surface_load_location(This, SFLAG_INSYSMEM, NULL);
|
2010-04-28 00:08:49 +02:00
|
|
|
surface_release_client_storage(This);
|
2006-05-06 18:08:33 +02:00
|
|
|
}
|
2009-12-15 11:25:14 +01:00
|
|
|
hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
|
|
|
|
if(FAILED(hr)) return WINED3DERR_INVALIDCALL;
|
2006-08-16 22:35:58 +02:00
|
|
|
|
2007-09-11 10:31:54 +02:00
|
|
|
/* Use the dib section from now on if we are not using a PBO */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_PBO))
|
2007-09-11 10:31:54 +02:00
|
|
|
This->resource.allocatedMemory = This->dib.bitmap_data;
|
2006-05-06 18:08:33 +02:00
|
|
|
}
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
/* Map the surface */
|
|
|
|
hr = IWineD3DSurface_Map(iface, &lock, NULL, 0);
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
/* Sync the DIB with the PBO. This can't be done earlier because Map()
|
|
|
|
* activates the allocatedMemory. */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_PBO)
|
2007-09-11 10:31:54 +02:00
|
|
|
memcpy(This->dib.bitmap_data, This->resource.allocatedMemory, This->dib.bitmap_size);
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("IWineD3DSurface_Map failed, hr %#x.\n", hr);
|
2006-05-06 18:08:33 +02:00
|
|
|
/* keep the dib section */
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (This->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| This->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2008-03-25 01:03:55 +01:00
|
|
|
/* GetDC on palettized formats is unsupported in D3D9, and the method is missing in
|
|
|
|
D3D8, so this should only be used for DX <=7 surfaces (with non-device palettes) */
|
2006-05-09 21:04:07 +02:00
|
|
|
unsigned int n;
|
2008-11-25 14:36:09 +01:00
|
|
|
const PALETTEENTRY *pal = NULL;
|
2006-05-09 21:04:07 +02:00
|
|
|
|
2008-03-25 01:03:55 +01:00
|
|
|
if(This->palette) {
|
|
|
|
pal = This->palette->palents;
|
2006-05-09 21:04:07 +02:00
|
|
|
} else {
|
2008-08-05 21:23:00 +02:00
|
|
|
IWineD3DSurfaceImpl *dds_primary;
|
|
|
|
IWineD3DSwapChainImpl *swapchain;
|
2009-12-09 20:32:08 +01:00
|
|
|
swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[0];
|
2010-04-26 21:33:00 +02:00
|
|
|
dds_primary = swapchain->front_buffer;
|
2008-03-25 01:03:55 +01:00
|
|
|
if (dds_primary && dds_primary->palette)
|
|
|
|
pal = dds_primary->palette->palents;
|
|
|
|
}
|
2006-05-09 21:04:07 +02:00
|
|
|
|
2008-03-25 01:03:55 +01:00
|
|
|
if (pal) {
|
2006-05-09 21:04:07 +02:00
|
|
|
for (n=0; n<256; n++) {
|
2008-03-25 01:03:55 +01:00
|
|
|
col[n].rgbRed = pal[n].peRed;
|
|
|
|
col[n].rgbGreen = pal[n].peGreen;
|
|
|
|
col[n].rgbBlue = pal[n].peBlue;
|
2006-05-09 21:04:07 +02:00
|
|
|
col[n].rgbReserved = 0;
|
|
|
|
}
|
2008-03-25 01:03:55 +01:00
|
|
|
SetDIBColorTable(This->hDC, 0, 256, col);
|
2006-05-09 21:04:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-06 18:08:33 +02:00
|
|
|
*pHDC = This->hDC;
|
|
|
|
TRACE("returning %p\n",*pHDC);
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_DCINUSE;
|
2006-05-06 18:08:33 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 11:57:40 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC)
|
|
|
|
{
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2006-05-06 18:08:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n",This,hDC);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_DCINUSE))
|
2008-12-16 00:01:11 +01:00
|
|
|
return WINEDDERR_NODC;
|
2006-05-06 18:08:33 +02:00
|
|
|
|
2007-08-14 14:40:33 +02:00
|
|
|
if (This->hDC !=hDC) {
|
|
|
|
WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
|
2008-12-16 00:01:11 +01:00
|
|
|
return WINEDDERR_NODC;
|
2007-08-14 14:40:33 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((This->flags & SFLAG_PBO) && This->resource.allocatedMemory)
|
|
|
|
{
|
2007-09-11 10:31:54 +02:00
|
|
|
/* Copy the contents of the DIB over to the PBO */
|
|
|
|
memcpy(This->resource.allocatedMemory, This->dib.bitmap_data, This->dib.bitmap_size);
|
|
|
|
}
|
|
|
|
|
2006-05-06 18:08:33 +02:00
|
|
|
/* we locked first, so unlock now */
|
2010-10-14 13:04:02 +02:00
|
|
|
IWineD3DSurface_Unmap(iface);
|
2006-05-06 18:08:33 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_DCINUSE;
|
2006-05-06 18:08:33 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ******************************************************
|
|
|
|
IWineD3DSurface Internal (No mapping to directx api) parts follow
|
|
|
|
****************************************************** */
|
2006-05-22 23:49:09 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck,
|
|
|
|
BOOL use_texturing, struct wined3d_format *format, CONVERT_TYPES *convert)
|
2010-04-08 22:49:45 +02:00
|
|
|
{
|
2007-04-14 22:44:55 +02:00
|
|
|
BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & WINEDDSD_CKSRCBLT);
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2010-05-26 21:51:31 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-04-06 22:20:42 +02:00
|
|
|
BOOL blit_supported = FALSE;
|
2006-05-22 23:49:09 +02:00
|
|
|
|
2010-04-08 22:49:45 +02:00
|
|
|
/* Copy the default values from the surface. Below we might perform fixups */
|
2010-04-15 12:41:57 +02:00
|
|
|
/* TODO: get rid of color keying desc fixups by using e.g. a table. */
|
2010-08-30 20:29:49 +02:00
|
|
|
*format = *This->resource.format;
|
2006-05-22 23:49:09 +02:00
|
|
|
*convert = NO_CONVERSION;
|
|
|
|
|
|
|
|
/* Ok, now look if we have to do any conversion */
|
2010-08-30 20:29:49 +02:00
|
|
|
switch (This->resource.format->id)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_P8_UINT:
|
2010-08-30 20:29:49 +02:00
|
|
|
/* Below the call to blit_supported is disabled for Wine 1.2
|
|
|
|
* because the function isn't operating correctly yet. At the
|
|
|
|
* moment 8-bit blits are handled in software and if certain GL
|
|
|
|
* extensions are around, surface conversion is performed at
|
|
|
|
* upload time. The blit_supported call recognizes it as a
|
|
|
|
* destination fixup. This type of upload 'fixup' and 8-bit to
|
|
|
|
* 8-bit blits need to be handled by the blit_shader.
|
|
|
|
* TODO: get rid of this #if 0. */
|
2010-05-26 21:51:31 +02:00
|
|
|
#if 0
|
2010-04-06 22:20:42 +02:00
|
|
|
blit_supported = device->blitter->blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
|
2010-08-30 20:29:49 +02:00
|
|
|
&rect, This->resource.usage, This->resource.pool, This->resource.format,
|
|
|
|
&rect, This->resource.usage, This->resource.pool, This->resource.format);
|
2010-05-26 21:51:31 +02:00
|
|
|
#endif
|
|
|
|
blit_supported = gl_info->supported[EXT_PALETTED_TEXTURE] || gl_info->supported[ARB_FRAGMENT_PROGRAM];
|
2010-04-06 22:20:42 +02:00
|
|
|
|
2010-03-18 23:11:55 +01:00
|
|
|
/* Use conversion when the blit_shader backend supports it. It only supports this in case of
|
|
|
|
* texturing. Further also use conversion in case of color keying.
|
2008-01-07 13:43:48 +01:00
|
|
|
* Paletted textures can be emulated using shaders but only do that for 2D purposes e.g. situations
|
|
|
|
* in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
|
|
|
|
* conflicts with this.
|
2006-08-03 12:39:04 +02:00
|
|
|
*/
|
2010-04-19 20:46:59 +02:00
|
|
|
if (!((blit_supported && device->render_targets && This == device->render_targets[0]))
|
2009-10-29 10:37:11 +01:00
|
|
|
|| colorkey_active || !use_texturing)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
format->glFormat = GL_RGBA;
|
|
|
|
format->glInternal = GL_RGBA;
|
|
|
|
format->glType = GL_UNSIGNED_BYTE;
|
|
|
|
format->conv_byte_count = 4;
|
|
|
|
if (colorkey_active)
|
2006-05-22 23:49:09 +02:00
|
|
|
*convert = CONVERT_PALETTED_CK;
|
2010-08-30 20:29:49 +02:00
|
|
|
else
|
2006-07-25 16:41:41 +02:00
|
|
|
*convert = CONVERT_PALETTED;
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B2G3R3_UNORM:
|
2006-05-22 23:49:09 +02:00
|
|
|
/* **********************
|
|
|
|
GL_UNSIGNED_BYTE_3_3_2
|
|
|
|
********************** */
|
|
|
|
if (colorkey_active) {
|
|
|
|
/* This texture format will never be used.. So do not care about color keying
|
|
|
|
up until the point in time it will be needed :-) */
|
|
|
|
FIXME(" ColorKeying not supported in the RGB 332 format !\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B5G6R5_UNORM:
|
2010-08-30 20:29:49 +02:00
|
|
|
if (colorkey_active)
|
|
|
|
{
|
2006-05-22 23:49:09 +02:00
|
|
|
*convert = CONVERT_CK_565;
|
2010-08-30 20:29:49 +02:00
|
|
|
format->glFormat = GL_RGBA;
|
|
|
|
format->glInternal = GL_RGB5_A1;
|
|
|
|
format->glType = GL_UNSIGNED_SHORT_5_5_5_1;
|
|
|
|
format->conv_byte_count = 2;
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B5G5R5X1_UNORM:
|
2010-08-30 20:29:49 +02:00
|
|
|
if (colorkey_active)
|
|
|
|
{
|
2007-05-22 03:29:44 +02:00
|
|
|
*convert = CONVERT_CK_5551;
|
2010-08-30 20:29:49 +02:00
|
|
|
format->glFormat = GL_BGRA;
|
|
|
|
format->glInternal = GL_RGB5_A1;
|
|
|
|
format->glType = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
|
|
|
format->conv_byte_count = 2;
|
2007-05-22 03:29:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B8G8R8_UNORM:
|
2010-08-30 20:29:49 +02:00
|
|
|
if (colorkey_active)
|
|
|
|
{
|
2006-05-22 23:49:09 +02:00
|
|
|
*convert = CONVERT_CK_RGB24;
|
2010-08-30 20:29:49 +02:00
|
|
|
format->glFormat = GL_RGBA;
|
|
|
|
format->glInternal = GL_RGBA8;
|
|
|
|
format->glType = GL_UNSIGNED_INT_8_8_8_8;
|
|
|
|
format->conv_byte_count = 4;
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B8G8R8X8_UNORM:
|
2010-08-30 20:29:49 +02:00
|
|
|
if (colorkey_active)
|
|
|
|
{
|
2006-05-22 23:49:09 +02:00
|
|
|
*convert = CONVERT_RGB32_888;
|
2010-08-30 20:29:49 +02:00
|
|
|
format->glFormat = GL_RGBA;
|
|
|
|
format->glInternal = GL_RGBA8;
|
|
|
|
format->glType = GL_UNSIGNED_INT_8_8_8_8;
|
|
|
|
format->conv_byte_count = 4;
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-05 20:05:13 +02:00
|
|
|
void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey)
|
2009-05-25 09:17:21 +02:00
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2009-05-25 09:17:21 +02:00
|
|
|
IWineD3DPaletteImpl *pal = This->palette;
|
|
|
|
BOOL index_in_alpha = FALSE;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Old games like StarCraft, C&C, Red Alert and others use P8 render targets.
|
|
|
|
* Reading back the RGB output each lockrect (each frame as they lock the whole screen)
|
|
|
|
* is slow. Further RGB->P8 conversion is not possible because palettes can have
|
|
|
|
* duplicate entries. Store the color key in the unused alpha component to speed the
|
|
|
|
* download up and to make conversion unneeded. */
|
|
|
|
index_in_alpha = primary_render_target_is_p8(device);
|
|
|
|
|
|
|
|
if (!pal)
|
|
|
|
{
|
2009-12-07 20:20:02 +01:00
|
|
|
UINT dxVersion = ((IWineD3DImpl *)device->wined3d)->dxVersion;
|
2009-05-25 09:17:21 +02:00
|
|
|
|
|
|
|
/* In DirectDraw the palette is a property of the surface, there are no such things as device palettes. */
|
|
|
|
if (dxVersion <= 7)
|
|
|
|
{
|
|
|
|
ERR("This code should never get entered for DirectDraw!, expect problems\n");
|
|
|
|
if (index_in_alpha)
|
|
|
|
{
|
|
|
|
/* Guarantees that memory representation remains correct after sysmem<->texture transfers even if
|
|
|
|
* there's no palette at this time. */
|
|
|
|
for (i = 0; i < 256; i++) table[i][3] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Direct3D >= 8 palette usage style: P8 textures use device palettes, palette entry format is A8R8G8B8,
|
|
|
|
* alpha is stored in peFlags and may be used by the app if D3DPTEXTURECAPS_ALPHAPALETTE device
|
|
|
|
* capability flag is present (wine does advertise this capability) */
|
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
table[i][0] = device->palettes[device->currentPalette][i].peRed;
|
|
|
|
table[i][1] = device->palettes[device->currentPalette][i].peGreen;
|
|
|
|
table[i][2] = device->palettes[device->currentPalette][i].peBlue;
|
|
|
|
table[i][3] = device->palettes[device->currentPalette][i].peFlags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Using surface palette %p\n", pal);
|
|
|
|
/* Get the surface's palette */
|
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
table[i][0] = pal->palents[i].peRed;
|
|
|
|
table[i][1] = pal->palents[i].peGreen;
|
|
|
|
table[i][2] = pal->palents[i].peBlue;
|
|
|
|
|
|
|
|
/* When index_in_alpha is set the palette index is stored in the
|
|
|
|
* alpha component. In case of a readback we can then read
|
|
|
|
* GL_ALPHA. Color keying is handled in BltOverride using a
|
|
|
|
* GL_ALPHA_TEST using GL_NOT_EQUAL. In case of index_in_alpha the
|
|
|
|
* color key itself is passed to glAlphaFunc in other cases the
|
|
|
|
* alpha component of pixels that should be masked away is set to 0. */
|
|
|
|
if (index_in_alpha)
|
|
|
|
{
|
|
|
|
table[i][3] = i;
|
|
|
|
}
|
|
|
|
else if (colorkey && (i >= This->SrcBltCKey.dwColorSpaceLowValue)
|
|
|
|
&& (i <= This->SrcBltCKey.dwColorSpaceHighValue))
|
|
|
|
{
|
|
|
|
table[i][3] = 0x00;
|
|
|
|
}
|
|
|
|
else if(pal->Flags & WINEDDPCAPS_ALPHA)
|
|
|
|
{
|
|
|
|
table[i][3] = pal->palents[i].peFlags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
table[i][3] = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UINT width,
|
2008-11-25 11:57:40 +01:00
|
|
|
UINT height, UINT outpitch, CONVERT_TYPES convert, IWineD3DSurfaceImpl *This)
|
|
|
|
{
|
2008-11-25 14:36:09 +01:00
|
|
|
const BYTE *source;
|
|
|
|
BYTE *dest;
|
2007-09-01 20:00:10 +02:00
|
|
|
TRACE("(%p)->(%p),(%d,%d,%d,%d,%p)\n", src, dst, pitch, height, outpitch, convert,This);
|
2006-05-22 23:49:09 +02:00
|
|
|
|
|
|
|
switch (convert) {
|
|
|
|
case NO_CONVERSION:
|
|
|
|
{
|
2006-10-05 21:35:10 +02:00
|
|
|
memcpy(dst, src, pitch * height);
|
2006-05-22 23:49:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CONVERT_PALETTED:
|
|
|
|
case CONVERT_PALETTED_CK:
|
|
|
|
{
|
|
|
|
BYTE table[256][4];
|
2006-10-05 21:35:10 +02:00
|
|
|
unsigned int x, y;
|
2006-05-22 23:49:09 +02:00
|
|
|
|
2007-10-08 22:11:06 +02:00
|
|
|
d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
|
2006-05-22 23:49:09 +02:00
|
|
|
|
2006-10-05 21:35:10 +02:00
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
2006-11-06 19:45:10 +01:00
|
|
|
source = src + pitch * y;
|
2006-10-05 21:35:10 +02:00
|
|
|
dest = dst + outpitch * y;
|
2006-11-06 19:45:10 +01:00
|
|
|
/* This is an 1 bpp format, using the width here is fine */
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
BYTE color = *source++;
|
2006-10-05 21:35:10 +02:00
|
|
|
*dest++ = table[color][0];
|
|
|
|
*dest++ = table[color][1];
|
|
|
|
*dest++ = table[color][2];
|
|
|
|
*dest++ = table[color][3];
|
|
|
|
}
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONVERT_CK_565:
|
|
|
|
{
|
|
|
|
/* Converting the 565 format in 5551 packed to emulate color-keying.
|
|
|
|
|
|
|
|
Note : in all these conversion, it would be best to average the averaging
|
|
|
|
pixels to get the color of the pixel that will be color-keyed to
|
|
|
|
prevent 'color bleeding'. This will be done later on if ever it is
|
|
|
|
too visible.
|
|
|
|
|
2006-10-05 21:31:50 +02:00
|
|
|
Note2: Nvidia documents say that their driver does not support alpha + color keying
|
|
|
|
on the same surface and disables color keying in such a case
|
2006-05-22 23:49:09 +02:00
|
|
|
*/
|
2006-10-05 21:35:10 +02:00
|
|
|
unsigned int x, y;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WORD *Source;
|
2006-10-05 21:35:10 +02:00
|
|
|
WORD *Dest;
|
2006-05-22 23:49:09 +02:00
|
|
|
|
|
|
|
TRACE("Color keyed 565\n");
|
|
|
|
|
2006-10-05 21:35:10 +02:00
|
|
|
for (y = 0; y < height; y++) {
|
2008-11-25 14:36:09 +01:00
|
|
|
Source = (const WORD *)(src + y * pitch);
|
2006-10-05 21:35:10 +02:00
|
|
|
Dest = (WORD *) (dst + y * outpitch);
|
2006-11-08 02:22:29 +01:00
|
|
|
for (x = 0; x < width; x++ ) {
|
2006-10-05 21:35:10 +02:00
|
|
|
WORD color = *Source++;
|
|
|
|
*Dest = ((color & 0xFFC0) | ((color & 0x1F) << 1));
|
2007-09-01 20:00:10 +02:00
|
|
|
if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
(color > This->SrcBltCKey.dwColorSpaceHighValue)) {
|
2006-10-05 21:35:10 +02:00
|
|
|
*Dest |= 0x0001;
|
|
|
|
}
|
|
|
|
Dest++;
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-05-22 03:29:44 +02:00
|
|
|
case CONVERT_CK_5551:
|
|
|
|
{
|
|
|
|
/* Converting X1R5G5B5 format to R5G5B5A1 to emulate color-keying. */
|
|
|
|
unsigned int x, y;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WORD *Source;
|
2007-05-22 03:29:44 +02:00
|
|
|
WORD *Dest;
|
|
|
|
TRACE("Color keyed 5551\n");
|
|
|
|
for (y = 0; y < height; y++) {
|
2008-11-25 14:36:09 +01:00
|
|
|
Source = (const WORD *)(src + y * pitch);
|
2007-05-22 03:29:44 +02:00
|
|
|
Dest = (WORD *) (dst + y * outpitch);
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
WORD color = *Source++;
|
2009-01-09 10:23:43 +01:00
|
|
|
*Dest = color;
|
2007-09-01 20:00:10 +02:00
|
|
|
if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
(color > This->SrcBltCKey.dwColorSpaceHighValue)) {
|
2007-05-22 03:29:44 +02:00
|
|
|
*Dest |= (1 << 15);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*Dest &= ~(1 << 15);
|
|
|
|
}
|
|
|
|
Dest++;
|
|
|
|
}
|
2008-11-23 21:31:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONVERT_CK_RGB24:
|
|
|
|
{
|
|
|
|
/* Converting R8G8B8 format to R8G8B8A8 with color-keying. */
|
|
|
|
unsigned int x, y;
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
source = src + pitch * y;
|
|
|
|
dest = dst + outpitch * y;
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
DWORD color = ((DWORD)source[0] << 16) + ((DWORD)source[1] << 8) + (DWORD)source[2] ;
|
|
|
|
DWORD dstcolor = color << 8;
|
|
|
|
if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
(color > This->SrcBltCKey.dwColorSpaceHighValue)) {
|
|
|
|
dstcolor |= 0xff;
|
|
|
|
}
|
|
|
|
*(DWORD*)dest = dstcolor;
|
|
|
|
source += 3;
|
|
|
|
dest += 4;
|
|
|
|
}
|
2007-05-22 03:29:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-04-06 23:05:48 +02:00
|
|
|
case CONVERT_RGB32_888:
|
|
|
|
{
|
|
|
|
/* Converting X8R8G8B8 format to R8G8B8A8 with color-keying. */
|
|
|
|
unsigned int x, y;
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
source = src + pitch * y;
|
|
|
|
dest = dst + outpitch * y;
|
|
|
|
for (x = 0; x < width; x++) {
|
2008-11-25 14:36:09 +01:00
|
|
|
DWORD color = 0xffffff & *(const DWORD*)source;
|
2008-04-06 23:05:48 +02:00
|
|
|
DWORD dstcolor = color << 8;
|
|
|
|
if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
(color > This->SrcBltCKey.dwColorSpaceHighValue)) {
|
|
|
|
dstcolor |= 0xff;
|
|
|
|
}
|
|
|
|
*(DWORD*)dest = dstcolor;
|
|
|
|
source += 4;
|
|
|
|
dest += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-05-22 23:49:09 +02:00
|
|
|
default:
|
2009-06-17 10:19:49 +02:00
|
|
|
ERR("Unsupported conversion type %#x.\n", convert);
|
2006-05-22 23:49:09 +02:00
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-09 20:32:08 +01:00
|
|
|
BOOL palette9_changed(IWineD3DSurfaceImpl *This)
|
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2007-02-19 15:23:36 +01:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (This->palette || (This->resource.format->id != WINED3DFMT_P8_UINT
|
|
|
|
&& This->resource.format->id != WINED3DFMT_P8_UINT_A8_UNORM))
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2007-02-19 15:23:36 +01:00
|
|
|
/* If a ddraw-style palette is attached assume no d3d9 palette change.
|
|
|
|
* Also the palette isn't interesting if the surface format isn't P8 or A8P8
|
|
|
|
*/
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-23 10:26:12 +02:00
|
|
|
if (This->palette9)
|
|
|
|
{
|
|
|
|
if (!memcmp(This->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256))
|
|
|
|
{
|
2007-02-19 15:23:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-27 00:13:32 +02:00
|
|
|
This->palette9 = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256);
|
2007-02-19 15:23:36 +01:00
|
|
|
}
|
2009-10-23 10:26:12 +02:00
|
|
|
memcpy(This->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256);
|
2007-02-19 15:23:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-07 01:08:26 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BOOL srgb_mode) {
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2009-01-16 16:22:09 +01:00
|
|
|
DWORD flag = srgb_mode ? SFLAG_INSRGBTEX : SFLAG_INTEXTURE;
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-08-17 19:03:21 +02:00
|
|
|
TRACE("iface %p, srgb %#x.\n", iface, srgb_mode);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & flag))
|
|
|
|
{
|
2006-07-25 16:41:41 +02:00
|
|
|
TRACE("Reloading because surface is dirty\n");
|
2010-11-12 13:12:03 +01:00
|
|
|
}
|
|
|
|
/* Reload if either the texture and sysmem have different ideas about the
|
|
|
|
* color key, or the actual key values changed. */
|
2010-11-12 13:12:04 +01:00
|
|
|
else if (!(This->flags & SFLAG_GLCKEY) != !(This->CKeyFlags & WINEDDSD_CKSRCBLT)
|
2010-11-12 13:12:03 +01:00
|
|
|
|| ((This->CKeyFlags & WINEDDSD_CKSRCBLT)
|
|
|
|
&& (This->glCKey.dwColorSpaceLowValue != This->SrcBltCKey.dwColorSpaceLowValue
|
|
|
|
|| This->glCKey.dwColorSpaceHighValue != This->SrcBltCKey.dwColorSpaceHighValue)))
|
|
|
|
{
|
2006-07-25 16:41:41 +02:00
|
|
|
TRACE("Reloading because of color keying\n");
|
2007-10-13 12:54:10 +02:00
|
|
|
/* To perform the color key conversion we need a sysmem copy of
|
|
|
|
* the surface. Make sure we have it
|
|
|
|
*/
|
2008-01-29 22:42:32 +01:00
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(This, SFLAG_INSYSMEM, NULL);
|
2008-01-29 22:42:32 +01:00
|
|
|
/* Make sure the texture is reloaded because of the color key change, this kills performance though :( */
|
|
|
|
/* TODO: This is not necessarily needed with hw palettized texture support */
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INSYSMEM, TRUE);
|
2006-07-25 16:41:41 +02:00
|
|
|
} else {
|
2007-03-06 21:47:45 +01:00
|
|
|
TRACE("surface is already in texture\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-11 16:25:54 +02:00
|
|
|
}
|
|
|
|
|
2006-02-06 20:57:42 +01:00
|
|
|
/* Resources are placed in system RAM and do not need to be recreated when a device is lost.
|
2007-10-13 12:54:10 +02:00
|
|
|
* These resources are not bound by device size or format restrictions. Because of this,
|
|
|
|
* these resources cannot be accessed by the Direct3D device nor set as textures or render targets.
|
|
|
|
* However, these resources can always be created, locked, and copied.
|
|
|
|
*/
|
2007-03-13 03:44:22 +01:00
|
|
|
if (This->resource.pool == WINED3DPOOL_SCRATCH )
|
2005-07-11 16:25:54 +02:00
|
|
|
{
|
2006-05-18 22:59:33 +02:00
|
|
|
FIXME("(%p) Operation not supported for scratch textures\n",This);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-11 16:25:54 +02:00
|
|
|
}
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(This, flag, NULL /* no partial locking for textures yet */);
|
2005-01-09 18:37:02 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_DONOTFREE))
|
|
|
|
{
|
2007-10-22 13:02:03 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
2006-09-11 18:51:18 +02:00
|
|
|
This->resource.allocatedMemory = NULL;
|
2007-10-22 13:02:03 +02:00
|
|
|
This->resource.heapMemory = NULL;
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INSYSMEM, FALSE);
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-08-16 20:00:27 +02:00
|
|
|
static void WINAPI IWineD3DSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb)
|
|
|
|
{
|
2007-11-15 14:38:34 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
TRACE("iface %p, srgb %#x.\n", iface, srgb);
|
|
|
|
|
|
|
|
if (This->container.type == WINED3D_CONTAINER_TEXTURE)
|
|
|
|
{
|
|
|
|
TRACE("Passing to container.\n");
|
|
|
|
IWineD3DBaseTexture_BindTexture((IWineD3DBaseTexture *)This->container.u.texture, srgb);
|
2009-10-28 11:00:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-16 16:22:09 +01:00
|
|
|
GLuint *name;
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2007-11-15 14:38:34 +01:00
|
|
|
TRACE("(%p) : Binding surface\n", This);
|
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
name = srgb ? &This->texture_name_srgb : &This->texture_name;
|
2008-08-19 17:49:07 +02:00
|
|
|
|
2007-11-15 14:38:34 +01:00
|
|
|
ENTER_GL();
|
2008-08-19 17:49:07 +02:00
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
if (!This->texture_level)
|
|
|
|
{
|
2009-01-16 16:22:09 +01:00
|
|
|
if (!*name) {
|
|
|
|
glGenTextures(1, name);
|
2008-08-19 17:49:07 +02:00
|
|
|
checkGLcall("glGenTextures");
|
2009-01-16 16:22:09 +01:00
|
|
|
TRACE("Surface %p given name %d\n", This, *name);
|
2008-09-22 08:54:40 +02:00
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
glBindTexture(This->texture_target, *name);
|
2008-09-22 08:54:40 +02:00
|
|
|
checkGLcall("glBindTexture");
|
2009-07-10 10:20:13 +02:00
|
|
|
glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
2008-09-22 08:54:40 +02:00
|
|
|
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
|
2009-07-10 10:20:13 +02:00
|
|
|
glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2008-09-22 08:54:40 +02:00
|
|
|
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
|
2009-07-10 10:20:13 +02:00
|
|
|
glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
2008-09-22 08:54:40 +02:00
|
|
|
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)");
|
2009-07-10 10:20:13 +02:00
|
|
|
glTexParameteri(This->texture_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2008-09-22 08:54:40 +02:00
|
|
|
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
|
2009-07-10 10:20:13 +02:00
|
|
|
glTexParameteri(This->texture_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2008-09-22 08:54:40 +02:00
|
|
|
checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
|
2008-08-19 17:49:07 +02:00
|
|
|
}
|
|
|
|
/* This is where we should be reducing the amount of GLMemoryUsed */
|
2009-01-16 16:22:09 +01:00
|
|
|
} else if (*name) {
|
2008-08-19 17:49:07 +02:00
|
|
|
/* Mipmap surfaces should have a base texture container */
|
|
|
|
ERR("Mipmap surface has a glTexture bound to it!\n");
|
|
|
|
}
|
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
glBindTexture(This->texture_target, *name);
|
2008-08-19 17:49:07 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
2007-11-15 14:38:34 +01:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:28:10 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, enum wined3d_format_id format)
|
|
|
|
{
|
2005-11-02 21:01:54 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2007-09-16 16:49:02 +02:00
|
|
|
HRESULT hr;
|
2005-11-02 21:01:54 +01:00
|
|
|
|
2007-09-16 16:49:02 +02:00
|
|
|
TRACE("(%p) : Calling base function first\n", This);
|
|
|
|
hr = IWineD3DBaseSurfaceImpl_SetFormat(iface, format);
|
2010-11-12 13:12:04 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
This->flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
|
2010-08-30 20:29:49 +02:00
|
|
|
TRACE("(%p) : glFormat %d, glFormatInternal %d, glType %d\n", This, This->resource.format->glFormat,
|
|
|
|
This->resource.format->glInternal, This->resource.format->glType);
|
2005-11-02 21:01:54 +01:00
|
|
|
}
|
2007-09-16 16:49:02 +02:00
|
|
|
return hr;
|
2005-11-02 21:01:54 +01:00
|
|
|
}
|
|
|
|
|
2008-12-02 15:31:17 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) {
|
2006-07-25 16:38:02 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & (SFLAG_LOCKED | SFLAG_DCINUSE))
|
|
|
|
{
|
2006-07-25 16:38:02 +02:00
|
|
|
WARN("Surface is locked or the HDC is in use\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Mem && Mem != This->resource.allocatedMemory) {
|
2007-03-31 23:02:37 +02:00
|
|
|
void *release = NULL;
|
2006-07-25 16:38:02 +02:00
|
|
|
|
|
|
|
/* Do I have to copy the old surface content? */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DIBSECTION)
|
|
|
|
{
|
|
|
|
SelectObject(This->hDC, This->dib.holdbitmap);
|
|
|
|
DeleteDC(This->hDC);
|
|
|
|
/* Release the DIB section */
|
|
|
|
DeleteObject(This->dib.DIBsection);
|
|
|
|
This->dib.bitmap_data = NULL;
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
This->hDC = NULL;
|
|
|
|
This->flags &= ~SFLAG_DIBSECTION;
|
|
|
|
}
|
|
|
|
else if (!(This->flags & SFLAG_USERPTR))
|
|
|
|
{
|
2007-10-22 13:02:03 +02:00
|
|
|
release = This->resource.heapMemory;
|
|
|
|
This->resource.heapMemory = NULL;
|
2006-07-25 16:38:02 +02:00
|
|
|
}
|
|
|
|
This->resource.allocatedMemory = Mem;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
|
2007-03-31 23:02:37 +02:00
|
|
|
|
|
|
|
/* Now the surface memory is most up do date. Invalidate drawable and texture */
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INSYSMEM, TRUE);
|
2007-03-31 23:02:37 +02:00
|
|
|
|
|
|
|
/* For client textures opengl has to be notified */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_CLIENT)
|
2010-04-28 00:08:49 +02:00
|
|
|
surface_release_client_storage(This);
|
2007-03-31 23:02:37 +02:00
|
|
|
|
|
|
|
/* Now free the old memory if any */
|
|
|
|
HeapFree(GetProcessHeap(), 0, release);
|
2010-10-14 13:04:02 +02:00
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
else if (This->flags & SFLAG_USERPTR)
|
2010-10-14 13:04:02 +02:00
|
|
|
{
|
|
|
|
/* Map and GetDC will re-create the dib section and allocated memory. */
|
2006-07-25 16:38:02 +02:00
|
|
|
This->resource.allocatedMemory = NULL;
|
2007-10-22 13:02:03 +02:00
|
|
|
/* HeapMemory should be NULL already */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (This->resource.heapMemory)
|
|
|
|
ERR("User pointer surface has heap memory allocated.\n");
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_USERPTR;
|
2007-03-31 23:02:37 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_CLIENT)
|
2010-04-28 00:08:49 +02:00
|
|
|
surface_release_client_storage(This);
|
2006-07-25 16:38:02 +02:00
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-24 18:38:51 +02:00
|
|
|
void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back) {
|
|
|
|
|
|
|
|
/* Flip the surface contents */
|
|
|
|
/* Flip the DC */
|
|
|
|
{
|
|
|
|
HDC tmp;
|
|
|
|
tmp = front->hDC;
|
|
|
|
front->hDC = back->hDC;
|
|
|
|
back->hDC = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the DIBsection */
|
|
|
|
{
|
|
|
|
HBITMAP tmp;
|
2010-11-12 13:12:04 +01:00
|
|
|
BOOL hasDib = front->flags & SFLAG_DIBSECTION;
|
2008-07-24 18:38:51 +02:00
|
|
|
tmp = front->dib.DIBsection;
|
|
|
|
front->dib.DIBsection = back->dib.DIBsection;
|
|
|
|
back->dib.DIBsection = tmp;
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (back->flags & SFLAG_DIBSECTION) front->flags |= SFLAG_DIBSECTION;
|
|
|
|
else front->flags &= ~SFLAG_DIBSECTION;
|
|
|
|
if (hasDib) back->flags |= SFLAG_DIBSECTION;
|
|
|
|
else back->flags &= ~SFLAG_DIBSECTION;
|
2008-07-24 18:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the surface data */
|
|
|
|
{
|
|
|
|
void* tmp;
|
|
|
|
|
|
|
|
tmp = front->dib.bitmap_data;
|
|
|
|
front->dib.bitmap_data = back->dib.bitmap_data;
|
|
|
|
back->dib.bitmap_data = tmp;
|
|
|
|
|
|
|
|
tmp = front->resource.allocatedMemory;
|
|
|
|
front->resource.allocatedMemory = back->resource.allocatedMemory;
|
|
|
|
back->resource.allocatedMemory = tmp;
|
|
|
|
|
|
|
|
tmp = front->resource.heapMemory;
|
|
|
|
front->resource.heapMemory = back->resource.heapMemory;
|
|
|
|
back->resource.heapMemory = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the PBO */
|
|
|
|
{
|
|
|
|
GLuint tmp_pbo = front->pbo;
|
|
|
|
front->pbo = back->pbo;
|
|
|
|
back->pbo = tmp_pbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* client_memory should not be different, but just in case */
|
|
|
|
{
|
|
|
|
BOOL tmp;
|
|
|
|
tmp = front->dib.client_memory;
|
|
|
|
front->dib.client_memory = back->dib.client_memory;
|
|
|
|
back->dib.client_memory = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the opengl texture */
|
|
|
|
{
|
2009-07-10 10:20:13 +02:00
|
|
|
GLuint tmp;
|
|
|
|
|
|
|
|
tmp = back->texture_name;
|
|
|
|
back->texture_name = front->texture_name;
|
|
|
|
front->texture_name = tmp;
|
|
|
|
|
|
|
|
tmp = back->texture_name_srgb;
|
|
|
|
back->texture_name_srgb = front->texture_name_srgb;
|
|
|
|
front->texture_name_srgb = tmp;
|
2008-07-24 18:38:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
DWORD tmp_flags = back->flags;
|
|
|
|
back->flags = front->flags;
|
|
|
|
front->flags = tmp_flags;
|
2008-07-24 18:38:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_Flip(IWineD3DSurface *iface, IWineD3DSurface *override, DWORD Flags) {
|
2006-05-09 19:49:24 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2007-06-03 13:20:27 +02:00
|
|
|
IWineD3DSwapChainImpl *swapchain = NULL;
|
2010-08-20 13:56:23 +02:00
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p)->(%p,%x)\n", This, override, Flags);
|
2006-05-09 19:49:24 +02:00
|
|
|
|
2008-07-24 18:38:51 +02:00
|
|
|
/* Flipping is only supported on RenderTargets and overlays*/
|
|
|
|
if( !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_OVERLAY)) ) {
|
|
|
|
WARN("Tried to flip a non-render target, non-overlay surface\n");
|
|
|
|
return WINEDDERR_NOTFLIPPABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->resource.usage & WINED3DUSAGE_OVERLAY) {
|
|
|
|
flip_surface(This, (IWineD3DSurfaceImpl *) override);
|
|
|
|
|
|
|
|
/* Update the overlay if it is visible */
|
|
|
|
if(This->overlay_dest) {
|
|
|
|
return IWineD3DSurface_DrawOverlay((IWineD3DSurface *) This);
|
|
|
|
} else {
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
2006-05-09 19:49:24 +02:00
|
|
|
|
|
|
|
if(override) {
|
2009-08-27 10:04:56 +02:00
|
|
|
/* DDraw sets this for the X11 surfaces, so don't confuse the user
|
2006-05-09 19:49:24 +02:00
|
|
|
* FIXME("(%p) Target override is not supported by now\n", This);
|
|
|
|
* Additionally, it isn't really possible to support triple-buffering
|
|
|
|
* properly on opengl at all
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
if (This->container.type != WINED3D_CONTAINER_SWAPCHAIN)
|
|
|
|
{
|
2007-06-03 13:20:27 +02:00
|
|
|
ERR("Flipped surface is not on a swapchain\n");
|
|
|
|
return WINEDDERR_NOTFLIPPABLE;
|
|
|
|
}
|
2010-08-16 20:00:27 +02:00
|
|
|
swapchain = This->container.u.swapchain;
|
2007-06-03 13:20:27 +02:00
|
|
|
|
|
|
|
/* Just overwrite the swapchain presentation interval. This is ok because only ddraw apps can call Flip,
|
|
|
|
* and only d3d8 and d3d9 apps specify the presentation interval
|
|
|
|
*/
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!(Flags & (WINEDDFLIP_NOVSYNC | WINEDDFLIP_INTERVAL2 | WINEDDFLIP_INTERVAL3 | WINEDDFLIP_INTERVAL4)))
|
|
|
|
{
|
2007-06-03 13:20:27 +02:00
|
|
|
/* Most common case first to avoid wasting time on all the other cases */
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_ONE;
|
|
|
|
} else if(Flags & WINEDDFLIP_NOVSYNC) {
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
} else if(Flags & WINEDDFLIP_INTERVAL2) {
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_TWO;
|
|
|
|
} else if(Flags & WINEDDFLIP_INTERVAL3) {
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_THREE;
|
|
|
|
} else {
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_FOUR;
|
|
|
|
}
|
|
|
|
|
2006-05-09 19:49:24 +02:00
|
|
|
/* Flipping a OpenGL surface -> Use WineD3DDevice::Present */
|
2010-08-20 13:56:23 +02:00
|
|
|
return IWineD3DSwapChain_Present((IWineD3DSwapChain *)swapchain,
|
2010-04-06 20:05:17 +02:00
|
|
|
NULL, NULL, swapchain->win_handle, NULL, 0);
|
2006-04-12 22:32:44 +02:00
|
|
|
}
|
|
|
|
|
2007-02-12 19:18:46 +01:00
|
|
|
/* Does a direct frame buffer -> texture copy. Stretching is done
|
|
|
|
* with single pixel copy calls
|
|
|
|
*/
|
2010-04-22 18:56:00 +02:00
|
|
|
static void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *dst_surface, IWineD3DSurfaceImpl *src_surface,
|
2010-04-01 23:58:49 +02:00
|
|
|
const RECT *src_rect, const RECT *dst_rect_in, WINED3DTEXTUREFILTERTYPE Filter)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2010-04-22 18:56:00 +02:00
|
|
|
IWineD3DDeviceImpl *device = dst_surface->resource.device;
|
2007-02-12 19:18:46 +01:00
|
|
|
float xrel, yrel;
|
|
|
|
UINT row;
|
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;
|
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);
|
|
|
|
context_apply_blit_state(context, device);
|
2010-04-26 11:02:34 +02:00
|
|
|
surface_internal_preload(dst_surface, SRGB_RGB);
|
2008-04-06 23:06:27 +02:00
|
|
|
ENTER_GL();
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* Bind the target texture */
|
2010-04-22 18:56:00 +02:00
|
|
|
glBindTexture(dst_surface->texture_target, dst_surface->texture_name);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glBindTexture");
|
2010-04-22 18:56:00 +02:00
|
|
|
if (surface_is_offscreen(src_surface))
|
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;
|
2010-04-18 22:50:42 +02:00
|
|
|
glReadBuffer(device->offscreenBuffer);
|
2009-12-15 17:51:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-22 18:56:00 +02:00
|
|
|
glReadBuffer(surface_get_gl_buffer(src_surface));
|
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))
|
|
|
|
{
|
2007-02-12 19:18:46 +01:00
|
|
|
FIXME("Doing a pixel by pixel copy from the framebuffer to a texture, expect major performance issues\n");
|
2007-04-03 12:00:15 +02:00
|
|
|
|
2007-05-10 17:42:41 +02:00
|
|
|
if(Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) {
|
2007-04-03 12:00:15 +02:00
|
|
|
ERR("Texture filtering not supported in direct blit\n");
|
|
|
|
}
|
2009-07-07 11:08:01 +02:00
|
|
|
}
|
|
|
|
else if ((Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT)
|
|
|
|
&& ((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
|
|
|
}
|
|
|
|
|
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)))
|
|
|
|
{
|
2007-02-12 19:18:46 +01:00
|
|
|
/* Upside down copy without stretching is nice, one glCopyTexSubImage call will do */
|
|
|
|
|
2010-04-22 18:56:00 +02:00
|
|
|
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 */,
|
2010-04-22 18:56:00 +02:00
|
|
|
src_rect->left, src_surface->currentDesc.Height - src_rect->bottom,
|
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
|
|
|
} else {
|
2010-04-22 18:56:00 +02:00
|
|
|
UINT yoffset = src_surface->currentDesc.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
|
|
|
|
*/
|
|
|
|
UINT col;
|
|
|
|
|
2010-04-22 18:56:00 +02:00
|
|
|
for (col = dst_rect.left; col < dst_rect.right; ++col)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2007-02-12 19:18:46 +01:00
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2009-09-05 22:32:51 +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
|
|
|
|
*/
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(dst_surface, SFLAG_INTEXTURE, TRUE);
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Uses the hardware to stretch and flip the image */
|
2010-04-22 18:56:01 +02:00
|
|
|
static void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *dst_surface, IWineD3DSurfaceImpl *src_surface,
|
2010-04-01 23:58:50 +02:00
|
|
|
const RECT *src_rect, const RECT *dst_rect_in, WINED3DTEXTUREFILTERTYPE Filter)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2010-04-22 18:56:01 +02:00
|
|
|
IWineD3DDeviceImpl *device = dst_surface->resource.device;
|
2007-03-01 01:42:50 +01:00
|
|
|
GLuint src, backup = 0;
|
2010-04-01 23:58:50 +02:00
|
|
|
IWineD3DSwapChainImpl *src_swapchain = NULL;
|
2007-02-12 19:18:46 +01:00
|
|
|
float left, right, top, bottom; /* Texture coordinates */
|
2010-04-22 18:56:01 +02:00
|
|
|
UINT fbwidth = src_surface->currentDesc.Width;
|
|
|
|
UINT fbheight = src_surface->currentDesc.Height;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2007-03-04 23:47:57 +01:00
|
|
|
GLenum drawBuffer = GL_BACK;
|
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);
|
|
|
|
context_apply_blit_state(context, device);
|
2010-04-26 11:02:34 +02:00
|
|
|
surface_internal_preload(dst_surface, SRGB_RGB);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-04-22 18:56:01 +02:00
|
|
|
src_offscreen = surface_is_offscreen(src_surface);
|
2009-12-15 17:51:33 +01:00
|
|
|
noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
|
2010-04-22 18:56:01 +02:00
|
|
|
if (!noBackBufferBackup && !src_surface->texture_name)
|
2009-07-10 10:20:13 +02:00
|
|
|
{
|
2008-04-06 23:06:27 +02:00
|
|
|
/* Get it a description */
|
2010-04-26 11:02:34 +02:00
|
|
|
surface_internal_preload(src_surface, SRGB_RGB);
|
2008-04-06 23:06:27 +02:00
|
|
|
}
|
|
|
|
ENTER_GL();
|
|
|
|
|
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
|
|
|
}
|
2010-04-18 22:50:42 +02:00
|
|
|
else if ((!src_offscreen || device->offscreenBuffer == 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;
|
|
|
|
}
|
|
|
|
|
2008-04-06 23:06:27 +02:00
|
|
|
if(noBackBufferBackup) {
|
2007-03-01 01:42:50 +01:00
|
|
|
glGenTextures(1, &backup);
|
2009-07-07 11:08:02 +02:00
|
|
|
checkGLcall("glGenTextures");
|
2007-03-01 01:42:50 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, backup);
|
2009-07-10 10:20:13 +02:00
|
|
|
checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
|
2007-11-26 21:28:20 +01:00
|
|
|
texture_target = GL_TEXTURE_2D;
|
2007-03-01 01:42:50 +01:00
|
|
|
} else {
|
|
|
|
/* 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;
|
|
|
|
glBindTexture(texture_target, src_surface->texture_name);
|
|
|
|
checkGLcall("glBindTexture(texture_target, src_surface->texture_name)");
|
2007-11-26 21:28:20 +01:00
|
|
|
glEnable(texture_target);
|
|
|
|
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 */
|
2010-11-12 13:12:04 +01:00
|
|
|
src_surface->flags &= ~SFLAG_INTEXTURE;
|
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;
|
2010-04-18 22:50:42 +02:00
|
|
|
glReadBuffer(device->offscreenBuffer);
|
2009-12-15 17:51:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-22 18:56:01 +02:00
|
|
|
glReadBuffer(surface_get_gl_buffer(src_surface));
|
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 */
|
2007-11-26 21:28:20 +01:00
|
|
|
glCopyTexSubImage2D(texture_target, 0,
|
2007-02-12 19:18:46 +01:00
|
|
|
0, 0 /* read offsets */,
|
|
|
|
0, 0,
|
|
|
|
fbwidth,
|
|
|
|
fbheight);
|
|
|
|
|
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
2007-03-01 01:42:50 +01:00
|
|
|
/* No issue with overriding these - the sampler is dirty due to blit usage */
|
2007-11-26 21:28:20 +01:00
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER,
|
2009-08-05 09:00:59 +02:00
|
|
|
wined3d_gl_mag_filter(magLookup, Filter));
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
2007-11-26 21:28:20 +01:00
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER,
|
2009-08-05 09:00:59 +02:00
|
|
|
wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE));
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
if (src_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
|
|
|
src_swapchain = src_surface->container.u.swapchain;
|
2010-04-26 21:33:01 +02:00
|
|
|
if (!src_swapchain || src_surface == src_swapchain->back_buffers[0])
|
2010-04-22 18:56:01 +02:00
|
|
|
{
|
|
|
|
src = backup ? backup : src_surface->texture_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-12 19:18:46 +01:00
|
|
|
glReadBuffer(GL_FRONT);
|
|
|
|
checkGLcall("glReadBuffer(GL_FRONT)");
|
|
|
|
|
|
|
|
glGenTextures(1, &src);
|
|
|
|
checkGLcall("glGenTextures(1, &src)");
|
|
|
|
glBindTexture(GL_TEXTURE_2D, src);
|
|
|
|
checkGLcall("glBindTexture(GL_TEXTURE_2D, src)");
|
|
|
|
|
2010-03-30 22:19:00 +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
|
2007-02-12 19:18:46 +01:00
|
|
|
* out for power of 2 sizes
|
|
|
|
*/
|
2010-04-22 18:56:01 +02:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_surface->pow2Width,
|
|
|
|
src_surface->pow2Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
|
|
|
|
0, 0 /* read offsets */,
|
|
|
|
0, 0,
|
|
|
|
fbwidth,
|
|
|
|
fbheight);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
checkGLcall("glReadBuffer(GL_BACK)");
|
2007-11-26 21:28:20 +01:00
|
|
|
|
|
|
|
if(texture_target != GL_TEXTURE_2D) {
|
|
|
|
glDisable(texture_target);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
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
|
|
|
{
|
|
|
|
top = src_surface->currentDesc.Height - src_rect->top;
|
|
|
|
bottom = src_surface->currentDesc.Height - src_rect->bottom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top = src_surface->currentDesc.Height - src_rect->bottom;
|
|
|
|
bottom = src_surface->currentDesc.Height - src_rect->top;
|
2008-04-23 02:48:55 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (src_surface->flags & SFLAG_NORMCOORD)
|
2010-04-22 18:56:01 +02:00
|
|
|
{
|
|
|
|
left /= src_surface->pow2Width;
|
|
|
|
right /= src_surface->pow2Width;
|
|
|
|
top /= src_surface->pow2Height;
|
|
|
|
bottom /= src_surface->pow2Height;
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the source texture stretched and upside down. The correct surface is bound already */
|
2007-11-26 21:28:20 +01:00
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2009-12-13 22:04:00 +01:00
|
|
|
context_set_draw_buffer(context, drawBuffer);
|
2007-03-04 23:47:57 +01:00
|
|
|
glReadBuffer(drawBuffer);
|
|
|
|
|
2007-02-12 19:18:46 +01:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
/* bottom left */
|
|
|
|
glTexCoord2f(left, bottom);
|
2010-10-29 12:25:18 +02:00
|
|
|
glVertex2i(0, 0);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* top left */
|
|
|
|
glTexCoord2f(left, top);
|
2010-10-29 12:25:18 +02:00
|
|
|
glVertex2i(0, dst_rect.bottom - dst_rect.top);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* top right */
|
|
|
|
glTexCoord2f(right, top);
|
2010-10-29 12:25:18 +02:00
|
|
|
glVertex2i(dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* bottom right */
|
|
|
|
glTexCoord2f(right, bottom);
|
2010-10-29 12:25:18 +02:00
|
|
|
glVertex2i(dst_rect.right - dst_rect.left, 0);
|
2007-02-12 19:18:46 +01:00
|
|
|
glEnd();
|
|
|
|
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
|
|
|
{
|
2007-11-26 21:28:20 +01:00
|
|
|
glDisable(texture_target);
|
2010-04-22 18:56:01 +02:00
|
|
|
glEnable(dst_surface->texture_target);
|
|
|
|
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 */
|
2010-04-22 18:56:01 +02:00
|
|
|
glBindTexture(texture_target, dst_surface->texture_name);
|
2007-02-12 19:18:46 +01:00
|
|
|
checkGLcall("glBindTexture");
|
2007-11-26 21:28:20 +01:00
|
|
|
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");
|
|
|
|
|
2007-03-04 23:47:57 +01:00
|
|
|
if(drawBuffer == GL_BACK) {
|
2007-11-26 21:28:20 +01:00
|
|
|
/* Write the back buffer backup back */
|
|
|
|
if(backup) {
|
|
|
|
if(texture_target != GL_TEXTURE_2D) {
|
|
|
|
glDisable(texture_target);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
texture_target = GL_TEXTURE_2D;
|
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D, backup);
|
|
|
|
checkGLcall("glBindTexture(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
|
|
|
{
|
2007-11-26 21:28:20 +01:00
|
|
|
glDisable(texture_target);
|
2010-04-22 18:56:01 +02:00
|
|
|
glEnable(src_surface->texture_target);
|
|
|
|
texture_target = src_surface->texture_target;
|
2007-11-26 21:28:20 +01:00
|
|
|
}
|
2010-04-22 18:56:01 +02:00
|
|
|
glBindTexture(src_surface->texture_target, src_surface->texture_name);
|
|
|
|
checkGLcall("glBindTexture(src_surface->texture_target, src_surface->texture_name)");
|
2007-11-26 21:28:20 +01:00
|
|
|
}
|
|
|
|
|
2007-03-04 23:47:57 +01:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
/* top left */
|
2009-07-07 11:08:01 +02:00
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
2007-03-04 23:47:57 +01:00
|
|
|
glVertex2i(0, fbheight);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-10-29 12:25:18 +02:00
|
|
|
/* bottom left */
|
|
|
|
glTexCoord2f(0.0f, (float)fbheight / (float)src_surface->pow2Height);
|
|
|
|
glVertex2i(0, 0);
|
2007-02-12 19:18:46 +01:00
|
|
|
|
2010-10-29 12:25:18 +02:00
|
|
|
/* bottom right */
|
2010-04-22 18:56:01 +02:00
|
|
|
glTexCoord2f((float)fbwidth / (float)src_surface->pow2Width,
|
|
|
|
(float)fbheight / (float)src_surface->pow2Height);
|
2007-03-04 23:47:57 +01:00
|
|
|
glVertex2i(fbwidth, 0);
|
2010-10-29 12:25:18 +02:00
|
|
|
|
|
|
|
/* top right */
|
|
|
|
glTexCoord2f((float)fbwidth / (float)src_surface->pow2Width, 0.0f);
|
|
|
|
glVertex2i(fbwidth, fbheight);
|
2007-03-04 23:47:57 +01:00
|
|
|
glEnd();
|
|
|
|
}
|
2007-11-26 21:28:20 +01:00
|
|
|
glDisable(texture_target);
|
|
|
|
checkGLcall("glDisable(texture_target)");
|
2007-02-12 19:18:46 +01:00
|
|
|
|
|
|
|
/* Cleanup */
|
2010-04-22 18:56:01 +02:00
|
|
|
if (src != src_surface->texture_name && src != backup)
|
2009-07-10 10:20:13 +02:00
|
|
|
{
|
2007-02-12 19:18:46 +01:00
|
|
|
glDeleteTextures(1, &src);
|
|
|
|
checkGLcall("glDeleteTextures(1, &src)");
|
|
|
|
}
|
2007-03-01 01:42:50 +01:00
|
|
|
if(backup) {
|
|
|
|
glDeleteTextures(1, &backup);
|
|
|
|
checkGLcall("glDeleteTextures(1, &backup)");
|
|
|
|
}
|
2007-11-26 21:43:08 +01:00
|
|
|
|
2007-02-12 19:18:46 +01:00
|
|
|
LEAVE_GL();
|
2010-01-27 20:19:40 +01:00
|
|
|
|
2010-04-13 20:46:26 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* 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
|
|
|
|
|
|
|
/* The texture is now most up to date - If the surface is a render target and has a drawable, this
|
|
|
|
* path is never entered
|
|
|
|
*/
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(dst_surface, SFLAG_INTEXTURE, TRUE);
|
2007-02-12 19:18:46 +01:00
|
|
|
}
|
|
|
|
|
2010-03-31 13:54:57 +02:00
|
|
|
/* Until the blit_shader is ready, define some prototypes here. */
|
|
|
|
static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
|
2010-08-30 20:29:49 +02:00
|
|
|
const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format);
|
2010-03-31 13:54:57 +02: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. */
|
2010-11-01 11:57:57 +01:00
|
|
|
void surface_translate_drawable_coords(IWineD3DSurfaceImpl *surface, HWND window, RECT *rect)
|
2010-05-21 09:35:21 +02:00
|
|
|
{
|
2010-11-01 11:57:57 +01:00
|
|
|
UINT drawable_height;
|
2010-05-21 09:35:21 +02:00
|
|
|
|
2010-11-01 11:57:57 +01:00
|
|
|
if (surface->container.type == WINED3D_CONTAINER_SWAPCHAIN
|
|
|
|
&& surface == surface->container.u.swapchain->front_buffer)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
drawable_height = surface->currentDesc.Height;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect->top = drawable_height - rect->top;
|
|
|
|
rect->bottom = drawable_height - rect->bottom;
|
2010-05-21 09:35:21 +02:00
|
|
|
}
|
|
|
|
|
2010-07-26 12:06:33 +02:00
|
|
|
static BOOL surface_is_full_rect(IWineD3DSurfaceImpl *surface, const RECT *r)
|
|
|
|
{
|
|
|
|
if ((r->left && r->right) || abs(r->right - r->left) != surface->currentDesc.Width)
|
|
|
|
return FALSE;
|
|
|
|
if ((r->top && r->bottom) || abs(r->bottom - r->top) != surface->currentDesc.Height)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* blit between surface locations. onscreen on different swapchains is not supported.
|
|
|
|
* depth / stencil is not supported. */
|
|
|
|
static void surface_blt_fbo(IWineD3DDeviceImpl *device, const WINED3DTEXTUREFILTERTYPE filter,
|
|
|
|
IWineD3DSurfaceImpl *src_surface, DWORD src_location, const RECT *src_rect_in,
|
|
|
|
IWineD3DSurfaceImpl *dst_surface, DWORD dst_location, const RECT *dst_rect_in)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
RECT src_rect, dst_rect;
|
|
|
|
GLenum gl_filter;
|
|
|
|
|
|
|
|
TRACE("device %p, filter %s,\n", device, debug_d3dtexturefiltertype(filter));
|
|
|
|
TRACE("src_surface %p, src_location %s, src_rect %s,\n",
|
|
|
|
src_surface, debug_surflocation(src_location), wine_dbgstr_rect(src_rect_in));
|
|
|
|
TRACE("dst_surface %p, dst_location %s, dst_rect %s.\n",
|
|
|
|
dst_surface, debug_surflocation(dst_location), wine_dbgstr_rect(dst_rect_in));
|
|
|
|
|
|
|
|
src_rect = *src_rect_in;
|
|
|
|
dst_rect = *dst_rect_in;
|
|
|
|
|
|
|
|
switch (filter)
|
|
|
|
{
|
|
|
|
case WINED3DTEXF_LINEAR:
|
|
|
|
gl_filter = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported filter mode %s (%#x).\n", debug_d3dtexturefiltertype(filter), filter);
|
|
|
|
case WINED3DTEXF_NONE:
|
|
|
|
case WINED3DTEXF_POINT:
|
|
|
|
gl_filter = GL_NEAREST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_location == SFLAG_INDRAWABLE && surface_is_offscreen(src_surface))
|
|
|
|
src_location = SFLAG_INTEXTURE;
|
|
|
|
if (dst_location == SFLAG_INDRAWABLE && surface_is_offscreen(dst_surface))
|
|
|
|
dst_location = SFLAG_INTEXTURE;
|
|
|
|
|
|
|
|
/* 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.) */
|
|
|
|
surface_load_location(src_surface, src_location, NULL);
|
|
|
|
if (!surface_is_full_rect(dst_surface, &dst_rect))
|
|
|
|
surface_load_location(dst_surface, dst_location, NULL);
|
|
|
|
|
|
|
|
if (src_location == SFLAG_INDRAWABLE) context = context_acquire(device, src_surface);
|
|
|
|
else if (dst_location == SFLAG_INDRAWABLE) context = context_acquire(device, dst_surface);
|
|
|
|
else context = context_acquire(device, NULL);
|
|
|
|
|
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping blit.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (src_location == SFLAG_INDRAWABLE)
|
|
|
|
{
|
|
|
|
GLenum buffer = surface_get_gl_buffer(src_surface);
|
|
|
|
|
|
|
|
TRACE("Source surface %p is onscreen.\n", src_surface);
|
|
|
|
|
2010-11-01 11:57:57 +01:00
|
|
|
surface_translate_drawable_coords(src_surface, context->win_handle, &src_rect);
|
2010-07-26 12:06:33 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
context_bind_fbo(context, GL_READ_FRAMEBUFFER, NULL);
|
|
|
|
glReadBuffer(buffer);
|
|
|
|
checkGLcall("glReadBuffer()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Source surface %p is offscreen.\n", src_surface);
|
|
|
|
ENTER_GL();
|
|
|
|
context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, src_surface, NULL, src_location);
|
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
|
|
|
checkGLcall("glReadBuffer()");
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
if (dst_location == SFLAG_INDRAWABLE)
|
|
|
|
{
|
|
|
|
GLenum buffer = surface_get_gl_buffer(dst_surface);
|
|
|
|
|
|
|
|
TRACE("Destination surface %p is onscreen.\n", dst_surface);
|
|
|
|
|
2010-11-01 11:57:57 +01:00
|
|
|
surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect);
|
2010-07-26 12:06:33 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
|
|
|
|
context_set_draw_buffer(context, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Destination surface %p is offscreen.\n", dst_surface);
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, dst_surface, NULL, dst_location);
|
|
|
|
context_set_draw_buffer(context, GL_COLOR_ATTACHMENT0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE));
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1));
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2));
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3));
|
|
|
|
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE));
|
|
|
|
|
|
|
|
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()");
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:40:45 +02:00
|
|
|
static void surface_blt_to_drawable(IWineD3DDeviceImpl *device,
|
|
|
|
WINED3DTEXTUREFILTERTYPE filter, BOOL color_key,
|
|
|
|
IWineD3DSurfaceImpl *src_surface, const RECT *src_rect_in,
|
|
|
|
IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect_in)
|
|
|
|
{
|
|
|
|
IWineD3DSwapChainImpl *swapchain = NULL;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
RECT src_rect, dst_rect;
|
|
|
|
|
|
|
|
src_rect = *src_rect_in;
|
|
|
|
dst_rect = *dst_rect_in;
|
|
|
|
|
|
|
|
if (dst_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
|
|
|
swapchain = dst_surface->container.u.swapchain;
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
surface_internal_preload(src_surface, SRGB_RGB);
|
|
|
|
|
|
|
|
/* Activate the destination context, set it up for blitting */
|
|
|
|
context = context_acquire(device, dst_surface);
|
|
|
|
context_apply_blit_state(context, device);
|
|
|
|
|
2010-10-29 12:25:18 +02:00
|
|
|
if (!surface_is_offscreen(dst_surface))
|
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
|
|
|
|
|
|
|
device->blitter->set_shader((IWineD3DDevice *)device, src_surface);
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
if (color_key)
|
|
|
|
{
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
checkGLcall("glEnable(GL_ALPHA_TEST)");
|
|
|
|
|
|
|
|
/* When the primary render target uses P8, 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. */
|
|
|
|
if (primary_render_target_is_p8(device))
|
|
|
|
glAlphaFunc(GL_NOTEQUAL, (float)src_surface->SrcBltCKey.dwColorSpaceLowValue / 256.0f);
|
|
|
|
else
|
|
|
|
glAlphaFunc(GL_NOTEQUAL, 0.0f);
|
|
|
|
checkGLcall("glAlphaFunc");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_textured_quad(src_surface, &src_rect, &dst_rect, filter);
|
|
|
|
|
|
|
|
if (color_key)
|
|
|
|
{
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
|
|
|
}
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
/* Leave the opengl state valid for blitting */
|
|
|
|
device->blitter->unset_shader((IWineD3DDevice *)device);
|
|
|
|
|
|
|
|
if (wined3d_settings.strict_draw_ordering || (swapchain
|
|
|
|
&& (dst_surface == swapchain->front_buffer || swapchain->num_contexts > 1)))
|
|
|
|
wglFlush(); /* Flush to ensure ordering across contexts. */
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-08-29 21:57:43 +02:00
|
|
|
HRESULT surface_color_fill(IWineD3DSurfaceImpl *s, const RECT *rect, const WINED3DCOLORVALUE *color)
|
2010-08-29 21:57:42 +02:00
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *device = s->resource.device;
|
|
|
|
const struct blit_shader *blitter;
|
|
|
|
|
|
|
|
blitter = wined3d_select_blitter(&device->adapter->gl_info, BLIT_OP_COLOR_FILL,
|
2010-08-30 20:29:49 +02:00
|
|
|
NULL, 0, 0, NULL, rect, s->resource.usage, s->resource.pool, s->resource.format);
|
2010-08-29 21:57:42 +02:00
|
|
|
if (!blitter)
|
|
|
|
{
|
|
|
|
FIXME("No blitter is capable of performing the requested color fill operation.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return blitter->color_fill(device, s, rect, color);
|
|
|
|
}
|
|
|
|
|
2006-05-23 00:48:54 +02:00
|
|
|
/* Not called from the VTable */
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-04-26 11:02:35 +02:00
|
|
|
static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *dst_surface, const RECT *DestRect,
|
|
|
|
IWineD3DSurfaceImpl *src_surface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx,
|
2008-11-25 11:57:39 +01:00
|
|
|
WINED3DTEXTUREFILTERTYPE Filter)
|
|
|
|
{
|
2010-04-26 11:02:35 +02:00
|
|
|
IWineD3DDeviceImpl *device = dst_surface->resource.device;
|
2010-08-24 18:43:20 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2007-02-15 03:02:39 +01:00
|
|
|
IWineD3DSwapChainImpl *srcSwapchain = NULL, *dstSwapchain = NULL;
|
2010-03-30 22:18:58 +02:00
|
|
|
RECT dst_rect, src_rect;
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, blt_fx %p, filter %s.\n",
|
|
|
|
dst_surface, wine_dbgstr_rect(DestRect), src_surface, wine_dbgstr_rect(SrcRect),
|
|
|
|
Flags, DDBltFx, debug_d3dtexturefiltertype(Filter));
|
2006-05-23 00:48:54 +02:00
|
|
|
|
|
|
|
/* Get the swapchain. One of the surfaces has to be a primary surface */
|
2010-04-26 11:02:35 +02:00
|
|
|
if (dst_surface->resource.pool == WINED3DPOOL_SYSTEMMEM)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
if (dst_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
|
|
|
dstSwapchain = dst_surface->container.u.swapchain;
|
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
if (src_surface)
|
|
|
|
{
|
|
|
|
if (src_surface->resource.pool == WINED3DPOOL_SYSTEMMEM)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
if (src_surface->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
|
|
|
srcSwapchain = src_surface->container.u.swapchain;
|
2007-02-15 03:02:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Early sort out of cases where no render target is used */
|
2010-04-18 22:50:42 +02:00
|
|
|
if (!dstSwapchain && !srcSwapchain
|
2010-04-26 11:02:35 +02:00
|
|
|
&& src_surface != device->render_targets[0]
|
|
|
|
&& dst_surface != device->render_targets[0])
|
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 */
|
2007-04-14 22:44:55 +02:00
|
|
|
if(Flags & (WINEDDBLT_KEYDEST | WINEDDBLT_KEYDESTOVERRIDE)) {
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
surface_get_rect(dst_surface, DestRect, &dst_rect);
|
|
|
|
if (src_surface) surface_get_rect(src_surface, SrcRect, &src_rect);
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2007-02-15 03:02:39 +01:00
|
|
|
/* The only case where both surfaces on a swapchain are supported is a back buffer -> front buffer blit on the same swapchain */
|
2010-04-26 21:33:01 +02:00
|
|
|
if (dstSwapchain && dstSwapchain == srcSwapchain && dstSwapchain->back_buffers
|
2010-04-26 21:33:00 +02:00
|
|
|
&& dst_surface == dstSwapchain->front_buffer
|
2010-04-26 21:33:01 +02:00
|
|
|
&& src_surface == dstSwapchain->back_buffers[0])
|
2010-04-26 11:02:35 +02:00
|
|
|
{
|
2010-06-24 10:18:34 +02:00
|
|
|
/* Half-Life does a Blt from the back buffer to the front buffer,
|
2007-02-15 03:02:39 +01:00
|
|
|
* Full surface size, no flags... Use present instead
|
2007-04-29 12:48:34 +02:00
|
|
|
*
|
|
|
|
* This path will only be entered for d3d7 and ddraw apps, because d3d8/9 offer no way to blit TO the front buffer
|
2007-02-15 03:02:39 +01:00
|
|
|
*/
|
2006-05-23 00:48:54 +02:00
|
|
|
|
|
|
|
/* Check rects - IWineD3DDevice_Present doesn't handle them */
|
2007-04-29 12:48:34 +02:00
|
|
|
while(1)
|
|
|
|
{
|
2007-05-10 18:51:00 +02:00
|
|
|
TRACE("Looking if a Present can be done...\n");
|
2007-04-29 12:48:34 +02:00
|
|
|
/* Source Rectangle must be full surface */
|
2010-04-26 11:02:35 +02:00
|
|
|
if (src_rect.left || src_rect.top
|
|
|
|
|| src_rect.right != src_surface->currentDesc.Width
|
|
|
|
|| src_rect.bottom != src_surface->currentDesc.Height)
|
|
|
|
{
|
2010-03-30 22:19:02 +02:00
|
|
|
TRACE("No, Source rectangle doesn't match\n");
|
|
|
|
break;
|
2007-04-29 12:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No stretching may occur */
|
2010-03-30 22:19:02 +02:00
|
|
|
if(src_rect.right != dst_rect.right - dst_rect.left ||
|
|
|
|
src_rect.bottom != dst_rect.bottom - dst_rect.top) {
|
2007-04-29 12:48:34 +02:00
|
|
|
TRACE("No, stretching is done\n");
|
|
|
|
break;
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
2007-04-29 12:48:34 +02:00
|
|
|
/* Destination must be full surface or match the clipping rectangle */
|
2010-04-26 11:02:35 +02:00
|
|
|
if (dst_surface->clipper && ((IWineD3DClipperImpl *)dst_surface->clipper)->hWnd)
|
2007-04-29 12:48:34 +02:00
|
|
|
{
|
|
|
|
RECT cliprect;
|
|
|
|
POINT pos[2];
|
2010-04-26 11:02:35 +02:00
|
|
|
GetClientRect(((IWineD3DClipperImpl *)dst_surface->clipper)->hWnd, &cliprect);
|
2010-03-30 22:19:01 +02:00
|
|
|
pos[0].x = dst_rect.left;
|
|
|
|
pos[0].y = dst_rect.top;
|
|
|
|
pos[1].x = dst_rect.right;
|
|
|
|
pos[1].y = dst_rect.bottom;
|
2010-04-26 11:02:35 +02:00
|
|
|
MapWindowPoints(GetDesktopWindow(), ((IWineD3DClipperImpl *)dst_surface->clipper)->hWnd, pos, 2);
|
2007-04-29 12:48:34 +02:00
|
|
|
|
|
|
|
if(pos[0].x != cliprect.left || pos[0].y != cliprect.top ||
|
|
|
|
pos[1].x != cliprect.right || pos[1].y != cliprect.bottom)
|
|
|
|
{
|
|
|
|
TRACE("No, dest rectangle doesn't match(clipper)\n");
|
2010-03-30 22:19:01 +02:00
|
|
|
TRACE("Clip rect at %s\n", wine_dbgstr_rect(&cliprect));
|
|
|
|
TRACE("Blt dest: %s\n", wine_dbgstr_rect(&dst_rect));
|
2007-04-29 12:48:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-26 11:02:35 +02:00
|
|
|
else if (dst_rect.left || dst_rect.top
|
|
|
|
|| dst_rect.right != dst_surface->currentDesc.Width
|
|
|
|
|| dst_rect.bottom != dst_surface->currentDesc.Height)
|
2007-04-29 12:48:34 +02:00
|
|
|
{
|
2010-04-26 11:02:35 +02:00
|
|
|
TRACE("No, dest rectangle doesn't match(surface size)\n");
|
|
|
|
break;
|
2007-04-29 12:48:34 +02:00
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2007-04-29 12:48:34 +02:00
|
|
|
TRACE("Yes\n");
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2007-04-29 12:48:34 +02:00
|
|
|
/* These flags are unimportant for the flag check, remove them */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!(Flags & ~(WINEDDBLT_DONOTWAIT | WINEDDBLT_WAIT)))
|
|
|
|
{
|
2007-04-29 12:48:34 +02:00
|
|
|
WINED3DSWAPEFFECT orig_swap = dstSwapchain->presentParms.SwapEffect;
|
|
|
|
|
|
|
|
/* The idea behind this is that a glReadPixels and a glDrawPixels call
|
|
|
|
* take very long, while a flip is fast.
|
|
|
|
* This applies to Half-Life, which does such Blts every time it finished
|
|
|
|
* a frame, and to Prince of Persia 3D, which uses this to draw at least the main
|
|
|
|
* menu. This is also used by all apps when they do windowed rendering
|
|
|
|
*
|
|
|
|
* The problem is that flipping is not really the same as copying. After a
|
|
|
|
* Blt the front buffer is a copy of the back buffer, and the back buffer is
|
|
|
|
* untouched. Therefore it's necessary to override the swap effect
|
|
|
|
* and to set it back after the flip.
|
|
|
|
*
|
2007-06-06 00:21:08 +02:00
|
|
|
* Windowed Direct3D < 7 apps do the same. The D3D7 sdk demos are nice
|
2007-04-29 12:48:34 +02:00
|
|
|
* testcases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dstSwapchain->presentParms.SwapEffect = WINED3DSWAPEFFECT_COPY;
|
2007-06-03 13:20:27 +02:00
|
|
|
dstSwapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE;
|
2007-04-29 12:48:34 +02:00
|
|
|
|
|
|
|
TRACE("Full screen back buffer -> front buffer blt, performing a flip instead\n");
|
2010-04-06 20:05:16 +02:00
|
|
|
IWineD3DSwapChain_Present((IWineD3DSwapChain *)dstSwapchain,
|
|
|
|
NULL, NULL, dstSwapchain->win_handle, NULL, 0);
|
2007-04-29 12:48:34 +02:00
|
|
|
|
|
|
|
dstSwapchain->presentParms.SwapEffect = orig_swap;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
2007-04-29 12:48:34 +02:00
|
|
|
break;
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
2007-02-15 03:02:39 +01:00
|
|
|
TRACE("Unsupported blit between buffers on the same swapchain\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2007-12-16 00:18:20 +01:00
|
|
|
} else if(dstSwapchain && dstSwapchain == srcSwapchain) {
|
|
|
|
FIXME("Implement hardware blit between two surfaces on the same swapchain\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
} else if(dstSwapchain && srcSwapchain) {
|
|
|
|
FIXME("Implement hardware blit between two different swapchains\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2010-04-18 22:50:42 +02:00
|
|
|
}
|
|
|
|
else if (dstSwapchain)
|
|
|
|
{
|
2010-04-19 20:46:59 +02:00
|
|
|
/* Handled with regular texture -> swapchain blit */
|
2010-04-26 11:02:35 +02:00
|
|
|
if (src_surface == device->render_targets[0])
|
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
|
|
|
}
|
2010-04-26 11:02:35 +02:00
|
|
|
else if (srcSwapchain && dst_surface == device->render_targets[0])
|
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
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
if ((srcSwapchain || src_surface == device->render_targets[0]) && !dstSwapchain)
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
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 */
|
2010-08-30 20:29:49 +02:00
|
|
|
if (src_surface->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| dst_surface->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
|
|
|
|
2007-04-14 22:44:55 +02:00
|
|
|
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
|
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 */
|
|
|
|
}
|
|
|
|
|
2010-03-30 22:18:58 +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;
|
|
|
|
} else {
|
|
|
|
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
|
|
|
*
|
|
|
|
* -> If the app asks for a unscaled, upside down copy, just perform one glCopyTexSubImage2D call
|
|
|
|
* -> If the app wants a image width an unscaled width, copy it line per line
|
|
|
|
* -> If the app wants a image that is scaled on the x axis, and the destination rectangle is smaller
|
|
|
|
* 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
|
|
|
|
* pixel by pixel
|
2007-04-09 01:54:07 +02:00
|
|
|
*
|
|
|
|
* If EXT_framebuffer_blit is supported that can be used instead. Note that EXT_framebuffer_blit implies
|
|
|
|
* FBO support, so it doesn't really make sense to try and make it work with different offscreen rendering
|
|
|
|
* backends.
|
2007-02-15 03:02:39 +01:00
|
|
|
*/
|
2010-08-24 18:43:20 +02:00
|
|
|
if (fbo_blit_supported(gl_info, BLIT_OP_BLIT,
|
2010-08-30 20:29:49 +02:00
|
|
|
&src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format,
|
|
|
|
&dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format))
|
2009-06-05 14:39:20 +02:00
|
|
|
{
|
2010-07-26 12:06:33 +02:00
|
|
|
surface_blt_fbo(device, Filter,
|
|
|
|
src_surface, SFLAG_INDRAWABLE, &src_rect,
|
|
|
|
dst_surface, SFLAG_INDRAWABLE, &dst_rect);
|
|
|
|
surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE);
|
2010-04-20 22:38:43 +02:00
|
|
|
}
|
2010-04-26 11:02:35 +02:00
|
|
|
else if (!stretchx || dst_rect.right - dst_rect.left > src_surface->currentDesc.Width
|
|
|
|
|| dst_rect.bottom - dst_rect.top > src_surface->currentDesc.Height)
|
2010-04-20 22:38:43 +02:00
|
|
|
{
|
2007-02-15 03:02:39 +01:00
|
|
|
TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n");
|
2010-04-26 11:02:35 +02:00
|
|
|
fb_copy_to_texture_direct(dst_surface, src_surface, &src_rect, &dst_rect, Filter);
|
2007-02-15 03:02:39 +01:00
|
|
|
} else {
|
|
|
|
TRACE("Using hardware stretching to flip / stretch the texture\n");
|
2010-04-26 11:02:35 +02:00
|
|
|
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
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(dst_surface->flags & SFLAG_DONOTFREE))
|
2010-04-26 11:02:35 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, dst_surface->resource.heapMemory);
|
|
|
|
dst_surface->resource.allocatedMemory = NULL;
|
|
|
|
dst_surface->resource.heapMemory = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
dst_surface->flags &= ~SFLAG_INSYSMEM;
|
2007-02-15 03:02:39 +01:00
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2007-02-15 03:02:39 +01:00
|
|
|
return WINED3D_OK;
|
2010-04-26 11:02:35 +02:00
|
|
|
}
|
|
|
|
else if (src_surface)
|
|
|
|
{
|
2007-02-15 03:02:39 +01:00
|
|
|
/* Blit from offscreen surface to render target */
|
2010-04-26 11:02:35 +02:00
|
|
|
DWORD oldCKeyFlags = src_surface->CKeyFlags;
|
|
|
|
WINEDDCOLORKEY oldBltCKey = src_surface->SrcBltCKey;
|
2007-02-15 03:02:39 +01:00
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
TRACE("Blt from surface %p to rendertarget %p\n", src_surface, dst_surface);
|
2007-02-15 03:02:39 +01:00
|
|
|
|
2010-03-31 13:54:57 +02:00
|
|
|
if (!(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE))
|
2010-08-24 18:43:20 +02:00
|
|
|
&& fbo_blit_supported(gl_info, BLIT_OP_BLIT,
|
2010-04-26 11:02:35 +02:00
|
|
|
&src_rect, src_surface->resource.usage, src_surface->resource.pool,
|
2010-08-30 20:29:49 +02:00
|
|
|
src_surface->resource.format,
|
2010-04-26 11:02:35 +02:00
|
|
|
&dst_rect, dst_surface->resource.usage, dst_surface->resource.pool,
|
2010-08-30 20:29:49 +02:00
|
|
|
dst_surface->resource.format))
|
2009-06-05 14:39:20 +02:00
|
|
|
{
|
2010-07-26 12:06:33 +02:00
|
|
|
TRACE("Using surface_blt_fbo.\n");
|
2007-12-18 13:52:48 +01:00
|
|
|
/* The source is always a texture, but never the currently active render target, and the texture
|
2010-04-18 22:50:42 +02:00
|
|
|
* contents are never upside down. */
|
2010-07-26 12:06:33 +02:00
|
|
|
surface_blt_fbo(device, Filter,
|
|
|
|
src_surface, SFLAG_INDRAWABLE, &src_rect,
|
|
|
|
dst_surface, SFLAG_INDRAWABLE, &dst_rect);
|
|
|
|
surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE);
|
2007-12-18 13:52:48 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2010-04-08 22:49:51 +02:00
|
|
|
if (!(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE))
|
2010-08-24 18:43:20 +02:00
|
|
|
&& arbfp_blit.blit_supported(gl_info, BLIT_OP_BLIT,
|
2010-04-26 11:02:35 +02:00
|
|
|
&src_rect, src_surface->resource.usage, src_surface->resource.pool,
|
2010-08-30 20:29:49 +02:00
|
|
|
src_surface->resource.format,
|
2010-04-26 11:02:35 +02:00
|
|
|
&dst_rect, dst_surface->resource.usage, dst_surface->resource.pool,
|
2010-08-30 20:29:49 +02:00
|
|
|
dst_surface->resource.format))
|
2010-04-08 22:49:51 +02:00
|
|
|
{
|
2010-04-26 11:02:35 +02:00
|
|
|
return arbfp_blit_surface(device, src_surface, &src_rect, dst_surface, &dst_rect, BLIT_OP_BLIT, Filter);
|
2010-04-08 22:49:51 +02:00
|
|
|
}
|
|
|
|
|
2010-10-21 12:40:44 +02:00
|
|
|
if (!device->blitter->blit_supported(gl_info, BLIT_OP_BLIT,
|
|
|
|
&src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format,
|
|
|
|
&dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format))
|
|
|
|
{
|
|
|
|
FIXME("Unsupported blit operation falling back to software\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2007-02-15 03:02:39 +01:00
|
|
|
/* Color keying: Check if we have to do a color keyed blt,
|
|
|
|
* and if not check if a color key is activated.
|
2007-02-15 03:03:05 +01:00
|
|
|
*
|
|
|
|
* Just modify the color keying parameters in the surface and restore them afterwards
|
|
|
|
* The surface keeps track of the color key last used to load the opengl surface.
|
2007-06-06 00:21:08 +02:00
|
|
|
* PreLoad will catch the change to the flags and color key and reload if necessary.
|
2007-02-15 03:02:39 +01:00
|
|
|
*/
|
2007-04-14 22:44:55 +02:00
|
|
|
if(Flags & WINEDDBLT_KEYSRC) {
|
2007-02-15 03:03:05 +01:00
|
|
|
/* Use color key from surface */
|
2007-04-14 22:44:55 +02:00
|
|
|
} else if(Flags & WINEDDBLT_KEYSRCOVERRIDE) {
|
2007-02-15 03:03:05 +01:00
|
|
|
/* Use color key from DDBltFx */
|
2010-04-26 11:02:35 +02:00
|
|
|
src_surface->CKeyFlags |= WINEDDSD_CKSRCBLT;
|
|
|
|
src_surface->SrcBltCKey = DDBltFx->ddckSrcColorkey;
|
2007-02-15 03:03:05 +01:00
|
|
|
} else {
|
|
|
|
/* Do not use color key */
|
2010-04-26 11:02:35 +02:00
|
|
|
src_surface->CKeyFlags &= ~WINEDDSD_CKSRCBLT;
|
2007-02-15 03:02:39 +01:00
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2010-10-21 12:40:45 +02:00
|
|
|
surface_blt_to_drawable(device, Filter, Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE),
|
|
|
|
src_surface, &src_rect, dst_surface, &dst_rect);
|
2007-02-15 03:04:40 +01:00
|
|
|
|
2007-02-15 03:03:05 +01:00
|
|
|
/* Restore the color key parameters */
|
2010-04-26 11:02:35 +02:00
|
|
|
src_surface->CKeyFlags = oldCKeyFlags;
|
|
|
|
src_surface->SrcBltCKey = oldBltCKey;
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(dst_surface, SFLAG_INDRAWABLE, TRUE);
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2007-02-15 03:02:39 +01:00
|
|
|
return WINED3D_OK;
|
2010-08-23 18:28:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-15 03:02:39 +01:00
|
|
|
/* Source-Less Blit to render target */
|
2010-08-23 18:28:08 +02:00
|
|
|
if (Flags & WINEDDBLT_COLORFILL)
|
|
|
|
{
|
|
|
|
WINED3DCOLORVALUE color;
|
2007-02-15 03:02:39 +01:00
|
|
|
|
|
|
|
TRACE("Colorfill\n");
|
|
|
|
|
2010-08-23 18:28:08 +02:00
|
|
|
/* The color as given in the Blt function is in the surface format. */
|
|
|
|
if (!surface_convert_color_to_float(dst_surface, DDBltFx->u5.dwFillColor, &color))
|
2007-02-15 03:02:39 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2010-08-29 21:57:42 +02:00
|
|
|
return surface_color_fill(dst_surface, &dst_rect, &color);
|
2006-06-24 12:32:18 +02:00
|
|
|
}
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
2007-02-20 15:57:10 +01:00
|
|
|
/* Default: Fall back to the generic blt. Not an error, a TRACE is enough */
|
2007-02-15 03:02:39 +01:00
|
|
|
TRACE("Didn't find any usable render target setup for hw blit, falling back to software\n");
|
2006-04-14 19:15:46 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2008-11-25 11:57:39 +01:00
|
|
|
static HRESULT IWineD3DSurfaceImpl_BltZ(IWineD3DSurfaceImpl *This, const RECT *DestRect,
|
2010-08-15 23:21:43 +02:00
|
|
|
IWineD3DSurface *src_surface, const RECT *src_rect, DWORD Flags, const WINEDDBLTFX *DDBltFx)
|
2007-05-10 21:10:49 +02:00
|
|
|
{
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2007-08-27 22:01:06 +02:00
|
|
|
float depth;
|
|
|
|
|
2010-08-25 20:46:51 +02:00
|
|
|
if (Flags & WINEDDBLT_DEPTHFILL)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
switch (This->resource.format->id)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2009-02-19 16:59:42 +01:00
|
|
|
case WINED3DFMT_D16_UNORM:
|
2007-08-27 22:01:06 +02:00
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x0000ffff;
|
|
|
|
break;
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_S1_UINT_D15_UNORM:
|
2010-08-03 10:13:31 +02:00
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x00007fff;
|
2007-08-27 22:01:06 +02:00
|
|
|
break;
|
2009-10-29 18:56:21 +01:00
|
|
|
case WINED3DFMT_D24_UNORM_S8_UINT:
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_X8D24_UNORM:
|
2007-08-27 22:01:06 +02:00
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x00ffffff;
|
|
|
|
break;
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_D32_UNORM:
|
2007-08-27 22:01:06 +02:00
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0xffffffff;
|
|
|
|
break;
|
|
|
|
default:
|
2009-07-07 11:08:01 +02:00
|
|
|
depth = 0.0f;
|
2010-08-30 20:29:49 +02:00
|
|
|
ERR("Unexpected format for depth fill: %s.\n", debug_d3dformat(This->resource.format->id));
|
2007-08-27 22:01:06 +02:00
|
|
|
}
|
2007-05-10 21:10:49 +02:00
|
|
|
|
2010-08-30 20:29:47 +02:00
|
|
|
return IWineD3DDevice_Clear((IWineD3DDevice *)device, DestRect ? 1 : 0, DestRect,
|
2010-04-18 22:50:42 +02:00
|
|
|
WINED3DCLEAR_ZBUFFER, 0x00000000, depth, 0x00000000);
|
2007-08-27 22:01:06 +02:00
|
|
|
}
|
2007-05-10 21:10:49 +02:00
|
|
|
|
|
|
|
FIXME("(%p): Unsupp depthstencil blit\n", This);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect,
|
|
|
|
IWineD3DSurface *src_surface, const RECT *SrcRect, DWORD Flags,
|
|
|
|
const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter)
|
|
|
|
{
|
2006-05-23 00:48:54 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2010-08-15 23:21:43 +02:00
|
|
|
IWineD3DSurfaceImpl *src = (IWineD3DSurfaceImpl *)src_surface;
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2009-12-09 20:32:08 +01:00
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p, filter %s.\n",
|
|
|
|
iface, wine_dbgstr_rect(DestRect), src_surface, wine_dbgstr_rect(SrcRect),
|
|
|
|
Flags, DDBltFx, debug_d3dtexturefiltertype(Filter));
|
|
|
|
TRACE("Usage is %s.\n", debug_d3dusage(This->resource.usage));
|
2006-05-23 00:48:54 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((This->flags & SFLAG_LOCKED) || (src && (src->flags & SFLAG_LOCKED)))
|
2008-02-15 23:55:36 +01:00
|
|
|
{
|
|
|
|
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
|
|
|
|
return WINEDDERR_SURFACEBUSY;
|
|
|
|
}
|
|
|
|
|
2007-06-08 20:59:57 +02:00
|
|
|
/* Accessing the depth stencil is supposed to fail between a BeginScene and EndScene pair,
|
|
|
|
* except depth blits, which seem to work
|
|
|
|
*/
|
2010-08-15 23:21:43 +02:00
|
|
|
if (This == device->depth_stencil || (src && src == device->depth_stencil))
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
|
|
|
if (device->inScene && !(Flags & WINEDDBLT_DEPTHFILL))
|
|
|
|
{
|
2007-05-10 21:10:49 +02:00
|
|
|
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2010-08-15 23:21:43 +02:00
|
|
|
}
|
|
|
|
else if (SUCCEEDED(IWineD3DSurfaceImpl_BltZ(This, DestRect, src_surface, SrcRect, Flags, DDBltFx)))
|
|
|
|
{
|
2007-05-10 21:10:49 +02:00
|
|
|
TRACE("Z Blit override handled the blit\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2007-02-09 16:35:45 +01:00
|
|
|
}
|
|
|
|
|
2006-05-23 00:48:54 +02:00
|
|
|
/* Special cases for RenderTargets */
|
2010-04-26 11:02:35 +02:00
|
|
|
if ((This->resource.usage & WINED3DUSAGE_RENDERTARGET)
|
2010-08-15 23:21:43 +02:00
|
|
|
|| (src && (src->resource.usage & WINED3DUSAGE_RENDERTARGET)))
|
2010-04-26 11:02:35 +02:00
|
|
|
{
|
2010-08-15 23:21:43 +02:00
|
|
|
if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(This, DestRect, src, SrcRect, Flags, DDBltFx, Filter)))
|
2010-04-26 11:02:35 +02:00
|
|
|
return WINED3D_OK;
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For the rest call the X11 surface implementation.
|
|
|
|
* For RenderTargets this should be implemented OpenGL accelerated in BltOverride,
|
2010-08-15 23:21:43 +02:00
|
|
|
* other Blts are rather rare. */
|
|
|
|
return IWineD3DBaseSurfaceImpl_Blt(iface, DestRect, src_surface, SrcRect, Flags, DDBltFx, Filter);
|
2006-05-23 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 11:57:40 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty,
|
2010-08-15 23:21:43 +02:00
|
|
|
IWineD3DSurface *src_surface, const RECT *rsrc, DWORD trans)
|
2008-11-25 11:57:40 +01:00
|
|
|
{
|
2010-08-15 23:21:43 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
IWineD3DSurfaceImpl *src = (IWineD3DSurfaceImpl *)src_surface;
|
2010-04-18 22:50:42 +02:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2009-12-09 20:32:08 +01:00
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
|
|
|
|
iface, dstx, dsty, src_surface, wine_dbgstr_rect(rsrc), trans);
|
2006-05-26 12:19:28 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((This->flags & SFLAG_LOCKED) || (src->flags & SFLAG_LOCKED))
|
2008-02-15 23:58:38 +01:00
|
|
|
{
|
|
|
|
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
|
|
|
|
return WINEDDERR_SURFACEBUSY;
|
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
if (device->inScene && (This == device->depth_stencil || src == device->depth_stencil))
|
2010-04-18 22:50:42 +02:00
|
|
|
{
|
2007-02-09 16:35:45 +01:00
|
|
|
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2006-05-26 12:19:28 +02:00
|
|
|
/* Special cases for RenderTargets */
|
2010-08-15 23:21:43 +02:00
|
|
|
if ((This->resource.usage & WINED3DUSAGE_RENDERTARGET)
|
|
|
|
|| (src->resource.usage & WINED3DUSAGE_RENDERTARGET))
|
|
|
|
{
|
2006-05-26 12:19:28 +02:00
|
|
|
|
|
|
|
RECT SrcRect, DstRect;
|
2006-07-26 23:19:04 +02:00
|
|
|
DWORD Flags=0;
|
2006-05-26 12:19:28 +02:00
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
surface_get_rect(src, rsrc, &SrcRect);
|
2006-05-26 12:19:28 +02:00
|
|
|
|
|
|
|
DstRect.left = dstx;
|
|
|
|
DstRect.top=dsty;
|
|
|
|
DstRect.right = dstx + SrcRect.right - SrcRect.left;
|
|
|
|
DstRect.bottom = dsty + SrcRect.bottom - SrcRect.top;
|
|
|
|
|
2006-09-28 21:03:22 +02:00
|
|
|
/* Convert BltFast flags into Btl ones because it is called from SurfaceImpl_Blt as well */
|
2007-04-14 22:44:55 +02:00
|
|
|
if(trans & WINEDDBLTFAST_SRCCOLORKEY)
|
|
|
|
Flags |= WINEDDBLT_KEYSRC;
|
|
|
|
if(trans & WINEDDBLTFAST_DESTCOLORKEY)
|
|
|
|
Flags |= WINEDDBLT_KEYDEST;
|
|
|
|
if(trans & WINEDDBLTFAST_WAIT)
|
|
|
|
Flags |= WINEDDBLT_WAIT;
|
|
|
|
if(trans & WINEDDBLTFAST_DONOTWAIT)
|
|
|
|
Flags |= WINEDDBLT_DONOTWAIT;
|
2006-07-26 23:19:04 +02:00
|
|
|
|
2010-04-26 11:02:35 +02:00
|
|
|
if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(This,
|
2010-08-15 23:21:43 +02:00
|
|
|
&DstRect, src, &SrcRect, Flags, NULL, WINED3DTEXF_POINT)))
|
2010-04-26 11:02:35 +02:00
|
|
|
return WINED3D_OK;
|
2006-05-26 12:19:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
return IWineD3DBaseSurfaceImpl_BltFast(iface, dstx, dsty, src_surface, rsrc, trans);
|
2006-04-17 17:25:55 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 11:57:40 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface)
|
|
|
|
{
|
2008-02-18 21:13:13 +01:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
RGBQUAD col[256];
|
|
|
|
IWineD3DPaletteImpl *pal = This->palette;
|
|
|
|
unsigned int n;
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2008-03-25 01:03:59 +01:00
|
|
|
if (!pal) return WINED3D_OK;
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (This->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| This->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
|
2008-02-18 21:13:13 +01:00
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
if (This->resource.usage & WINED3DUSAGE_RENDERTARGET)
|
2008-04-20 16:50:00 +02:00
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
/* Make sure the texture is up to date. This call doesn't do
|
|
|
|
* anything if the texture is already up to date. */
|
|
|
|
surface_load_location(This, SFLAG_INTEXTURE, NULL);
|
2008-04-20 16:50:00 +02:00
|
|
|
|
|
|
|
/* We want to force a palette refresh, so mark the drawable as not being up to date */
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INDRAWABLE, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_INSYSMEM))
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
TRACE("Palette changed with surface that does not have an up to date system memory copy.\n");
|
|
|
|
surface_load_location(This, SFLAG_INSYSMEM, NULL);
|
2008-04-20 16:50:00 +02:00
|
|
|
}
|
|
|
|
TRACE("Dirtifying surface\n");
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This, SFLAG_INSYSMEM, TRUE);
|
2008-02-18 21:13:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DIBSECTION)
|
|
|
|
{
|
2008-02-18 21:13:13 +01:00
|
|
|
TRACE("(%p): Updating the hdc's palette\n", This);
|
|
|
|
for (n=0; n<256; n++) {
|
2008-03-25 01:03:59 +01:00
|
|
|
col[n].rgbRed = pal->palents[n].peRed;
|
|
|
|
col[n].rgbGreen = pal->palents[n].peGreen;
|
|
|
|
col[n].rgbBlue = pal->palents[n].peBlue;
|
2008-02-18 21:13:13 +01:00
|
|
|
col[n].rgbReserved = 0;
|
|
|
|
}
|
|
|
|
SetDIBColorTable(This->hDC, 0, 256, col);
|
|
|
|
}
|
|
|
|
|
2008-04-20 16:50:00 +02:00
|
|
|
/* Propagate the changes to the drawable when we have a palette. */
|
2010-07-21 18:48:22 +02:00
|
|
|
if (This->resource.usage & WINED3DUSAGE_RENDERTARGET)
|
|
|
|
surface_load_location(This, SFLAG_INDRAWABLE, NULL);
|
2008-02-18 21:13:13 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_PrivateSetup(IWineD3DSurface *iface) {
|
2006-05-19 00:13:29 +02:00
|
|
|
/** Check against the maximum texture sizes supported by the video card **/
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2009-12-09 20:32:08 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
|
2007-07-16 20:42:16 +02:00
|
|
|
unsigned int pow2Width, pow2Height;
|
2007-07-27 13:22:54 +02:00
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
This->texture_name = 0;
|
|
|
|
This->texture_target = GL_TEXTURE_2D;
|
2007-07-16 20:42:16 +02:00
|
|
|
|
|
|
|
/* Non-power2 support */
|
2010-07-20 18:51:54 +02:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2007-07-16 20:42:16 +02:00
|
|
|
pow2Width = This->currentDesc.Width;
|
|
|
|
pow2Height = This->currentDesc.Height;
|
2009-10-29 10:37:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-16 20:42:16 +02:00
|
|
|
/* Find the nearest pow2 match */
|
|
|
|
pow2Width = pow2Height = 1;
|
|
|
|
while (pow2Width < This->currentDesc.Width) pow2Width <<= 1;
|
|
|
|
while (pow2Height < This->currentDesc.Height) pow2Height <<= 1;
|
|
|
|
}
|
|
|
|
This->pow2Width = pow2Width;
|
|
|
|
This->pow2Height = pow2Height;
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (pow2Width > This->currentDesc.Width || pow2Height > This->currentDesc.Height)
|
|
|
|
{
|
|
|
|
/* TODO: Add support for non power two compressed textures. */
|
2010-11-12 13:12:05 +01:00
|
|
|
if (This->resource.format->flags & WINED3DFMT_FLAG_COMPRESSED)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2007-07-16 20:42:16 +02:00
|
|
|
FIXME("(%p) Compressed non-power-two textures are not supported w(%d) h(%d)\n",
|
|
|
|
This, This->currentDesc.Width, This->currentDesc.Height);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (pow2Width != This->currentDesc.Width
|
|
|
|
|| pow2Height != This->currentDesc.Height)
|
|
|
|
{
|
|
|
|
This->flags |= SFLAG_NONPOW2;
|
2007-07-16 20:42:16 +02:00
|
|
|
}
|
2006-05-19 00:13:29 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", This);
|
2009-10-29 10:37:10 +01:00
|
|
|
if ((This->pow2Width > gl_info->limits.texture_size || This->pow2Height > gl_info->limits.texture_size)
|
2009-10-22 10:09:54 +02:00
|
|
|
&& !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
|
|
|
|
{
|
2006-05-19 00:13:29 +02:00
|
|
|
/* one of three options
|
|
|
|
1: Do the same as we do with nonpow 2 and scale the texture, (any texture ops would require the texture to be scaled which is potentially slow)
|
2007-06-06 00:21:08 +02:00
|
|
|
2: Set the texture to the maximum size (bad idea)
|
2006-05-19 00:13:29 +02:00
|
|
|
3: WARN and return WINED3DERR_NOTAVAILABLE;
|
|
|
|
4: Create the surface, but allow it to be used only for DirectDraw Blts. Some apps(e.g. Swat 3) create textures with a Height of 16 and a Width > 3000 and blt 16x16 letter areas from them to the render target.
|
|
|
|
*/
|
2010-03-11 15:03:50 +01:00
|
|
|
if(This->resource.pool == WINED3DPOOL_DEFAULT || This->resource.pool == WINED3DPOOL_MANAGED)
|
|
|
|
{
|
|
|
|
WARN("(%p) Unable to allocate a surface which exceeds the maximum OpenGL texture size\n", This);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We should never use this surface in combination with OpenGL! */
|
|
|
|
TRACE("(%p) Creating an oversized surface: %ux%u\n", This, This->pow2Width, This->pow2Height);
|
2010-04-15 19:21:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-11 15:03:50 +01:00
|
|
|
/* Don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
|
2008-01-21 22:29:03 +01:00
|
|
|
is used in combination with texture uploads (RTL_READTEX/RTL_TEXTEX). The reason is that EXT_PALETTED_TEXTURE
|
|
|
|
doesn't work in combination with ARB_TEXTURE_RECTANGLE.
|
|
|
|
*/
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_NONPOW2 && gl_info->supported[ARB_TEXTURE_RECTANGLE]
|
2010-08-30 20:29:49 +02:00
|
|
|
&& !(This->resource.format->id == WINED3DFMT_P8_UINT
|
2009-10-29 10:37:11 +01:00
|
|
|
&& gl_info->supported[EXT_PALETTED_TEXTURE]
|
2009-09-25 13:31:49 +02:00
|
|
|
&& wined3d_settings.rendertargetlock_mode == RTL_READTEX))
|
2008-01-21 22:29:03 +01:00
|
|
|
{
|
2009-07-10 10:20:13 +02:00
|
|
|
This->texture_target = GL_TEXTURE_RECTANGLE_ARB;
|
2007-11-28 20:35:04 +01:00
|
|
|
This->pow2Width = This->currentDesc.Width;
|
|
|
|
This->pow2Height = This->currentDesc.Height;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~(SFLAG_NONPOW2 | SFLAG_NORMCOORD);
|
2007-11-28 20:35:04 +01:00
|
|
|
}
|
2006-05-19 00:13:29 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 10:13:33 +02:00
|
|
|
switch (wined3d_settings.offscreen_rendering_mode)
|
|
|
|
{
|
|
|
|
case ORM_FBO:
|
|
|
|
This->get_drawable_size = get_drawable_size_fbo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ORM_BACKBUFFER:
|
|
|
|
This->get_drawable_size = get_drawable_size_backbuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Unhandled offscreen rendering mode %#x.\n", wined3d_settings.offscreen_rendering_mode);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2007-11-30 20:22:33 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_INSYSMEM;
|
2007-07-08 23:33:48 +02:00
|
|
|
|
2006-04-17 17:25:55 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-03-17 21:59:50 +01:00
|
|
|
static void surface_depth_blt(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
|
|
|
|
GLuint texture, GLsizei w, GLsizei h, GLenum target)
|
2008-10-27 18:31:31 +01:00
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->resource.device;
|
2010-05-17 11:14:48 +02:00
|
|
|
GLint compare_mode = GL_NONE;
|
2010-03-05 19:52:01 +01:00
|
|
|
struct blt_info info;
|
2008-10-27 18:31:31 +01:00
|
|
|
GLint old_binding = 0;
|
2010-10-19 12:00:00 +02:00
|
|
|
RECT rect;
|
2008-10-27 18:31:31 +01:00
|
|
|
|
|
|
|
glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
|
|
|
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
2009-07-03 09:39:21 +02:00
|
|
|
glDisable(GL_BLEND);
|
2008-10-27 18:31:31 +01:00
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_ALWAYS);
|
|
|
|
glDepthMask(GL_TRUE);
|
2009-07-03 09:39:21 +02:00
|
|
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
2008-10-27 18:31:31 +01:00
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
|
2010-10-19 12:00:00 +02:00
|
|
|
SetRect(&rect, 0, h, w, 0);
|
|
|
|
surface_get_blt_info(target, &rect, w, h, &info);
|
2008-10-27 18:31:31 +01:00
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
|
2008-10-28 21:25:06 +01:00
|
|
|
glGetIntegerv(info.binding, &old_binding);
|
|
|
|
glBindTexture(info.bind_target, texture);
|
2010-05-17 11:14:48 +02:00
|
|
|
if (gl_info->supported[ARB_SHADOW])
|
|
|
|
{
|
|
|
|
glGetTexParameteriv(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, &compare_mode);
|
|
|
|
if (compare_mode != GL_NONE) glTexParameteri(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
|
|
|
|
}
|
2008-10-27 18:31:31 +01:00
|
|
|
|
2010-04-29 00:08:59 +02:00
|
|
|
device->shader_backend->shader_select_depth_blt((IWineD3DDevice *)device,
|
|
|
|
info.tex_type, &This->ds_current_size);
|
2008-10-27 18:31:31 +01:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
2008-10-28 21:25:06 +01:00
|
|
|
glTexCoord3fv(info.coords[0]);
|
2008-10-27 18:31:31 +01:00
|
|
|
glVertex2f(-1.0f, -1.0f);
|
2008-10-28 21:25:06 +01:00
|
|
|
glTexCoord3fv(info.coords[1]);
|
2008-10-27 18:31:31 +01:00
|
|
|
glVertex2f(1.0f, -1.0f);
|
2008-10-28 21:25:06 +01:00
|
|
|
glTexCoord3fv(info.coords[2]);
|
2008-10-27 18:31:31 +01:00
|
|
|
glVertex2f(-1.0f, 1.0f);
|
2008-10-28 21:25:06 +01:00
|
|
|
glTexCoord3fv(info.coords[3]);
|
2008-10-27 18:31:31 +01:00
|
|
|
glVertex2f(1.0f, 1.0f);
|
|
|
|
glEnd();
|
|
|
|
|
2010-05-17 11:14:48 +02:00
|
|
|
if (compare_mode != GL_NONE) glTexParameteri(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, compare_mode);
|
2008-10-28 21:25:06 +01:00
|
|
|
glBindTexture(info.bind_target, old_binding);
|
2008-10-27 18:31:31 +01:00
|
|
|
|
|
|
|
glPopAttrib();
|
|
|
|
|
|
|
|
device->shader_backend->shader_deselect_depth_blt((IWineD3DDevice *)device);
|
|
|
|
}
|
|
|
|
|
2010-04-29 00:08:59 +02:00
|
|
|
void surface_modify_ds_location(IWineD3DSurfaceImpl *surface,
|
|
|
|
DWORD location, UINT w, UINT h)
|
2010-04-18 22:50:44 +02:00
|
|
|
{
|
2010-04-29 00:08:59 +02:00
|
|
|
TRACE("surface %p, new location %#x, w %u, h %u.\n", surface, location, w, h);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-18 22:50:44 +02:00
|
|
|
if (location & ~SFLAG_DS_LOCATIONS)
|
|
|
|
FIXME("Invalid location (%#x) specified.\n", location);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-29 00:08:59 +02:00
|
|
|
surface->ds_current_size.cx = w;
|
|
|
|
surface->ds_current_size.cy = h;
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~SFLAG_DS_LOCATIONS;
|
|
|
|
surface->flags |= location;
|
2008-07-02 23:00:41 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-04-18 22:50:43 +02:00
|
|
|
void surface_load_ds_location(IWineD3DSurfaceImpl *surface, struct wined3d_context *context, DWORD location)
|
2009-07-24 10:44:16 +02:00
|
|
|
{
|
2010-04-18 22:50:43 +02:00
|
|
|
IWineD3DDeviceImpl *device = surface->resource.device;
|
2009-09-23 10:05:55 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-18 22:50:43 +02:00
|
|
|
TRACE("surface %p, new location %#x.\n", surface, location);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
|
|
|
/* TODO: Make this work for modes other than FBO */
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return;
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(surface->flags & location))
|
2010-04-29 00:08:59 +02:00
|
|
|
{
|
|
|
|
surface->ds_current_size.cx = 0;
|
|
|
|
surface->ds_current_size.cy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface->ds_current_size.cx == surface->currentDesc.Width
|
|
|
|
&& surface->ds_current_size.cy == surface->currentDesc.Height)
|
2010-04-18 22:50:43 +02:00
|
|
|
{
|
|
|
|
TRACE("Location (%#x) is already up to date.\n", location);
|
2008-07-02 23:00:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-18 22:50:43 +02:00
|
|
|
if (surface->current_renderbuffer)
|
|
|
|
{
|
|
|
|
FIXME("Not supported with fixed up depth stencil.\n");
|
2008-07-02 23:00:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(surface->flags & SFLAG_LOCATIONS))
|
2010-04-28 00:08:52 +02:00
|
|
|
{
|
|
|
|
FIXME("No up to date depth stencil location.\n");
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= location;
|
2010-04-28 00:08:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-18 22:50:43 +02:00
|
|
|
if (location == SFLAG_DS_OFFSCREEN)
|
|
|
|
{
|
2010-04-28 00:08:52 +02:00
|
|
|
GLint old_binding = 0;
|
|
|
|
GLenum bind_target;
|
2010-09-05 23:38:50 +02:00
|
|
|
GLsizei w, h;
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
w = min(surface->currentDesc.Width, context->swapchain->presentParms.BackBufferWidth);
|
|
|
|
h = min(surface->currentDesc.Height, context->swapchain->presentParms.BackBufferHeight);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
TRACE("Copying onscreen depth buffer to depth texture.\n");
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
ENTER_GL();
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
if (!device->depth_blt_texture)
|
|
|
|
{
|
|
|
|
glGenTextures(1, &device->depth_blt_texture);
|
|
|
|
}
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +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. */
|
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
|
|
|
|
if (surface->texture_target == GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
|
|
|
|
bind_target = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
|
|
|
|
bind_target = GL_TEXTURE_2D;
|
|
|
|
}
|
|
|
|
glBindTexture(bind_target, device->depth_blt_texture);
|
2010-09-05 23:38:50 +02:00
|
|
|
glCopyTexImage2D(bind_target, surface->texture_level, surface->resource.format->glInternal, 0, 0, w, h, 0);
|
2010-04-28 00:08:52 +02:00
|
|
|
glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(bind_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(bind_target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
|
|
|
|
glBindTexture(bind_target, old_binding);
|
|
|
|
|
|
|
|
/* Setup the destination */
|
|
|
|
if (!device->depth_blt_rb)
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glGenRenderbuffers(1, &device->depth_blt_rb);
|
|
|
|
checkGLcall("glGenRenderbuffersEXT");
|
|
|
|
}
|
2010-09-05 23:38:50 +02:00
|
|
|
if (device->depth_blt_rb_w != w || device->depth_blt_rb_h != h)
|
2010-04-28 00:08:52 +02:00
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, device->depth_blt_rb);
|
|
|
|
checkGLcall("glBindRenderbufferEXT");
|
2010-09-05 23:38:50 +02:00
|
|
|
gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
|
2010-04-28 00:08:52 +02:00
|
|
|
checkGLcall("glRenderbufferStorageEXT");
|
2010-09-05 23:38:50 +02:00
|
|
|
device->depth_blt_rb_w = w;
|
|
|
|
device->depth_blt_rb_h = h;
|
2010-04-28 00:08:52 +02:00
|
|
|
}
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
|
|
|
|
gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
|
|
|
|
GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, device->depth_blt_rb);
|
|
|
|
checkGLcall("glFramebufferRenderbufferEXT");
|
|
|
|
context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, surface, FALSE);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
/* Do the actual blit */
|
2010-09-05 23:38:50 +02:00
|
|
|
surface_depth_blt(surface, gl_info, device->depth_blt_texture, w, h, bind_target);
|
2010-04-28 00:08:52 +02:00
|
|
|
checkGLcall("depth_blt");
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
|
|
|
|
else context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
LEAVE_GL();
|
2010-01-27 20:19:40 +01:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
|
2010-04-18 22:50:43 +02:00
|
|
|
}
|
|
|
|
else if (location == SFLAG_DS_ONSCREEN)
|
|
|
|
{
|
2010-04-28 00:08:52 +02:00
|
|
|
TRACE("Copying depth texture to onscreen depth buffer.\n");
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
ENTER_GL();
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
|
|
|
|
surface_depth_blt(surface, gl_info, surface->texture_name,
|
|
|
|
surface->currentDesc.Width, surface->currentDesc.Height, surface->texture_target);
|
|
|
|
checkGLcall("depth_blt");
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
LEAVE_GL();
|
2010-01-27 20:19:40 +01:00
|
|
|
|
2010-04-28 00:08:52 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
|
2010-04-18 22:50:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Invalid location (%#x) specified.\n", location);
|
2008-07-02 23:00:41 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= location;
|
2010-04-29 00:08:59 +02:00
|
|
|
surface->ds_current_size.cx = surface->currentDesc.Width;
|
|
|
|
surface->ds_current_size.cy = surface->currentDesc.Height;
|
2008-07-02 23:00:41 +02:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
void surface_modify_location(IWineD3DSurfaceImpl *surface, DWORD flag, BOOL persistent)
|
|
|
|
{
|
2008-08-20 17:48:14 +02:00
|
|
|
IWineD3DSurfaceImpl *overlay;
|
2007-10-09 22:17:59 +02:00
|
|
|
|
2010-08-15 23:21:49 +02:00
|
|
|
TRACE("surface %p, location %s, persistent %#x.\n",
|
2010-07-21 18:48:21 +02:00
|
|
|
surface, debug_surflocation(flag), persistent);
|
2007-10-09 22:17:59 +02:00
|
|
|
|
2010-04-18 22:50:45 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2010-07-21 18:48:21 +02:00
|
|
|
if (surface_is_offscreen(surface))
|
2009-03-25 10:12:27 +01:00
|
|
|
{
|
2008-01-02 19:53:13 +01:00
|
|
|
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
|
|
|
|
if (flag & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) flag |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
|
|
|
|
}
|
2009-12-06 15:45:46 +01:00
|
|
|
else
|
|
|
|
{
|
2010-07-21 18:48:21 +02:00
|
|
|
TRACE("Surface %p is an onscreen surface.\n", surface);
|
2009-12-06 15:45:46 +01:00
|
|
|
}
|
2008-01-02 19:53:13 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
if (persistent)
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if (((surface->flags & SFLAG_INTEXTURE) && !(flag & SFLAG_INTEXTURE))
|
|
|
|
|| ((surface->flags & SFLAG_INSRGBTEX) && !(flag & SFLAG_INSRGBTEX)))
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
if (surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
|
|
|
TRACE("Passing to container.\n");
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DBaseTexture_SetDirty((IWineD3DBaseTexture *)surface->container.u.texture, TRUE);
|
2007-11-03 16:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~SFLAG_LOCATIONS;
|
|
|
|
surface->flags |= flag;
|
2008-08-20 17:48:14 +02:00
|
|
|
|
|
|
|
/* Redraw emulated overlays, if any */
|
2010-07-21 18:48:21 +02:00
|
|
|
if (flag & SFLAG_INDRAWABLE && !list_empty(&surface->overlays))
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY(overlay, &surface->overlays, IWineD3DSurfaceImpl, overlay_entry)
|
|
|
|
{
|
|
|
|
IWineD3DSurface_DrawOverlay((IWineD3DSurface *)overlay);
|
2008-08-20 17:48:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-21 18:48:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) && (flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)))
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
if (surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
2007-11-03 16:41:13 +01:00
|
|
|
TRACE("Passing to container\n");
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DBaseTexture_SetDirty((IWineD3DBaseTexture *)surface->container.u.texture, TRUE);
|
2007-11-03 16:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~flag;
|
2007-10-09 22:17:59 +02:00
|
|
|
}
|
2009-01-16 16:22:09 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(surface->flags & SFLAG_LOCATIONS))
|
2010-07-21 18:48:21 +02:00
|
|
|
{
|
|
|
|
ERR("Surface %p does not have any up to date location.\n", surface);
|
2009-01-16 16:22:09 +01:00
|
|
|
}
|
2007-10-09 22:17:59 +02:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
HRESULT surface_load_location(IWineD3DSurfaceImpl *surface, DWORD flag, const RECT *rect)
|
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *device = surface->resource.device;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-07-21 18:48:22 +02:00
|
|
|
BOOL drawable_read_ok = surface_is_offscreen(surface);
|
2010-08-30 20:29:49 +02:00
|
|
|
struct wined3d_format format;
|
2007-10-13 12:54:10 +02:00
|
|
|
CONVERT_TYPES convert;
|
|
|
|
int width, pitch, outpitch;
|
|
|
|
BYTE *mem;
|
2009-12-06 15:45:46 +01:00
|
|
|
BOOL in_fbo = FALSE;
|
2007-09-25 00:16:05 +02:00
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
TRACE("surface %p, location %s, rect %s.\n", surface, debug_surflocation(flag), wine_dbgstr_rect(rect));
|
|
|
|
|
|
|
|
if (surface->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
2010-05-17 11:14:45 +02:00
|
|
|
{
|
|
|
|
if (flag == SFLAG_INTEXTURE)
|
|
|
|
{
|
|
|
|
struct wined3d_context *context = context_acquire(device, NULL);
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_ds_location(surface, context, SFLAG_DS_OFFSCREEN);
|
2010-05-17 11:14:45 +02:00
|
|
|
context_release(context);
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-30 20:29:46 +02:00
|
|
|
FIXME("Unimplemented location %s for depth/stencil buffers.\n", debug_surflocation(flag));
|
2010-05-17 11:14:45 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-18 22:50:45 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
if (surface_is_offscreen(surface))
|
2009-03-25 10:12:27 +01:00
|
|
|
{
|
2008-01-02 19:53:13 +01:00
|
|
|
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets.
|
|
|
|
* Prefer SFLAG_INTEXTURE. */
|
|
|
|
if (flag == SFLAG_INDRAWABLE) flag = SFLAG_INTEXTURE;
|
2009-01-16 16:22:09 +01:00
|
|
|
drawable_read_ok = FALSE;
|
2009-12-06 15:45:46 +01:00
|
|
|
in_fbo = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
TRACE("Surface %p is an onscreen surface.\n", surface);
|
2008-01-02 19:53:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (surface->flags & flag)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2007-09-25 00:02:14 +02:00
|
|
|
TRACE("Location already up to date\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(surface->flags & SFLAG_LOCATIONS))
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
|
|
|
ERR("Surface %p does not have any up to date location.\n", surface);
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= SFLAG_LOST;
|
2007-09-25 00:02:14 +02:00
|
|
|
return WINED3DERR_DEVICELOST;
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
if (flag == SFLAG_INSYSMEM)
|
|
|
|
{
|
|
|
|
surface_prepare_system_memory(surface);
|
2007-11-01 01:31:01 +01:00
|
|
|
|
2007-09-25 00:02:14 +02:00
|
|
|
/* Download the surface to system memory */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (surface->flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context = NULL;
|
2008-01-02 19:52:56 +01:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
if (!device->isInDraw) context = context_acquire(device, NULL);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
surface_bind_and_dirtify(surface, !(surface->flags & SFLAG_INTEXTURE));
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_download_data(surface, gl_info);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
if (context) context_release(context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-18 09:04:05 +02:00
|
|
|
/* Note: It might be faster to download into a texture first. */
|
2010-07-21 18:48:22 +02:00
|
|
|
read_from_framebuffer(surface, rect, surface->resource.allocatedMemory,
|
|
|
|
IWineD3DSurface_GetPitch((IWineD3DSurface *)surface));
|
2007-09-25 00:02:14 +02:00
|
|
|
}
|
2010-07-21 18:48:22 +02:00
|
|
|
}
|
|
|
|
else if (flag == SFLAG_INDRAWABLE)
|
|
|
|
{
|
2010-11-11 12:39:18 +01:00
|
|
|
if (wined3d_settings.rendertargetlock_mode == RTL_READTEX)
|
|
|
|
surface_load_location(surface, SFLAG_INTEXTURE, NULL);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (surface->flags & SFLAG_INTEXTURE)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2010-10-21 12:40:45 +02:00
|
|
|
RECT r;
|
|
|
|
|
|
|
|
surface_get_rect(surface, rect, &r);
|
|
|
|
surface_blt_to_drawable(device, WINED3DTEXF_POINT, FALSE, surface, &r, surface, &r);
|
2010-07-21 18:48:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-08 22:49:45 +02:00
|
|
|
int byte_count;
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((surface->flags & SFLAG_LOCATIONS) == SFLAG_INSRGBTEX)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2009-01-16 16:22:09 +01:00
|
|
|
/* This needs a shader to convert the srgb data sampled from the GL texture into RGB
|
|
|
|
* values, otherwise we get incorrect values in the target. For now go the slow way
|
|
|
|
* via a system memory copy
|
|
|
|
*/
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(surface, SFLAG_INSYSMEM, rect);
|
2009-01-16 16:22:09 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
d3dfmt_get_conv(surface, FALSE /* We need color keying */,
|
2010-08-30 20:29:49 +02:00
|
|
|
FALSE /* We won't use textures */, &format, &convert);
|
2008-01-07 21:18:34 +01:00
|
|
|
|
|
|
|
/* The width is in 'length' not in bytes */
|
2010-07-21 18:48:22 +02:00
|
|
|
width = surface->currentDesc.Width;
|
|
|
|
pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *)surface);
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2008-04-06 01:54:26 +02:00
|
|
|
/* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
|
|
|
|
* but it isn't set (yet) in all cases it is getting called. */
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((convert != NO_CONVERSION) && (surface->flags & SFLAG_PBO))
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
TRACE("Removing the pbo attached to surface %p.\n", surface);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
if (!device->isInDraw) context = context_acquire(device, NULL);
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_remove_pbo(surface, gl_info);
|
2009-10-28 11:00:11 +01:00
|
|
|
if (context) context_release(context);
|
2008-04-06 01:54:26 +02:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
if ((convert != NO_CONVERSION) && surface->resource.allocatedMemory)
|
|
|
|
{
|
|
|
|
int height = surface->currentDesc.Height;
|
2010-08-30 20:29:49 +02:00
|
|
|
byte_count = format.conv_byte_count;
|
2008-01-07 21:18:34 +01:00
|
|
|
|
|
|
|
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
|
2010-04-08 22:49:45 +02:00
|
|
|
outpitch = width * byte_count;
|
2008-01-07 21:18:34 +01:00
|
|
|
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
|
|
|
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
|
|
|
|
if(!mem) {
|
|
|
|
ERR("Out of memory %d, %d!\n", outpitch, height);
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
2010-07-21 18:48:22 +02:00
|
|
|
d3dfmt_convert_surface(surface->resource.allocatedMemory, mem, pitch,
|
|
|
|
width, height, outpitch, convert, surface);
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= SFLAG_CONVERTED;
|
2010-07-21 18:48:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~SFLAG_CONVERTED;
|
2010-07-21 18:48:22 +02:00
|
|
|
mem = surface->resource.allocatedMemory;
|
2010-08-30 20:29:49 +02:00
|
|
|
byte_count = format.byte_count;
|
2008-01-07 21:18:34 +01:00
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
flush_to_framebuffer_drawpixels(surface, format.glFormat, format.glType, byte_count, mem);
|
2008-01-07 21:18:34 +01:00
|
|
|
|
|
|
|
/* Don't delete PBO memory */
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((mem != surface->resource.allocatedMemory) && !(surface->flags & SFLAG_PBO))
|
2008-01-07 21:18:34 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2007-09-25 00:02:14 +02:00
|
|
|
}
|
2010-07-21 18:48:22 +02:00
|
|
|
}
|
|
|
|
else /* if(flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) */
|
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
const DWORD attach_flags = WINED3DFMT_FLAG_FBO_ATTACHABLE | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (drawable_read_ok && (surface->flags & SFLAG_INDRAWABLE))
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
|
|
|
read_from_framebuffer_texture(surface, flag == SFLAG_INSRGBTEX);
|
2009-10-28 11:00:11 +01:00
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
else if (surface->flags & (SFLAG_INSRGBTEX | SFLAG_INTEXTURE)
|
2010-11-12 13:12:05 +01:00
|
|
|
&& (surface->resource.format->flags & attach_flags) == attach_flags
|
2010-07-26 12:06:32 +02:00
|
|
|
&& fbo_blit_supported(gl_info, BLIT_OP_BLIT,
|
2010-08-30 20:29:49 +02:00
|
|
|
NULL, surface->resource.usage, surface->resource.pool, surface->resource.format,
|
|
|
|
NULL, surface->resource.usage, surface->resource.pool, surface->resource.format))
|
2010-07-26 12:06:32 +02:00
|
|
|
{
|
2010-07-26 12:06:33 +02:00
|
|
|
DWORD src_location = flag == SFLAG_INSRGBTEX ? SFLAG_INTEXTURE : SFLAG_INSRGBTEX;
|
|
|
|
RECT rect = {0, 0, surface->currentDesc.Width, surface->currentDesc.Height};
|
|
|
|
|
|
|
|
surface_blt_fbo(surface->resource.device, WINED3DTEXF_POINT,
|
|
|
|
surface, src_location, &rect, surface, flag, &rect);
|
2010-07-26 12:06:32 +02:00
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Upload from system memory */
|
2009-01-16 16:22:09 +01:00
|
|
|
BOOL srgb = flag == SFLAG_INSRGBTEX;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
d3dfmt_get_conv(surface, TRUE /* We need color keying */,
|
2010-08-30 20:29:49 +02:00
|
|
|
TRUE /* We will use textures */, &format, &convert);
|
2009-01-16 16:22:09 +01:00
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
if (srgb)
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((surface->flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)) == SFLAG_INTEXTURE)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
|
|
|
/* Performance warning... */
|
|
|
|
FIXME("Downloading RGB surface %p to reload it as sRGB.\n", surface);
|
|
|
|
surface_load_location(surface, SFLAG_INSYSMEM, rect);
|
2009-01-16 16:22:09 +01:00
|
|
|
}
|
2010-07-21 18:48:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((surface->flags & (SFLAG_INSRGBTEX | SFLAG_INSYSMEM)) == SFLAG_INSRGBTEX)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
|
|
|
/* Performance warning... */
|
|
|
|
FIXME("Downloading sRGB surface %p to reload it as RGB.\n", surface);
|
|
|
|
surface_load_location(surface, SFLAG_INSYSMEM, rect);
|
2009-01-16 16:22:09 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(surface->flags & SFLAG_INSYSMEM))
|
2010-06-22 12:49:07 +02:00
|
|
|
{
|
|
|
|
WARN("Trying to load a texture from sysmem, but SFLAG_INSYSMEM is not set.\n");
|
2009-09-07 11:37:38 +02:00
|
|
|
/* Lets hope we get it from somewhere... */
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(surface, SFLAG_INSYSMEM, rect);
|
2009-09-07 11:37:38 +02:00
|
|
|
}
|
2007-10-13 12:54:10 +02:00
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
if (!device->isInDraw) context = context_acquire(device, NULL);
|
2010-02-03 18:17:57 +01:00
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_prepare_texture(surface, gl_info, srgb);
|
|
|
|
surface_bind_and_dirtify(surface, srgb);
|
2007-10-13 12:54:10 +02:00
|
|
|
|
2010-07-21 18:48:22 +02:00
|
|
|
if (surface->CKeyFlags & WINEDDSD_CKSRCBLT)
|
|
|
|
{
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= SFLAG_GLCKEY;
|
2010-07-21 18:48:22 +02:00
|
|
|
surface->glCKey = surface->SrcBltCKey;
|
2007-10-13 12:54:10 +02:00
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
else surface->flags &= ~SFLAG_GLCKEY;
|
2007-10-13 12:54:10 +02:00
|
|
|
|
|
|
|
/* The width is in 'length' not in bytes */
|
2010-07-21 18:48:22 +02:00
|
|
|
width = surface->currentDesc.Width;
|
|
|
|
pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *)surface);
|
2007-10-13 12:54:10 +02:00
|
|
|
|
2008-04-06 01:54:26 +02:00
|
|
|
/* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
|
|
|
|
* but it isn't set (yet) in all cases it is getting called. */
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((convert != NO_CONVERSION || format.convert) && (surface->flags & SFLAG_PBO))
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
|
|
|
TRACE("Removing the pbo attached to surface %p.\n", surface);
|
|
|
|
surface_remove_pbo(surface, gl_info);
|
2008-04-06 01:54:26 +02:00
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (format.convert)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2010-04-08 22:49:47 +02:00
|
|
|
/* This code is entered for texture formats which need a fixup. */
|
2010-07-21 18:48:22 +02:00
|
|
|
int height = surface->currentDesc.Height;
|
2010-04-08 22:49:47 +02:00
|
|
|
|
|
|
|
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
|
2010-08-30 20:29:49 +02:00
|
|
|
outpitch = width * format.conv_byte_count;
|
2010-04-08 22:49:47 +02:00
|
|
|
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
|
|
|
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
|
|
|
|
if(!mem) {
|
|
|
|
ERR("Out of memory %d, %d!\n", outpitch, height);
|
|
|
|
if (context) context_release(context);
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
2010-08-30 20:29:49 +02:00
|
|
|
format.convert(surface->resource.allocatedMemory, mem, pitch, width, height);
|
2010-07-21 18:48:22 +02:00
|
|
|
}
|
|
|
|
else if (convert != NO_CONVERSION && surface->resource.allocatedMemory)
|
|
|
|
{
|
2010-04-08 22:49:47 +02:00
|
|
|
/* This code is only entered for color keying fixups */
|
2010-07-21 18:48:22 +02:00
|
|
|
int height = surface->currentDesc.Height;
|
2007-10-13 12:54:10 +02:00
|
|
|
|
|
|
|
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
|
2010-08-30 20:29:49 +02:00
|
|
|
outpitch = width * format.conv_byte_count;
|
2007-10-13 12:54:10 +02:00
|
|
|
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
|
|
|
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
|
|
|
|
if(!mem) {
|
|
|
|
ERR("Out of memory %d, %d!\n", outpitch, height);
|
2009-11-01 16:05:19 +01:00
|
|
|
if (context) context_release(context);
|
2007-10-13 12:54:10 +02:00
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
2010-07-21 18:48:22 +02:00
|
|
|
d3dfmt_convert_surface(surface->resource.allocatedMemory, mem, pitch,
|
|
|
|
width, height, outpitch, convert, surface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mem = surface->resource.allocatedMemory;
|
2007-10-13 12:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the correct pitch is used */
|
2008-10-19 01:29:42 +02:00
|
|
|
ENTER_GL();
|
2007-10-13 12:54:10 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
|
2008-10-19 01:29:42 +02:00
|
|
|
LEAVE_GL();
|
2007-10-13 12:54:10 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (mem || (surface->flags & SFLAG_PBO))
|
2010-08-30 20:29:49 +02:00
|
|
|
surface_upload_data(surface, gl_info, &format, srgb, mem);
|
2007-10-13 12:54:10 +02:00
|
|
|
|
|
|
|
/* Restore the default pitch */
|
2008-10-19 01:29:42 +02:00
|
|
|
ENTER_GL();
|
2007-10-13 12:54:10 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2008-02-10 22:20:15 +01:00
|
|
|
LEAVE_GL();
|
2007-10-13 12:54:10 +02:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
if (context) context_release(context);
|
|
|
|
|
2007-10-13 12:54:10 +02:00
|
|
|
/* Don't delete PBO memory */
|
2010-11-12 13:12:04 +01:00
|
|
|
if ((mem != surface->resource.allocatedMemory) && !(surface->flags & SFLAG_PBO))
|
2007-10-13 12:54:10 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2007-09-25 00:02:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!rect) surface->flags |= flag;
|
2008-01-02 19:53:13 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (in_fbo && (surface->flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)))
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2008-01-02 19:53:13 +01:00
|
|
|
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
|
2007-09-25 00:21:34 +02:00
|
|
|
}
|
|
|
|
|
2007-09-25 00:02:14 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-25 11:18:03 +01:00
|
|
|
static WINED3DSURFTYPE WINAPI IWineD3DSurfaceImpl_GetImplType(IWineD3DSurface *iface) {
|
|
|
|
return SURFACE_OPENGL;
|
|
|
|
}
|
|
|
|
|
2008-08-01 20:12:18 +02:00
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_DrawOverlay(IWineD3DSurface *iface) {
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* If there's no destination surface there is nothing to do */
|
|
|
|
if(!This->overlay_dest) return WINED3D_OK;
|
|
|
|
|
2008-08-20 17:48:14 +02:00
|
|
|
/* Blt calls ModifyLocation on the dest surface, which in turn calls DrawOverlay to
|
2010-11-12 13:12:04 +01:00
|
|
|
* update the overlay. Prevent an endless recursion. */
|
|
|
|
if (This->overlay_dest->flags & SFLAG_INOVERLAYDRAW)
|
2008-08-20 17:48:14 +02:00
|
|
|
return WINED3D_OK;
|
2010-11-12 13:12:04 +01:00
|
|
|
|
|
|
|
This->overlay_dest->flags |= SFLAG_INOVERLAYDRAW;
|
|
|
|
hr = IWineD3DSurfaceImpl_Blt((IWineD3DSurface *)This->overlay_dest,
|
|
|
|
&This->overlay_destrect, iface, &This->overlay_srcrect,
|
|
|
|
WINEDDBLT_WAIT, NULL, WINED3DTEXF_LINEAR);
|
|
|
|
This->overlay_dest->flags &= ~SFLAG_INOVERLAYDRAW;
|
2008-08-01 20:12:18 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-04-18 22:50:45 +02:00
|
|
|
BOOL surface_is_offscreen(IWineD3DSurfaceImpl *surface)
|
2009-12-06 15:45:46 +01:00
|
|
|
{
|
2010-08-16 20:00:25 +02:00
|
|
|
IWineD3DSwapChainImpl *swapchain = surface->container.u.swapchain;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* Not on a swapchain - must be offscreen */
|
2010-08-16 20:00:25 +02:00
|
|
|
if (surface->container.type != WINED3D_CONTAINER_SWAPCHAIN) return TRUE;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* The front buffer is always onscreen */
|
2010-04-26 21:33:00 +02:00
|
|
|
if (surface == swapchain->front_buffer) return FALSE;
|
2009-12-06 15:45:46 +01:00
|
|
|
|
2009-12-06 17:39:47 +01:00
|
|
|
/* If the swapchain is rendered to an FBO, the backbuffer is
|
|
|
|
* offscreen, otherwise onscreen */
|
|
|
|
return swapchain->render_to_fbo;
|
2009-12-06 15:45:46 +01:00
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl =
|
2005-01-09 18:37:02 +01:00
|
|
|
{
|
2005-03-14 11:12:52 +01:00
|
|
|
/* IUnknown */
|
2007-09-16 13:29:44 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_QueryInterface,
|
2007-09-16 13:42:18 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_AddRef,
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl_Release,
|
2005-03-29 21:01:00 +02:00
|
|
|
/* IWineD3DResource */
|
2007-09-16 13:42:18 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetParent,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPrivateData,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPrivateData,
|
|
|
|
IWineD3DBaseSurfaceImpl_FreePrivateData,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPriority,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPriority,
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl_PreLoad,
|
2008-01-12 22:56:30 +01:00
|
|
|
IWineD3DSurfaceImpl_UnLoad,
|
2007-09-16 13:42:18 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetType,
|
2005-07-13 16:15:54 +02:00
|
|
|
/* IWineD3DSurface */
|
2007-09-16 14:03:39 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetDesc,
|
2010-10-14 13:04:02 +02:00
|
|
|
IWineD3DSurfaceImpl_Map,
|
|
|
|
IWineD3DSurfaceImpl_Unmap,
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurfaceImpl_GetDC,
|
|
|
|
IWineD3DSurfaceImpl_ReleaseDC,
|
2006-04-12 22:32:44 +02:00
|
|
|
IWineD3DSurfaceImpl_Flip,
|
2006-04-14 19:15:46 +02:00
|
|
|
IWineD3DSurfaceImpl_Blt,
|
2007-09-16 14:03:39 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetBltStatus,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetFlipStatus,
|
|
|
|
IWineD3DBaseSurfaceImpl_IsLost,
|
|
|
|
IWineD3DBaseSurfaceImpl_Restore,
|
2006-04-17 17:25:55 +02:00
|
|
|
IWineD3DSurfaceImpl_BltFast,
|
2007-09-16 16:27:58 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetPalette,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPalette,
|
2008-02-18 21:13:13 +01:00
|
|
|
IWineD3DSurfaceImpl_RealizePalette,
|
2007-09-16 16:27:58 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_SetColorKey,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPitch,
|
2006-07-25 16:38:02 +02:00
|
|
|
IWineD3DSurfaceImpl_SetMem,
|
2007-09-16 16:27:58 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_SetOverlayPosition,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetOverlayPosition,
|
|
|
|
IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder,
|
|
|
|
IWineD3DBaseSurfaceImpl_UpdateOverlay,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetClipper,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetClipper,
|
2005-01-09 18:37:02 +01:00
|
|
|
/* Internal use: */
|
|
|
|
IWineD3DSurfaceImpl_LoadTexture,
|
2007-11-15 14:38:34 +01:00
|
|
|
IWineD3DSurfaceImpl_BindTexture,
|
2008-11-25 11:57:39 +01:00
|
|
|
IWineD3DBaseSurfaceImpl_GetData,
|
2006-04-17 17:25:55 +02:00
|
|
|
IWineD3DSurfaceImpl_SetFormat,
|
2007-10-09 22:17:59 +02:00
|
|
|
IWineD3DSurfaceImpl_PrivateSetup,
|
2008-08-01 20:12:18 +02:00
|
|
|
IWineD3DSurfaceImpl_GetImplType,
|
|
|
|
IWineD3DSurfaceImpl_DrawOverlay
|
2005-01-09 18:37:02 +01:00
|
|
|
};
|
2008-08-01 20:21:10 +02:00
|
|
|
|
|
|
|
static HRESULT ffp_blit_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2008-08-01 20:21:10 +02:00
|
|
|
static void ffp_blit_free(IWineD3DDevice *iface) { }
|
|
|
|
|
2010-04-05 20:05:14 +02:00
|
|
|
/* This function is used in case of 8bit paletted textures using GL_EXT_paletted_texture */
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void ffp_blit_p8_upload_palette(IWineD3DSurfaceImpl *surface, const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
|
|
|
BYTE table[256][4];
|
|
|
|
BOOL colorkey_active = (surface->CKeyFlags & WINEDDSD_CKSRCBLT) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
d3dfmt_p8_init_palette(surface, table, colorkey_active);
|
|
|
|
|
|
|
|
TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
|
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glColorTableEXT(surface->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table));
|
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-04-05 20:05:13 +02:00
|
|
|
static HRESULT ffp_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
|
2009-03-24 10:09:24 +01:00
|
|
|
{
|
2010-04-05 20:05:14 +02:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-08-30 20:29:49 +02:00
|
|
|
enum complex_fixup fixup = get_complex_fixup(surface->resource.format->color_fixup);
|
2010-04-05 20:05:14 +02:00
|
|
|
|
|
|
|
/* When EXT_PALETTED_TEXTURE is around, palette conversion is done by the GPU
|
|
|
|
* else the surface is converted in software at upload time in LoadLocation.
|
|
|
|
*/
|
|
|
|
if(fixup == COMPLEX_FIXUP_P8 && gl_info->supported[EXT_PALETTED_TEXTURE])
|
|
|
|
ffp_blit_p8_upload_palette(surface, gl_info);
|
|
|
|
|
2009-05-14 19:40:55 +02:00
|
|
|
ENTER_GL();
|
2010-04-05 20:05:13 +02:00
|
|
|
glEnable(surface->texture_target);
|
|
|
|
checkGLcall("glEnable(surface->texture_target)");
|
2009-05-14 19:40:55 +02:00
|
|
|
LEAVE_GL();
|
2008-08-01 20:21:10 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2009-10-29 10:37:11 +01:00
|
|
|
static void ffp_blit_unset(IWineD3DDevice *iface)
|
|
|
|
{
|
2008-08-01 20:21:10 +02:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
|
2009-05-14 19:40:55 +02:00
|
|
|
ENTER_GL();
|
2008-08-01 20:21:10 +02:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
checkGLcall("glDisable(GL_TEXTURE_2D)");
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2008-08-01 20:21:10 +02:00
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2008-08-01 20:21:10 +02:00
|
|
|
glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
|
|
|
|
}
|
2009-05-14 19:40:55 +02:00
|
|
|
LEAVE_GL();
|
2008-08-01 20:21:10 +02:00
|
|
|
}
|
|
|
|
|
2010-04-06 22:20:42 +02:00
|
|
|
static BOOL ffp_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
|
2010-08-30 20:29:49 +02:00
|
|
|
const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format)
|
2008-12-03 14:53:43 +01:00
|
|
|
{
|
2010-04-12 12:17:09 +02:00
|
|
|
enum complex_fixup src_fixup;
|
2010-03-18 23:11:55 +01:00
|
|
|
|
2010-04-12 12:17:09 +02:00
|
|
|
if (blit_op == BLIT_OP_COLOR_FILL)
|
|
|
|
{
|
|
|
|
if (!(dst_usage & WINED3DUSAGE_RENDERTARGET))
|
|
|
|
{
|
|
|
|
TRACE("Color fill not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
src_fixup = get_complex_fixup(src_format->color_fixup);
|
2008-12-03 14:53:43 +01:00
|
|
|
if (TRACE_ON(d3d_surface) && TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
TRACE("Checking support for fixup:\n");
|
2010-08-30 20:29:49 +02:00
|
|
|
dump_color_fixup_desc(src_format->color_fixup);
|
2008-12-03 14:53:43 +01:00
|
|
|
}
|
|
|
|
|
2010-04-06 22:20:42 +02:00
|
|
|
if (blit_op != BLIT_OP_BLIT)
|
2008-12-03 14:53:43 +01:00
|
|
|
{
|
2010-04-06 22:20:42 +02:00
|
|
|
TRACE("Unsupported blit_op=%d\n", blit_op);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (!is_identity_fixup(dst_format->color_fixup))
|
2010-04-06 22:20:42 +02:00
|
|
|
{
|
|
|
|
TRACE("Destination fixups are not supported\n");
|
|
|
|
return FALSE;
|
2008-12-03 14:53:43 +01:00
|
|
|
}
|
|
|
|
|
2010-04-06 22:20:42 +02:00
|
|
|
if (src_fixup == COMPLEX_FIXUP_P8 && gl_info->supported[EXT_PALETTED_TEXTURE])
|
2010-03-18 23:11:55 +01:00
|
|
|
{
|
|
|
|
TRACE("P8 fixup supported\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-06 22:20:42 +02:00
|
|
|
/* We only support identity conversions. */
|
2010-08-30 20:29:49 +02:00
|
|
|
if (is_identity_fixup(src_format->color_fixup))
|
2010-04-06 22:20:42 +02:00
|
|
|
{
|
|
|
|
TRACE("[OK]\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
TRACE("[FAILED]\n");
|
2008-08-07 21:51:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-08-23 18:28:08 +02:00
|
|
|
static HRESULT ffp_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface,
|
|
|
|
const RECT *dst_rect, const WINED3DCOLORVALUE *color)
|
2010-03-25 17:01:33 +01:00
|
|
|
{
|
2010-08-23 18:28:06 +02:00
|
|
|
const RECT draw_rect = {0, 0, dst_surface->currentDesc.Width, dst_surface->currentDesc.Height};
|
2010-08-03 10:13:32 +02:00
|
|
|
|
2010-07-23 11:31:03 +02:00
|
|
|
return device_clear_render_targets(device, 1 /* rt_count */, &dst_surface, 1 /* rect_count */,
|
2010-08-23 18:28:08 +02:00
|
|
|
dst_rect, &draw_rect, WINED3DCLEAR_TARGET, color, 0.0f /* depth */, 0 /* stencil */);
|
2010-03-25 17:01:33 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 20:21:10 +02:00
|
|
|
const struct blit_shader ffp_blit = {
|
|
|
|
ffp_blit_alloc,
|
|
|
|
ffp_blit_free,
|
|
|
|
ffp_blit_set,
|
2008-08-07 21:51:35 +02:00
|
|
|
ffp_blit_unset,
|
2010-04-06 22:20:42 +02:00
|
|
|
ffp_blit_supported,
|
2010-03-25 17:01:33 +01:00
|
|
|
ffp_blit_color_fill
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT cpu_blit_alloc(IWineD3DDevice *iface)
|
|
|
|
{
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void cpu_blit_free(IWineD3DDevice *iface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2010-04-05 20:05:13 +02:00
|
|
|
static HRESULT cpu_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
|
2010-03-25 17:01:33 +01:00
|
|
|
{
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void cpu_blit_unset(IWineD3DDevice *iface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-06 22:20:42 +02:00
|
|
|
static BOOL cpu_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
|
2010-08-30 20:29:49 +02:00
|
|
|
const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format)
|
2010-03-25 17:01:33 +01:00
|
|
|
{
|
2010-04-12 12:17:09 +02:00
|
|
|
if (blit_op == BLIT_OP_COLOR_FILL)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-25 17:01:33 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-08-23 18:28:08 +02:00
|
|
|
static HRESULT cpu_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface,
|
|
|
|
const RECT *dst_rect, const WINED3DCOLORVALUE *color)
|
2010-03-25 17:01:33 +01:00
|
|
|
{
|
|
|
|
WINEDDBLTFX BltFx;
|
2010-08-23 18:28:07 +02:00
|
|
|
|
2010-03-25 17:01:33 +01:00
|
|
|
memset(&BltFx, 0, sizeof(BltFx));
|
|
|
|
BltFx.dwSize = sizeof(BltFx);
|
2010-08-30 20:29:49 +02:00
|
|
|
BltFx.u5.dwFillColor = wined3d_format_convert_from_float(dst_surface->resource.format, color);
|
2010-08-23 18:28:07 +02:00
|
|
|
return IWineD3DBaseSurfaceImpl_Blt((IWineD3DSurface*)dst_surface, dst_rect,
|
|
|
|
NULL, NULL, WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
|
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,
|
2010-03-25 17:01:33 +01:00
|
|
|
cpu_blit_color_fill
|
2008-08-01 20:21:10 +02:00
|
|
|
};
|
2010-03-31 13:54:57 +02:00
|
|
|
|
|
|
|
static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
|
2010-08-30 20:29:49 +02:00
|
|
|
const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format *src_format,
|
|
|
|
const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format *dst_format)
|
2010-03-31 13:54:57 +02:00
|
|
|
{
|
|
|
|
if ((wined3d_settings.offscreen_rendering_mode != ORM_FBO) || !gl_info->fbo_ops.glBlitFramebuffer)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* We only support blitting. Things like color keying / color fill should
|
|
|
|
* be handled by other blitters.
|
|
|
|
*/
|
|
|
|
if (blit_op != BLIT_OP_BLIT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Source and/or destination need to be on the GL side */
|
|
|
|
if (src_pool == WINED3DPOOL_SYSTEMMEM || dst_pool == WINED3DPOOL_SYSTEMMEM)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (!((src_format->flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (src_usage & WINED3DUSAGE_RENDERTARGET))
|
|
|
|
&& ((dst_format->flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (dst_usage & WINED3DUSAGE_RENDERTARGET)))
|
2010-03-31 13:54:57 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (!(src_format->id == dst_format->id
|
|
|
|
|| (is_identity_fixup(src_format->color_fixup)
|
|
|
|
&& is_identity_fixup(dst_format->color_fixup))))
|
2010-03-31 13:54:57 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|