2004-10-07 06:22:21 +02:00
|
|
|
/*
|
2006-04-18 23:15:56 +02:00
|
|
|
* Copyright 2002 Lionel Ulmer
|
2005-03-02 13:16:10 +01:00
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
2004-10-07 06:22:21 +02:00
|
|
|
* Copyright 2003-2004 Raphael Junqueira
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-03-02 13:16:10 +01:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2006-2008 Stefan Dösinger for CodeWeavers
|
2008-08-21 18:34:55 +02:00
|
|
|
* Copyright 2006-2008 Henri Verbeet
|
2007-05-15 00:37:53 +02:00
|
|
|
* Copyright 2007 Andrew Riedi
|
2011-03-30 20:49:25 +02:00
|
|
|
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
|
2004-10-07 06:22:21 +02: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
|
2004-10-07 06:22:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2006-06-09 09:36:55 +02:00
|
|
|
#include <stdio.h>
|
2006-02-13 13:23:42 +01:00
|
|
|
#ifdef HAVE_FLOAT_H
|
|
|
|
# include <float.h>
|
|
|
|
#endif
|
2012-06-01 16:56:21 +02:00
|
|
|
|
2004-10-07 06:22:21 +02:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
/* Define the default light parameters as specified by MSDN. */
|
|
|
|
const struct wined3d_light WINED3D_default_light =
|
|
|
|
{
|
2011-12-11 21:43:31 +01:00
|
|
|
WINED3D_LIGHT_DIRECTIONAL, /* Type */
|
2009-07-07 11:08:01 +02:00
|
|
|
{ 1.0f, 1.0f, 1.0f, 0.0f }, /* Diffuse r,g,b,a */
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 0.0f }, /* Specular r,g,b,a */
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 0.0f }, /* Ambient r,g,b,a, */
|
|
|
|
{ 0.0f, 0.0f, 0.0f }, /* Position x,y,z */
|
|
|
|
{ 0.0f, 0.0f, 1.0f }, /* Direction x,y,z */
|
|
|
|
0.0f, /* Range */
|
|
|
|
0.0f, /* Falloff */
|
|
|
|
0.0f, 0.0f, 0.0f, /* Attenuation 0,1,2 */
|
|
|
|
0.0f, /* Theta */
|
|
|
|
0.0f /* Phi */
|
2006-06-07 05:37:05 +02:00
|
|
|
};
|
|
|
|
|
2009-03-05 12:30:43 +01:00
|
|
|
/* Note that except for WINED3DPT_POINTLIST and WINED3DPT_LINELIST these
|
|
|
|
* actually have the same values in GL and D3D. */
|
2012-11-14 23:05:59 +01:00
|
|
|
GLenum gl_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
|
|
|
switch(primitive_type)
|
|
|
|
{
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_POINTLIST:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_POINTS;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINELIST:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINES;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINESTRIP:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINE_STRIP;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLELIST:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLES;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLESTRIP:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLEFAN:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLE_FAN;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINELIST_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINES_ADJACENCY_ARB;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINESTRIP_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINE_STRIP_ADJACENCY_ARB;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLELIST_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLES_ADJACENCY_ARB;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLESTRIP_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLE_STRIP_ADJACENCY_ARB;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
static enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
|
|
|
switch(primitive_type)
|
|
|
|
{
|
|
|
|
case GL_POINTS:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_POINTLIST;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINES:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINELIST;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINE_STRIP:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINESTRIP;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLES:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLELIST;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLE_STRIP:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLESTRIP;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLE_FAN:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLEFAN;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINES_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINELIST_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINE_STRIP_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINESTRIP_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLES_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLELIST_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLE_STRIP_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLESTRIP_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_UNDEFINED;
|
2009-03-05 12:30:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context **new_array;
|
|
|
|
|
|
|
|
TRACE("Adding context %p.\n", context);
|
|
|
|
|
|
|
|
if (!device->contexts) new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
|
2011-03-30 20:49:27 +02:00
|
|
|
else new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts,
|
|
|
|
sizeof(*new_array) * (device->context_count + 1));
|
2010-03-14 21:53:25 +01:00
|
|
|
|
|
|
|
if (!new_array)
|
|
|
|
{
|
|
|
|
ERR("Failed to grow the context array.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
new_array[device->context_count++] = context;
|
2010-03-14 21:53:25 +01:00
|
|
|
device->contexts = new_array;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_context_remove(struct wined3d_device *device, struct wined3d_context *context)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context **new_array;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("Removing context %p.\n", context);
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
if (device->contexts[i] == context)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
ERR("Context %p doesn't exist in context array.\n", context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
if (!--device->context_count)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->contexts);
|
|
|
|
device->contexts = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
memmove(&device->contexts[i], &device->contexts[i + 1], (device->context_count - i) * sizeof(*device->contexts));
|
|
|
|
new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts, device->context_count * sizeof(*device->contexts));
|
2010-03-14 21:53:25 +01:00
|
|
|
if (!new_array)
|
|
|
|
{
|
|
|
|
ERR("Failed to shrink context array. Oh well.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->contexts = new_array;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_switch_onscreen_ds(struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_context *context, struct wined3d_surface *depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
|
|
|
if (device->onscreen_depth_stencil)
|
|
|
|
{
|
2012-01-09 15:52:44 +01:00
|
|
|
surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_INTEXTURE);
|
|
|
|
|
|
|
|
surface_modify_ds_location(device->onscreen_depth_stencil, SFLAG_INTEXTURE,
|
2010-04-29 00:08:59 +02:00
|
|
|
device->onscreen_depth_stencil->ds_current_size.cx,
|
|
|
|
device->onscreen_depth_stencil->ds_current_size.cy);
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_decref(device->onscreen_depth_stencil);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
|
|
|
device->onscreen_depth_stencil = depth_stencil;
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_incref(device->onscreen_depth_stencil);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
2010-03-14 21:53:25 +01:00
|
|
|
|
2011-08-28 23:27:46 +02:00
|
|
|
static BOOL is_full_clear(const struct wined3d_surface *target, const RECT *draw_rect, const RECT *clear_rect)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
/* partial draw rect */
|
|
|
|
if (draw_rect->left || draw_rect->top
|
2011-03-08 19:41:07 +01:00
|
|
|
|| draw_rect->right < target->resource.width
|
|
|
|
|| draw_rect->bottom < target->resource.height)
|
2010-07-23 11:31:03 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* partial clear rect */
|
|
|
|
if (clear_rect && (clear_rect->left > 0 || clear_rect->top > 0
|
2011-03-08 19:41:07 +01:00
|
|
|
|| clear_rect->right < target->resource.width
|
|
|
|
|| clear_rect->bottom < target->resource.height))
|
2010-07-23 11:31:03 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
static void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context *context,
|
2012-01-12 17:05:19 +01:00
|
|
|
DWORD location, const RECT *draw_rect, UINT rect_count, const RECT *clear_rect, RECT *out_rect)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
RECT current_rect, r;
|
|
|
|
|
2013-04-10 01:35:44 +02:00
|
|
|
if (ds->flags & SFLAG_DISCARDED)
|
|
|
|
{
|
|
|
|
/* Depth buffer was discarded, make it entirely current in its new location since
|
|
|
|
* there is no other place where we would get data anyway. */
|
|
|
|
SetRect(out_rect, 0, 0, ds->resource.width, ds->resource.height);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (ds->flags & location)
|
2010-07-23 11:31:03 +02:00
|
|
|
SetRect(¤t_rect, 0, 0,
|
|
|
|
ds->ds_current_size.cx,
|
|
|
|
ds->ds_current_size.cy);
|
|
|
|
else
|
|
|
|
SetRectEmpty(¤t_rect);
|
|
|
|
|
|
|
|
IntersectRect(&r, draw_rect, ¤t_rect);
|
|
|
|
if (EqualRect(&r, draw_rect))
|
|
|
|
{
|
|
|
|
/* current_rect ⊇ draw_rect, modify only. */
|
2012-01-12 17:05:19 +01:00
|
|
|
SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
2010-07-23 11:31:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EqualRect(&r, ¤t_rect))
|
|
|
|
{
|
|
|
|
/* draw_rect ⊇ current_rect, test if we're doing a full clear. */
|
|
|
|
|
|
|
|
if (!clear_rect)
|
|
|
|
{
|
|
|
|
/* Full clear, modify only. */
|
2012-01-12 17:05:19 +01:00
|
|
|
*out_rect = *draw_rect;
|
2010-07-23 11:31:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntersectRect(&r, draw_rect, clear_rect);
|
|
|
|
if (EqualRect(&r, draw_rect))
|
|
|
|
{
|
|
|
|
/* clear_rect ⊇ draw_rect, modify only. */
|
2012-01-12 17:05:19 +01:00
|
|
|
*out_rect = *draw_rect;
|
2010-07-23 11:31:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Full load. */
|
|
|
|
surface_load_ds_location(ds, context, location);
|
2012-01-12 17:05:19 +01:00
|
|
|
SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
2012-04-15 18:57:14 +02:00
|
|
|
void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb,
|
2011-11-15 21:18:27 +01:00
|
|
|
UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags, const struct wined3d_color *color,
|
2011-06-27 18:23:13 +02:00
|
|
|
float depth, DWORD stencil)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
const RECT *clear_rect = (rect_count > 0 && rects) ? (const RECT *)rects : NULL;
|
2011-06-27 18:23:13 +02:00
|
|
|
struct wined3d_surface *target = rt_count ? fb->render_targets[0] : NULL;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT drawable_width, drawable_height;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
GLbitfield clear_mask = 0;
|
2011-04-05 19:01:30 +02:00
|
|
|
BOOL render_offscreen;
|
2010-07-23 11:31:03 +02:00
|
|
|
unsigned int i;
|
2012-01-12 17:05:19 +01:00
|
|
|
RECT ds_rect;
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
/* When we're clearing parts of the drawable, make sure that the target surface is well up to date in the
|
|
|
|
* drawable. After the clear we'll mark the drawable up to date, so we have to make sure that this is true
|
|
|
|
* for the cleared parts, and the untouched parts.
|
|
|
|
*
|
|
|
|
* If we're clearing the whole target there is no need to copy it into the drawable, it will be overwritten
|
|
|
|
* anyway. If we're not clearing the color buffer we don't have to copy either since we're not going to set
|
|
|
|
* the drawable up to date. We have to check all settings that limit the clear area though. Do not bother
|
|
|
|
* checking all this if the dest surface is in the drawable anyway. */
|
2010-08-23 18:28:06 +02:00
|
|
|
if (flags & WINED3DCLEAR_TARGET && !is_full_clear(target, draw_rect, clear_rect))
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2011-08-23 20:08:10 +02:00
|
|
|
struct wined3d_surface *rt = fb->render_targets[i];
|
|
|
|
if (rt)
|
2013-11-20 12:33:31 +01:00
|
|
|
surface_load_location(rt, rt->draw_binding);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context = context_acquire(device, target);
|
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping clear.\n");
|
2012-04-15 18:57:14 +02:00
|
|
|
return;
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info = context->gl_info;
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
render_offscreen = context->render_offscreen;
|
|
|
|
target->get_drawable_size(context, &drawable_width, &drawable_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-11 20:55:13 +02:00
|
|
|
render_offscreen = TRUE;
|
2011-06-27 18:23:13 +02:00
|
|
|
drawable_width = fb->depth_stencil->pow2Width;
|
|
|
|
drawable_height = fb->depth_stencil->pow2Height;
|
2011-04-05 19:01:30 +02:00
|
|
|
}
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2011-07-31 17:33:41 +02:00
|
|
|
if (flags & WINED3DCLEAR_ZBUFFER)
|
|
|
|
{
|
2012-01-09 15:52:44 +01:00
|
|
|
DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
|
2011-07-31 17:33:41 +02:00
|
|
|
|
2012-01-09 15:52:44 +01:00
|
|
|
if (!render_offscreen && fb->depth_stencil != device->onscreen_depth_stencil)
|
2011-07-31 17:33:41 +02:00
|
|
|
device_switch_onscreen_ds(device, context, fb->depth_stencil);
|
2012-01-12 17:05:19 +01:00
|
|
|
prepare_ds_clear(fb->depth_stencil, context, location,
|
|
|
|
draw_rect, rect_count, clear_rect, &ds_rect);
|
2011-07-31 17:33:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!context_apply_clear_state(context, device, rt_count, fb))
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Failed to apply clear state, skipping clear.\n");
|
2012-04-15 18:57:14 +02:00
|
|
|
return;
|
2011-07-31 17:33:41 +02:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:31:03 +02:00
|
|
|
/* Only set the values up once, as they are not changing. */
|
|
|
|
if (flags & WINED3DCLEAR_STENCIL)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE));
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glStencilMask(~0U);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glClearStencil(stencil);
|
2010-07-23 11:31:03 +02:00
|
|
|
checkGLcall("glClearStencil");
|
|
|
|
clear_mask = clear_mask | GL_STENCIL_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3DCLEAR_ZBUFFER)
|
|
|
|
{
|
2012-01-09 15:52:44 +01:00
|
|
|
DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
|
|
|
|
|
2012-01-12 17:05:19 +01:00
|
|
|
surface_modify_ds_location(fb->depth_stencil, location, ds_rect.right, ds_rect.bottom);
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glClearDepth(depth);
|
2010-07-23 11:31:03 +02:00
|
|
|
checkGLcall("glClearDepth");
|
|
|
|
clear_mask = clear_mask | GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3DCLEAR_TARGET)
|
|
|
|
{
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2011-08-23 20:08:10 +02:00
|
|
|
struct wined3d_surface *rt = fb->render_targets[i];
|
|
|
|
|
|
|
|
if (rt)
|
2013-09-10 09:32:34 +02:00
|
|
|
{
|
|
|
|
surface_validate_location(rt, rt->draw_binding);
|
|
|
|
surface_invalidate_location(rt, ~rt->draw_binding);
|
|
|
|
}
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glClearColor(color->r, color->g, color->b, color->a);
|
2010-07-23 11:31:03 +02:00
|
|
|
checkGLcall("glClearColor");
|
|
|
|
clear_mask = clear_mask | GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clear_rect)
|
|
|
|
{
|
2011-04-05 19:01:30 +02:00
|
|
|
if (render_offscreen)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glScissor(draw_rect->left, draw_rect->top,
|
2010-08-23 18:28:06 +02:00
|
|
|
draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glScissor(draw_rect->left, drawable_height - draw_rect->bottom,
|
2010-08-23 18:28:06 +02:00
|
|
|
draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
checkGLcall("glScissor");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glClear(clear_mask);
|
2010-07-23 11:31:03 +02:00
|
|
|
checkGLcall("glClear");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT current_rect;
|
|
|
|
|
|
|
|
/* Now process each rect in turn. */
|
|
|
|
for (i = 0; i < rect_count; ++i)
|
|
|
|
{
|
|
|
|
/* Note that GL uses lower left, width/height. */
|
2010-08-23 18:28:06 +02:00
|
|
|
IntersectRect(¤t_rect, draw_rect, &clear_rect[i]);
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
TRACE("clear_rect[%u] %s, current_rect %s.\n", i,
|
|
|
|
wine_dbgstr_rect(&clear_rect[i]),
|
|
|
|
wine_dbgstr_rect(¤t_rect));
|
|
|
|
|
|
|
|
/* Tests show that rectangles where x1 > x2 or y1 > y2 are ignored silently.
|
2011-08-02 22:20:32 +02:00
|
|
|
* The rectangle is not cleared, no error is returned, but further rectangles are
|
2010-07-23 11:31:03 +02:00
|
|
|
* still cleared if they are valid. */
|
|
|
|
if (current_rect.left > current_rect.right || current_rect.top > current_rect.bottom)
|
|
|
|
{
|
|
|
|
TRACE("Rectangle with negative dimensions, ignoring.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (render_offscreen)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glScissor(current_rect.left, current_rect.top,
|
2010-07-23 11:31:03 +02:00
|
|
|
current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glScissor(current_rect.left, drawable_height - current_rect.bottom,
|
2010-07-23 11:31:03 +02:00
|
|
|
current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
|
|
|
|
}
|
|
|
|
checkGLcall("glScissor");
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glClear(clear_mask);
|
2010-07-23 11:31:03 +02:00
|
|
|
checkGLcall("glClear");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering || (flags & WINED3DCLEAR_TARGET
|
2013-06-03 09:19:35 +02:00
|
|
|
&& target->swapchain && target->swapchain->front_buffer == target))
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG CDECL wined3d_device_incref(struct wined3d_device *device)
|
2005-03-02 13:16:10 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&device->ref);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", device, refcount);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
return refcount;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&device->ref);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", device, refcount);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!refcount)
|
|
|
|
{
|
2009-01-07 02:20:08 +01:00
|
|
|
UINT i;
|
|
|
|
|
2013-09-27 00:15:13 +02:00
|
|
|
wined3d_cs_destroy(device->cs);
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording && wined3d_stateblock_decref(device->recording))
|
|
|
|
FIXME("Something's still holding the recording stateblock.\n");
|
|
|
|
device->recording = NULL;
|
2011-12-04 15:50:12 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
state_cleanup(&device->state);
|
2011-12-04 15:50:12 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
|
|
|
|
device->multistate_funcs[i] = NULL;
|
2009-01-07 02:20:08 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!list_empty(&device->resources))
|
2010-04-04 19:51:38 +02:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2010-04-04 19:51:38 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
FIXME("Device released with resources still bound, acceptable but unexpected.\n");
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
|
2010-04-04 19:51:38 +02:00
|
|
|
{
|
|
|
|
FIXME("Leftover resource %p with type %s (%#x).\n",
|
2012-01-17 21:13:36 +01:00
|
|
|
resource, debug_d3dresourcetype(resource->type), resource->type);
|
2010-04-04 19:51:38 +02:00
|
|
|
}
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->contexts)
|
|
|
|
ERR("Context array not freed!\n");
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
DestroyCursor(device->hardwareCursor);
|
2011-05-16 20:13:13 +02:00
|
|
|
device->hardwareCursor = 0;
|
2005-09-23 12:07:46 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
device->wined3d = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, device);
|
|
|
|
TRACE("Freed device %p.\n", device);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
|
|
|
|
return refcount;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-08-28 23:27:47 +02:00
|
|
|
UINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *device)
|
2011-04-06 19:17:53 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-04-06 19:17:53 +02:00
|
|
|
|
|
|
|
return device->swapchain_count;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
struct wined3d_swapchain * CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx)
|
2011-04-06 19:17:53 +02:00
|
|
|
{
|
2012-09-04 20:15:10 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u.\n", device, swapchain_idx);
|
2011-04-13 19:14:32 +02:00
|
|
|
|
|
|
|
if (swapchain_idx >= device->swapchain_count)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
WARN("swapchain_idx %u >= swapchain_count %u.\n",
|
|
|
|
swapchain_idx, device->swapchain_count);
|
2012-09-04 20:15:10 +02:00
|
|
|
return NULL;
|
2005-07-27 17:33:17 +02:00
|
|
|
}
|
2011-04-13 19:14:32 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
return device->swapchains[swapchain_idx];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-06-07 19:44:49 +02:00
|
|
|
static void device_load_logo(struct wined3d_device *device, const char *filename)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2011-12-07 22:08:59 +01:00
|
|
|
struct wined3d_color_key color_key;
|
2013-11-14 10:47:19 +01:00
|
|
|
struct wined3d_resource_desc desc;
|
|
|
|
struct wined3d_surface *surface;
|
2007-09-01 21:22:32 +02:00
|
|
|
HBITMAP hbm;
|
|
|
|
BITMAP bm;
|
|
|
|
HRESULT hr;
|
|
|
|
HDC dcb = NULL, dcs = NULL;
|
|
|
|
|
2009-02-03 09:36:07 +01:00
|
|
|
hbm = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
|
2007-09-01 21:22:32 +02:00
|
|
|
if(hbm)
|
|
|
|
{
|
|
|
|
GetObjectA(hbm, sizeof(BITMAP), &bm);
|
|
|
|
dcb = CreateCompatibleDC(NULL);
|
|
|
|
if(!dcb) goto out;
|
|
|
|
SelectObject(dcb, hbm);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Create a 32x32 white surface to indicate that wined3d is used, but the specified image
|
|
|
|
* couldn't be loaded
|
|
|
|
*/
|
|
|
|
memset(&bm, 0, sizeof(bm));
|
|
|
|
bm.bmWidth = 32;
|
|
|
|
bm.bmHeight = 32;
|
|
|
|
}
|
|
|
|
|
2013-11-14 10:47:19 +01:00
|
|
|
desc.resource_type = WINED3D_RTYPE_TEXTURE;
|
|
|
|
desc.format = WINED3DFMT_B5G6R5_UNORM;
|
|
|
|
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
|
|
|
|
desc.multisample_quality = 0;
|
|
|
|
desc.usage = 0;
|
|
|
|
desc.pool = WINED3D_POOL_SYSTEM_MEM;
|
|
|
|
desc.width = bm.bmWidth;
|
|
|
|
desc.height = bm.bmHeight;
|
|
|
|
desc.depth = 1;
|
|
|
|
desc.size = 0;
|
|
|
|
if (FAILED(hr = wined3d_texture_create_2d(device, &desc, 1, WINED3D_SURFACE_MAPPABLE,
|
|
|
|
NULL, &wined3d_null_parent_ops, &device->logo_texture)))
|
2010-08-31 18:41:40 +02:00
|
|
|
{
|
2013-11-14 10:47:19 +01:00
|
|
|
ERR("Wine logo requested, but failed to create texture, hr %#x.\n", hr);
|
2007-09-01 21:22:32 +02:00
|
|
|
goto out;
|
|
|
|
}
|
2013-11-14 10:47:19 +01:00
|
|
|
surface = surface_from_resource(wined3d_texture_get_sub_resource(device->logo_texture, 0));
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
if (dcb)
|
|
|
|
{
|
2013-11-14 10:47:19 +01:00
|
|
|
if (FAILED(hr = wined3d_surface_getdc(surface, &dcs)))
|
2011-04-29 13:03:41 +02:00
|
|
|
goto out;
|
2007-09-01 21:22:32 +02:00
|
|
|
BitBlt(dcs, 0, 0, bm.bmWidth, bm.bmHeight, dcb, 0, 0, SRCCOPY);
|
2013-11-14 10:47:19 +01:00
|
|
|
wined3d_surface_releasedc(surface, dcs);
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2011-12-07 22:08:59 +01:00
|
|
|
color_key.color_space_low_value = 0;
|
|
|
|
color_key.color_space_high_value = 0;
|
2013-11-14 10:47:19 +01:00
|
|
|
wined3d_surface_set_color_key(surface, WINEDDCKEY_SRCBLT, &color_key);
|
2010-08-23 18:28:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-15 21:18:27 +01:00
|
|
|
const struct wined3d_color c = {1.0f, 1.0f, 1.0f, 1.0f};
|
2007-09-01 21:22:32 +02:00
|
|
|
/* Fill the surface with a white color to show that wined3d is there */
|
2013-11-14 10:47:19 +01:00
|
|
|
wined3d_device_color_fill(device, surface, NULL, &c);
|
2007-09-01 21:22:32 +02:00
|
|
|
}
|
|
|
|
|
2009-12-29 17:10:20 +01:00
|
|
|
out:
|
|
|
|
if (dcb) DeleteDC(dcb);
|
|
|
|
if (hbm) DeleteObject(hbm);
|
2007-09-01 21:22:32 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-08-03 01:34:15 +02:00
|
|
|
static void create_dummy_textures(struct wined3d_device *device, struct wined3d_context *context)
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-08-26 01:12:27 +02:00
|
|
|
unsigned int i, j, count;
|
2011-06-30 15:01:07 +02:00
|
|
|
/* Under DirectX you can sample even if no texture is bound, whereas
|
|
|
|
* OpenGL will only allow that when a valid texture is bound.
|
|
|
|
* We emulate this by creating dummy textures and binding them
|
|
|
|
* to each texture stage when the currently set D3D texture is NULL. */
|
2008-02-15 15:54:37 +01:00
|
|
|
|
2011-08-26 01:12:27 +02:00
|
|
|
count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
|
|
|
|
for (i = 0; i < count; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-06-30 15:01:07 +02:00
|
|
|
DWORD color = 0x000000ff;
|
2008-02-15 15:54:37 +01:00
|
|
|
|
|
|
|
/* Make appropriate texture active */
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(context, gl_info, i);
|
2008-02-15 15:54:37 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_2d[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glGenTextures");
|
2011-08-26 01:12:29 +02:00
|
|
|
TRACE("Dummy 2D texture %u given name %u.\n", i, device->dummy_texture_2d[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glTexImage2D");
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_rect[i]);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Dummy rectangle texture %u given name %u.\n", i, device->dummy_texture_rect[i]);
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_3d[i]);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Dummy 3D texture %u given name %u.\n", i, device->dummy_texture_3d[i]);
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
|
|
|
|
checkGLcall("glTexImage3D");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_cube[i]);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Dummy cube texture %u given name %u.\n", i, device->dummy_texture_cube[i]);
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++j)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(j, 0, GL_RGBA8, 1, 1, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
|
|
|
}
|
2008-02-15 15:54:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:14:34 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-05-16 23:01:23 +02:00
|
|
|
static void destroy_dummy_textures(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
|
2009-12-17 19:14:34 +01:00
|
|
|
{
|
2011-08-26 01:12:27 +02:00
|
|
|
unsigned int count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_cube);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_cube)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_3d);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_3d)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_rect);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_rect)");
|
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_2d);
|
2011-08-26 01:12:29 +02:00
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_2d)");
|
2009-12-17 19:14:34 +01:00
|
|
|
|
2013-04-10 01:35:40 +02:00
|
|
|
memset(device->dummy_texture_cube, 0, count * sizeof(*device->dummy_texture_cube));
|
|
|
|
memset(device->dummy_texture_3d, 0, count * sizeof(*device->dummy_texture_3d));
|
|
|
|
memset(device->dummy_texture_rect, 0, count * sizeof(*device->dummy_texture_rect));
|
|
|
|
memset(device->dummy_texture_2d, 0, count * sizeof(*device->dummy_texture_2d));
|
2009-12-17 19:14:34 +01:00
|
|
|
}
|
|
|
|
|
2010-11-08 11:50:31 +01:00
|
|
|
static LONG fullscreen_style(LONG style)
|
|
|
|
{
|
|
|
|
/* Make sure the window is managed, otherwise we won't get keyboard input. */
|
|
|
|
style |= WS_POPUP | WS_SYSMENU;
|
|
|
|
style &= ~(WS_CAPTION | WS_THICKFRAME);
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG fullscreen_exstyle(LONG exstyle)
|
|
|
|
{
|
|
|
|
/* Filter out window decorations. */
|
|
|
|
exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
|
|
|
|
|
|
|
|
return exstyle;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_setup_fullscreen_window(struct wined3d_device *device, HWND window, UINT w, UINT h)
|
2010-11-08 11:50:31 +01:00
|
|
|
{
|
|
|
|
BOOL filter_messages;
|
|
|
|
LONG style, exstyle;
|
|
|
|
|
|
|
|
TRACE("Setting up window %p for fullscreen mode.\n", window);
|
|
|
|
|
|
|
|
if (device->style || device->exStyle)
|
|
|
|
{
|
|
|
|
ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
|
|
|
|
window, device->style, device->exStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
device->style = GetWindowLongW(window, GWL_STYLE);
|
|
|
|
device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
|
|
|
|
|
|
|
|
style = fullscreen_style(device->style);
|
|
|
|
exstyle = fullscreen_exstyle(device->exStyle);
|
|
|
|
|
|
|
|
TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
|
|
|
|
device->style, device->exStyle, style, exstyle);
|
|
|
|
|
|
|
|
filter_messages = device->filter_messages;
|
|
|
|
device->filter_messages = TRUE;
|
|
|
|
|
|
|
|
SetWindowLongW(window, GWL_STYLE, style);
|
|
|
|
SetWindowLongW(window, GWL_EXSTYLE, exstyle);
|
2013-04-01 02:25:18 +02:00
|
|
|
SetWindowPos(window, HWND_TOPMOST, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
|
2010-11-08 11:50:31 +01:00
|
|
|
|
|
|
|
device->filter_messages = filter_messages;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window)
|
2010-11-08 11:50:31 +01:00
|
|
|
{
|
|
|
|
BOOL filter_messages;
|
|
|
|
LONG style, exstyle;
|
|
|
|
|
|
|
|
if (!device->style && !device->exStyle) return;
|
|
|
|
|
|
|
|
style = GetWindowLongW(window, GWL_STYLE);
|
|
|
|
exstyle = GetWindowLongW(window, GWL_EXSTYLE);
|
|
|
|
|
2013-04-01 02:25:27 +02:00
|
|
|
/* These flags are set by wined3d_device_setup_fullscreen_window, not the
|
|
|
|
* application, and we want to ignore them in the test below, since it's
|
|
|
|
* not the application's fault that they changed. Additionally, we want to
|
|
|
|
* preserve the current status of these flags (i.e. don't restore them) to
|
|
|
|
* more closely emulate the behavior of Direct3D, which leaves these flags
|
|
|
|
* alone when returning to windowed mode. */
|
|
|
|
device->style ^= (device->style ^ style) & WS_VISIBLE;
|
|
|
|
device->exStyle ^= (device->exStyle ^ exstyle) & WS_EX_TOPMOST;
|
|
|
|
|
|
|
|
TRACE("Restoring window style of window %p to %08x, %08x.\n",
|
|
|
|
window, device->style, device->exStyle);
|
|
|
|
|
2010-11-08 11:50:31 +01:00
|
|
|
filter_messages = device->filter_messages;
|
|
|
|
device->filter_messages = TRUE;
|
|
|
|
|
|
|
|
/* Only restore the style if the application didn't modify it during the
|
|
|
|
* fullscreen phase. Some applications change it before calling Reset()
|
|
|
|
* when switching between windowed and fullscreen modes (HL2), some
|
|
|
|
* depend on the original style (Eve Online). */
|
|
|
|
if (style == fullscreen_style(device->style) && exstyle == fullscreen_exstyle(device->exStyle))
|
|
|
|
{
|
|
|
|
SetWindowLongW(window, GWL_STYLE, device->style);
|
|
|
|
SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
|
|
|
|
}
|
2010-11-08 11:50:32 +01:00
|
|
|
SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
2010-11-08 11:50:31 +01:00
|
|
|
|
|
|
|
device->filter_messages = filter_messages;
|
|
|
|
|
|
|
|
/* Delete the old values. */
|
|
|
|
device->style = 0;
|
|
|
|
device->exStyle = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window)
|
2010-03-17 21:59:49 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p, window %p.\n", device, window);
|
2010-10-11 13:06:20 +02:00
|
|
|
|
2010-03-17 21:59:49 +01:00
|
|
|
if (!wined3d_register_window(window, device))
|
|
|
|
{
|
|
|
|
ERR("Failed to register window %p.\n", window);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-01-24 21:47:45 +01:00
|
|
|
InterlockedExchangePointer((void **)&device->focus_window, window);
|
2010-11-05 14:11:38 +01:00
|
|
|
SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
2010-03-17 21:59:49 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
|
2010-03-17 21:59:49 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2010-10-11 13:06:20 +02:00
|
|
|
|
2010-03-17 21:59:49 +01:00
|
|
|
if (device->focus_window) wined3d_unregister_window(device->focus_window);
|
2012-01-24 21:47:45 +01:00
|
|
|
InterlockedExchangePointer((void **)&device->focus_window, NULL);
|
2010-03-17 21:59:49 +01:00
|
|
|
}
|
|
|
|
|
2013-09-25 09:58:13 +02:00
|
|
|
static void device_init_swapchain_state(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
|
2013-09-23 10:26:44 +02:00
|
|
|
{
|
2013-09-25 09:58:13 +02:00
|
|
|
BOOL ds_enable = !!swapchain->desc.enable_auto_depth_stencil;
|
|
|
|
unsigned int i;
|
2013-09-23 10:26:44 +02:00
|
|
|
|
2013-09-25 09:58:13 +02:00
|
|
|
if (device->fb.render_targets)
|
|
|
|
{
|
|
|
|
for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
|
|
|
|
{
|
|
|
|
wined3d_device_set_render_target(device, i, NULL, FALSE);
|
|
|
|
}
|
|
|
|
if (swapchain->back_buffers && swapchain->back_buffers[0])
|
|
|
|
wined3d_device_set_render_target(device, 0, swapchain->back_buffers[0], TRUE);
|
|
|
|
}
|
2013-09-23 10:26:44 +02:00
|
|
|
|
2013-09-25 09:58:13 +02:00
|
|
|
wined3d_device_set_depth_stencil(device, ds_enable ? device->auto_depth_stencil : NULL);
|
|
|
|
wined3d_device_set_render_state(device, WINED3D_RS_ZENABLE, ds_enable);
|
2013-09-23 10:26:44 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
|
2011-12-02 08:15:52 +01:00
|
|
|
struct wined3d_swapchain_desc *swapchain_desc)
|
2009-01-16 10:14:24 +01:00
|
|
|
{
|
2011-11-15 21:18:28 +01:00
|
|
|
static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f};
|
2011-05-16 23:01:22 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain = NULL;
|
2009-10-28 11:00:12 +01:00
|
|
|
struct wined3d_context *context;
|
2013-09-13 10:18:11 +02:00
|
|
|
DWORD clear_flags = 0;
|
2007-06-12 17:49:58 +02:00
|
|
|
HRESULT hr;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
|
2009-01-16 10:14:24 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2013-01-17 10:24:29 +01:00
|
|
|
if (device->wined3d->flags & WINED3D_NO3D)
|
2011-05-16 23:01:22 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(*device->fb.render_targets) * gl_info->limits.buffers);
|
2007-07-16 19:49:34 +02:00
|
|
|
|
2013-04-25 12:16:47 +02:00
|
|
|
if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
|
|
|
|
device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
|
2012-10-24 21:23:37 +02:00
|
|
|
{
|
|
|
|
TRACE("Shader private data couldn't be allocated\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
if (FAILED(hr = device->blitter->alloc_private(device)))
|
|
|
|
{
|
|
|
|
TRACE("Blitter private data couldn't be allocated\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Setup the implicit swapchain. This also initializes a context. */
|
2006-04-18 22:38:30 +02:00
|
|
|
TRACE("Creating implicit swapchain\n");
|
2011-05-18 22:30:13 +02:00
|
|
|
hr = device->device_parent->ops->create_swapchain(device->device_parent,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc, &swapchain);
|
2009-01-16 10:14:24 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2006-04-18 22:38:30 +02:00
|
|
|
WARN("Failed to create implicit swapchain\n");
|
2007-10-09 22:04:18 +02:00
|
|
|
goto err_out;
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchain_count = 1;
|
|
|
|
device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
|
|
|
|
if (!device->swapchains)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
2006-05-24 11:34:30 +02:00
|
|
|
ERR("Out of memory!\n");
|
2007-10-09 22:04:18 +02:00
|
|
|
goto err_out;
|
2006-05-24 11:34:30 +02:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchains[0] = swapchain;
|
2013-09-25 09:58:13 +02:00
|
|
|
device_init_swapchain_state(device, swapchain);
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
context = context_acquire(device, swapchain->front_buffer);
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2011-08-03 01:34:15 +02:00
|
|
|
create_dummy_textures(device, context);
|
2008-04-06 23:06:22 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->contexts[0]->last_was_rhw = 0;
|
2007-02-27 21:32:15 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
switch (wined3d_settings.offscreen_rendering_mode)
|
|
|
|
{
|
2007-02-27 21:32:15 +01:00
|
|
|
case ORM_FBO:
|
2011-05-16 23:01:22 +02:00
|
|
|
device->offscreenBuffer = GL_COLOR_ATTACHMENT0;
|
2009-12-04 10:21:01 +01:00
|
|
|
break;
|
|
|
|
|
2007-02-27 21:32:15 +01:00
|
|
|
case ORM_BACKBUFFER:
|
|
|
|
{
|
2009-07-24 10:44:17 +02:00
|
|
|
if (context_get_current()->aux_buffers > 0)
|
|
|
|
{
|
2011-08-02 22:20:32 +02:00
|
|
|
TRACE("Using auxiliary buffer for offscreen rendering\n");
|
2011-05-16 23:01:22 +02:00
|
|
|
device->offscreenBuffer = GL_AUX0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-27 21:32:15 +01:00
|
|
|
TRACE("Using back buffer for offscreen rendering\n");
|
2011-05-16 23:01:22 +02:00
|
|
|
device->offscreenBuffer = GL_BACK;
|
2007-02-27 21:32:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("All defaults now set up, leaving 3D init.\n");
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2009-10-28 11:00:12 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
/* Clear the screen */
|
2013-09-25 09:58:13 +02:00
|
|
|
if (swapchain->back_buffers && swapchain->back_buffers[0])
|
|
|
|
clear_flags |= WINED3DCLEAR_TARGET;
|
2013-09-13 10:18:11 +02:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil)
|
|
|
|
clear_flags |= WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL;
|
|
|
|
if (clear_flags)
|
|
|
|
wined3d_device_clear(device, 0, NULL, clear_flags, &black, 1.0f, 0);
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->d3d_initialized = TRUE;
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (wined3d_settings.logo)
|
2011-06-07 19:44:49 +02:00
|
|
|
device_load_logo(device, wined3d_settings.logo);
|
2006-04-18 22:38:30 +02:00
|
|
|
return WINED3D_OK;
|
2007-10-09 22:04:18 +02:00
|
|
|
|
2008-01-22 09:27:00 +01:00
|
|
|
err_out:
|
2011-05-18 22:30:15 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
|
2011-05-16 23:01:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->swapchains);
|
|
|
|
device->swapchain_count = 0;
|
2011-04-06 19:17:52 +02:00
|
|
|
if (swapchain)
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->blit_priv)
|
|
|
|
device->blitter->free_private(device);
|
|
|
|
if (device->shader_priv)
|
|
|
|
device->shader_backend->shader_free_private(device);
|
|
|
|
|
2007-10-09 22:04:18 +02:00
|
|
|
return hr;
|
2006-04-12 21:08:57 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device,
|
2011-12-02 08:15:52 +01:00
|
|
|
struct wined3d_swapchain_desc *swapchain_desc)
|
2009-01-16 10:14:24 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain = NULL;
|
2008-08-05 21:23:00 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
|
2011-05-16 23:01:22 +02:00
|
|
|
|
2008-08-05 21:23:00 +02:00
|
|
|
/* Setup the implicit swapchain */
|
|
|
|
TRACE("Creating implicit swapchain\n");
|
2011-05-18 22:30:13 +02:00
|
|
|
hr = device->device_parent->ops->create_swapchain(device->device_parent,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc, &swapchain);
|
2009-01-16 10:14:24 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
WARN("Failed to create implicit swapchain\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchain_count = 1;
|
|
|
|
device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
|
|
|
|
if (!device->swapchains)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
ERR("Out of memory!\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchains[0] = swapchain;
|
2008-08-05 21:23:00 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
err_out:
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2008-08-05 21:23:00 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
|
2009-09-16 08:37:15 +02:00
|
|
|
{
|
2011-07-25 20:45:07 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2009-09-23 10:05:55 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2011-04-29 13:03:41 +02:00
|
|
|
struct wined3d_surface *surface;
|
2007-08-06 16:38:00 +02:00
|
|
|
UINT i;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
if (!device->d3d_initialized)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-03-18 19:18:40 +01:00
|
|
|
/* Force making the context current again, to verify it is still valid
|
|
|
|
* (workaround for broken drivers) */
|
|
|
|
context_set_current(NULL);
|
2008-01-09 20:37:05 +01:00
|
|
|
/* I don't think that the interface guarantees that the device is destroyed from the same thread
|
2007-03-17 23:00:39 +01:00
|
|
|
* it was created. Thus make sure a context is active for the glDelete* calls
|
|
|
|
*/
|
2011-05-16 23:01:22 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info = context->gl_info;
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2013-11-14 10:47:19 +01:00
|
|
|
if (device->logo_texture)
|
|
|
|
wined3d_texture_decref(device->logo_texture);
|
2013-11-18 10:46:16 +01:00
|
|
|
if (device->cursor_texture)
|
|
|
|
wined3d_texture_decref(device->cursor_texture);
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
state_unbind_resources(&device->state);
|
2011-12-06 22:57:44 +01:00
|
|
|
|
2009-03-23 13:54:34 +01:00
|
|
|
/* Unload resources */
|
2011-07-25 20:45:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Unloading resource %p.\n", resource);
|
|
|
|
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
|
|
|
}
|
2009-03-23 13:54:34 +01:00
|
|
|
|
2008-03-18 19:49:05 +01:00
|
|
|
/* Destroy the depth blt resources, they will be invalid after the reset. Also free shader
|
|
|
|
* private data, it might contain opengl pointers
|
|
|
|
*/
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->depth_blt_texture)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
|
2011-05-16 23:01:22 +02:00
|
|
|
device->depth_blt_texture = 0;
|
2008-06-27 00:52:13 +02:00
|
|
|
}
|
2008-03-18 19:49:05 +01:00
|
|
|
|
2008-07-10 23:26:10 +02:00
|
|
|
/* Destroy the shader backend. Note that this has to happen after all shaders are destroyed. */
|
2011-05-16 23:01:22 +02:00
|
|
|
device->blitter->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
2013-07-22 20:24:30 +02:00
|
|
|
destroy_dummy_textures(device, gl_info);
|
2008-07-10 23:26:10 +02:00
|
|
|
|
2006-05-24 11:34:30 +02:00
|
|
|
/* Release the buffers (with sanity checks)*/
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->onscreen_depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
surface = device->onscreen_depth_stencil;
|
|
|
|
device->onscreen_depth_stencil = NULL;
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_decref(surface);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
surface = device->fb.depth_stencil;
|
2010-10-05 14:32:36 +02:00
|
|
|
|
2011-01-28 20:05:40 +01:00
|
|
|
TRACE("Releasing depth/stencil buffer %p.\n", surface);
|
2010-10-05 14:32:36 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = NULL;
|
2012-01-17 21:13:30 +01:00
|
|
|
wined3d_surface_decref(surface);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->auto_depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
surface = device->auto_depth_stencil;
|
|
|
|
device->auto_depth_stencil = NULL;
|
2011-04-29 13:03:41 +02:00
|
|
|
if (wined3d_surface_decref(surface))
|
2011-05-16 23:01:22 +02:00
|
|
|
FIXME("Something's still holding the auto depth stencil buffer (%p).\n", surface);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2013-09-13 10:18:09 +02:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2011-01-28 20:05:40 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_set_render_target(device, i, NULL, FALSE);
|
2011-01-28 20:05:40 +01:00
|
|
|
}
|
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
|
|
|
TRACE("Releasing the implicit swapchain %u.\n", i);
|
2011-05-16 23:01:22 +02:00
|
|
|
if (wined3d_swapchain_decref(device->swapchains[i]))
|
2011-04-13 19:14:31 +02:00
|
|
|
FIXME("Something's still holding the implicit swapchain.\n");
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2006-05-24 11:34:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->swapchains);
|
|
|
|
device->swapchains = NULL;
|
|
|
|
device->swapchain_count = 0;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
|
|
|
|
device->fb.render_targets = NULL;
|
2007-07-16 19:49:34 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->d3d_initialized = FALSE;
|
2009-12-22 18:32:13 +01:00
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
return WINED3D_OK;
|
2006-04-12 21:08:57 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_uninit_gdi(struct wined3d_device *device)
|
2011-04-12 18:28:39 +02:00
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
|
|
|
TRACE("Releasing the implicit swapchain %u.\n", i);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (wined3d_swapchain_decref(device->swapchains[i]))
|
2011-04-13 19:14:31 +02:00
|
|
|
FIXME("Something's still holding the implicit swapchain.\n");
|
2008-08-05 21:23:00 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->swapchains);
|
|
|
|
device->swapchains = NULL;
|
|
|
|
device->swapchain_count = 0;
|
2008-08-05 21:23:00 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-19 05:40:40 +02:00
|
|
|
/* Enables thread safety in the wined3d device and its resources. Called by DirectDraw
|
|
|
|
* from SetCooperativeLevel if DDSCL_MULTITHREADED is specified, and by d3d8/9 from
|
2007-03-04 17:03:03 +01:00
|
|
|
* CreateDevice if D3DCREATE_MULTITHREADED is passed.
|
|
|
|
*
|
2007-10-19 05:40:40 +02:00
|
|
|
* There is no way to deactivate thread safety once it is enabled.
|
2007-03-04 17:03:03 +01:00
|
|
|
*/
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_set_multithreaded(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
2007-03-04 17:03:03 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
/* For now just store the flag (needed in case of ddraw). */
|
2011-11-27 21:34:48 +01:00
|
|
|
device->create_parms.flags |= WINED3DCREATE_MULTITHREADED;
|
2007-03-04 17:03:03 +01:00
|
|
|
}
|
|
|
|
|
2011-08-29 18:58:55 +02:00
|
|
|
UINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
TRACE("Emulating %d MB, returning %d MB left.\n",
|
|
|
|
device->adapter->TextureRam / (1024 * 1024),
|
|
|
|
(device->adapter->TextureRam - device->adapter->UsedTextureRam) / (1024 * 1024));
|
2007-09-23 00:46:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
return device->adapter->TextureRam - device->adapter->UsedTextureRam;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:37 +01:00
|
|
|
void CDECL wined3d_device_set_stream_output(struct wined3d_device *device, UINT idx,
|
|
|
|
struct wined3d_buffer *buffer, UINT offset)
|
|
|
|
{
|
2013-10-10 23:49:46 +02:00
|
|
|
struct wined3d_stream_output *stream;
|
2012-11-22 21:13:37 +01:00
|
|
|
struct wined3d_buffer *prev_buffer;
|
|
|
|
|
|
|
|
TRACE("device %p, idx %u, buffer %p, offset %u.\n", device, idx, buffer, offset);
|
|
|
|
|
|
|
|
if (idx >= MAX_STREAM_OUT)
|
|
|
|
{
|
|
|
|
WARN("Invalid stream output %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-10 23:49:46 +02:00
|
|
|
stream = &device->update_state->stream_output[idx];
|
|
|
|
prev_buffer = stream->buffer;
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
stream->buffer = buffer;
|
|
|
|
stream->offset = offset;
|
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_stream_output(device->cs, idx, buffer, offset);
|
|
|
|
if (prev_buffer)
|
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2012-11-22 21:13:37 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:38 +01:00
|
|
|
struct wined3d_buffer * CDECL wined3d_device_get_stream_output(struct wined3d_device *device,
|
|
|
|
UINT idx, UINT *offset)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, offset %p.\n", device, idx, offset);
|
|
|
|
|
|
|
|
if (idx >= MAX_STREAM_OUT)
|
|
|
|
{
|
|
|
|
WARN("Invalid stream output %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*offset = device->state.stream_output[idx].offset;
|
|
|
|
return device->state.stream_output[idx].buffer;
|
2012-11-22 21:13:38 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_stream_source(struct wined3d_device *device, UINT stream_idx,
|
2011-05-16 23:01:21 +02:00
|
|
|
struct wined3d_buffer *buffer, UINT offset, UINT stride)
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
2011-03-03 21:49:10 +01:00
|
|
|
struct wined3d_buffer *prev_buffer;
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
|
|
|
|
device, stream_idx, buffer, offset, stride);
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stream_idx >= MAX_STREAMS)
|
|
|
|
{
|
|
|
|
WARN("Stream index %u out of range.\n", stream_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-05-16 23:01:21 +02:00
|
|
|
}
|
|
|
|
else if (offset & 0x3)
|
|
|
|
{
|
|
|
|
WARN("Offset %u is not 4 byte aligned.\n", offset);
|
2007-12-20 22:14:53 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-02 13:17:17 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
stream = &device->update_state->streams[stream_idx];
|
2011-03-03 21:49:10 +01:00
|
|
|
prev_buffer = stream->buffer;
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.streamSource |= 1 << stream_idx;
|
2007-01-04 00:08:20 +01:00
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
if (prev_buffer == buffer
|
2011-05-16 23:01:21 +02:00
|
|
|
&& stream->stride == stride
|
|
|
|
&& stream->offset == offset)
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application is setting the old values over, nothing to do.\n");
|
2007-01-04 00:08:20 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
stream->buffer = buffer;
|
|
|
|
if (buffer)
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
stream->stride = stride;
|
|
|
|
stream->offset = offset;
|
2006-12-24 10:00:05 +01:00
|
|
|
}
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
2013-10-02 09:55:26 +02:00
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_stream_source(device->cs, stream_idx, buffer, offset, stride);
|
2011-03-03 21:49:10 +01:00
|
|
|
if (prev_buffer)
|
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2007-01-02 00:35:07 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-23 14:52:46 +01:00
|
|
|
}
|
|
|
|
|
2011-08-30 20:12:34 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_stream_source(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT stream_idx, struct wined3d_buffer **buffer, UINT *offset, UINT *stride)
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
const struct wined3d_stream_state *stream;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
|
|
|
|
device, stream_idx, buffer, offset, stride);
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stream_idx >= MAX_STREAMS)
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Stream index %u out of range.\n", stream_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-02 13:17:17 +02:00
|
|
|
}
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
stream = &device->state.streams[stream_idx];
|
2011-03-03 21:49:10 +01:00
|
|
|
*buffer = stream->buffer;
|
|
|
|
if (*buffer)
|
|
|
|
wined3d_buffer_incref(*buffer);
|
2011-05-16 23:01:21 +02:00
|
|
|
if (offset)
|
|
|
|
*offset = stream->offset;
|
|
|
|
*stride = stream->stride;
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-23 14:52:46 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT divider)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT old_flags, old_freq;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, divider %#x.\n", device, stream_idx, divider);
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Verify input. At least in d3d9 this is invalid. */
|
|
|
|
if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && (divider & WINED3DSTREAMSOURCE_INDEXEDDATA))
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("INSTANCEDATA and INDEXEDDATA were set, returning D3DERR_INVALIDCALL.\n");
|
2008-04-06 18:50:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && !stream_idx)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("INSTANCEDATA used on stream 0, returning D3DERR_INVALIDCALL.\n");
|
2008-04-06 18:50:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!divider)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Divider is 0, returning D3DERR_INVALIDCALL.\n");
|
2008-04-06 18:50:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
stream = &device->update_state->streams[stream_idx];
|
2010-11-18 20:50:40 +01:00
|
|
|
old_flags = stream->flags;
|
2011-05-16 23:01:21 +02:00
|
|
|
old_freq = stream->frequency;
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
stream->flags = divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
|
|
|
|
stream->frequency = divider & 0x7fffff;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.streamFreq |= 1 << stream_idx;
|
2013-08-23 10:18:16 +02:00
|
|
|
else if (stream->frequency != old_freq || stream->flags != old_flags)
|
2013-10-03 08:54:11 +02:00
|
|
|
wined3d_cs_emit_set_stream_source_freq(device->cs, stream_idx, stream->frequency, stream->flags);
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-08-30 20:12:35 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_stream_source_freq(const struct wined3d_device *device,
|
|
|
|
UINT stream_idx, UINT *divider)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
const struct wined3d_stream_state *stream;
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, divider %p.\n", device, stream_idx, divider);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
stream = &device->state.streams[stream_idx];
|
2011-05-16 23:01:21 +02:00
|
|
|
*divider = stream->flags | stream->frequency;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Returning %#x.\n", *divider);
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-12 11:30:52 +02:00
|
|
|
void CDECL wined3d_device_set_transform(struct wined3d_device *device,
|
2012-01-11 21:27:32 +01:00
|
|
|
enum wined3d_transform_state d3dts, const struct wined3d_matrix *matrix)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, state %s, matrix %p.\n",
|
|
|
|
device, debug_d3dtstype(d3dts), matrix);
|
2012-05-22 18:01:05 +02:00
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._11, matrix->u.s._12, matrix->u.s._13, matrix->u.s._14);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._21, matrix->u.s._22, matrix->u.s._23, matrix->u.s._24);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._31, matrix->u.s._32, matrix->u.s._33, matrix->u.s._34);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._41, matrix->u.s._42, matrix->u.s._43, matrix->u.s._44);
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.transform[d3dts >> 5] |= 1 << (d3dts & 0x1f);
|
|
|
|
device->update_state->transforms[d3dts] = *matrix;
|
2012-09-12 11:30:52 +02:00
|
|
|
return;
|
2004-11-28 16:04:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* If the new matrix is the same as the current one,
|
2004-11-28 16:04:41 +01:00
|
|
|
* we cut off any further processing. this seems to be a reasonable
|
|
|
|
* optimization because as was noticed, some apps (warcraft3 for example)
|
|
|
|
* tend towards setting the same matrix repeatedly for some reason.
|
|
|
|
*
|
2011-05-16 23:01:21 +02:00
|
|
|
* From here on we assume that the new matrix is different, wherever it matters. */
|
2013-08-27 08:44:59 +02:00
|
|
|
if (!memcmp(&device->state.transforms[d3dts].u.m[0][0], matrix, sizeof(*matrix)))
|
2010-09-16 11:19:56 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("The application is setting the same matrix over again.\n");
|
2012-09-12 11:30:52 +02:00
|
|
|
return;
|
2010-09-16 11:19:56 +02:00
|
|
|
}
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
device->state.transforms[d3dts] = *matrix;
|
2013-10-07 22:15:49 +02:00
|
|
|
wined3d_cs_emit_set_transform(device->cs, d3dts, matrix);
|
2004-11-28 16:04:41 +01:00
|
|
|
}
|
2010-09-16 11:19:56 +02:00
|
|
|
|
2012-09-12 11:30:53 +02:00
|
|
|
void CDECL wined3d_device_get_transform(const struct wined3d_device *device,
|
2012-01-11 21:27:32 +01:00
|
|
|
enum wined3d_transform_state state, struct wined3d_matrix *matrix)
|
2010-09-16 11:19:56 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
|
2010-09-16 11:19:56 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*matrix = device->state.transforms[state];
|
2004-11-28 16:04:41 +01:00
|
|
|
}
|
|
|
|
|
2012-09-14 13:11:33 +02:00
|
|
|
void CDECL wined3d_device_multiply_transform(struct wined3d_device *device,
|
2012-01-11 21:27:32 +01:00
|
|
|
enum wined3d_transform_state state, const struct wined3d_matrix *matrix)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2012-09-14 13:11:33 +02:00
|
|
|
const struct wined3d_matrix *mat;
|
2011-11-17 20:11:41 +01:00
|
|
|
struct wined3d_matrix temp;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
|
|
|
|
|
2004-12-20 20:27:06 +01:00
|
|
|
/* Note: Using 'updateStateBlock' rather than 'stateblock' in the code
|
|
|
|
* below means it will be recorded in a state block change, but it
|
2005-07-13 16:15:54 +02:00
|
|
|
* works regardless where it is recorded.
|
2011-05-16 23:01:23 +02:00
|
|
|
* If this is found to be wrong, change to StateBlock. */
|
2011-06-11 18:05:02 +02:00
|
|
|
if (state > HIGHEST_TRANSFORMSTATE)
|
|
|
|
{
|
|
|
|
WARN("Unhandled transform state %#x.\n", state);
|
2012-09-14 13:11:33 +02:00
|
|
|
return;
|
2011-06-11 18:05:02 +02:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
mat = &device->update_state->transforms[state];
|
2011-05-16 23:01:23 +02:00
|
|
|
multiply_matrix(&temp, mat, matrix);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Apply change via set transform - will reapply to eg. lights this way. */
|
2012-09-12 11:30:52 +02:00
|
|
|
wined3d_device_set_transform(device, state, &temp);
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Note lights are real special cases. Although the device caps state only
|
|
|
|
* e.g. 8 are supported, you can reference any indexes you want as long as
|
|
|
|
* that number max are enabled at any one point in time. Therefore since the
|
|
|
|
* indices can be anything, we need a hashmap of them. However, this causes
|
|
|
|
* stateblock problems. When capturing the state block, I duplicate the
|
|
|
|
* hashmap, but when recording, just build a chain pretty much of commands to
|
|
|
|
* be replayed. */
|
2011-11-20 20:27:12 +01:00
|
|
|
HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device,
|
|
|
|
UINT light_idx, const struct wined3d_light *light)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
2009-10-14 10:55:16 +02:00
|
|
|
struct wined3d_light_info *object = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2011-05-16 23:01:21 +02:00
|
|
|
float rho;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Check the parameter range. Need for speed most wanted sets junk lights
|
|
|
|
* which confuse the GL driver. */
|
|
|
|
if (!light)
|
2007-02-20 22:43:13 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
switch (light->type)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_POINT:
|
|
|
|
case WINED3D_LIGHT_SPOT:
|
|
|
|
case WINED3D_LIGHT_PARALLELPOINT:
|
|
|
|
case WINED3D_LIGHT_GLSPOT:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Incorrect attenuation values can cause the gl driver to crash.
|
|
|
|
* Happens with Need for speed most wanted. */
|
2011-11-20 20:27:12 +01:00
|
|
|
if (light->attenuation0 < 0.0f || light->attenuation1 < 0.0f || light->attenuation2 < 0.0f)
|
2009-07-07 11:08:01 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Attenuation is negative, returning WINED3DERR_INVALIDCALL.\n");
|
2007-02-20 22:43:13 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_DIRECTIONAL:
|
2007-02-20 22:43:13 +01:00
|
|
|
/* Ignores attenuation */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("Light type out of range, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
LIST_FOR_EACH(e, &device->update_state->light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
|
|
|
object = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
2011-05-16 23:01:21 +02:00
|
|
|
if (object->OriginalIndex == light_idx)
|
|
|
|
break;
|
2007-02-14 17:46:54 +01:00
|
|
|
object = NULL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!object)
|
|
|
|
{
|
2007-02-14 17:46:54 +01:00
|
|
|
TRACE("Adding new light\n");
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!object)
|
2007-02-14 17:46:54 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2013-02-05 15:49:14 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
list_add_head(&device->update_state->light_map[hash_idx], &object->entry);
|
2004-11-29 18:53:42 +01:00
|
|
|
object->glIndex = -1;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->OriginalIndex = light_idx;
|
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Initialize the object. */
|
|
|
|
TRACE("Light %d setting to type %d, Diffuse(%f,%f,%f,%f), Specular(%f,%f,%f,%f), Ambient(%f,%f,%f,%f)\n",
|
2011-11-20 20:27:12 +01:00
|
|
|
light_idx, light->type,
|
|
|
|
light->diffuse.r, light->diffuse.g, light->diffuse.b, light->diffuse.a,
|
|
|
|
light->specular.r, light->specular.g, light->specular.b, light->specular.a,
|
|
|
|
light->ambient.r, light->ambient.g, light->ambient.b, light->ambient.a);
|
|
|
|
TRACE("... Pos(%f,%f,%f), Dir(%f,%f,%f)\n", light->position.x, light->position.y, light->position.z,
|
|
|
|
light->direction.x, light->direction.y, light->direction.z);
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("... Range(%f), Falloff(%f), Theta(%f), Phi(%f)\n",
|
2011-11-20 20:27:12 +01:00
|
|
|
light->range, light->falloff, light->theta, light->phi);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2013-05-29 09:45:38 +02:00
|
|
|
/* Update the live definitions if the light is currently assigned a glIndex. */
|
2013-08-26 09:23:37 +02:00
|
|
|
if (object->glIndex != -1 && !device->recording)
|
2013-05-29 09:45:38 +02:00
|
|
|
{
|
|
|
|
if (object->OriginalParms.type != light->type)
|
|
|
|
device_invalidate_state(device, STATE_LIGHT_TYPE);
|
|
|
|
device_invalidate_state(device, STATE_ACTIVELIGHT(object->glIndex));
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Save away the information. */
|
|
|
|
object->OriginalParms = *light;
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
switch (light->type)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_POINT:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Position */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightPosn[0] = light->position.x;
|
|
|
|
object->lightPosn[1] = light->position.y;
|
|
|
|
object->lightPosn[2] = light->position.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightPosn[3] = 1.0f;
|
|
|
|
object->cutoff = 180.0f;
|
|
|
|
/* FIXME: Range */
|
|
|
|
break;
|
|
|
|
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_DIRECTIONAL:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Direction */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightPosn[0] = -light->direction.x;
|
|
|
|
object->lightPosn[1] = -light->direction.y;
|
|
|
|
object->lightPosn[2] = -light->direction.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightPosn[3] = 0.0f;
|
2009-07-07 11:08:01 +02:00
|
|
|
object->exponent = 0.0f;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->cutoff = 180.0f;
|
|
|
|
break;
|
|
|
|
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_SPOT:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Position */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightPosn[0] = light->position.x;
|
|
|
|
object->lightPosn[1] = light->position.y;
|
|
|
|
object->lightPosn[2] = light->position.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightPosn[3] = 1.0f;
|
|
|
|
|
|
|
|
/* Direction */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightDirn[0] = light->direction.x;
|
|
|
|
object->lightDirn[1] = light->direction.y;
|
|
|
|
object->lightDirn[2] = light->direction.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightDirn[3] = 1.0f;
|
|
|
|
|
|
|
|
/* opengl-ish and d3d-ish spot lights use too different models
|
|
|
|
* for the light "intensity" as a function of the angle towards
|
|
|
|
* the main light direction, so we only can approximate very
|
|
|
|
* roughly. However, spot lights are rather rarely used in games
|
|
|
|
* (if ever used at all). Furthermore if still used, probably
|
|
|
|
* nobody pays attention to such details. */
|
2011-11-20 20:27:12 +01:00
|
|
|
if (!light->falloff)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
/* Falloff = 0 is easy, because d3d's and opengl's spot light
|
|
|
|
* equations have the falloff resp. exponent parameter as an
|
|
|
|
* exponent, so the spot light lighting will always be 1.0 for
|
|
|
|
* both of them, and we don't have to care for the rest of the
|
|
|
|
* rather complex calculation. */
|
|
|
|
object->exponent = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-20 20:27:12 +01:00
|
|
|
rho = light->theta + (light->phi - light->theta) / (2 * light->falloff);
|
2011-05-16 23:01:21 +02:00
|
|
|
if (rho < 0.0001f)
|
|
|
|
rho = 0.0001f;
|
|
|
|
object->exponent = -0.3f / logf(cosf(rho / 2));
|
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (object->exponent > 128.0f)
|
|
|
|
object->exponent = 128.0f;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
object->cutoff = (float)(light->phi * 90 / M_PI);
|
2011-05-16 23:01:21 +02:00
|
|
|
/* FIXME: Range */
|
|
|
|
break;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
default:
|
2011-11-20 20:27:12 +01:00
|
|
|
FIXME("Unrecognized light type %#x.\n", light->type);
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
HRESULT CDECL wined3d_device_get_light(const struct wined3d_device *device,
|
|
|
|
UINT light_idx, struct wined3d_light *light)
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
|
|
|
struct wined3d_light_info *light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
LIST_FOR_EACH(e, &device->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2004-11-29 18:53:42 +01:00
|
|
|
TRACE("Light information requested but light not defined\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*light = light_info->OriginalParms;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UINT light_idx, BOOL enable)
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
|
|
|
struct wined3d_light_info *light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, enable %#x.\n", device, light_idx, enable);
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
LIST_FOR_EACH(e, &device->update_state->light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Found light %p.\n", light_info);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Special case - enabling an undefined light creates one with a strict set of parameters. */
|
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2005-07-13 16:15:54 +02:00
|
|
|
TRACE("Light enabled requested but light not defined, so defining one!\n");
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_set_light(device, light_idx, &WINED3D_default_light);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Search for it again! Should be fairly quick as near head of list. */
|
2013-08-26 09:23:37 +02:00
|
|
|
LIST_FOR_EACH(e, &device->update_state->light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2004-11-29 18:53:42 +01:00
|
|
|
FIXME("Adding default lights has failed dismally\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!enable)
|
|
|
|
{
|
|
|
|
if (light_info->glIndex != -1)
|
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
if (!device->recording)
|
2013-05-29 09:45:38 +02:00
|
|
|
{
|
|
|
|
device_invalidate_state(device, STATE_LIGHT_TYPE);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_ACTIVELIGHT(light_info->glIndex));
|
2013-05-29 09:45:38 +02:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->lights[light_info->glIndex] = NULL;
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info->glIndex = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-14 17:46:54 +01:00
|
|
|
TRACE("Light already disabled, nothing to do\n");
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info->enabled = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
light_info->enabled = TRUE;
|
|
|
|
if (light_info->glIndex != -1)
|
|
|
|
{
|
2004-11-29 18:53:42 +01:00
|
|
|
TRACE("Nothing to do as light was enabled\n");
|
2011-05-16 23:01:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-18 09:12:40 +02:00
|
|
|
unsigned int i;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Find a free GL light. */
|
2011-05-18 09:12:40 +02:00
|
|
|
for (i = 0; i < gl_info->limits.lights; ++i)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
if (!device->update_state->lights[i])
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->lights[i] = light_info;
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info->glIndex = i;
|
2007-02-14 17:46:54 +01:00
|
|
|
break;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if (light_info->glIndex == -1)
|
|
|
|
{
|
2007-11-29 13:22:47 +01:00
|
|
|
/* Our tests show that Windows returns D3D_OK in this situation, even with
|
|
|
|
* D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE devices. This
|
|
|
|
* is consistent among ddraw, d3d8 and d3d9. GetLightEnable returns TRUE
|
|
|
|
* as well for those lights.
|
|
|
|
*
|
2011-05-16 23:01:21 +02:00
|
|
|
* TODO: Test how this affects rendering. */
|
2008-12-29 16:31:22 +01:00
|
|
|
WARN("Too many concurrently active lights\n");
|
2007-11-29 13:22:47 +01:00
|
|
|
return WINED3D_OK;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* i == light_info->glIndex */
|
2013-08-26 09:23:37 +02:00
|
|
|
if (!device->recording)
|
2013-05-29 09:45:38 +02:00
|
|
|
{
|
|
|
|
device_invalidate_state(device, STATE_LIGHT_TYPE);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_ACTIVELIGHT(i));
|
2013-05-29 09:45:38 +02:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
}
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-09-01 20:20:56 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable)
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
|
|
|
struct wined3d_light_info *light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, enable %p.\n", device, light_idx, enable);
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
LIST_FOR_EACH(e, &device->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Light enabled state requested but light not defined.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2007-02-14 17:46:54 +01:00
|
|
|
/* true is 128 according to SetLightEnable */
|
2011-05-16 23:01:21 +02:00
|
|
|
*enable = light_info->enabled ? 128 : 0;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device,
|
|
|
|
UINT plane_idx, const struct wined3d_vec4 *plane)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Validate plane_idx. */
|
|
|
|
if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application has requested clipplane this device doesn't support.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.clipplane |= 1 << plane_idx;
|
2007-02-28 14:36:36 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (!memcmp(&device->update_state->clip_planes[plane_idx], plane, sizeof(*plane)))
|
2010-09-21 21:20:55 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application is setting old values over, nothing to do.\n");
|
2007-02-28 14:36:36 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->clip_planes[plane_idx] = *plane;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2013-10-09 10:39:36 +02:00
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_clip_plane(device->cs, plane_idx, plane);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_clip_plane(const struct wined3d_device *device,
|
|
|
|
UINT plane_idx, struct wined3d_vec4 *plane)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Validate plane_idx. */
|
|
|
|
if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application has requested clipplane this device doesn't support.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*plane = device->state.clip_planes[plane_idx];
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-11-24 22:52:35 +01:00
|
|
|
HRESULT CDECL wined3d_device_set_clip_status(struct wined3d_device *device,
|
|
|
|
const struct wined3d_clip_status *clip_status)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
FIXME("device %p, clip_status %p stub!\n", device, clip_status);
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!clip_status)
|
2010-09-14 13:38:39 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-11-24 22:52:35 +01:00
|
|
|
HRESULT CDECL wined3d_device_get_clip_status(const struct wined3d_device *device,
|
|
|
|
struct wined3d_clip_status *clip_status)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
FIXME("device %p, clip_status %p stub!\n", device, clip_status);
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!clip_status)
|
2010-09-14 13:38:39 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-09-17 21:48:51 +02:00
|
|
|
void CDECL wined3d_device_set_material(struct wined3d_device *device, const struct wined3d_material *material)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, material %p.\n", device, material);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->material = *material;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.material = TRUE;
|
2013-10-09 10:39:37 +02:00
|
|
|
else
|
|
|
|
wined3d_cs_emit_set_material(device->cs, material);
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-09-17 21:48:52 +02:00
|
|
|
void CDECL wined3d_device_get_material(const struct wined3d_device *device, struct wined3d_material *material)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, material %p.\n", device, material);
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*material = device->state.material;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2011-11-20 20:27:13 +01:00
|
|
|
TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->diffuse.r, material->diffuse.g,
|
|
|
|
material->diffuse.b, material->diffuse.a);
|
|
|
|
TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->ambient.r, material->ambient.g,
|
|
|
|
material->ambient.b, material->ambient.a);
|
|
|
|
TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->specular.r, material->specular.g,
|
|
|
|
material->specular.b, material->specular.a);
|
|
|
|
TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->emissive.r, material->emissive.g,
|
|
|
|
material->emissive.b, material->emissive.a);
|
|
|
|
TRACE("power %.8e.\n", material->power);
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 11:25:02 +02:00
|
|
|
void CDECL wined3d_device_set_index_buffer(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
struct wined3d_buffer *buffer, enum wined3d_format_id format_id)
|
2009-09-25 13:31:45 +02:00
|
|
|
{
|
2013-10-03 08:54:12 +02:00
|
|
|
enum wined3d_format_id prev_format;
|
2011-03-03 21:49:10 +01:00
|
|
|
struct wined3d_buffer *prev_buffer;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, buffer %p, format %s.\n",
|
|
|
|
device, buffer, debug_d3dformat(format_id));
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
prev_buffer = device->update_state->index_buffer;
|
2013-10-03 08:54:12 +02:00
|
|
|
prev_format = device->update_state->index_format;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->index_buffer = buffer;
|
|
|
|
device->update_state->index_format = format_id;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.indices = TRUE;
|
2013-10-03 08:54:12 +02:00
|
|
|
|
|
|
|
if (prev_buffer == buffer && prev_format == format_id)
|
2012-09-06 11:25:02 +02:00
|
|
|
return;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-10-03 08:54:12 +02:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id);
|
|
|
|
if (prev_buffer)
|
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2012-11-20 22:40:21 +01:00
|
|
|
struct wined3d_buffer * CDECL wined3d_device_get_index_buffer(const struct wined3d_device *device,
|
|
|
|
enum wined3d_format_id *format)
|
2009-09-25 13:31:46 +02:00
|
|
|
{
|
2012-11-20 22:40:21 +01:00
|
|
|
TRACE("device %p, format %p.\n", device, format);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*format = device->state.index_format;
|
|
|
|
return device->state.index_buffer;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2012-09-13 09:18:16 +02:00
|
|
|
void CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device, INT base_index)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, base_index %d.\n", device, base_index);
|
2007-01-02 21:07:39 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->base_vertex_index = base_index;
|
2007-01-02 21:07:39 +01:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:15:54 +02:00
|
|
|
INT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
2007-06-06 18:40:02 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
return device->state.base_vertex_index;
|
2007-06-06 18:40:02 +02:00
|
|
|
}
|
|
|
|
|
2012-09-08 11:26:24 +02:00
|
|
|
void CDECL wined3d_device_set_viewport(struct wined3d_device *device, const struct wined3d_viewport *viewport)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, viewport %p.\n", device, viewport);
|
2011-11-21 18:48:40 +01:00
|
|
|
TRACE("x %u, y %u, w %u, h %u, min_z %.8e, max_z %.8e.\n",
|
|
|
|
viewport->x, viewport->y, viewport->width, viewport->height, viewport->min_z, viewport->max_z);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->viewport = *viewport;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
|
|
|
/* Handle recording of state blocks */
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2004-12-09 12:42:34 +01:00
|
|
|
TRACE("Recording... not performing anything\n");
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.viewport = TRUE;
|
2012-09-08 11:26:24 +02:00
|
|
|
return;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2013-09-30 09:40:39 +02:00
|
|
|
wined3d_cs_emit_set_viewport(device->cs, viewport);
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2012-09-08 11:26:25 +02:00
|
|
|
void CDECL wined3d_device_get_viewport(const struct wined3d_device *device, struct wined3d_viewport *viewport)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, viewport %p.\n", device, viewport);
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*viewport = device->state.viewport;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2013-02-18 13:56:23 +01:00
|
|
|
static void resolve_depth_buffer(struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = state->textures[0];
|
|
|
|
struct wined3d_surface *depth_stencil, *surface;
|
|
|
|
|
|
|
|
if (!texture || texture->resource.type != WINED3D_RTYPE_TEXTURE
|
|
|
|
|| !(texture->resource.format->flags & WINED3DFMT_FLAG_DEPTH))
|
|
|
|
return;
|
|
|
|
surface = surface_from_resource(texture->sub_resources[0]);
|
|
|
|
depth_stencil = state->fb->depth_stencil;
|
|
|
|
if (!depth_stencil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wined3d_surface_blt(surface, NULL, depth_stencil, NULL, 0, NULL, WINED3D_TEXF_POINT);
|
|
|
|
}
|
|
|
|
|
2012-09-11 00:27:02 +02:00
|
|
|
void CDECL wined3d_device_set_render_state(struct wined3d_device *device,
|
2011-12-19 21:00:09 +01:00
|
|
|
enum wined3d_render_state state, DWORD value)
|
2010-09-15 12:00:04 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
DWORD old_value = device->state.render_states[state];
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, state %s (%#x), value %#x.\n", device, debug_d3drenderstate(state), state, value);
|
2006-12-15 19:16:36 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->render_states[state] = value;
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.renderState[state >> 5] |= 1 << (state & 0x1f);
|
2012-09-11 00:27:02 +02:00
|
|
|
return;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Compared here and not before the assignment to allow proper stateblock recording. */
|
|
|
|
if (value == old_value)
|
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
|
|
|
else
|
2013-10-06 17:33:04 +02:00
|
|
|
wined3d_cs_emit_set_render_state(device->cs, state, value);
|
2013-02-18 13:56:23 +01:00
|
|
|
|
|
|
|
if (state == WINED3D_RS_POINTSIZE && value == WINED3D_RESZ_CODE)
|
|
|
|
{
|
|
|
|
TRACE("RESZ multisampled depth buffer resolve triggered.\n");
|
2013-08-27 08:44:59 +02:00
|
|
|
resolve_depth_buffer(&device->state);
|
2013-02-18 13:56:23 +01:00
|
|
|
}
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2012-09-11 00:27:03 +02:00
|
|
|
DWORD CDECL wined3d_device_get_render_state(const struct wined3d_device *device, enum wined3d_render_state state)
|
2010-09-15 12:00:04 +02:00
|
|
|
{
|
2012-09-11 00:27:03 +02:00
|
|
|
TRACE("device %p, state %s (%#x).\n", device, debug_d3drenderstate(state), state);
|
2010-07-26 12:06:35 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
return device->state.render_states[state];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-18 22:13:57 +02:00
|
|
|
void CDECL wined3d_device_set_sampler_state(struct wined3d_device *device,
|
2012-01-08 21:14:59 +01:00
|
|
|
UINT sampler_idx, enum wined3d_sampler_state state, DWORD value)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
DWORD old_value;
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, sampler_idx %u, state %s, value %#x.\n",
|
|
|
|
device, sampler_idx, debug_d3dsamplerstate(state), value);
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2006-12-19 23:17:17 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (sampler_idx >= sizeof(device->state.sampler_states) / sizeof(*device->state.sampler_states))
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Invalid sampler %u.\n", sampler_idx);
|
2012-09-18 22:13:57 +02:00
|
|
|
return; /* Windows accepts overflowing this array ... we do not. */
|
2008-01-15 08:06:37 +01:00
|
|
|
}
|
2010-09-16 11:19:58 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
old_value = device->state.sampler_states[sampler_idx][state];
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->sampler_states[sampler_idx][state] = value;
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.samplerState[sampler_idx] |= 1 << state;
|
2012-09-18 22:13:57 +02:00
|
|
|
return;
|
2005-08-01 12:58:31 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (old_value == value)
|
|
|
|
{
|
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
2012-09-18 22:13:57 +02:00
|
|
|
return;
|
2006-12-19 23:17:17 +01:00
|
|
|
}
|
|
|
|
|
2013-10-07 22:15:48 +02:00
|
|
|
wined3d_cs_emit_set_sampler_state(device->cs, sampler_idx, state, value);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-18 22:13:58 +02:00
|
|
|
DWORD CDECL wined3d_device_get_sampler_state(const struct wined3d_device *device,
|
|
|
|
UINT sampler_idx, enum wined3d_sampler_state state)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2012-09-18 22:13:58 +02:00
|
|
|
TRACE("device %p, sampler_idx %u, state %s.\n",
|
|
|
|
device, sampler_idx, debug_d3dsamplerstate(state));
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (sampler_idx >= sizeof(device->state.sampler_states) / sizeof(*device->state.sampler_states))
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Invalid sampler %u.\n", sampler_idx);
|
2012-09-18 22:13:58 +02:00
|
|
|
return 0; /* Windows accepts overflowing this array ... we do not. */
|
2008-01-15 08:06:37 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
return device->state.sampler_states[sampler_idx][state];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 21:50:21 +02:00
|
|
|
void CDECL wined3d_device_set_scissor_rect(struct wined3d_device *device, const RECT *rect)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, rect %s.\n", device, wine_dbgstr_rect(rect));
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.scissorRect = TRUE;
|
2013-08-23 10:18:16 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (EqualRect(&device->update_state->scissor_rect, rect))
|
2010-09-15 12:00:05 +02:00
|
|
|
{
|
|
|
|
TRACE("App is setting the old scissor rectangle over, nothing to do.\n");
|
2012-09-19 21:50:21 +02:00
|
|
|
return;
|
2007-02-19 15:25:16 +01:00
|
|
|
}
|
2013-08-26 09:23:37 +02:00
|
|
|
CopyRect(&device->update_state->scissor_rect, rect);
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2012-09-19 21:50:21 +02:00
|
|
|
return;
|
2007-01-10 11:28:42 +01:00
|
|
|
}
|
|
|
|
|
2013-09-30 09:40:41 +02:00
|
|
|
wined3d_cs_emit_set_scissor_rect(device->cs, rect);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 21:50:22 +02:00
|
|
|
void CDECL wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, rect %p.\n", device, rect);
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*rect = device->state.scissor_rect;
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Returning rect %s.\n", wine_dbgstr_rect(rect));
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-20 22:59:20 +02:00
|
|
|
void CDECL wined3d_device_set_vertex_declaration(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
struct wined3d_vertex_declaration *declaration)
|
2011-02-02 20:22:51 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
struct wined3d_vertex_declaration *prev = device->update_state->vertex_declaration;
|
2005-07-07 22:45:39 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, declaration %p.\n", device, declaration);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.vertexDecl = TRUE;
|
2012-09-20 22:59:20 +02:00
|
|
|
|
|
|
|
if (declaration == prev)
|
|
|
|
return;
|
2005-12-16 12:38:24 +01:00
|
|
|
|
2013-10-01 10:38:31 +02:00
|
|
|
if (declaration)
|
|
|
|
wined3d_vertex_declaration_incref(declaration);
|
|
|
|
device->update_state->vertex_declaration = declaration;
|
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_vertex_declaration(device->cs, declaration);
|
|
|
|
if (prev)
|
|
|
|
wined3d_vertex_declaration_decref(prev);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-20 22:59:21 +02:00
|
|
|
struct wined3d_vertex_declaration * CDECL wined3d_device_get_vertex_declaration(const struct wined3d_device *device)
|
2011-02-02 20:22:51 +01:00
|
|
|
{
|
2012-09-20 22:59:21 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-02-02 20:22:50 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
return device->state.vertex_declaration;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-23 22:14:47 +02:00
|
|
|
void CDECL wined3d_device_set_vertex_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
2010-09-20 12:04:27 +02:00
|
|
|
{
|
2013-10-09 22:57:45 +02:00
|
|
|
struct wined3d_shader *prev = device->update_state->shader[WINED3D_SHADER_TYPE_VERTEX];
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.vertexShader = TRUE;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
if (shader == prev)
|
2012-09-23 22:14:47 +02:00
|
|
|
return;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2013-10-03 23:31:44 +02:00
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2013-10-09 22:57:45 +02:00
|
|
|
device->update_state->shader[WINED3D_SHADER_TYPE_VERTEX] = shader;
|
2013-10-03 23:31:44 +02:00
|
|
|
if (!device->recording)
|
2013-10-09 22:57:45 +02:00
|
|
|
wined3d_cs_emit_set_shader(device->cs, WINED3D_SHADER_TYPE_VERTEX, shader);
|
2013-10-03 23:31:44 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_shader_decref(prev);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-08 23:50:39 +02:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_vertex_shader(const struct wined3d_device *device)
|
2010-09-06 22:18:55 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2013-10-09 22:57:45 +02:00
|
|
|
return device->state.shader[WINED3D_SHADER_TYPE_VERTEX];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
static void wined3d_device_set_constant_buffer(struct wined3d_device *device,
|
|
|
|
enum wined3d_shader_type type, UINT idx, struct wined3d_buffer *buffer)
|
2012-11-29 22:44:45 +01:00
|
|
|
{
|
|
|
|
struct wined3d_buffer *prev;
|
|
|
|
|
|
|
|
if (idx >= MAX_CONSTANT_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("Invalid constant buffer index %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
prev = device->update_state->cb[type][idx];
|
2013-10-10 23:49:44 +02:00
|
|
|
if (buffer == prev)
|
2012-11-29 22:44:45 +01:00
|
|
|
return;
|
|
|
|
|
2013-10-10 23:49:44 +02:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
device->update_state->cb[type][idx] = buffer;
|
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_constant_buffer(device->cs, type, idx, buffer);
|
|
|
|
if (prev)
|
|
|
|
wined3d_buffer_decref(prev);
|
2012-11-29 22:44:45 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
void CDECL wined3d_device_set_vs_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
|
|
|
|
|
|
|
|
wined3d_device_set_constant_buffer(device, WINED3D_SHADER_TYPE_VERTEX, idx, buffer);
|
|
|
|
}
|
|
|
|
|
2012-11-29 22:44:46 +01:00
|
|
|
struct wined3d_buffer * CDECL wined3d_device_get_vs_cb(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
if (idx >= MAX_CONSTANT_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("Invalid constant buffer index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
return device->state.cb[WINED3D_SHADER_TYPE_VERTEX][idx];
|
2012-11-29 22:44:46 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
static void wined3d_device_set_sampler(struct wined3d_device *device,
|
|
|
|
enum wined3d_shader_type type, UINT idx, struct wined3d_sampler *sampler)
|
2012-12-05 21:01:47 +01:00
|
|
|
{
|
|
|
|
struct wined3d_sampler *prev;
|
|
|
|
|
|
|
|
if (idx >= MAX_SAMPLER_OBJECTS)
|
|
|
|
{
|
|
|
|
WARN("Invalid sampler index %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
prev = device->update_state->sampler[type][idx];
|
2013-10-10 23:49:45 +02:00
|
|
|
if (sampler == prev)
|
|
|
|
return;
|
2012-12-05 21:01:47 +01:00
|
|
|
|
|
|
|
if (sampler)
|
|
|
|
wined3d_sampler_incref(sampler);
|
2013-10-10 23:49:45 +02:00
|
|
|
device->update_state->sampler[type][idx] = sampler;
|
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_sampler(device->cs, type, idx, sampler);
|
2012-12-05 21:01:47 +01:00
|
|
|
if (prev)
|
|
|
|
wined3d_sampler_decref(prev);
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
void CDECL wined3d_device_set_vs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
|
|
|
|
|
|
|
|
wined3d_device_set_sampler(device, WINED3D_SHADER_TYPE_VERTEX, idx, sampler);
|
|
|
|
}
|
|
|
|
|
2012-12-05 21:01:48 +01:00
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_vs_sampler(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
if (idx >= MAX_SAMPLER_OBJECTS)
|
|
|
|
{
|
|
|
|
WARN("Invalid sampler index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
return device->state.sampler[WINED3D_SHADER_TYPE_VERTEX][idx];
|
2012-12-05 21:01:48 +01:00
|
|
|
}
|
|
|
|
|
2013-09-24 17:36:21 +02:00
|
|
|
static void device_invalidate_shader_constants(const struct wined3d_device *device, DWORD mask)
|
2013-08-16 09:12:30 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < device->context_count; ++i)
|
|
|
|
{
|
|
|
|
device->contexts[i]->constant_update_mask |= mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_b(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
|
|
|
UINT i;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
memcpy(&device->update_state->vs_consts_b[start_register], constants, count * sizeof(BOOL));
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set BOOL constant %u to %s.\n", start_register + i, constants[i] ? "true" : "false");
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.vertexShaderConstantsB |= (1 << i);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-16 09:12:30 +02:00
|
|
|
device_invalidate_shader_constants(device, WINED3D_SHADER_CONST_VS_B);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 22:25:41 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_b(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
memcpy(constants, &device->state.vs_consts_b[start_register], count * sizeof(BOOL));
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_i(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
|
|
|
UINT i;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
memcpy(&device->update_state->vs_consts_i[start_register * 4], constants, count * sizeof(int) * 4);
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set INT constant %u to {%d, %d, %d, %d}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.vertexShaderConstantsI |= (1 << i);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-16 09:12:30 +02:00
|
|
|
device_invalidate_shader_constants(device, WINED3D_SHADER_CONST_VS_I);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-12-20 11:46:52 +01:00
|
|
|
}
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-09-11 22:25:42 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_i(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
memcpy(constants, &device->state.vs_consts_i[start_register * 4], count * sizeof(int) * 4);
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-12-20 11:46:52 +01:00
|
|
|
}
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const float *constants, UINT vector4f_count)
|
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
UINT i;
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Specifically test start_register > limit to catch MAX_UINT overflows
|
|
|
|
* when adding start_register + vector4f_count. */
|
|
|
|
if (!constants
|
2013-04-25 15:20:27 +02:00
|
|
|
|| start_register + vector4f_count > d3d_info->limits.vs_uniform_count
|
|
|
|
|| start_register > d3d_info->limits.vs_uniform_count)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
memcpy(&device->update_state->vs_consts_f[start_register * 4],
|
2011-05-16 23:01:21 +02:00
|
|
|
constants, vector4f_count * sizeof(float) * 4);
|
|
|
|
if (TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
for (i = 0; i < vector4f_count; ++i)
|
|
|
|
TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2007-02-20 22:43:53 +01:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
memset(device->recording->changed.vertexShaderConstantsF + start_register, 1,
|
|
|
|
sizeof(*device->recording->changed.vertexShaderConstantsF) * vector4f_count);
|
2013-08-23 10:18:16 +02:00
|
|
|
else
|
2011-05-16 23:01:21 +02:00
|
|
|
device->shader_backend->shader_update_float_vertex_constants(device, start_register, vector4f_count);
|
2008-03-04 02:30:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-12 19:51:19 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_f(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, float *constants, UINT vector4f_count)
|
|
|
|
{
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
|
|
|
int count = min(vector4f_count, d3d_info->limits.vs_uniform_count - start_register);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || count < 0)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
memcpy(constants, &device->state.vs_consts_f[start_register * 4], count * sizeof(float) * 4);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-11-29 17:05:54 +01:00
|
|
|
}
|
|
|
|
|
2012-09-25 10:34:42 +02:00
|
|
|
void CDECL wined3d_device_set_pixel_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
2010-09-20 12:04:29 +02:00
|
|
|
{
|
2013-10-09 22:57:45 +02:00
|
|
|
struct wined3d_shader *prev = device->update_state->shader[WINED3D_SHADER_TYPE_PIXEL];
|
2011-03-29 19:21:49 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.pixelShader = TRUE;
|
2005-12-15 10:25:47 +01:00
|
|
|
|
2011-03-29 19:21:49 +02:00
|
|
|
if (shader == prev)
|
2012-09-25 10:34:42 +02:00
|
|
|
return;
|
2006-12-19 23:22:48 +01:00
|
|
|
|
2013-10-03 23:31:46 +02:00
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2013-10-09 22:57:45 +02:00
|
|
|
device->update_state->shader[WINED3D_SHADER_TYPE_PIXEL] = shader;
|
2013-10-03 23:31:46 +02:00
|
|
|
if (!device->recording)
|
2013-10-09 22:57:45 +02:00
|
|
|
wined3d_cs_emit_set_shader(device->cs, WINED3D_SHADER_TYPE_PIXEL, shader);
|
2013-10-03 23:31:46 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_shader_decref(prev);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-13 20:02:27 +02:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_pixel_shader(const struct wined3d_device *device)
|
2010-09-06 22:18:56 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2013-10-09 22:57:45 +02:00
|
|
|
return device->state.shader[WINED3D_SHADER_TYPE_PIXEL];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-12-04 22:10:10 +01:00
|
|
|
void CDECL wined3d_device_set_ps_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
wined3d_device_set_constant_buffer(device, WINED3D_SHADER_TYPE_PIXEL, idx, buffer);
|
2012-12-04 22:10:10 +01:00
|
|
|
}
|
|
|
|
|
2012-12-04 22:10:11 +01:00
|
|
|
struct wined3d_buffer * CDECL wined3d_device_get_ps_cb(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
if (idx >= MAX_CONSTANT_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("Invalid constant buffer index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
return device->state.cb[WINED3D_SHADER_TYPE_PIXEL][idx];
|
2012-12-04 22:10:11 +01:00
|
|
|
}
|
|
|
|
|
2012-12-09 21:22:06 +01:00
|
|
|
void CDECL wined3d_device_set_ps_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
wined3d_device_set_sampler(device, WINED3D_SHADER_TYPE_PIXEL, idx, sampler);
|
2012-12-09 21:22:06 +01:00
|
|
|
}
|
|
|
|
|
2012-12-09 21:22:07 +01:00
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_ps_sampler(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
if (idx >= MAX_SAMPLER_OBJECTS)
|
|
|
|
{
|
|
|
|
WARN("Invalid sampler index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
return device->state.sampler[WINED3D_SHADER_TYPE_PIXEL][idx];
|
2012-12-09 21:22:07 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_ps_consts_b(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
|
|
|
UINT i;
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
memcpy(&device->update_state->ps_consts_b[start_register], constants, count * sizeof(BOOL));
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set BOOL constant %u to %s.\n", start_register + i, constants[i] ? "true" : "false");
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.pixelShaderConstantsB |= (1 << i);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-16 09:12:30 +02:00
|
|
|
device_invalidate_shader_constants(device, WINED3D_SHADER_CONST_PS_B);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-14 20:17:31 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_b(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
2005-12-20 11:46:52 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
memcpy(constants, &device->state.ps_consts_b[start_register], count * sizeof(BOOL));
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_ps_consts_i(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
|
|
|
UINT i;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
memcpy(&device->update_state->ps_consts_i[start_register * 4], constants, count * sizeof(int) * 4);
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set INT constant %u to {%d, %d, %d, %d}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.pixelShaderConstantsI |= (1 << i);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-16 09:12:30 +02:00
|
|
|
device_invalidate_shader_constants(device, WINED3D_SHADER_CONST_PS_I);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-12-20 11:46:52 +01:00
|
|
|
}
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-09-14 20:17:32 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_i(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
memcpy(constants, &device->state.ps_consts_i[start_register * 4], count * sizeof(int) * 4);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const float *constants, UINT vector4f_count)
|
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
UINT i;
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Specifically test start_register > limit to catch MAX_UINT overflows
|
|
|
|
* when adding start_register + vector4f_count. */
|
|
|
|
if (!constants
|
2013-04-25 15:20:27 +02:00
|
|
|
|| start_register + vector4f_count > d3d_info->limits.ps_uniform_count
|
|
|
|
|| start_register > d3d_info->limits.ps_uniform_count)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
memcpy(&device->update_state->ps_consts_f[start_register * 4],
|
2011-05-16 23:01:21 +02:00
|
|
|
constants, vector4f_count * sizeof(float) * 4);
|
|
|
|
if (TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
for (i = 0; i < vector4f_count; ++i)
|
|
|
|
TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2007-02-20 22:43:53 +01:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
memset(device->recording->changed.pixelShaderConstantsF + start_register, 1,
|
|
|
|
sizeof(*device->recording->changed.pixelShaderConstantsF) * vector4f_count);
|
2013-08-23 10:18:16 +02:00
|
|
|
else
|
2011-05-16 23:01:21 +02:00
|
|
|
device->shader_backend->shader_update_float_pixel_constants(device, start_register, vector4f_count);
|
2008-03-04 02:30:23 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-15 20:01:52 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_f(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, float *constants, UINT vector4f_count)
|
|
|
|
{
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
|
|
|
int count = min(vector4f_count, d3d_info->limits.ps_uniform_count - start_register);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || count < 0)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
memcpy(constants, &device->state.ps_consts_f[start_register * 4], count * sizeof(float) * 4);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-11-29 17:05:54 +01:00
|
|
|
}
|
|
|
|
|
2012-11-13 21:24:22 +01:00
|
|
|
void CDECL wined3d_device_set_geometry_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
|
|
|
{
|
2013-10-09 22:57:45 +02:00
|
|
|
struct wined3d_shader *prev = device->update_state->shader[WINED3D_SHADER_TYPE_GEOMETRY];
|
2012-11-13 21:24:22 +01:00
|
|
|
|
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2013-10-03 23:31:45 +02:00
|
|
|
if (device->recording || shader == prev)
|
|
|
|
return;
|
2012-11-13 21:24:22 +01:00
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2013-10-09 22:57:45 +02:00
|
|
|
device->update_state->shader[WINED3D_SHADER_TYPE_GEOMETRY] = shader;
|
|
|
|
wined3d_cs_emit_set_shader(device->cs, WINED3D_SHADER_TYPE_GEOMETRY, shader);
|
2012-11-13 21:24:22 +01:00
|
|
|
if (prev)
|
|
|
|
wined3d_shader_decref(prev);
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:24:23 +01:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_geometry_shader(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
2013-10-09 22:57:45 +02:00
|
|
|
return device->state.shader[WINED3D_SHADER_TYPE_GEOMETRY];
|
2012-11-13 21:24:23 +01:00
|
|
|
}
|
|
|
|
|
2012-12-03 21:16:33 +01:00
|
|
|
void CDECL wined3d_device_set_gs_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
wined3d_device_set_constant_buffer(device, WINED3D_SHADER_TYPE_GEOMETRY, idx, buffer);
|
2012-12-03 21:16:33 +01:00
|
|
|
}
|
|
|
|
|
2012-12-03 21:16:34 +01:00
|
|
|
struct wined3d_buffer * CDECL wined3d_device_get_gs_cb(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
if (idx >= MAX_CONSTANT_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("Invalid constant buffer index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:46 +02:00
|
|
|
return device->state.cb[WINED3D_SHADER_TYPE_GEOMETRY][idx];
|
2012-12-03 21:16:34 +01:00
|
|
|
}
|
|
|
|
|
2012-12-07 00:07:07 +01:00
|
|
|
void CDECL wined3d_device_set_gs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
wined3d_device_set_sampler(device, WINED3D_SHADER_TYPE_GEOMETRY, idx, sampler);
|
2012-12-07 00:07:07 +01:00
|
|
|
}
|
|
|
|
|
2012-12-07 00:07:08 +01:00
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_gs_sampler(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
if (idx >= MAX_SAMPLER_OBJECTS)
|
|
|
|
{
|
|
|
|
WARN("Invalid sampler index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:57:47 +02:00
|
|
|
return device->state.sampler[WINED3D_SHADER_TYPE_GEOMETRY][idx];
|
2012-12-07 00:07:08 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2006-05-12 22:21:31 +02:00
|
|
|
#define copy_and_next(dest, src, size) memcpy(dest, src, size); dest += (size)
|
2011-09-15 20:01:53 +02:00
|
|
|
static HRESULT process_vertices_strided(const struct wined3d_device *device, DWORD dwDestIndex, DWORD dwCount,
|
2010-11-18 20:50:40 +01:00
|
|
|
const struct wined3d_stream_info *stream_info, struct wined3d_buffer *dest, DWORD flags,
|
2009-04-06 14:16:59 +02:00
|
|
|
DWORD DestFVF)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2011-11-17 20:11:41 +01:00
|
|
|
struct wined3d_matrix mat, proj_mat, view_mat, world_mat;
|
2011-11-21 18:48:40 +01:00
|
|
|
struct wined3d_viewport vp;
|
2012-01-23 20:33:33 +01:00
|
|
|
UINT vertex_size;
|
2006-05-12 22:21:31 +02:00
|
|
|
unsigned int i;
|
2012-01-23 20:33:33 +01:00
|
|
|
BYTE *dest_ptr;
|
2006-05-12 22:21:31 +02:00
|
|
|
BOOL doClip;
|
2008-11-20 23:13:48 +01:00
|
|
|
DWORD numTextures;
|
2012-01-23 20:33:33 +01:00
|
|
|
HRESULT hr;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2009-08-21 09:12:29 +02:00
|
|
|
if (stream_info->use_map & (1 << WINED3D_FFP_NORMAL))
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
|
|
|
|
}
|
|
|
|
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << WINED3D_FFP_POSITION)))
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("Source has no position mask\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (device->state.render_states[WINED3D_RS_CLIPPING])
|
2010-09-15 12:00:04 +02:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
static BOOL warned = FALSE;
|
|
|
|
/*
|
|
|
|
* The clipping code is not quite correct. Some things need
|
|
|
|
* to be checked against IDirect3DDevice3 (!), d3d8 and d3d9,
|
|
|
|
* so disable clipping for now.
|
|
|
|
* (The graphics in Half-Life are broken, and my processvertices
|
|
|
|
* test crashes with IDirect3DDevice3)
|
|
|
|
doClip = TRUE;
|
|
|
|
*/
|
|
|
|
doClip = FALSE;
|
|
|
|
if(!warned) {
|
|
|
|
warned = TRUE;
|
|
|
|
FIXME("Clipping is broken and disabled for now\n");
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
doClip = FALSE;
|
|
|
|
|
|
|
|
vertex_size = get_flexible_vertex_size(DestFVF);
|
|
|
|
if (FAILED(hr = wined3d_buffer_map(dest, dwDestIndex * vertex_size, dwCount * vertex_size, &dest_ptr, 0)))
|
|
|
|
{
|
|
|
|
WARN("Failed to map buffer, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2012-01-11 21:27:32 +01:00
|
|
|
wined3d_device_get_transform(device, WINED3D_TS_VIEW, &view_mat);
|
|
|
|
wined3d_device_get_transform(device, WINED3D_TS_PROJECTION, &proj_mat);
|
|
|
|
wined3d_device_get_transform(device, WINED3D_TS_WORLD_MATRIX(0), &world_mat);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("View mat:\n");
|
2007-01-09 00:39:30 +01:00
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._11, view_mat.u.s._12, view_mat.u.s._13, view_mat.u.s._14);
|
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._21, view_mat.u.s._22, view_mat.u.s._23, view_mat.u.s._24);
|
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._31, view_mat.u.s._32, view_mat.u.s._33, view_mat.u.s._34);
|
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._41, view_mat.u.s._42, view_mat.u.s._43, view_mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("Proj mat:\n");
|
2007-01-09 00:39:30 +01:00
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._11, proj_mat.u.s._12, proj_mat.u.s._13, proj_mat.u.s._14);
|
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._21, proj_mat.u.s._22, proj_mat.u.s._23, proj_mat.u.s._24);
|
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._31, proj_mat.u.s._32, proj_mat.u.s._33, proj_mat.u.s._34);
|
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._41, proj_mat.u.s._42, proj_mat.u.s._43, proj_mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("World mat:\n");
|
2007-01-09 00:39:30 +01:00
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._11, world_mat.u.s._12, world_mat.u.s._13, world_mat.u.s._14);
|
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._21, world_mat.u.s._22, world_mat.u.s._23, world_mat.u.s._24);
|
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._31, world_mat.u.s._32, world_mat.u.s._33, world_mat.u.s._34);
|
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._41, world_mat.u.s._42, world_mat.u.s._43, world_mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
/* Get the viewport */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_get_viewport(device, &vp);
|
2011-11-21 18:48:40 +01:00
|
|
|
TRACE("viewport x %u, y %u, width %u, height %u, min_z %.8e, max_z %.8e.\n",
|
|
|
|
vp.x, vp.y, vp.width, vp.height, vp.min_z, vp.max_z);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
multiply_matrix(&mat,&view_mat,&world_mat);
|
|
|
|
multiply_matrix(&mat,&proj_mat,&mat);
|
|
|
|
|
2006-10-31 09:16:08 +01:00
|
|
|
numTextures = (DestFVF & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
for (i = 0; i < dwCount; i+= 1) {
|
|
|
|
unsigned int tex_index;
|
|
|
|
|
2006-10-31 09:16:08 +01:00
|
|
|
if ( ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZ ) ||
|
|
|
|
((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW ) ) {
|
2006-05-12 22:21:31 +02:00
|
|
|
/* The position first */
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_POSITION];
|
2011-07-11 01:06:46 +02:00
|
|
|
const float *p = (const float *)(element->data.addr + i * element->stride);
|
2006-05-12 22:21:31 +02:00
|
|
|
float x, y, z, rhw;
|
|
|
|
TRACE("In: ( %06.2f %06.2f %06.2f )\n", p[0], p[1], p[2]);
|
|
|
|
|
|
|
|
/* Multiplication with world, view and projection matrix */
|
2009-07-07 11:08:01 +02:00
|
|
|
x = (p[0] * mat.u.s._11) + (p[1] * mat.u.s._21) + (p[2] * mat.u.s._31) + (1.0f * mat.u.s._41);
|
|
|
|
y = (p[0] * mat.u.s._12) + (p[1] * mat.u.s._22) + (p[2] * mat.u.s._32) + (1.0f * mat.u.s._42);
|
|
|
|
z = (p[0] * mat.u.s._13) + (p[1] * mat.u.s._23) + (p[2] * mat.u.s._33) + (1.0f * mat.u.s._43);
|
|
|
|
rhw = (p[0] * mat.u.s._14) + (p[1] * mat.u.s._24) + (p[2] * mat.u.s._34) + (1.0f * mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
TRACE("x=%f y=%f z=%f rhw=%f\n", x, y, z, rhw);
|
|
|
|
|
|
|
|
/* WARNING: The following things are taken from d3d7 and were not yet checked
|
|
|
|
* against d3d8 or d3d9!
|
|
|
|
*/
|
|
|
|
|
2008-03-01 05:34:39 +01:00
|
|
|
/* Clipping conditions: From msdn
|
2006-05-12 22:21:31 +02:00
|
|
|
*
|
|
|
|
* A vertex is clipped if it does not match the following requirements
|
|
|
|
* -rhw < x <= rhw
|
|
|
|
* -rhw < y <= rhw
|
|
|
|
* 0 < z <= rhw
|
|
|
|
* 0 < rhw ( Not in d3d7, but tested in d3d7)
|
|
|
|
*
|
|
|
|
* If clipping is on is determined by the D3DVOP_CLIP flag in D3D7, and
|
|
|
|
* by the D3DRS_CLIPPING in D3D9(according to the msdn, not checked)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-09-26 20:31:58 +02:00
|
|
|
if( !doClip ||
|
2006-05-12 22:21:31 +02:00
|
|
|
( (-rhw -eps < x) && (-rhw -eps < y) && ( -eps < z) &&
|
2009-08-27 10:04:56 +02:00
|
|
|
(x <= rhw + eps) && (y <= rhw + eps ) && (z <= rhw + eps) &&
|
2006-05-12 22:21:31 +02:00
|
|
|
( rhw > eps ) ) ) {
|
|
|
|
|
|
|
|
/* "Normal" viewport transformation (not clipped)
|
2006-06-15 17:38:04 +02:00
|
|
|
* 1) The values are divided by rhw
|
2006-05-12 22:21:31 +02:00
|
|
|
* 2) The y axis is negative, so multiply it with -1
|
|
|
|
* 3) Screen coordinates go from -(Width/2) to +(Width/2) and
|
|
|
|
* -(Height/2) to +(Height/2). The z range is MinZ to MaxZ
|
|
|
|
* 4) Multiply x with Width/2 and add Width/2
|
|
|
|
* 5) The same for the height
|
|
|
|
* 6) Add the viewpoint X and Y to the 2D coordinates and
|
|
|
|
* The minimum Z value to z
|
|
|
|
* 7) rhw = 1 / rhw Reciprocal of Homogeneous W....
|
|
|
|
*
|
|
|
|
* Well, basically it's simply a linear transformation into viewport
|
|
|
|
* coordinates
|
|
|
|
*/
|
|
|
|
|
|
|
|
x /= rhw;
|
|
|
|
y /= rhw;
|
|
|
|
z /= rhw;
|
|
|
|
|
|
|
|
y *= -1;
|
|
|
|
|
2011-11-21 18:48:40 +01:00
|
|
|
x *= vp.width / 2;
|
|
|
|
y *= vp.height / 2;
|
|
|
|
z *= vp.max_z - vp.min_z;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2011-11-21 18:48:40 +01:00
|
|
|
x += vp.width / 2 + vp.x;
|
|
|
|
y += vp.height / 2 + vp.y;
|
|
|
|
z += vp.min_z;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
rhw = 1 / rhw;
|
|
|
|
} else {
|
|
|
|
/* That vertex got clipped
|
|
|
|
* Contrary to OpenGL it is not dropped completely, it just
|
|
|
|
* undergoes a different calculation.
|
|
|
|
*/
|
|
|
|
TRACE("Vertex got clipped\n");
|
|
|
|
x += rhw;
|
|
|
|
y += rhw;
|
|
|
|
|
|
|
|
x /= 2;
|
|
|
|
y /= 2;
|
|
|
|
|
2006-06-23 18:18:02 +02:00
|
|
|
/* Msdn mentions that Direct3D9 keeps a list of clipped vertices
|
2006-05-12 22:21:31 +02:00
|
|
|
* outside of the main vertex buffer memory. That needs some more
|
|
|
|
* investigation...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Writing (%f %f %f) %f\n", x, y, z, rhw);
|
|
|
|
|
|
|
|
|
|
|
|
( (float *) dest_ptr)[0] = x;
|
|
|
|
( (float *) dest_ptr)[1] = y;
|
|
|
|
( (float *) dest_ptr)[2] = z;
|
|
|
|
( (float *) dest_ptr)[3] = rhw; /* SIC, see ddraw test! */
|
|
|
|
|
|
|
|
dest_ptr += 3 * sizeof(float);
|
|
|
|
|
2012-01-23 20:33:33 +01:00
|
|
|
if ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW)
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(float);
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
|
|
|
|
if (DestFVF & WINED3DFVF_PSIZE)
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
2012-01-23 20:33:33 +01:00
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
if (DestFVF & WINED3DFVF_NORMAL)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_NORMAL];
|
2011-07-11 01:06:46 +02:00
|
|
|
const float *normal = (const float *)(element->data.addr + i * element->stride);
|
2006-05-12 22:21:31 +02:00
|
|
|
/* AFAIK this should go into the lighting information */
|
|
|
|
FIXME("Didn't expect the destination to have a normal\n");
|
|
|
|
copy_and_next(dest_ptr, normal, 3 * sizeof(float));
|
|
|
|
}
|
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
if (DestFVF & WINED3DFVF_DIFFUSE)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_DIFFUSE];
|
2011-07-11 01:06:46 +02:00
|
|
|
const DWORD *color_d = (const DWORD *)(element->data.addr + i * element->stride);
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << WINED3D_FFP_DIFFUSE)))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
static BOOL warned = FALSE;
|
|
|
|
|
2006-09-26 20:31:58 +02:00
|
|
|
if(!warned) {
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No diffuse color in source, but destination has one\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*( (DWORD *) dest_ptr) = 0xffffffff;
|
|
|
|
dest_ptr += sizeof(DWORD);
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
copy_and_next(dest_ptr, color_d, sizeof(DWORD));
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:04:56 +02:00
|
|
|
if (DestFVF & WINED3DFVF_SPECULAR)
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
/* What's the color value in the feedback buffer? */
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_SPECULAR];
|
2011-07-11 01:06:46 +02:00
|
|
|
const DWORD *color_s = (const DWORD *)(element->data.addr + i * element->stride);
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << WINED3D_FFP_SPECULAR)))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
static BOOL warned = FALSE;
|
|
|
|
|
2006-09-26 20:31:58 +02:00
|
|
|
if(!warned) {
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No specular color in source, but destination has one\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:24:27 +02:00
|
|
|
*(DWORD *)dest_ptr = 0xff000000;
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
copy_and_next(dest_ptr, color_s, sizeof(DWORD));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
for (tex_index = 0; tex_index < numTextures; ++tex_index)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_TEXCOORD0 + tex_index];
|
2011-07-11 01:06:46 +02:00
|
|
|
const float *tex_coord = (const float *)(element->data.addr + i * element->stride);
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + tex_index))))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No source texture, but destination requests one\n");
|
2012-01-23 20:33:33 +01:00
|
|
|
dest_ptr += GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-23 20:33:33 +01:00
|
|
|
wined3d_buffer_unmap(dest);
|
2006-06-21 15:05:38 +02:00
|
|
|
|
2006-05-12 22:21:31 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
#undef copy_and_next
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_process_vertices(struct wined3d_device *device,
|
|
|
|
UINT src_start_idx, UINT dst_idx, UINT vertex_count, struct wined3d_buffer *dst_buffer,
|
2011-09-18 21:05:30 +02:00
|
|
|
const struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf)
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
struct wined3d_state *state = &device->state;
|
2009-03-27 10:25:55 +01:00
|
|
|
struct wined3d_stream_info stream_info;
|
2010-05-21 09:35:24 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2011-07-26 19:52:43 +02:00
|
|
|
struct wined3d_shader *vs;
|
2012-03-28 20:22:36 +02:00
|
|
|
unsigned int i;
|
2009-10-28 11:00:11 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_start_idx %u, dst_idx %u, vertex_count %u, "
|
|
|
|
"dst_buffer %p, declaration %p, flags %#x, dst_fvf %#x.\n",
|
|
|
|
device, src_start_idx, dst_idx, vertex_count,
|
|
|
|
dst_buffer, declaration, flags, dst_fvf);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (declaration)
|
|
|
|
FIXME("Output vertex declaration not implemented yet.\n");
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2008-01-02 19:51:51 +01:00
|
|
|
/* Need any context to write to the vbo. */
|
2011-05-16 23:01:23 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-05-21 09:35:24 +02:00
|
|
|
gl_info = context->gl_info;
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2013-10-09 22:57:45 +02:00
|
|
|
vs = state->shader[WINED3D_SHADER_TYPE_VERTEX];
|
|
|
|
state->shader[WINED3D_SHADER_TYPE_VERTEX] = NULL;
|
2013-09-12 12:23:29 +02:00
|
|
|
context_stream_info_from_declaration(context, state, &stream_info);
|
2013-10-09 22:57:45 +02:00
|
|
|
state->shader[WINED3D_SHADER_TYPE_VERTEX] = vs;
|
2006-06-21 15:05:38 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
/* We can't convert FROM a VBO, and vertex buffers used to source into
|
|
|
|
* process_vertices() are unlikely to ever be used for drawing. Release
|
|
|
|
* VBOs in those buffers and fix up the stream_info structure.
|
|
|
|
*
|
|
|
|
* Also apply the start index. */
|
|
|
|
for (i = 0; i < (sizeof(stream_info.elements) / sizeof(*stream_info.elements)); ++i)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2012-03-28 20:22:36 +02:00
|
|
|
struct wined3d_stream_info_element *e;
|
2009-08-21 09:12:29 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
if (!(stream_info.use_map & (1 << i)))
|
|
|
|
continue;
|
2009-08-21 09:12:29 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
e = &stream_info.elements[i];
|
|
|
|
if (e->data.buffer_object)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
|
|
|
|
e->data.buffer_object = 0;
|
2013-09-09 15:15:36 +02:00
|
|
|
e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, context));
|
2012-03-28 20:22:36 +02:00
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &vb->buffer_object));
|
|
|
|
vb->buffer_object = 0;
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
2012-03-28 20:22:36 +02:00
|
|
|
if (e->data.addr)
|
|
|
|
e->data.addr += e->stride * src_start_idx;
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = process_vertices_strided(device, dst_idx, vertex_count,
|
|
|
|
&stream_info, dst_buffer, flags, dst_fvf);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
return hr;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2012-09-26 10:12:13 +02:00
|
|
|
void CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device,
|
2012-01-09 22:16:51 +01:00
|
|
|
UINT stage, enum wined3d_texture_stage_state state, DWORD value)
|
2010-09-12 10:34:20 +02:00
|
|
|
{
|
2013-04-25 15:20:30 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2011-05-16 23:01:21 +02:00
|
|
|
DWORD old_value;
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stage %u, state %s, value %#x.\n",
|
|
|
|
device, stage, debug_d3dtexturestate(state), value);
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (state > WINED3D_HIGHEST_TEXTURE_STATE)
|
2010-09-12 10:34:20 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Invalid state %#x passed.\n", state);
|
2012-09-26 10:12:13 +02:00
|
|
|
return;
|
2010-09-12 10:34:20 +02:00
|
|
|
}
|
|
|
|
|
2013-04-25 15:20:30 +02:00
|
|
|
if (stage >= d3d_info->limits.ffp_blend_stages)
|
2010-01-27 20:19:42 +01:00
|
|
|
{
|
|
|
|
WARN("Attempting to set stage %u which is higher than the max stage %u, ignoring.\n",
|
2013-04-25 15:20:30 +02:00
|
|
|
stage, d3d_info->limits.ffp_blend_stages - 1);
|
2012-09-26 10:12:13 +02:00
|
|
|
return;
|
2007-04-16 21:44:27 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
old_value = device->update_state->texture_states[stage][state];
|
|
|
|
device->update_state->texture_states[stage][state] = value;
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.textureState[stage] |= 1 << state;
|
2012-09-26 10:12:13 +02:00
|
|
|
return;
|
2006-12-19 23:00:58 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Checked after the assignments to allow proper stateblock recording. */
|
|
|
|
if (old_value == value)
|
|
|
|
{
|
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
2012-09-26 10:12:13 +02:00
|
|
|
return;
|
2006-12-19 23:12:26 +01:00
|
|
|
}
|
|
|
|
|
2013-10-07 22:15:47 +02:00
|
|
|
wined3d_cs_emit_set_texture_state(device->cs, stage, state, value);
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2012-09-26 10:12:14 +02:00
|
|
|
DWORD CDECL wined3d_device_get_texture_stage_state(const struct wined3d_device *device,
|
|
|
|
UINT stage, enum wined3d_texture_stage_state state)
|
2010-09-12 10:34:20 +02:00
|
|
|
{
|
2012-09-26 10:12:14 +02:00
|
|
|
TRACE("device %p, stage %u, state %s.\n",
|
|
|
|
device, stage, debug_d3dtexturestate(state));
|
2010-09-16 11:19:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (state > WINED3D_HIGHEST_TEXTURE_STATE)
|
2010-09-12 10:34:20 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Invalid state %#x passed.\n", state);
|
2012-09-26 10:12:14 +02:00
|
|
|
return 0;
|
2010-09-12 10:34:20 +02:00
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
return device->state.texture_states[stage][state];
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT stage, struct wined3d_texture *texture)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *prev;
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, stage %u, texture %p.\n", device, stage, texture);
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2007-06-25 22:46:01 +02:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
/* Windows accepts overflowing this array... we do not. */
|
2013-08-27 08:44:59 +02:00
|
|
|
if (stage >= sizeof(device->state.textures) / sizeof(*device->state.textures))
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
WARN("Ignoring invalid stage %u.\n", stage);
|
|
|
|
return WINED3D_OK;
|
2008-01-15 08:06:37 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
if (texture && texture->resource.pool == WINED3D_POOL_SCRATCH)
|
2008-12-12 09:33:51 +01:00
|
|
|
{
|
2009-09-28 10:05:02 +02:00
|
|
|
WARN("Rejecting attempt to set scratch texture.\n");
|
2008-12-12 09:33:51 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-02-06 20:57:42 +01:00
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.textures |= 1 << stage;
|
2009-09-28 10:04:59 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
prev = device->update_state->textures[stage];
|
2009-09-28 10:05:02 +02:00
|
|
|
TRACE("Previous texture %p.\n", prev);
|
2009-09-28 10:04:59 +02:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
if (texture == prev)
|
|
|
|
{
|
|
|
|
TRACE("App is setting the same texture again, nothing to do.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
TRACE("Setting new texture to %p.\n", texture);
|
2013-08-26 09:23:37 +02:00
|
|
|
device->update_state->textures[stage] = texture;
|
2009-09-28 10:05:02 +02:00
|
|
|
|
|
|
|
if (texture)
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_incref(texture);
|
2013-10-03 08:54:13 +02:00
|
|
|
if (!device->recording)
|
|
|
|
wined3d_cs_emit_set_texture(device->cs, stage, texture);
|
2009-09-28 10:05:02 +02:00
|
|
|
if (prev)
|
2012-09-29 11:14:54 +02:00
|
|
|
wined3d_texture_decref(prev);
|
2006-12-19 23:26:39 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2012-09-26 22:34:02 +02:00
|
|
|
struct wined3d_texture * CDECL wined3d_device_get_texture(const struct wined3d_device *device, UINT stage)
|
2011-03-18 19:11:00 +01:00
|
|
|
{
|
2012-09-26 22:34:02 +02:00
|
|
|
TRACE("device %p, stage %u.\n", device, stage);
|
2007-06-25 22:46:01 +02:00
|
|
|
|
2011-03-18 19:11:00 +01:00
|
|
|
if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (stage >= sizeof(device->state.textures) / sizeof(*device->state.textures))
|
2010-09-17 11:59:40 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Ignoring invalid stage %u.\n", stage);
|
2012-09-26 22:34:02 +02:00
|
|
|
return NULL; /* Windows accepts overflowing this array ... we do not. */
|
2008-01-15 08:06:37 +01:00
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
return device->state.textures[stage];
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-19 21:50:27 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx,
|
2012-01-06 11:20:06 +01:00
|
|
|
UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer)
|
2009-12-16 19:55:58 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
|
|
|
|
device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer);
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2009-12-16 19:55:58 +01:00
|
|
|
|
2012-10-04 13:53:27 +02:00
|
|
|
if (!(*backbuffer = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-21 21:01:46 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps)
|
2011-02-01 19:39:53 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, caps %p.\n", device, caps);
|
2011-02-01 19:39:53 +01:00
|
|
|
|
2011-11-27 21:34:49 +01:00
|
|
|
return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal,
|
|
|
|
device->create_parms.device_type, caps);
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 19:02:29 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_display_mode(const struct wined3d_device *device, UINT swapchain_idx,
|
|
|
|
struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
|
2011-04-13 19:14:32 +02:00
|
|
|
{
|
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2012-06-27 19:02:29 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, mode %p, rotation %p.\n",
|
|
|
|
device, swapchain_idx, mode, rotation);
|
2011-04-13 19:14:32 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
return wined3d_swapchain_get_display_mode(swapchain, mode, rotation);
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
2006-04-13 23:37:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device)
|
2011-01-28 20:05:42 +01:00
|
|
|
{
|
|
|
|
struct wined3d_stateblock *stateblock;
|
2009-01-09 10:23:43 +01:00
|
|
|
HRESULT hr;
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2011-05-16 23:01:23 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2012-01-17 21:13:39 +01:00
|
|
|
hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &stateblock);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording = stateblock;
|
|
|
|
device->update_state = &stateblock->state;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("Recording stateblock %p.\n", stateblock);
|
2009-01-09 10:23:43 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device,
|
2011-01-28 20:05:42 +01:00
|
|
|
struct wined3d_stateblock **stateblock)
|
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
struct wined3d_stateblock *object = device->recording;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, stateblock %p.\n", device, stateblock);
|
2011-01-28 20:05:42 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (!device->recording)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
|
|
|
WARN("Not recording.\n");
|
2011-01-28 20:05:42 +01:00
|
|
|
*stateblock = NULL;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2009-09-30 10:49:13 +02:00
|
|
|
stateblock_init_contained_states(object);
|
2007-07-31 15:04:56 +02:00
|
|
|
|
2011-01-28 20:05:42 +01:00
|
|
|
*stateblock = object;
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording = NULL;
|
2013-08-27 08:44:59 +02:00
|
|
|
device->update_state = &device->state;
|
2011-01-28 20:05:42 +01:00
|
|
|
|
|
|
|
TRACE("Returning stateblock %p.\n", *stateblock);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_begin_scene(struct wined3d_device *device)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2004-11-28 16:04:41 +01:00
|
|
|
/* At the moment we have no need for any functionality at the beginning
|
2011-05-16 23:01:23 +02:00
|
|
|
* of a scene. */
|
|
|
|
TRACE("device %p.\n", device);
|
2007-02-09 16:35:45 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->inScene)
|
|
|
|
{
|
|
|
|
WARN("Already in scene, returning WINED3DERR_INVALIDCALL.\n");
|
2007-02-09 16:35:45 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
device->inScene = TRUE;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-28 16:04:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_end_scene(struct wined3d_device *device)
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2007-02-09 16:35:45 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->inScene)
|
|
|
|
{
|
|
|
|
WARN("Not in scene, returning WINED3DERR_INVALIDCALL.\n");
|
2007-02-09 16:35:45 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2005-03-14 11:12:52 +01:00
|
|
|
/* We only have to do this if we need to read the, swapbuffers performs a flush for us */
|
2012-07-24 11:32:27 +02:00
|
|
|
context->gl_info->gl_ops.gl.p_glFlush();
|
2008-08-04 20:34:47 +02:00
|
|
|
/* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever
|
2009-10-28 11:00:11 +01:00
|
|
|
* fails. */
|
|
|
|
context_release(context);
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->inScene = FALSE;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2011-10-03 20:22:52 +02:00
|
|
|
HRESULT CDECL wined3d_device_present(const struct wined3d_device *device, const RECT *src_rect,
|
2012-06-29 07:37:56 +02:00
|
|
|
const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region, DWORD flags)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-04-07 18:45:57 +02:00
|
|
|
UINT i;
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2012-06-29 07:37:56 +02:00
|
|
|
TRACE("device %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
|
2011-05-16 23:01:23 +02:00
|
|
|
device, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
|
2012-06-29 07:37:56 +02:00
|
|
|
dst_window_override, dirty_region, flags);
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2011-04-07 18:45:57 +02:00
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_present(device->swapchains[i], src_rect,
|
2012-06-29 07:37:56 +02:00
|
|
|
dst_rect, dst_window_override, dirty_region, flags);
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_clear(struct wined3d_device *device, DWORD rect_count,
|
2011-11-15 21:18:28 +01:00
|
|
|
const RECT *rects, DWORD flags, const struct wined3d_color *color, float depth, DWORD stencil)
|
2010-04-19 20:46:59 +02:00
|
|
|
{
|
2011-11-15 21:18:28 +01:00
|
|
|
TRACE("device %p, rect_count %u, rects %p, flags %#x, color {%.8e, %.8e, %.8e, %.8e}, depth %.8e, stencil %u.\n",
|
|
|
|
device, rect_count, rects, flags, color->r, color->g, color->b, color->a, depth, stencil);
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2013-01-23 15:02:45 +01:00
|
|
|
if (!rect_count && rects)
|
|
|
|
{
|
|
|
|
WARN("Rects is %p, but rect_count is 0, ignoring clear\n", rects);
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-11 11:15:25 +01:00
|
|
|
if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL))
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
struct wined3d_surface *ds = device->fb.depth_stencil;
|
2011-03-11 11:15:25 +01:00
|
|
|
if (!ds)
|
|
|
|
{
|
|
|
|
WARN("Clearing depth and/or stencil without a depth stencil buffer attached, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
/* TODO: What about depth stencil buffers without stencil bits? */
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
else if (flags & WINED3DCLEAR_TARGET)
|
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
if (ds->resource.width < device->fb.render_targets[0]->resource.width
|
|
|
|
|| ds->resource.height < device->fb.render_targets[0]->resource.height)
|
2011-03-11 11:15:25 +01:00
|
|
|
{
|
|
|
|
WARN("Silently ignoring depth and target clear with mismatching sizes\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
2007-03-06 13:35:56 +01:00
|
|
|
}
|
|
|
|
|
2013-09-27 00:15:14 +02:00
|
|
|
wined3d_cs_emit_clear(device->cs, rect_count, rects, flags, color, depth, stencil);
|
2010-08-23 18:28:06 +02:00
|
|
|
|
2012-04-15 18:57:14 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_set_primitive_type(struct wined3d_device *device,
|
2011-12-11 21:43:32 +01:00
|
|
|
enum wined3d_primitive_type primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2013-05-29 09:45:36 +02:00
|
|
|
GLenum gl_primitive_type, prev;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, primitive_type %s\n", device, debug_d3dprimitivetype(primitive_type));
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2013-05-29 09:45:36 +02:00
|
|
|
gl_primitive_type = gl_primitive_type_from_d3d(primitive_type);
|
2013-08-26 09:23:37 +02:00
|
|
|
prev = device->update_state->gl_primitive_type;
|
|
|
|
device->update_state->gl_primitive_type = gl_primitive_type;
|
|
|
|
if (device->recording)
|
|
|
|
device->recording->changed.primitive_type = TRUE;
|
2013-08-23 10:18:16 +02:00
|
|
|
else if (gl_primitive_type != prev && (gl_primitive_type == GL_POINTS || prev == GL_POINTS))
|
2013-05-29 09:45:36 +02:00
|
|
|
device_invalidate_state(device, STATE_POINT_SIZE_ENABLE);
|
2009-03-05 12:30:43 +01:00
|
|
|
}
|
|
|
|
|
2011-10-09 19:01:22 +02:00
|
|
|
void CDECL wined3d_device_get_primitive_type(const struct wined3d_device *device,
|
2011-12-11 21:43:32 +01:00
|
|
|
enum wined3d_primitive_type *primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, primitive_type %p\n", device, primitive_type);
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*primitive_type = d3d_primitive_type_from_gl(device->state.gl_primitive_type);
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
TRACE("Returning %s\n", debug_d3dprimitivetype(*primitive_type));
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_primitive(struct wined3d_device *device, UINT start_vertex, UINT vertex_count)
|
2009-03-05 12:30:42 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, start_vertex %u, vertex_count %u.\n", device, start_vertex, vertex_count);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (!device->state.vertex_declaration)
|
2010-09-17 11:59:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Called without a valid vertex declaration set.\n");
|
2008-04-07 12:08:16 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (device->state.load_base_vertex_index)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
device->state.load_base_vertex_index = 0;
|
2011-06-11 16:18:45 +02:00
|
|
|
device_invalidate_state(device, STATE_BASEVERTEXINDEX);
|
2007-01-06 18:19:55 +01:00
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2013-09-27 00:15:15 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, start_vertex, vertex_count, 0, 0, FALSE);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *device, UINT start_idx, UINT index_count)
|
2009-03-05 12:30:42 +01:00
|
|
|
{
|
2011-06-11 16:18:45 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (!device->state.index_buffer)
|
2010-09-20 19:41:23 +02:00
|
|
|
{
|
2007-06-02 15:54:49 +02:00
|
|
|
/* D3D9 returns D3DERR_INVALIDCALL when DrawIndexedPrimitive is called
|
|
|
|
* without an index buffer set. (The first time at least...)
|
|
|
|
* D3D8 simply dies, but I doubt it can do much harm to return
|
|
|
|
* D3DERR_INVALIDCALL there as well. */
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Called without a valid index buffer set, returning WINED3DERR_INVALIDCALL.\n");
|
2007-06-02 15:54:49 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (!device->state.vertex_declaration)
|
2010-09-17 11:59:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Called without a valid vertex declaration set.\n");
|
2008-04-07 12:08:16 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-06-11 16:18:45 +02:00
|
|
|
if (!gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX] &&
|
2013-08-27 08:44:59 +02:00
|
|
|
device->state.load_base_vertex_index != device->state.base_vertex_index)
|
2010-09-20 19:41:24 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
device->state.load_base_vertex_index = device->state.base_vertex_index;
|
2011-06-11 16:18:45 +02:00
|
|
|
device_invalidate_state(device, STATE_BASEVERTEXINDEX);
|
2007-01-06 18:19:55 +01:00
|
|
|
}
|
|
|
|
|
2013-09-27 00:15:15 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, start_idx, index_count, 0, 0, TRUE);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2012-11-26 22:52:41 +01:00
|
|
|
void CDECL wined3d_device_draw_indexed_primitive_instanced(struct wined3d_device *device,
|
|
|
|
UINT start_idx, UINT index_count, UINT start_instance, UINT instance_count)
|
|
|
|
{
|
|
|
|
TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
|
|
|
|
|
2013-09-27 00:15:15 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, start_idx, index_count, start_instance, instance_count, TRUE);
|
2012-11-26 22:52:41 +01:00
|
|
|
}
|
|
|
|
|
2009-12-21 23:17:26 +01:00
|
|
|
/* This is a helper function for UpdateTexture, there is no UpdateVolume method in D3D. */
|
2011-06-09 20:40:45 +02:00
|
|
|
static HRESULT device_update_volume(struct wined3d_device *device,
|
2011-04-14 22:41:48 +02:00
|
|
|
struct wined3d_volume *src_volume, struct wined3d_volume *dst_volume)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc src;
|
2007-09-01 01:54:15 +02:00
|
|
|
HRESULT hr;
|
2013-08-22 23:22:47 +02:00
|
|
|
struct wined3d_bo_address data;
|
|
|
|
struct wined3d_context *context;
|
2009-12-21 23:17:26 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_volume %p, dst_volume %p.\n",
|
|
|
|
device, src_volume, dst_volume);
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2013-08-26 02:01:31 +02:00
|
|
|
if (src_volume->resource.format != dst_volume->resource.format)
|
|
|
|
{
|
|
|
|
FIXME("Source and destination formats do not match.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
if (src_volume->resource.width != dst_volume->resource.width
|
|
|
|
|| src_volume->resource.height != dst_volume->resource.height
|
|
|
|
|| src_volume->resource.depth != dst_volume->resource.depth)
|
|
|
|
{
|
|
|
|
FIXME("Source and destination sizes do not match.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2012-06-18 17:19:42 +02:00
|
|
|
if (FAILED(hr = wined3d_volume_map(src_volume, &src, NULL, WINED3D_MAP_READONLY)))
|
|
|
|
return hr;
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2013-08-22 23:22:47 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2013-08-22 23:22:47 +02:00
|
|
|
wined3d_volume_load(dst_volume, context, FALSE);
|
|
|
|
|
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = src.data;
|
|
|
|
wined3d_volume_upload_data(dst_volume, context, &data);
|
|
|
|
wined3d_volume_invalidate_location(dst_volume, ~WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
hr = wined3d_volume_unmap(src_volume);
|
2010-10-14 13:04:02 +02:00
|
|
|
|
2007-09-01 01:54:15 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2007-07-27 14:39:55 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
enum wined3d_resource_type type;
|
2009-10-19 10:12:19 +02:00
|
|
|
unsigned int level_count, i;
|
|
|
|
HRESULT hr;
|
2013-09-16 12:43:16 +02:00
|
|
|
struct wined3d_context *context;
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_texture %p, dst_texture %p.\n", device, src_texture, dst_texture);
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Verify that the source and destination textures are non-NULL. */
|
|
|
|
if (!src_texture || !dst_texture)
|
|
|
|
{
|
|
|
|
WARN("Source and destination textures must be non-NULL, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2013-08-26 02:01:30 +02:00
|
|
|
if (src_texture->resource.pool != WINED3D_POOL_SYSTEM_MEM)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2013-08-26 02:01:30 +02:00
|
|
|
WARN("Source texture not in WINED3D_POOL_SYSTEM_MEM, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
if (dst_texture->resource.pool != WINED3D_POOL_DEFAULT)
|
|
|
|
{
|
|
|
|
WARN("Destination texture not in WINED3D_POOL_DEFAULT, returning WINED3DERR_INVALIDCALL.\n");
|
2009-10-19 10:12:19 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Verify that the source and destination textures are the same type. */
|
2012-01-17 21:13:36 +01:00
|
|
|
type = src_texture->resource.type;
|
|
|
|
if (dst_texture->resource.type != type)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
WARN("Source and destination have different types, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Check that both textures have the identical numbers of levels. */
|
2011-03-18 19:10:59 +01:00
|
|
|
level_count = wined3d_texture_get_level_count(src_texture);
|
|
|
|
if (wined3d_texture_get_level_count(dst_texture) != level_count)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
WARN("Source and destination have different level counts, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2005-11-04 13:39:17 +01:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Make sure that the destination texture is loaded. */
|
2013-09-16 12:43:16 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
dst_texture->texture_ops->texture_preload(dst_texture, context, SRGB_RGB);
|
|
|
|
context_release(context);
|
2005-11-04 13:39:17 +01:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Update every surface level of the texture. */
|
|
|
|
switch (type)
|
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface;
|
|
|
|
struct wined3d_surface *dst_surface;
|
2009-10-19 10:12:19 +02:00
|
|
|
|
|
|
|
for (i = 0; i < level_count; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
|
|
|
|
dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
|
2009-10-19 10:12:19 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-07-03 22:27:21 +02:00
|
|
|
WARN("Failed to update surface, hr %#x.\n", hr);
|
2009-10-19 10:12:19 +02:00
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_CUBE_TEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface;
|
|
|
|
struct wined3d_surface *dst_surface;
|
2009-10-19 10:12:19 +02:00
|
|
|
|
2010-10-25 12:33:39 +02:00
|
|
|
for (i = 0; i < level_count * 6; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
|
|
|
|
dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
|
2010-10-25 12:33:39 +02:00
|
|
|
if (FAILED(hr))
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2011-07-03 22:27:21 +02:00
|
|
|
WARN("Failed to update surface, hr %#x.\n", hr);
|
2010-10-25 12:33:39 +02:00
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_VOLUME_TEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < level_count; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-06-09 20:40:45 +02:00
|
|
|
hr = device_update_volume(device,
|
2011-04-14 22:41:48 +02:00
|
|
|
volume_from_resource(wined3d_texture_get_sub_resource(src_texture, i)),
|
|
|
|
volume_from_resource(wined3d_texture_get_sub_resource(dst_texture, i)));
|
2009-10-19 10:12:19 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-06-09 20:40:45 +02:00
|
|
|
WARN("Failed to update volume, hr %#x.\n", hr);
|
2009-10-19 10:12:19 +02:00
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2005-11-04 13:39:17 +01:00
|
|
|
default:
|
2009-10-19 10:12:19 +02:00
|
|
|
FIXME("Unsupported texture type %#x.\n", type);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-10-11 17:24:53 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_front_buffer_data(const struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
UINT swapchain_idx, struct wined3d_surface *dst_surface)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2010-08-15 23:21:43 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, dst_surface %p.\n", device, swapchain_idx, dst_surface);
|
2010-08-15 23:21:43 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2010-08-15 23:21:43 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
return wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-10-11 17:24:54 +02:00
|
|
|
HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes)
|
2011-03-18 19:11:00 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
const struct wined3d_state *state = &device->state;
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *texture;
|
|
|
|
DWORD i;
|
2008-08-21 15:10:46 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, num_passes %p.\n", device, num_passes);
|
2008-08-21 15:10:46 +02:00
|
|
|
|
2010-09-16 11:19:58 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] == WINED3D_TEXF_NONE)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Sampler state %u has minfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
|
|
|
|
return WINED3DERR_UNSUPPORTEDTEXTUREFILTER;
|
|
|
|
}
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] == WINED3D_TEXF_NONE)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Sampler state %u has magfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
|
|
|
|
return WINED3DERR_UNSUPPORTEDTEXTUREFILTER;
|
|
|
|
}
|
|
|
|
|
2011-03-11 11:49:01 +01:00
|
|
|
texture = state->textures[i];
|
2010-11-12 13:12:05 +01:00
|
|
|
if (!texture || texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING) continue;
|
2008-08-21 15:10:46 +02:00
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2013-07-23 14:07:08 +02:00
|
|
|
WARN("Non-filterable texture and mag filter enabled on sampler %u, returning E_FAIL\n", i);
|
2008-08-21 15:10:46 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_POINT)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2013-07-23 14:07:08 +02:00
|
|
|
WARN("Non-filterable texture and min filter enabled on sampler %u, returning E_FAIL\n", i);
|
2008-08-21 15:10:46 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_NONE
|
|
|
|
&& state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_POINT)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2013-07-23 14:07:08 +02:00
|
|
|
WARN("Non-filterable texture and mip filter enabled on sampler %u, returning E_FAIL\n", i);
|
2008-08-21 15:10:46 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:00:09 +01:00
|
|
|
if (state->render_states[WINED3D_RS_ZENABLE] || state->render_states[WINED3D_RS_ZWRITEENABLE]
|
|
|
|
|| state->render_states[WINED3D_RS_STENCILENABLE])
|
2011-03-11 11:49:01 +01:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
struct wined3d_surface *ds = device->fb.depth_stencil;
|
|
|
|
struct wined3d_surface *target = device->fb.render_targets[0];
|
2011-03-11 11:49:01 +01:00
|
|
|
|
|
|
|
if(ds && target
|
|
|
|
&& (ds->resource.width < target->resource.width || ds->resource.height < target->resource.height))
|
|
|
|
{
|
|
|
|
WARN("Depth stencil is smaller than the color buffer, returning D3DERR_CONFLICTINGRENDERSTATE\n");
|
|
|
|
return WINED3DERR_CONFLICTINGRENDERSTATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-02 13:16:10 +01:00
|
|
|
/* return a sensible default */
|
2011-05-16 23:01:23 +02:00
|
|
|
*num_passes = 1;
|
2008-08-21 15:10:46 +02:00
|
|
|
|
|
|
|
TRACE("returning D3D_OK\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2012-09-26 22:34:03 +02:00
|
|
|
void CDECL wined3d_device_set_software_vertex_processing(struct wined3d_device *device, BOOL software)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
static BOOL warned;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
TRACE("device %p, software %#x.\n", device, software);
|
|
|
|
|
2008-12-01 15:32:14 +01:00
|
|
|
if (!warned)
|
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
FIXME("device %p, software %#x stub!\n", device, software);
|
2008-12-01 15:32:14 +01:00
|
|
|
warned = TRUE;
|
2005-08-11 12:31:40 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->softwareVertexProcessing = software;
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
|
|
|
|
2011-10-11 17:24:55 +02:00
|
|
|
BOOL CDECL wined3d_device_get_software_vertex_processing(const struct wined3d_device *device)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
static BOOL warned;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
2008-12-01 15:32:14 +01:00
|
|
|
if (!warned)
|
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p stub!\n", device);
|
2008-12-01 15:32:14 +01:00
|
|
|
warned = TRUE;
|
2005-08-11 12:31:40 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
return device->softwareVertexProcessing;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 21:43:08 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_raster_status(const struct wined3d_device *device,
|
2011-12-02 08:15:53 +01:00
|
|
|
UINT swapchain_idx, struct wined3d_raster_status *raster_status)
|
2009-12-20 20:41:37 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, raster_status %p.\n",
|
|
|
|
device, swapchain_idx, raster_status);
|
2005-08-27 11:58:53 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2009-12-20 20:41:37 +01:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
return wined3d_swapchain_get_raster_status(swapchain, raster_status);
|
2009-12-20 20:41:37 +01:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
static BOOL warned;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, segments %.8e.\n", device, segments);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
if (segments != 0.0f)
|
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
if (!warned)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("device %p, segments %.8e stub!\n", device, segments);
|
2008-12-01 15:32:14 +01:00
|
|
|
warned = TRUE;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-10-13 21:43:09 +02:00
|
|
|
float CDECL wined3d_device_get_npatch_mode(const struct wined3d_device *device)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
static BOOL warned;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2008-12-01 15:32:14 +01:00
|
|
|
if (!warned)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("device %p stub!\n", device);
|
2008-12-01 15:32:14 +01:00
|
|
|
warned = TRUE;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2005-03-02 13:16:10 +01:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect,
|
|
|
|
struct wined3d_surface *dst_surface, const POINT *dst_point)
|
2010-03-31 11:28:56 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %s.\n",
|
|
|
|
device, src_surface, wine_dbgstr_rect(src_rect),
|
2010-03-31 11:28:56 +02:00
|
|
|
dst_surface, wine_dbgstr_point(dst_point));
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
if (src_surface->resource.pool != WINED3D_POOL_SYSTEM_MEM || dst_surface->resource.pool != WINED3D_POOL_DEFAULT)
|
2010-03-31 11:28:56 +02:00
|
|
|
{
|
|
|
|
WARN("source %p must be SYSTEMMEM and dest %p must be DEFAULT, returning WINED3DERR_INVALIDCALL\n",
|
|
|
|
src_surface, dst_surface);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2005-11-04 12:13:45 +01:00
|
|
|
|
2011-10-24 20:45:42 +02:00
|
|
|
return surface_upload_from_surface(dst_surface, dst_point, src_surface, src_rect);
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_color_fill(struct wined3d_device *device,
|
2011-11-15 21:18:27 +01:00
|
|
|
struct wined3d_surface *surface, const RECT *rect, const struct wined3d_color *color)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-08-04 19:53:29 +02:00
|
|
|
RECT r;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, surface %p, rect %s, color {%.8e, %.8e, %.8e, %.8e}.\n",
|
|
|
|
device, surface, wine_dbgstr_rect(rect),
|
2010-08-23 18:28:09 +02:00
|
|
|
color->r, color->g, color->b, color->a);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
if (surface->resource.pool != WINED3D_POOL_DEFAULT && surface->resource.pool != WINED3D_POOL_SYSTEM_MEM)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2012-01-17 21:13:37 +01:00
|
|
|
WARN("Color-fill not allowed on %s surfaces.\n", debug_d3dpool(surface->resource.pool));
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-18 12:32:00 +02:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-08-04 19:53:29 +02:00
|
|
|
if (!rect)
|
|
|
|
{
|
|
|
|
SetRect(&r, 0, 0, surface->resource.width, surface->resource.height);
|
|
|
|
rect = &r;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
return surface_color_fill(surface, rect, color);
|
2004-10-07 06:22:21 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
|
2011-11-15 21:18:27 +01:00
|
|
|
struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color)
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2009-02-25 08:39:01 +01:00
|
|
|
HRESULT hr;
|
2011-08-04 19:53:30 +02:00
|
|
|
RECT rect;
|
2009-02-25 08:39:01 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
resource = rendertarget_view->resource;
|
2012-01-17 21:13:36 +01:00
|
|
|
if (resource->type != WINED3D_RTYPE_SURFACE)
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
|
|
|
FIXME("Only supported on surface resources\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-04 19:53:30 +02:00
|
|
|
SetRect(&rect, 0, 0, resource->width, resource->height);
|
|
|
|
hr = surface_color_fill(surface_from_resource(resource), &rect, color);
|
2010-08-29 21:57:44 +02:00
|
|
|
if (FAILED(hr)) ERR("Color fill failed, hr %#x.\n", hr);
|
2009-02-25 08:39:01 +01:00
|
|
|
}
|
|
|
|
|
2012-10-01 11:05:21 +02:00
|
|
|
struct wined3d_surface * CDECL wined3d_device_get_render_target(const struct wined3d_device *device,
|
|
|
|
UINT render_target_idx)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2012-10-01 11:05:21 +02:00
|
|
|
TRACE("device %p, render_target_idx %u.\n", device, render_target_idx);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
|
|
|
if (render_target_idx >= device->adapter->gl_info.limits.buffers)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2010-08-04 11:10:24 +02:00
|
|
|
WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
|
2012-10-01 11:05:21 +02:00
|
|
|
return NULL;
|
2006-12-19 19:25:42 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2012-10-01 11:05:21 +02:00
|
|
|
return device->fb.render_targets[render_target_idx];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-12 20:50:22 +01:00
|
|
|
|
2012-10-01 11:05:22 +02:00
|
|
|
struct wined3d_surface * CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device)
|
2010-08-04 11:10:25 +02:00
|
|
|
{
|
2012-10-01 11:05:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2010-08-04 11:10:25 +02:00
|
|
|
|
2012-10-01 11:05:22 +02:00
|
|
|
return device->fb.depth_stencil;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_render_target(struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT render_target_idx, struct wined3d_surface *render_target, BOOL set_viewport)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *prev;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, render_target_idx %u, render_target %p, set_viewport %#x.\n",
|
|
|
|
device, render_target_idx, render_target, set_viewport);
|
2006-12-19 19:25:42 +01:00
|
|
|
|
2010-08-04 11:10:24 +02:00
|
|
|
if (render_target_idx >= device->adapter->gl_info.limits.buffers)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2010-08-04 11:10:24 +02:00
|
|
|
WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
|
2006-12-19 19:25:42 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
if (render_target && !(render_target->resource.usage & WINED3DUSAGE_RENDERTARGET))
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2013-09-20 10:41:44 +02:00
|
|
|
WARN("Surface %p doesn't have render target usage.\n", render_target);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2012-11-19 00:15:49 +01:00
|
|
|
/* Set the viewport and scissor rectangles, if requested. Tests show that
|
|
|
|
* stateblock recording is ignored, the change goes directly into the
|
|
|
|
* primary stateblock. */
|
|
|
|
if (!render_target_idx && set_viewport)
|
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
struct wined3d_state *state = &device->state;
|
2012-11-19 00:15:49 +01:00
|
|
|
|
|
|
|
state->viewport.x = 0;
|
|
|
|
state->viewport.y = 0;
|
|
|
|
state->viewport.width = render_target->resource.width;
|
|
|
|
state->viewport.height = render_target->resource.height;
|
|
|
|
state->viewport.min_z = 0.0f;
|
|
|
|
state->viewport.max_z = 1.0f;
|
2013-09-30 09:40:39 +02:00
|
|
|
wined3d_cs_emit_set_viewport(device->cs, &state->viewport);
|
2012-11-19 00:15:49 +01:00
|
|
|
|
|
|
|
state->scissor_rect.top = 0;
|
|
|
|
state->scissor_rect.left = 0;
|
|
|
|
state->scissor_rect.right = render_target->resource.width;
|
|
|
|
state->scissor_rect.bottom = render_target->resource.height;
|
2013-09-30 09:40:41 +02:00
|
|
|
wined3d_cs_emit_set_scissor_rect(device->cs, &state->scissor_rect);
|
2012-11-19 00:15:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev = device->fb.render_targets[render_target_idx];
|
|
|
|
if (render_target == prev)
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
if (render_target)
|
|
|
|
wined3d_surface_incref(render_target);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[render_target_idx] = render_target;
|
2013-10-01 10:38:29 +02:00
|
|
|
wined3d_cs_emit_set_render_target(device->cs, render_target_idx, render_target);
|
2010-08-17 19:03:27 +02:00
|
|
|
/* Release after the assignment, to prevent device_resource_released()
|
|
|
|
* from seeing the surface as still in use. */
|
2011-04-29 13:03:41 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_surface_decref(prev);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2012-10-01 22:48:11 +02:00
|
|
|
void CDECL wined3d_device_set_depth_stencil(struct wined3d_device *device, struct wined3d_surface *depth_stencil)
|
2010-08-04 11:10:25 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
struct wined3d_surface *prev = device->fb.depth_stencil;
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, depth_stencil %p, old depth_stencil %p.\n",
|
2011-05-18 22:30:15 +02:00
|
|
|
device, depth_stencil, prev);
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (prev == depth_stencil)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
|
|
|
TRACE("Trying to do a NOP SetRenderTarget operation.\n");
|
2012-10-01 22:48:11 +02:00
|
|
|
return;
|
2010-04-19 20:47:01 +02:00
|
|
|
}
|
2010-04-19 20:47:03 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = depth_stencil;
|
|
|
|
if (depth_stencil)
|
|
|
|
wined3d_surface_incref(depth_stencil);
|
2013-10-01 10:38:30 +02:00
|
|
|
wined3d_cs_emit_set_depth_stencil(device->cs, depth_stencil);
|
2011-08-12 08:21:51 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_surface_decref(prev);
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
|
|
|
|
2013-11-20 09:56:02 +01:00
|
|
|
static struct wined3d_texture *wined3d_device_create_cursor_texture(struct wined3d_device *device,
|
2013-11-18 10:46:16 +01:00
|
|
|
struct wined3d_surface *cursor_image)
|
|
|
|
{
|
|
|
|
struct wined3d_resource_desc desc;
|
|
|
|
struct wined3d_map_desc map_desc;
|
|
|
|
struct wined3d_texture *texture;
|
|
|
|
struct wined3d_surface *surface;
|
|
|
|
BYTE *src_data, *dst_data;
|
|
|
|
unsigned int src_pitch;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (FAILED(wined3d_surface_map(cursor_image, &map_desc, NULL, WINED3D_MAP_READONLY)))
|
|
|
|
{
|
|
|
|
ERR("Failed to map source surface.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
src_pitch = map_desc.row_pitch;
|
|
|
|
src_data = map_desc.data;
|
|
|
|
|
|
|
|
desc.resource_type = WINED3D_RTYPE_TEXTURE;
|
|
|
|
desc.format = WINED3DFMT_B8G8R8A8_UNORM;
|
|
|
|
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
|
|
|
|
desc.multisample_quality = 0;
|
|
|
|
desc.usage = 0;
|
|
|
|
desc.pool = WINED3D_POOL_SYSTEM_MEM;
|
|
|
|
desc.width = cursor_image->resource.width;
|
|
|
|
desc.height = cursor_image->resource.height;
|
|
|
|
desc.depth = 1;
|
|
|
|
desc.size = 0;
|
|
|
|
|
|
|
|
if (FAILED(wined3d_texture_create_2d(device, &desc, 1, WINED3D_SURFACE_MAPPABLE,
|
|
|
|
NULL, &wined3d_null_parent_ops, &texture)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create cursor texture.\n");
|
|
|
|
wined3d_surface_unmap(cursor_image);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface = surface_from_resource(wined3d_texture_get_sub_resource(texture, 0));
|
|
|
|
if (FAILED(wined3d_surface_map(surface, &map_desc, NULL, 0)))
|
|
|
|
{
|
|
|
|
ERR("Failed to map destination surface.\n");
|
|
|
|
wined3d_texture_decref(texture);
|
|
|
|
wined3d_surface_unmap(cursor_image);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_data = map_desc.data;
|
|
|
|
|
|
|
|
for (i = 0; i < desc.height; ++i)
|
|
|
|
memcpy(&dst_data[map_desc.row_pitch * i], &src_data[src_pitch * i], desc.width * 4);
|
|
|
|
|
|
|
|
wined3d_surface_unmap(surface);
|
|
|
|
wined3d_surface_unmap(cursor_image);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device,
|
|
|
|
UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_image)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, x_hotspot %u, y_hotspot %u, cursor_image %p.\n",
|
|
|
|
device, x_hotspot, y_hotspot, cursor_image);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2013-11-18 10:46:16 +01:00
|
|
|
if (device->cursor_texture)
|
2010-05-03 22:03:28 +02:00
|
|
|
{
|
2013-11-18 10:46:16 +01:00
|
|
|
wined3d_texture_decref(device->cursor_texture);
|
|
|
|
device->cursor_texture = NULL;
|
2006-07-27 17:39:03 +02:00
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
if (cursor_image)
|
|
|
|
{
|
2012-06-22 15:57:29 +02:00
|
|
|
struct wined3d_display_mode mode;
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc map_desc;
|
2012-06-22 15:57:29 +02:00
|
|
|
HRESULT hr;
|
2007-03-13 03:44:22 +01:00
|
|
|
|
2006-07-23 00:03:33 +02:00
|
|
|
/* MSDN: Cursor must be A8R8G8B8 */
|
2011-04-29 13:03:42 +02:00
|
|
|
if (cursor_image->resource.format->id != WINED3DFMT_B8G8R8A8_UNORM)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2010-08-15 23:21:43 +02:00
|
|
|
WARN("surface %p has an invalid format.\n", cursor_image);
|
2006-07-23 00:03:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2012-06-27 19:02:28 +02:00
|
|
|
if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d, device->adapter->ordinal, &mode, NULL)))
|
2012-06-22 15:57:29 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get display mode, hr %#x.\n", hr);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2006-07-23 00:03:33 +02:00
|
|
|
/* MSDN: Cursor must be smaller than the display mode */
|
2012-06-22 15:57:29 +02:00
|
|
|
if (cursor_image->resource.width > mode.width || cursor_image->resource.height > mode.height)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
|
|
|
WARN("Surface %p dimensions are %ux%u, but screen dimensions are %ux%u.\n",
|
2011-04-29 13:03:42 +02:00
|
|
|
cursor_image, cursor_image->resource.width, cursor_image->resource.height,
|
2012-06-22 15:57:29 +02:00
|
|
|
mode.width, mode.height);
|
2006-07-23 00:03:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 20:18:33 +02:00
|
|
|
/* TODO: MSDN: Cursor sizes must be a power of 2 */
|
|
|
|
|
|
|
|
/* Do not store the surface's pointer because the application may
|
|
|
|
* release it after setting the cursor image. Windows doesn't
|
|
|
|
* addref the set surface, so we can't do this either without
|
2013-11-18 10:46:16 +01:00
|
|
|
* creating circular refcount dependencies. */
|
|
|
|
if (!(device->cursor_texture = wined3d_device_create_cursor_texture(device, cursor_image)))
|
2011-05-16 20:18:33 +02:00
|
|
|
{
|
2013-11-18 10:46:16 +01:00
|
|
|
ERR("Failed to create cursor texture.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-05-16 20:18:33 +02:00
|
|
|
}
|
|
|
|
|
2013-11-18 10:46:16 +01:00
|
|
|
device->cursorWidth = cursor_image->resource.width;
|
|
|
|
device->cursorHeight = cursor_image->resource.height;
|
|
|
|
|
2011-05-16 20:18:33 +02:00
|
|
|
if (cursor_image->resource.width == 32 && cursor_image->resource.height == 32)
|
2007-03-13 03:44:22 +01:00
|
|
|
{
|
2012-01-26 23:04:19 +01:00
|
|
|
UINT mask_size = cursor_image->resource.width * cursor_image->resource.height / 8;
|
2007-05-15 00:37:53 +02:00
|
|
|
ICONINFO cursorInfo;
|
2012-01-26 23:04:19 +01:00
|
|
|
DWORD *maskBits;
|
2007-05-15 00:37:53 +02:00
|
|
|
HCURSOR cursor;
|
2012-01-26 23:04:19 +01:00
|
|
|
|
|
|
|
/* 32-bit user32 cursors ignore the alpha channel if it's all
|
|
|
|
* zeroes, and use the mask instead. Fill the mask with all ones
|
|
|
|
* to ensure we still get a fully transparent cursor. */
|
|
|
|
maskBits = HeapAlloc(GetProcessHeap(), 0, mask_size);
|
|
|
|
memset(maskBits, 0xff, mask_size);
|
2012-04-12 22:49:04 +02:00
|
|
|
wined3d_surface_map(cursor_image, &map_desc, NULL,
|
2012-06-18 17:19:42 +02:00
|
|
|
WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY);
|
2011-04-29 13:03:42 +02:00
|
|
|
TRACE("width: %u height: %u.\n", cursor_image->resource.width, cursor_image->resource.height);
|
2007-05-15 00:37:53 +02:00
|
|
|
|
|
|
|
cursorInfo.fIcon = FALSE;
|
2011-05-16 23:01:23 +02:00
|
|
|
cursorInfo.xHotspot = x_hotspot;
|
|
|
|
cursorInfo.yHotspot = y_hotspot;
|
2011-04-29 13:03:42 +02:00
|
|
|
cursorInfo.hbmMask = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
|
|
|
|
1, 1, maskBits);
|
|
|
|
cursorInfo.hbmColor = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
|
2012-04-12 22:49:04 +02:00
|
|
|
1, 32, map_desc.data);
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_unmap(cursor_image);
|
2007-05-15 00:37:53 +02:00
|
|
|
/* Create our cursor and clean up. */
|
|
|
|
cursor = CreateIconIndirect(&cursorInfo);
|
|
|
|
if (cursorInfo.hbmMask) DeleteObject(cursorInfo.hbmMask);
|
|
|
|
if (cursorInfo.hbmColor) DeleteObject(cursorInfo.hbmColor);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->hardwareCursor) DestroyCursor(device->hardwareCursor);
|
|
|
|
device->hardwareCursor = cursor;
|
2011-05-16 20:22:25 +02:00
|
|
|
if (device->bCursorVisible) SetCursor( cursor );
|
2007-05-15 00:37:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, maskBits);
|
2007-03-13 03:44:22 +01:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->xHotSpot = x_hotspot;
|
|
|
|
device->yHotSpot = y_hotspot;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_set_cursor_position(struct wined3d_device *device,
|
|
|
|
int x_screen_space, int y_screen_space, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, x %d, y %d, flags %#x.\n",
|
|
|
|
device, x_screen_space, y_screen_space, flags);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->xScreenSpace = x_screen_space;
|
|
|
|
device->yScreenSpace = y_screen_space;
|
2011-05-16 20:22:25 +02:00
|
|
|
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
{
|
|
|
|
POINT pt;
|
2011-10-20 21:42:55 +02:00
|
|
|
|
|
|
|
GetCursorPos( &pt );
|
|
|
|
if (x_screen_space == pt.x && y_screen_space == pt.y)
|
|
|
|
return;
|
|
|
|
SetCursorPos( x_screen_space, y_screen_space );
|
|
|
|
|
|
|
|
/* Switch to the software cursor if position diverges from the hardware one. */
|
2011-05-16 20:22:25 +02:00
|
|
|
GetCursorPos( &pt );
|
|
|
|
if (x_screen_space != pt.x || y_screen_space != pt.y)
|
|
|
|
{
|
|
|
|
if (device->bCursorVisible) SetCursor( NULL );
|
|
|
|
DestroyCursor( device->hardwareCursor );
|
|
|
|
device->hardwareCursor = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL CDECL wined3d_device_show_cursor(struct wined3d_device *device, BOOL show)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL oldVisible = device->bCursorVisible;
|
2007-03-02 09:25:02 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, show %#x.\n", device, show);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 20:16:15 +02:00
|
|
|
/*
|
|
|
|
* When ShowCursor is first called it should make the cursor appear at the OS's last
|
|
|
|
* known cursor position.
|
|
|
|
*/
|
|
|
|
if (show && !oldVisible)
|
|
|
|
{
|
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
device->xScreenSpace = pt.x;
|
|
|
|
device->yScreenSpace = pt.y;
|
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 20:13:13 +02:00
|
|
|
if (device->hardwareCursor)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
|
|
|
device->bCursorVisible = show;
|
|
|
|
if (show)
|
|
|
|
SetCursor(device->hardwareCursor);
|
2007-05-15 00:37:53 +02:00
|
|
|
else
|
|
|
|
SetCursor(NULL);
|
|
|
|
}
|
2013-11-18 10:46:16 +01:00
|
|
|
else if (device->cursor_texture)
|
2007-05-15 00:37:53 +02:00
|
|
|
{
|
2013-11-18 10:46:16 +01:00
|
|
|
device->bCursorVisible = show;
|
2007-05-15 00:37:53 +02:00
|
|
|
}
|
|
|
|
|
2006-08-09 22:23:31 +02:00
|
|
|
return oldVisible;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-07-28 22:27:54 +02:00
|
|
|
void CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
2011-07-25 20:45:07 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2011-07-25 20:45:07 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2011-07-25 20:45:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Checking resource %p for eviction.\n", resource);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2012-05-21 20:48:35 +02:00
|
|
|
if (resource->pool == WINED3D_POOL_MANAGED && !resource->map_count)
|
2011-07-25 20:45:07 +02:00
|
|
|
{
|
|
|
|
TRACE("Evicting %p.\n", resource);
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 08:06:06 +02:00
|
|
|
|
2010-07-08 12:20:57 +02:00
|
|
|
/* Invalidate stream sources, the buffer(s) may have been evicted. */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
|
2010-04-04 19:51:39 +02:00
|
|
|
{
|
2011-07-25 20:45:07 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2009-09-23 10:05:55 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2011-03-30 20:49:26 +02:00
|
|
|
struct wined3d_shader *shader;
|
2008-07-29 19:09:34 +02:00
|
|
|
|
2011-01-04 17:42:01 +01:00
|
|
|
context = context_acquire(device, NULL);
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info = context->gl_info;
|
2009-06-25 10:24:54 +02:00
|
|
|
|
2011-07-25 20:45:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Unloading resource %p.\n", resource);
|
|
|
|
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:26 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(shader, &device->shaders, struct wined3d_shader, shader_list_entry)
|
2010-12-13 13:40:32 +01:00
|
|
|
{
|
2011-01-04 17:42:01 +01:00
|
|
|
device->shader_backend->shader_destroy(shader);
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
2011-01-04 17:42:01 +01:00
|
|
|
if (device->depth_blt_texture)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
|
2011-01-04 17:42:01 +01:00
|
|
|
device->depth_blt_texture = 0;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
2008-10-19 01:21:06 +02:00
|
|
|
|
2011-01-04 17:42:01 +01:00
|
|
|
device->blitter->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
|
|
|
destroy_dummy_textures(device, gl_info);
|
2008-07-29 19:09:34 +02:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
while (device->context_count)
|
2009-10-28 11:00:14 +01:00
|
|
|
{
|
2011-06-28 02:26:20 +02:00
|
|
|
swapchain_destroy_contexts(device->contexts[0]->swapchain);
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
2011-06-28 02:26:20 +02:00
|
|
|
|
2008-07-29 19:09:34 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
swapchain->context = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT create_primary_opengl_context(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
|
2010-04-04 19:51:39 +02:00
|
|
|
{
|
2009-12-17 19:14:35 +01:00
|
|
|
struct wined3d_context *context;
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *target;
|
2008-07-29 19:09:34 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-04-25 12:16:47 +02:00
|
|
|
if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
|
|
|
|
device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
|
2012-10-24 21:23:37 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate shader private data, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = device->blitter->alloc_private(device)))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate blitter private data, hr %#x.\n", hr);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-07-29 19:09:34 +02:00
|
|
|
/* Recreate the primary swapchain's context */
|
|
|
|
swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
|
2009-12-17 19:14:35 +01:00
|
|
|
if (!swapchain->context)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory for swapchain context array.\n");
|
2012-10-24 21:23:37 +02:00
|
|
|
device->blitter->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
target = swapchain->back_buffers ? swapchain->back_buffers[0] : swapchain->front_buffer;
|
2010-03-28 16:25:04 +02:00
|
|
|
if (!(context = context_create(swapchain, target, swapchain->ds_format)))
|
2009-12-17 19:14:35 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create context.\n");
|
2012-10-24 21:23:37 +02:00
|
|
|
device->blitter->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-07-29 19:09:34 +02:00
|
|
|
|
2009-12-17 19:14:35 +01:00
|
|
|
swapchain->context[0] = context;
|
|
|
|
swapchain->num_contexts = 1;
|
2011-08-03 01:34:15 +02:00
|
|
|
create_dummy_textures(device, context);
|
2009-12-17 19:14:35 +01:00
|
|
|
context_release(context);
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2008-07-29 19:09:34 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
|
2012-07-08 16:06:37 +02:00
|
|
|
const struct wined3d_swapchain_desc *swapchain_desc, const struct wined3d_display_mode *mode,
|
2012-11-19 22:04:12 +01:00
|
|
|
wined3d_device_reset_cb callback, BOOL reset_state)
|
2010-09-02 19:25:00 +02:00
|
|
|
{
|
2011-07-25 20:45:06 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2012-07-08 16:06:37 +02:00
|
|
|
struct wined3d_display_mode m;
|
2006-12-08 16:13:15 +01:00
|
|
|
BOOL DisplayModeChanged = FALSE;
|
2011-08-25 21:05:03 +02:00
|
|
|
BOOL update_desc = FALSE;
|
2013-04-09 08:48:43 +02:00
|
|
|
UINT backbuffer_width = swapchain_desc->backbuffer_width;
|
|
|
|
UINT backbuffer_height = swapchain_desc->backbuffer_height;
|
2012-11-19 22:04:12 +01:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2012-06-18 17:19:39 +02:00
|
|
|
unsigned int i;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
2012-07-08 16:06:37 +02:00
|
|
|
TRACE("device %p, swapchain_desc %p, mode %p, callback %p.\n", device, swapchain_desc, mode, callback);
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if (!(swapchain = wined3d_device_get_swapchain(device, 0)))
|
2012-06-18 17:19:39 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get the first implicit swapchain.\n");
|
2012-09-04 20:15:10 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2012-06-18 17:19:39 +02:00
|
|
|
}
|
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
if (reset_state)
|
2013-08-27 08:44:59 +02:00
|
|
|
state_unbind_resources(&device->state);
|
2012-11-19 22:04:12 +01:00
|
|
|
|
2012-08-29 15:09:59 +02:00
|
|
|
if (device->fb.render_targets)
|
2012-06-18 17:19:39 +02:00
|
|
|
{
|
2013-09-13 10:18:10 +02:00
|
|
|
for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
|
2012-08-29 15:09:59 +02:00
|
|
|
{
|
|
|
|
wined3d_device_set_render_target(device, i, NULL, FALSE);
|
|
|
|
}
|
2013-09-13 10:18:10 +02:00
|
|
|
if (swapchain->back_buffers && swapchain->back_buffers[0])
|
|
|
|
wined3d_device_set_render_target(device, 0, swapchain->back_buffers[0], FALSE);
|
2012-06-18 17:19:39 +02:00
|
|
|
}
|
2012-06-18 17:19:38 +02:00
|
|
|
wined3d_device_set_depth_stencil(device, NULL);
|
2011-12-06 22:57:44 +01:00
|
|
|
|
2011-07-25 20:45:10 +02:00
|
|
|
if (device->onscreen_depth_stencil)
|
|
|
|
{
|
|
|
|
wined3d_surface_decref(device->onscreen_depth_stencil);
|
|
|
|
device->onscreen_depth_stencil = NULL;
|
|
|
|
}
|
2011-07-25 20:45:08 +02:00
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
if (reset_state)
|
2011-07-25 20:45:06 +02:00
|
|
|
{
|
2012-11-19 22:04:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Enumerating resource %p.\n", resource);
|
|
|
|
if (FAILED(hr = callback(resource)))
|
|
|
|
return hr;
|
|
|
|
}
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is it necessary to recreate the gl context? Actually every setting can be changed
|
|
|
|
* on an existing gl context, so there's no real need for recreation.
|
|
|
|
*
|
|
|
|
* TODO: Figure out how Reset influences resources in D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEMORY and D3DPOOL_MANAGED
|
|
|
|
*
|
|
|
|
* TODO: Figure out what happens to explicit swapchains, or if we have more than one implicit swapchain
|
|
|
|
*/
|
|
|
|
TRACE("New params:\n");
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("backbuffer_width %u\n", swapchain_desc->backbuffer_width);
|
|
|
|
TRACE("backbuffer_height %u\n", swapchain_desc->backbuffer_height);
|
|
|
|
TRACE("backbuffer_format %s\n", debug_d3dformat(swapchain_desc->backbuffer_format));
|
|
|
|
TRACE("backbuffer_count %u\n", swapchain_desc->backbuffer_count);
|
|
|
|
TRACE("multisample_type %#x\n", swapchain_desc->multisample_type);
|
|
|
|
TRACE("multisample_quality %u\n", swapchain_desc->multisample_quality);
|
|
|
|
TRACE("swap_effect %#x\n", swapchain_desc->swap_effect);
|
|
|
|
TRACE("device_window %p\n", swapchain_desc->device_window);
|
|
|
|
TRACE("windowed %#x\n", swapchain_desc->windowed);
|
|
|
|
TRACE("enable_auto_depth_stencil %#x\n", swapchain_desc->enable_auto_depth_stencil);
|
2011-12-11 21:43:30 +01:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil)
|
|
|
|
TRACE("auto_depth_stencil_format %s\n", debug_d3dformat(swapchain_desc->auto_depth_stencil_format));
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("flags %#x\n", swapchain_desc->flags);
|
|
|
|
TRACE("refresh_rate %u\n", swapchain_desc->refresh_rate);
|
|
|
|
TRACE("swap_interval %u\n", swapchain_desc->swap_interval);
|
2011-12-11 21:43:30 +01:00
|
|
|
TRACE("auto_restore_display_mode %#x\n", swapchain_desc->auto_restore_display_mode);
|
2006-12-08 16:13:15 +01:00
|
|
|
|
|
|
|
/* No special treatment of these parameters. Just store them */
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.swap_effect = swapchain_desc->swap_effect;
|
2013-09-23 10:26:45 +02:00
|
|
|
swapchain->desc.enable_auto_depth_stencil = swapchain_desc->enable_auto_depth_stencil;
|
|
|
|
swapchain->desc.auto_depth_stencil_format = swapchain_desc->auto_depth_stencil_format;
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.flags = swapchain_desc->flags;
|
|
|
|
swapchain->desc.refresh_rate = swapchain_desc->refresh_rate;
|
2013-09-23 10:26:45 +02:00
|
|
|
swapchain->desc.swap_interval = swapchain_desc->swap_interval;
|
|
|
|
swapchain->desc.auto_restore_display_mode = swapchain_desc->auto_restore_display_mode;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
|
|
|
/* What to do about these? */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->backbuffer_count
|
|
|
|
&& swapchain_desc->backbuffer_count != swapchain->desc.backbuffer_count)
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("Cannot change the back buffer count yet.\n");
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->device_window
|
|
|
|
&& swapchain_desc->device_window != swapchain->desc.device_window)
|
2012-02-29 17:22:32 +01:00
|
|
|
{
|
|
|
|
TRACE("Changing the device window from %p to %p.\n",
|
|
|
|
swapchain->desc.device_window, swapchain_desc->device_window);
|
|
|
|
swapchain->desc.device_window = swapchain_desc->device_window;
|
|
|
|
swapchain->device_window = swapchain_desc->device_window;
|
|
|
|
wined3d_swapchain_set_window(swapchain, NULL);
|
|
|
|
}
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil && !device->auto_depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2013-06-04 09:57:08 +02:00
|
|
|
struct wined3d_resource_desc surface_desc;
|
|
|
|
|
2009-04-23 08:33:21 +02:00
|
|
|
TRACE("Creating the depth stencil buffer\n");
|
|
|
|
|
2013-06-04 09:57:08 +02:00
|
|
|
surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
|
|
|
|
surface_desc.format = swapchain_desc->auto_depth_stencil_format;
|
|
|
|
surface_desc.multisample_type = swapchain_desc->multisample_type;
|
|
|
|
surface_desc.multisample_quality = swapchain_desc->multisample_quality;
|
|
|
|
surface_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
|
|
|
|
surface_desc.pool = WINED3D_POOL_DEFAULT;
|
|
|
|
surface_desc.width = swapchain_desc->backbuffer_width;
|
|
|
|
surface_desc.height = swapchain_desc->backbuffer_height;
|
|
|
|
surface_desc.depth = 1;
|
|
|
|
surface_desc.size = 0;
|
|
|
|
|
2012-07-11 12:19:03 +02:00
|
|
|
if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
|
2013-06-04 09:57:08 +02:00
|
|
|
device->device_parent, &surface_desc, &device->auto_depth_stencil)))
|
2011-04-13 19:14:31 +02:00
|
|
|
{
|
2012-07-09 23:16:38 +02:00
|
|
|
ERR("Failed to create the depth stencil buffer, hr %#x.\n", hr);
|
2009-04-23 08:33:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2008-01-08 22:34:43 +01:00
|
|
|
|
2008-09-10 11:08:58 +02:00
|
|
|
/* Reset the depth stencil */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil)
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_set_depth_stencil(device, device->auto_depth_stencil);
|
2008-09-10 11:08:58 +02:00
|
|
|
|
2012-07-08 16:06:37 +02:00
|
|
|
if (mode)
|
|
|
|
{
|
|
|
|
DisplayModeChanged = TRUE;
|
|
|
|
m = *mode;
|
|
|
|
}
|
|
|
|
else if (swapchain_desc->windowed)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2013-08-20 10:20:09 +02:00
|
|
|
m = swapchain->original_mode;
|
2011-05-16 23:01:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-08 16:06:37 +02:00
|
|
|
m.width = swapchain_desc->backbuffer_width;
|
|
|
|
m.height = swapchain_desc->backbuffer_height;
|
|
|
|
m.refresh_rate = swapchain_desc->refresh_rate;
|
|
|
|
m.format_id = swapchain_desc->backbuffer_format;
|
|
|
|
m.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
2013-04-09 08:48:43 +02:00
|
|
|
if (!backbuffer_width || !backbuffer_height)
|
|
|
|
{
|
|
|
|
/* The application is requesting that either the swapchain width or
|
|
|
|
* height be set to the corresponding dimension in the window's
|
|
|
|
* client rect. */
|
|
|
|
|
|
|
|
RECT client_rect;
|
|
|
|
|
|
|
|
if (!swapchain_desc->windowed)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (!GetClientRect(swapchain->device_window, &client_rect))
|
|
|
|
{
|
|
|
|
ERR("Failed to get client rect, last error %#x.\n", GetLastError());
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!backbuffer_width)
|
|
|
|
backbuffer_width = client_rect.right;
|
|
|
|
|
|
|
|
if (!backbuffer_height)
|
|
|
|
backbuffer_height = client_rect.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backbuffer_width != swapchain->desc.backbuffer_width
|
|
|
|
|| backbuffer_height != swapchain->desc.backbuffer_height)
|
2006-12-08 16:13:15 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain_desc->windowed)
|
2006-12-08 16:13:15 +01:00
|
|
|
DisplayModeChanged = TRUE;
|
|
|
|
|
2013-04-09 08:48:43 +02:00
|
|
|
swapchain->desc.backbuffer_width = backbuffer_width;
|
|
|
|
swapchain->desc.backbuffer_height = backbuffer_height;
|
2011-08-25 21:05:03 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->backbuffer_format != WINED3DFMT_UNKNOWN
|
|
|
|
&& swapchain_desc->backbuffer_format != swapchain->desc.backbuffer_format)
|
2011-11-24 22:52:34 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.backbuffer_format = swapchain_desc->backbuffer_format;
|
2011-11-24 22:52:34 +01:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->multisample_type != swapchain->desc.multisample_type
|
|
|
|
|| swapchain_desc->multisample_quality != swapchain->desc.multisample_quality)
|
2011-08-25 21:05:03 +02:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.multisample_type = swapchain_desc->multisample_type;
|
|
|
|
swapchain->desc.multisample_quality = swapchain_desc->multisample_quality;
|
2011-08-25 21:05:03 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_desc)
|
|
|
|
{
|
|
|
|
UINT i;
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if (FAILED(hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
|
2012-01-12 21:43:08 +01:00
|
|
|
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
|
2012-09-04 20:15:10 +02:00
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
|
2009-12-04 13:07:18 +01:00
|
|
|
return hr;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
|
2010-04-26 21:33:01 +02:00
|
|
|
{
|
2012-09-04 20:15:10 +02:00
|
|
|
if (FAILED(hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
|
2012-01-12 21:43:08 +01:00
|
|
|
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
|
2012-09-04 20:15:10 +02:00
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
|
2009-12-04 13:07:18 +01:00
|
|
|
return hr;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->auto_depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2012-09-04 20:15:10 +02:00
|
|
|
if (FAILED(hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width,
|
2012-01-12 21:43:08 +01:00
|
|
|
swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id,
|
2012-09-04 20:15:10 +02:00
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
|
2009-12-04 13:07:18 +01:00
|
|
|
return hr;
|
2008-01-25 18:04:05 +01:00
|
|
|
}
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain_desc->windowed != !swapchain->desc.windowed
|
2010-03-15 21:07:29 +01:00
|
|
|
|| DisplayModeChanged)
|
|
|
|
{
|
2012-07-08 16:06:37 +02:00
|
|
|
if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m)))
|
2012-06-22 15:57:27 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to set display mode, hr %#x.\n", hr);
|
2012-06-27 19:02:25 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2012-06-22 15:57:27 +02:00
|
|
|
}
|
2008-08-04 21:11:22 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain_desc->windowed)
|
2010-03-15 21:07:28 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain->desc.windowed)
|
2010-10-06 12:01:29 +02:00
|
|
|
{
|
2011-11-27 21:34:48 +01:00
|
|
|
HWND focus_window = device->create_parms.focus_window;
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!focus_window)
|
2011-12-02 08:15:52 +01:00
|
|
|
focus_window = swapchain_desc->device_window;
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
|
2010-10-06 12:01:29 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to acquire focus window, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-08-04 21:11:22 +02:00
|
|
|
/* switch from windowed to fs */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height);
|
2010-10-06 12:01:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-04 21:11:22 +02:00
|
|
|
/* Fullscreen -> fullscreen mode change */
|
2010-03-15 21:07:30 +01:00
|
|
|
MoveWindow(swapchain->device_window, 0, 0,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height,
|
|
|
|
TRUE);
|
2008-08-04 21:11:22 +02:00
|
|
|
}
|
2010-03-15 21:07:28 +01:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
else if (!swapchain->desc.windowed)
|
2010-03-15 21:07:28 +01:00
|
|
|
{
|
2008-08-04 21:11:22 +02:00
|
|
|
/* Fullscreen -> windowed switch */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_restore_fullscreen_window(device, swapchain->device_window);
|
|
|
|
wined3d_device_release_focus_window(device);
|
2008-08-04 21:11:22 +02:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.windowed = swapchain_desc->windowed;
|
2010-10-06 12:01:29 +02:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
else if (!swapchain_desc->windowed)
|
2010-10-06 12:01:29 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
DWORD style = device->style;
|
|
|
|
DWORD exStyle = device->exStyle;
|
2008-02-06 22:12:06 +01:00
|
|
|
/* If we're in fullscreen, and the mode wasn't changed, we have to get the window back into
|
|
|
|
* the right position. Some applications(Battlefield 2, Guild Wars) move it and then call
|
|
|
|
* Reset to clear up their mess. Guild Wars also loses the device during that.
|
|
|
|
*/
|
2011-05-16 23:01:23 +02:00
|
|
|
device->style = 0;
|
|
|
|
device->exStyle = 0;
|
|
|
|
wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->style = style;
|
|
|
|
device->exStyle = exStyle;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2008-12-19 19:21:55 +01:00
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
if (reset_state)
|
|
|
|
{
|
|
|
|
TRACE("Resetting stateblock.\n");
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
|
|
|
{
|
|
|
|
wined3d_stateblock_decref(device->recording);
|
|
|
|
device->recording = NULL;
|
|
|
|
}
|
2013-08-27 08:44:59 +02:00
|
|
|
state_cleanup(&device->state);
|
2012-06-26 15:32:10 +02:00
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
delete_opengl_contexts(device, swapchain);
|
2012-06-26 15:32:10 +02:00
|
|
|
|
2013-09-30 09:40:40 +02:00
|
|
|
if (FAILED(hr = state_init(&device->state, &device->fb, &device->adapter->gl_info,
|
|
|
|
&device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT)))
|
2013-08-27 08:44:59 +02:00
|
|
|
ERR("Failed to initialize device state, hr %#x.\n", hr);
|
|
|
|
device->update_state = &device->state;
|
2013-09-25 09:58:13 +02:00
|
|
|
|
|
|
|
device_init_swapchain_state(device, swapchain);
|
2012-11-19 22:04:12 +01:00
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
else
|
2012-11-19 22:04:12 +01:00
|
|
|
{
|
|
|
|
struct wined3d_surface *rt = device->fb.render_targets[0];
|
2013-08-27 08:44:59 +02:00
|
|
|
struct wined3d_state *state = &device->state;
|
2008-12-19 19:21:55 +01:00
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
/* Note the min_z / max_z is not reset. */
|
|
|
|
state->viewport.x = 0;
|
|
|
|
state->viewport.y = 0;
|
|
|
|
state->viewport.width = rt->resource.width;
|
|
|
|
state->viewport.height = rt->resource.height;
|
2013-09-30 09:40:39 +02:00
|
|
|
wined3d_cs_emit_set_viewport(device->cs, &state->viewport);
|
2012-11-19 22:04:12 +01:00
|
|
|
|
|
|
|
state->scissor_rect.top = 0;
|
|
|
|
state->scissor_rect.left = 0;
|
|
|
|
state->scissor_rect.right = rt->resource.width;
|
|
|
|
state->scissor_rect.bottom = rt->resource.height;
|
2013-09-30 09:40:41 +02:00
|
|
|
wined3d_cs_emit_set_scissor_rect(device->cs, &state->scissor_rect);
|
2012-11-19 22:04:12 +01:00
|
|
|
}
|
2008-03-18 19:31:24 +01:00
|
|
|
|
2011-08-22 21:02:47 +02:00
|
|
|
swapchain_update_render_to_fbo(swapchain);
|
2011-08-23 20:08:08 +02:00
|
|
|
swapchain_update_draw_bindings(swapchain);
|
2009-12-06 18:08:39 +01:00
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
if (reset_state && device->d3d_initialized)
|
2011-12-04 15:50:13 +01:00
|
|
|
hr = create_primary_opengl_context(device, swapchain);
|
2008-03-18 19:31:24 +01:00
|
|
|
|
2008-02-05 00:05:26 +01:00
|
|
|
/* All done. There is no need to reload resources or shaders, this will happen automatically on the
|
|
|
|
* first use
|
|
|
|
*/
|
2008-07-29 19:09:34 +02:00
|
|
|
return hr;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, enable_dialogs %#x.\n", device, enable_dialogs);
|
2009-12-21 23:17:26 +01:00
|
|
|
|
|
|
|
if (!enable_dialogs) FIXME("Dialogs cannot be disabled yet.\n");
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-01 22:48:12 +02:00
|
|
|
void CDECL wined3d_device_get_creation_parameters(const struct wined3d_device *device,
|
2011-11-27 21:34:48 +01:00
|
|
|
struct wined3d_device_creation_parameters *parameters)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, parameters %p.\n", device, parameters);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-11-27 21:34:48 +01:00
|
|
|
*parameters = device->create_parms;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-10-19 22:03:13 +02:00
|
|
|
void CDECL wined3d_device_set_gamma_ramp(const struct wined3d_device *device,
|
2011-11-21 18:48:41 +01:00
|
|
|
UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, flags %#x, ramp %p.\n",
|
|
|
|
device, swapchain_idx, flags, ramp);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_swapchain_set_gamma_ramp(swapchain, flags, ramp);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-10-19 22:03:14 +02:00
|
|
|
void CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device,
|
2011-11-21 18:48:41 +01:00
|
|
|
UINT swapchain_idx, struct wined3d_gamma_ramp *ramp)
|
2011-04-13 19:14:32 +02:00
|
|
|
{
|
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, ramp %p.\n",
|
|
|
|
device, swapchain_idx, ramp);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2012-09-04 20:15:10 +02:00
|
|
|
if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_swapchain_get_gamma_ramp(swapchain, ramp);
|
2004-10-07 06:22:21 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)
|
2009-05-29 09:13:21 +02:00
|
|
|
{
|
2011-01-16 23:36:45 +01:00
|
|
|
TRACE("device %p, resource %p.\n", device, resource);
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
list_add_head(&device->resources, &resource->resource_list_entry);
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
static void device_resource_remove(struct wined3d_device *device, struct wined3d_resource *resource)
|
2009-05-29 09:13:21 +02:00
|
|
|
{
|
2011-01-16 23:36:44 +01:00
|
|
|
TRACE("device %p, resource %p.\n", device, resource);
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
list_remove(&resource->resource_list_entry);
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource)
|
2009-05-29 09:13:21 +02:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
enum wined3d_resource_type type = resource->type;
|
2010-08-17 19:03:28 +02:00
|
|
|
unsigned int i;
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2010-08-17 19:03:28 +02:00
|
|
|
TRACE("device %p, resource %p, type %s.\n", device, resource, debug_d3dresourcetype(type));
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2011-01-16 23:36:47 +01:00
|
|
|
context_resource_released(device, resource, type);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-08-17 19:03:28 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_SURFACE:
|
2009-06-25 10:24:56 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface = surface_from_resource(resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
|
|
|
if (!device->d3d_initialized) break;
|
|
|
|
|
|
|
|
for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.render_targets[i] == surface)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
ERR("Surface %p is still in use as render target %u.\n", surface, i);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[i] = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
2007-07-18 23:13:58 +02:00
|
|
|
}
|
2007-04-09 01:53:27 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.depth_stencil == surface)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
ERR("Surface %p is still in use as depth/stencil buffer.\n", surface);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
}
|
2007-04-09 01:53:27 +02:00
|
|
|
break;
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE:
|
|
|
|
case WINED3D_RTYPE_CUBE_TEXTURE:
|
|
|
|
case WINED3D_RTYPE_VOLUME_TEXTURE:
|
2010-08-17 19:03:28 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (device->state.textures[i] == texture)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
ERR("Texture %p is still in use, stage %u.\n", texture, i);
|
|
|
|
device->state.textures[i] = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording && device->update_state->textures[i] == texture)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
ERR("Texture %p is still in use by recording stateblock %p, stage %u.\n",
|
|
|
|
texture, device->recording, i);
|
|
|
|
device->update_state->textures[i] = NULL;
|
2010-08-17 19:03:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_BUFFER:
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_STREAMS; ++i)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
if (device->state.streams[i].buffer == buffer)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
ERR("Buffer %p is still in use, stream %u.\n", buffer, i);
|
|
|
|
device->state.streams[i].buffer = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording && device->update_state->streams[i].buffer == buffer)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
|
2013-08-26 09:23:37 +02:00
|
|
|
buffer, device->recording, i);
|
|
|
|
device->update_state->streams[i].buffer = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
if (device->state.index_buffer == buffer)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
ERR("Buffer %p is still in use as index buffer.\n", buffer);
|
|
|
|
device->state.index_buffer = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording && device->update_state->index_buffer == buffer)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
|
2013-08-26 09:23:37 +02:00
|
|
|
buffer, device->recording);
|
|
|
|
device->update_state->index_buffer = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
break;
|
2009-02-23 09:16:02 +01:00
|
|
|
|
2005-07-26 12:34:15 +02:00
|
|
|
default:
|
2010-08-17 19:03:28 +02:00
|
|
|
break;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2008-01-09 20:37:05 +01:00
|
|
|
/* Remove the resource from the resourceStore */
|
2011-01-16 23:36:46 +01:00
|
|
|
device_resource_remove(device, resource);
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2010-08-17 19:03:28 +02:00
|
|
|
TRACE("Resource released.\n");
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 22:15:38 +02:00
|
|
|
struct wined3d_surface * CDECL wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2010-03-16 19:02:21 +01:00
|
|
|
|
2012-10-02 22:15:38 +02:00
|
|
|
TRACE("device %p, dc %p.\n", device, dc);
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2011-11-23 08:51:42 +01:00
|
|
|
if (!dc)
|
2012-10-02 22:15:38 +02:00
|
|
|
return NULL;
|
2011-11-23 08:51:42 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
if (resource->type == WINED3D_RTYPE_SURFACE)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *s = surface_from_resource(resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
|
|
|
if (s->hDC == dc)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
TRACE("Found surface %p for dc %p.\n", s, dc);
|
2012-10-02 22:15:38 +02:00
|
|
|
return s;
|
2010-03-16 19:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 22:15:38 +02:00
|
|
|
return NULL;
|
2010-03-16 19:02:21 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d,
|
2011-12-12 20:53:59 +01:00
|
|
|
UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags,
|
2011-06-23 11:43:39 +02:00
|
|
|
BYTE surface_alignment, struct wined3d_device_parent *device_parent)
|
2009-11-18 10:45:53 +01:00
|
|
|
{
|
|
|
|
struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
|
|
|
|
const struct fragment_pipeline *fragment_pipeline;
|
2013-04-25 12:16:47 +02:00
|
|
|
const struct wined3d_vertex_pipe_ops *vertex_pipeline;
|
2009-11-18 10:45:53 +01:00
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
device->ref = 1;
|
2011-02-01 19:39:54 +01:00
|
|
|
device->wined3d = wined3d;
|
2011-02-01 19:39:53 +01:00
|
|
|
wined3d_incref(device->wined3d);
|
2009-11-18 10:45:53 +01:00
|
|
|
device->adapter = wined3d->adapter_count ? adapter : NULL;
|
|
|
|
device->device_parent = device_parent;
|
|
|
|
list_init(&device->resources);
|
|
|
|
list_init(&device->shaders);
|
2011-06-23 11:43:39 +02:00
|
|
|
device->surface_alignment = surface_alignment;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
|
|
|
/* Save the creation parameters. */
|
2011-11-27 21:34:48 +01:00
|
|
|
device->create_parms.adapter_idx = adapter_idx;
|
|
|
|
device->create_parms.device_type = device_type;
|
|
|
|
device->create_parms.focus_window = focus_window;
|
|
|
|
device->create_parms.flags = flags;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2010-02-02 12:06:57 +01:00
|
|
|
device->shader_backend = adapter->shader_backend;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2013-04-25 12:16:47 +02:00
|
|
|
vertex_pipeline = adapter->vertex_pipe;
|
|
|
|
|
2010-02-02 12:06:56 +01:00
|
|
|
fragment_pipeline = adapter->fragment_pipe;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2013-04-25 12:16:47 +02:00
|
|
|
if (vertex_pipeline->vp_states && fragment_pipeline->states
|
2013-01-16 08:51:47 +01:00
|
|
|
&& FAILED(hr = compile_state_table(device->StateTable, device->multistate_funcs,
|
2013-04-25 15:20:30 +02:00
|
|
|
&adapter->gl_info, &adapter->d3d_info, vertex_pipeline,
|
|
|
|
fragment_pipeline, misc_state_template)))
|
2013-01-16 08:51:47 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to compile state table, hr %#x.\n", hr);
|
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
return hr;
|
2010-05-06 14:57:21 +02:00
|
|
|
}
|
2013-01-16 08:51:47 +01:00
|
|
|
|
2010-02-03 11:02:20 +01:00
|
|
|
device->blitter = adapter->blitter;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2013-09-30 09:40:40 +02:00
|
|
|
if (FAILED(hr = state_init(&device->state, &device->fb, &adapter->gl_info,
|
|
|
|
&adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT)))
|
2011-12-04 15:50:12 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
ERR("Failed to initialize device state, hr %#x.\n", hr);
|
2013-09-27 00:15:13 +02:00
|
|
|
goto err;
|
2011-12-04 15:50:12 +01:00
|
|
|
}
|
2013-08-27 08:44:59 +02:00
|
|
|
device->update_state = &device->state;
|
2011-12-04 15:50:12 +01:00
|
|
|
|
2013-09-27 00:15:14 +02:00
|
|
|
if (!(device->cs = wined3d_cs_create(device)))
|
2013-09-27 00:15:13 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to create command stream.\n");
|
|
|
|
state_cleanup(&device->state);
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:45:53 +01:00
|
|
|
return WINED3D_OK;
|
2013-09-27 00:15:13 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
|
|
|
|
}
|
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
return hr;
|
2009-11-18 10:45:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 23:21:13 +02:00
|
|
|
void device_invalidate_state(const struct wined3d_device *device, DWORD state)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
|
|
|
DWORD rep = device->StateTable[state].representative;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2006-12-19 13:00:03 +01:00
|
|
|
DWORD idx;
|
|
|
|
BYTE shift;
|
2007-02-12 19:18:31 +01:00
|
|
|
UINT i;
|
2006-12-19 13:00:03 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2011-03-30 20:49:27 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
context = device->contexts[i];
|
2007-02-12 19:18:31 +01:00
|
|
|
if(isStateDirty(context, rep)) continue;
|
|
|
|
|
|
|
|
context->dirtyArray[context->numDirtyEntries++] = rep;
|
2009-12-29 17:10:22 +01:00
|
|
|
idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
|
|
|
|
shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
|
2007-02-12 19:18:31 +01:00
|
|
|
context->isStateDirty[idx] |= (1 << shift);
|
|
|
|
}
|
2006-12-19 13:00:03 +01:00
|
|
|
}
|
2007-11-30 20:22:33 +01:00
|
|
|
|
2011-07-06 23:14:25 +02:00
|
|
|
void get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height)
|
2009-07-24 10:44:15 +02:00
|
|
|
{
|
|
|
|
/* The drawable size of a fbo target is the opengl texture size, which is the power of two size. */
|
2010-04-21 22:02:31 +02:00
|
|
|
*width = context->current_rt->pow2Width;
|
|
|
|
*height = context->current_rt->pow2Height;
|
2007-11-30 20:22:33 +01:00
|
|
|
}
|
|
|
|
|
2011-07-06 23:14:25 +02:00
|
|
|
void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height)
|
2009-07-24 10:44:15 +02:00
|
|
|
{
|
2011-07-06 23:14:25 +02:00
|
|
|
const struct wined3d_swapchain *swapchain = context->swapchain;
|
2007-11-30 20:22:33 +01:00
|
|
|
/* The drawable size of a backbuffer / aux buffer offscreen target is the size of the
|
|
|
|
* current context's drawable, which is the size of the back buffer of the swapchain
|
2010-03-15 21:07:25 +01:00
|
|
|
* the active context belongs to. */
|
2011-12-02 08:15:52 +01:00
|
|
|
*width = swapchain->desc.backbuffer_width;
|
|
|
|
*height = swapchain->desc.backbuffer_height;
|
2007-11-30 20:22:33 +01:00
|
|
|
}
|
2009-12-22 18:32:13 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
|
2009-12-22 18:32:13 +01:00
|
|
|
UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc)
|
|
|
|
{
|
|
|
|
if (device->filter_messages)
|
|
|
|
{
|
|
|
|
TRACE("Filtering message: window %p, message %#x, wparam %#lx, lparam %#lx.\n",
|
|
|
|
window, message, wparam, lparam);
|
2010-11-02 12:02:47 +01:00
|
|
|
if (unicode)
|
|
|
|
return DefWindowProcW(window, message, wparam, lparam);
|
|
|
|
else
|
|
|
|
return DefWindowProcA(window, message, wparam, lparam);
|
2009-12-22 18:32:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message == WM_DESTROY)
|
|
|
|
{
|
|
|
|
TRACE("unregister window %p.\n", window);
|
|
|
|
wined3d_unregister_window(window);
|
2009-12-28 17:38:04 +01:00
|
|
|
|
2012-01-24 21:47:45 +01:00
|
|
|
if (InterlockedCompareExchangePointer((void **)&device->focus_window, NULL, window) != window)
|
|
|
|
ERR("Window %p is not the focus window for device %p.\n", window, device);
|
2009-12-22 18:32:13 +01:00
|
|
|
}
|
2011-11-30 06:01:44 +01:00
|
|
|
else if (message == WM_DISPLAYCHANGE)
|
|
|
|
{
|
|
|
|
device->device_parent->ops->mode_changed(device->device_parent);
|
|
|
|
}
|
2009-12-22 18:32:13 +01:00
|
|
|
|
2010-11-02 12:02:47 +01:00
|
|
|
if (unicode)
|
|
|
|
return CallWindowProcW(proc, window, message, wparam, lparam);
|
|
|
|
else
|
|
|
|
return CallWindowProcA(proc, window, message, wparam, lparam);
|
2009-12-22 18:32:13 +01:00
|
|
|
}
|