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);
|
2017-03-28 23:37:37 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
2004-10-07 06:22:21 +02:00
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
struct wined3d_matrix_3x3
|
|
|
|
{
|
|
|
|
float _11, _12, _13;
|
|
|
|
float _21, _22, _23;
|
|
|
|
float _31, _32, _33;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct light_transformed
|
|
|
|
{
|
|
|
|
struct wined3d_color diffuse, specular, ambient;
|
|
|
|
struct wined3d_vec4 position;
|
|
|
|
struct wined3d_vec3 direction;
|
|
|
|
float range, falloff, c_att, l_att, q_att, cos_htheta, cos_hphi;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lights_settings
|
|
|
|
{
|
|
|
|
struct light_transformed lights[WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS];
|
|
|
|
struct wined3d_color ambient_light;
|
|
|
|
struct wined3d_matrix modelview_matrix;
|
|
|
|
struct wined3d_matrix_3x3 normal_matrix;
|
2019-06-10 12:11:49 +02:00
|
|
|
struct wined3d_vec4 position_transformed;
|
|
|
|
|
|
|
|
float fog_start, fog_end, fog_density;
|
2019-05-20 22:57:34 +02:00
|
|
|
|
|
|
|
uint32_t point_light_count : 8;
|
|
|
|
uint32_t spot_light_count : 8;
|
|
|
|
uint32_t directional_light_count : 8;
|
|
|
|
uint32_t parallel_point_light_count : 8;
|
2019-06-10 12:11:49 +02:00
|
|
|
uint32_t lighting : 1;
|
2019-05-20 22:57:34 +02:00
|
|
|
uint32_t legacy_lighting : 1;
|
|
|
|
uint32_t normalise : 1;
|
|
|
|
uint32_t localviewer : 1;
|
2019-06-10 12:11:49 +02:00
|
|
|
uint32_t fog_coord_mode : 2;
|
|
|
|
uint32_t fog_mode : 2;
|
|
|
|
uint32_t padding : 24;
|
2019-05-20 22:57:34 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2017-03-31 13:11:51 +02:00
|
|
|
switch (primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
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;
|
|
|
|
|
2017-05-15 12:05:47 +02:00
|
|
|
case WINED3D_PT_PATCH:
|
|
|
|
return GL_PATCHES;
|
|
|
|
|
2009-03-05 12:30:43 +01:00
|
|
|
default:
|
2017-03-31 13:11:51 +02:00
|
|
|
FIXME("Unhandled primitive type %s.\n", debug_d3dprimitivetype(primitive_type));
|
2014-09-18 10:56:27 +02:00
|
|
|
case WINED3D_PT_UNDEFINED:
|
|
|
|
return ~0u;
|
2009-03-05 12:30:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 16:20:16 +02:00
|
|
|
enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2017-03-31 13:11:51 +02:00
|
|
|
switch (primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-05-15 12:05:47 +02:00
|
|
|
case GL_PATCHES:
|
|
|
|
return WINED3D_PT_PATCH;
|
|
|
|
|
2009-03-05 12:30:43 +01:00
|
|
|
default:
|
2017-03-31 13:11:51 +02:00
|
|
|
FIXME("Unhandled primitive type %s.\n", debug_d3dprimitivetype(primitive_type));
|
2014-09-18 10:56:27 +02:00
|
|
|
case ~0u:
|
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);
|
|
|
|
|
2019-05-03 12:56:03 +02:00
|
|
|
if (!device->shader_backend->shader_allocate_context_data(context))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate shader backend context data.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
device->shader_backend->shader_init_context_state(context);
|
|
|
|
|
|
|
|
if (!device->adapter->fragment_pipe->allocate_context_data(context))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate fragment pipeline context data.\n");
|
|
|
|
device->shader_backend->shader_free_context_data(context);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(new_array = heap_realloc(device->contexts, sizeof(*new_array) * (device->context_count + 1))))
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to grow the context array.\n");
|
2019-05-03 12:56:03 +02:00
|
|
|
device->adapter->fragment_pipe->free_context_data(context);
|
|
|
|
device->shader_backend->shader_free_context_data(context);
|
2010-03-14 21:53:25 +01:00
|
|
|
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;
|
2019-05-03 12:56:03 +02:00
|
|
|
|
2010-03-14 21:53:25 +01:00
|
|
|
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);
|
|
|
|
|
2019-05-03 12:56:02 +02:00
|
|
|
device->adapter->fragment_pipe->free_context_data(context);
|
|
|
|
device->shader_backend->shader_free_context_data(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
|
|
|
{
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(device->contexts);
|
2010-03-14 21:53:25 +01:00
|
|
|
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));
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(new_array = heap_realloc(device->contexts, device->context_count * sizeof(*device->contexts))))
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to shrink context array. Oh well.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->contexts = new_array;
|
|
|
|
}
|
|
|
|
|
2018-02-26 07:51:51 +01:00
|
|
|
static BOOL is_full_clear(const struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
const RECT *draw_rect, const RECT *clear_rect)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2018-02-26 07:51:51 +01:00
|
|
|
unsigned int width, height, level;
|
|
|
|
|
|
|
|
level = sub_resource_idx % texture->level_count;
|
|
|
|
width = wined3d_texture_get_level_width(texture, level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, level);
|
2016-03-30 21:30:16 +02:00
|
|
|
|
2010-07-23 11:31:03 +02:00
|
|
|
/* partial draw rect */
|
2016-03-30 21:30:16 +02:00
|
|
|
if (draw_rect->left || draw_rect->top || draw_rect->right < width || draw_rect->bottom < 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
|
2016-03-30 21:30:16 +02:00
|
|
|
|| clear_rect->right < width || clear_rect->bottom < height))
|
2010-07-23 11:31:03 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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,
|
2016-03-17 16:30:02 +01:00
|
|
|
UINT rect_count, const RECT *clear_rect, 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
|
|
|
{
|
2016-11-04 13:43:44 +01:00
|
|
|
struct wined3d_rendertarget_view *rtv = rt_count ? fb->render_targets[0] : NULL;
|
2016-04-20 19:29:15 +02:00
|
|
|
struct wined3d_rendertarget_view *dsv = fb->depth_stencil;
|
2017-02-26 07:46:34 +01:00
|
|
|
const struct wined3d_state *state = &device->cs->state;
|
2018-03-14 09:09:14 +01:00
|
|
|
struct wined3d_texture *depth_stencil = NULL;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-05-14 12:56:23 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2018-03-14 09:09:14 +01:00
|
|
|
struct wined3d_texture *target = NULL;
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT drawable_width, drawable_height;
|
2015-11-27 20:39:36 +01:00
|
|
|
struct wined3d_color corrected_color;
|
2010-07-23 11:31:03 +02:00
|
|
|
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;
|
|
|
|
|
2018-03-14 09:09:14 +01:00
|
|
|
if (rtv && rtv->resource->type != WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
target = texture_from_resource(rtv->resource);
|
|
|
|
context = context_acquire(device, target, rtv->sub_resource_idx);
|
|
|
|
}
|
2017-02-15 14:17:15 +01:00
|
|
|
else
|
2018-03-14 09:09:14 +01:00
|
|
|
{
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(device, NULL, 0);
|
2018-03-14 09:09:14 +01:00
|
|
|
}
|
2019-05-14 12:56:23 +02:00
|
|
|
context_gl = wined3d_context_gl(context);
|
2018-03-14 09:09:14 +01:00
|
|
|
|
|
|
|
if (dsv && dsv->resource->type != WINED3D_RTYPE_BUFFER)
|
|
|
|
depth_stencil = texture_from_resource(dsv->resource);
|
|
|
|
|
2019-06-06 14:51:06 +02:00
|
|
|
if (!context_gl->valid)
|
2015-10-15 22:41:12 +02:00
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping clear.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
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. */
|
2015-10-28 15:29:17 +01:00
|
|
|
for (i = 0; i < rt_count; ++i)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2016-03-06 20:59:47 +01:00
|
|
|
struct wined3d_rendertarget_view *rtv = fb->render_targets[i];
|
|
|
|
|
2016-08-02 12:26:30 +02:00
|
|
|
if (rtv && rtv->format->id != WINED3DFMT_NULL)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2016-08-02 12:26:30 +02:00
|
|
|
struct wined3d_texture *rt = wined3d_texture_from_resource(rtv->resource);
|
|
|
|
|
2018-02-26 07:51:51 +01:00
|
|
|
if (flags & WINED3DCLEAR_TARGET && !is_full_clear(rt, rtv->sub_resource_idx,
|
|
|
|
draw_rect, rect_count ? clear_rect : NULL))
|
2016-08-02 12:26:30 +02:00
|
|
|
wined3d_texture_load_location(rt, rtv->sub_resource_idx, context, rtv->resource->draw_binding);
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
2016-08-02 12:26:30 +02:00
|
|
|
wined3d_texture_prepare_location(rt, rtv->sub_resource_idx, context, rtv->resource->draw_binding);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
render_offscreen = context->render_offscreen;
|
2016-11-04 13:43:44 +01:00
|
|
|
wined3d_rendertarget_view_get_drawable_size(rtv, context, &drawable_width, &drawable_height);
|
2011-04-05 19:01:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-14 09:09:14 +01:00
|
|
|
unsigned int ds_level = dsv->sub_resource_idx % depth_stencil->level_count;
|
2018-02-27 07:25:11 +01:00
|
|
|
|
2011-04-11 20:55:13 +02:00
|
|
|
render_offscreen = TRUE;
|
2018-03-14 09:09:14 +01:00
|
|
|
drawable_width = wined3d_texture_get_level_pow2_width(depth_stencil, ds_level);
|
|
|
|
drawable_height = wined3d_texture_get_level_pow2_height(depth_stencil, ds_level);
|
2011-04-05 19:01:30 +02:00
|
|
|
}
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2018-02-08 22:58:45 +01:00
|
|
|
if (depth_stencil)
|
2011-07-31 17:33:41 +02:00
|
|
|
{
|
2018-02-08 22:58:45 +01:00
|
|
|
DWORD ds_location = render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
|
|
|
|
struct wined3d_texture *ds = wined3d_texture_from_resource(dsv->resource);
|
2011-07-31 17:33:41 +02:00
|
|
|
|
2018-02-08 22:58:45 +01:00
|
|
|
if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL)
|
2018-02-26 07:51:51 +01:00
|
|
|
&& !is_full_clear(ds, dsv->sub_resource_idx, draw_rect, rect_count ? clear_rect : NULL))
|
2018-02-08 22:58:45 +01:00
|
|
|
wined3d_texture_load_location(ds, dsv->sub_resource_idx, context, ds_location);
|
|
|
|
else
|
|
|
|
wined3d_texture_prepare_location(ds, dsv->sub_resource_idx, context, ds_location);
|
|
|
|
|
|
|
|
if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL))
|
|
|
|
{
|
|
|
|
wined3d_texture_validate_location(ds, dsv->sub_resource_idx, ds_location);
|
|
|
|
wined3d_texture_invalidate_location(ds, dsv->sub_resource_idx, ~ds_location);
|
|
|
|
}
|
2011-07-31 17:33:41 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:23 +02:00
|
|
|
if (!wined3d_context_gl_apply_clear_state(context_gl, state, rt_count, fb))
|
2011-07-31 17:33:41 +02:00
|
|
|
{
|
|
|
|
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-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)
|
|
|
|
{
|
2016-03-06 20:59:47 +01:00
|
|
|
struct wined3d_rendertarget_view *rtv = fb->render_targets[i];
|
2016-03-30 21:30:19 +02:00
|
|
|
struct wined3d_texture *texture;
|
2011-08-23 20:08:10 +02:00
|
|
|
|
2016-03-30 21:30:19 +02:00
|
|
|
if (!rtv)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (rtv->resource->type == WINED3D_RTYPE_BUFFER)
|
2013-09-10 09:32:34 +02:00
|
|
|
{
|
2016-03-30 21:30:19 +02:00
|
|
|
FIXME("Not supported on buffer resources.\n");
|
|
|
|
continue;
|
2013-09-10 09:32:34 +02:00
|
|
|
}
|
2016-03-30 21:30:19 +02:00
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
texture = texture_from_resource(rtv->resource);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_validate_location(texture, rtv->sub_resource_idx, rtv->resource->draw_binding);
|
|
|
|
wined3d_texture_invalidate_location(texture, rtv->sub_resource_idx, ~rtv->resource->draw_binding);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:03 +02:00
|
|
|
if (!gl_info->supported[ARB_FRAMEBUFFER_SRGB] && needs_srgb_write(context, state, fb))
|
2015-11-27 20:39:36 +01:00
|
|
|
{
|
2016-02-08 00:04:37 +01:00
|
|
|
if (rt_count > 1)
|
|
|
|
WARN("Clearing multiple sRGB render targets with no GL_ARB_framebuffer_sRGB "
|
|
|
|
"support, this might cause graphical issues.\n");
|
|
|
|
|
|
|
|
corrected_color.r = color->r < wined3d_srgb_const1[0]
|
|
|
|
? color->r * wined3d_srgb_const0[3]
|
|
|
|
: pow(color->r, wined3d_srgb_const0[0]) * wined3d_srgb_const0[1]
|
|
|
|
- wined3d_srgb_const0[2];
|
|
|
|
corrected_color.r = min(max(corrected_color.r, 0.0f), 1.0f);
|
|
|
|
corrected_color.g = color->g < wined3d_srgb_const1[0]
|
|
|
|
? color->g * wined3d_srgb_const0[3]
|
|
|
|
: pow(color->g, wined3d_srgb_const0[0]) * wined3d_srgb_const0[1]
|
|
|
|
- wined3d_srgb_const0[2];
|
|
|
|
corrected_color.g = min(max(corrected_color.g, 0.0f), 1.0f);
|
|
|
|
corrected_color.b = color->b < wined3d_srgb_const1[0]
|
|
|
|
? color->b * wined3d_srgb_const0[3]
|
|
|
|
: pow(color->b, wined3d_srgb_const0[0]) * wined3d_srgb_const0[1]
|
|
|
|
- wined3d_srgb_const0[2];
|
|
|
|
corrected_color.b = min(max(corrected_color.b, 0.0f), 1.0f);
|
|
|
|
color = &corrected_color;
|
2015-11-27 20:39:36 +01: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;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:30:02 +01:00
|
|
|
if (!rect_count)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2018-04-23 14:34:03 +02:00
|
|
|
context->scissor_rect_count = WINED3D_MAX_VIEWPORTS;
|
|
|
|
checkGLcall("clear");
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2018-03-22 10:52:43 +01:00
|
|
|
if (flags & WINED3DCLEAR_TARGET && target->swapchain && target->swapchain->front_buffer == target)
|
|
|
|
gl_info->gl_ops.gl.p_glFlush();
|
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
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:06 +01:00
|
|
|
static void device_leftover_sampler(struct wine_rb_entry *entry, void *context)
|
|
|
|
{
|
|
|
|
struct wined3d_sampler *sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);
|
|
|
|
|
|
|
|
ERR("Leftover sampler %p.\n", sampler);
|
|
|
|
}
|
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
void wined3d_device_cleanup(struct wined3d_device *device)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2019-04-18 11:00:20 +02:00
|
|
|
unsigned int i;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
if (device->swapchain_count)
|
|
|
|
wined3d_device_uninit_3d(device);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
wined3d_stateblock_state_cleanup(&device->stateblock_state);
|
2009-01-07 02:20:08 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
wined3d_cs_destroy(device->cs);
|
2019-04-12 14:50:47 +02:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
if (device->recording && wined3d_stateblock_decref(device->recording))
|
|
|
|
ERR("Something's still holding the recording stateblock.\n");
|
|
|
|
device->recording = NULL;
|
2019-01-28 05:44:52 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
state_cleanup(&device->state);
|
2013-09-27 00:15:13 +02:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(device->multistate_funcs); ++i)
|
|
|
|
{
|
|
|
|
heap_free(device->multistate_funcs[i]);
|
|
|
|
device->multistate_funcs[i] = NULL;
|
|
|
|
}
|
2011-12-04 15:50:12 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
if (!list_empty(&device->resources))
|
|
|
|
{
|
|
|
|
struct wined3d_resource *resource;
|
|
|
|
|
|
|
|
ERR("Device released with resources still bound.\n");
|
2011-12-04 15:50:12 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2019-04-18 11:00:20 +02:00
|
|
|
ERR("Leftover resource %p with type %s (%#x).\n",
|
|
|
|
resource, debug_d3dresourcetype(resource->type), resource->type);
|
2009-01-07 02:20:08 +01:00
|
|
|
}
|
2019-04-18 11:00:20 +02:00
|
|
|
}
|
2009-01-07 02:20:08 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
if (device->contexts)
|
|
|
|
ERR("Context array not freed!\n");
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
DestroyCursor(device->hardwareCursor);
|
|
|
|
device->hardwareCursor = 0;
|
2010-04-04 19:51:38 +02:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
wine_rb_destroy(&device->samplers, device_leftover_sampler, NULL);
|
2011-05-16 23:01:22 +02:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
device->wined3d = NULL;
|
|
|
|
}
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&device->ref);
|
2005-09-23 12:07:46 +02:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", device, refcount);
|
2015-01-15 17:19:06 +01:00
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
device->adapter->adapter_ops->adapter_destroy_device(device);
|
|
|
|
TRACE("Destroyed 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;
|
2007-09-01 21:22:32 +02:00
|
|
|
HBITMAP hbm;
|
|
|
|
BITMAP bm;
|
|
|
|
HRESULT hr;
|
|
|
|
HDC dcb = NULL, dcs = NULL;
|
|
|
|
|
2017-03-28 23:37:37 +02:00
|
|
|
if (!(hbm = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION)))
|
2007-09-01 21:22:32 +02:00
|
|
|
{
|
2017-03-28 23:37:37 +02:00
|
|
|
ERR_(winediag)("Failed to load logo %s.\n", wine_dbgstr_a(filename));
|
|
|
|
return;
|
2007-09-01 21:22:32 +02:00
|
|
|
}
|
2017-03-28 23:37:37 +02:00
|
|
|
GetObjectA(hbm, sizeof(BITMAP), &bm);
|
|
|
|
|
|
|
|
if (!(dcb = CreateCompatibleDC(NULL)))
|
|
|
|
goto out;
|
|
|
|
SelectObject(dcb, hbm);
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2013-11-14 10:47:19 +01:00
|
|
|
desc.format = WINED3DFMT_B5G6R5_UNORM;
|
|
|
|
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
|
|
|
|
desc.multisample_quality = 0;
|
2014-01-10 10:43:03 +01:00
|
|
|
desc.usage = WINED3DUSAGE_DYNAMIC;
|
2018-10-31 10:31:47 +01:00
|
|
|
desc.bind_flags = 0;
|
2018-02-02 17:58:54 +01:00
|
|
|
desc.access = WINED3D_RESOURCE_ACCESS_GPU;
|
2013-11-14 10:47:19 +01:00
|
|
|
desc.width = bm.bmWidth;
|
|
|
|
desc.height = bm.bmHeight;
|
|
|
|
desc.depth = 1;
|
|
|
|
desc.size = 0;
|
2018-11-26 19:40:13 +01:00
|
|
|
if (FAILED(hr = wined3d_texture_create(device, &desc, 1, 1, WINED3D_TEXTURE_CREATE_GET_DC,
|
2015-01-05 13:24:58 +01:00
|
|
|
NULL, 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;
|
|
|
|
}
|
|
|
|
|
2017-03-28 23:37:37 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_get_dc(device->logo_texture, 0, &dcs)))
|
2011-04-29 13:03:41 +02:00
|
|
|
{
|
2017-03-28 23:37:37 +02:00
|
|
|
wined3d_texture_decref(device->logo_texture);
|
|
|
|
device->logo_texture = NULL;
|
|
|
|
goto out;
|
2010-08-23 18:28:09 +02:00
|
|
|
}
|
2017-03-28 23:37:37 +02:00
|
|
|
BitBlt(dcs, 0, 0, bm.bmWidth, bm.bmHeight, dcb, 0, 0, SRCCOPY);
|
|
|
|
wined3d_texture_release_dc(device->logo_texture, 0, dcs);
|
2014-08-22 12:32:02 +02:00
|
|
|
|
2017-03-28 23:37:37 +02:00
|
|
|
color_key.color_space_low_value = 0;
|
|
|
|
color_key.color_space_high_value = 0;
|
|
|
|
wined3d_texture_set_color_key(device->logo_texture, WINED3D_CKEY_SRC_BLT, &color_key);
|
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. */
|
2019-06-04 13:01:52 +02:00
|
|
|
static void wined3d_device_gl_create_dummy_textures(struct wined3d_device_gl *device_gl,
|
|
|
|
struct wined3d_context_gl *context_gl)
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2019-06-04 13:01:52 +02:00
|
|
|
struct wined3d_dummy_textures *textures = &device_gl->dummy_textures;
|
|
|
|
const struct wined3d_d3d_info *d3d_info = context_gl->c.d3d_info;
|
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->c.gl_info;
|
2016-10-03 00:38:37 +02:00
|
|
|
unsigned int i;
|
2016-05-23 00:41:51 +02:00
|
|
|
DWORD color;
|
|
|
|
|
|
|
|
if (d3d_info->wined3d_creation_flags & WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR)
|
|
|
|
color = 0x000000ff;
|
|
|
|
else
|
|
|
|
color = 0x00000000;
|
|
|
|
|
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. */
|
2019-06-05 14:24:04 +02:00
|
|
|
wined3d_context_gl_active_texture(context_gl, gl_info, 0);
|
2016-10-03 00:38:37 +02:00
|
|
|
|
2018-04-02 22:58:23 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_1d);
|
|
|
|
TRACE("Dummy 1D texture given name %u.\n", textures->tex_1d);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, textures->tex_1d);
|
|
|
|
gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, 1, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_2d);
|
|
|
|
TRACE("Dummy 2D texture given name %u.\n", textures->tex_2d);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, textures->tex_2d);
|
2016-10-03 00:38:37 +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);
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_rect);
|
|
|
|
TRACE("Dummy rectangle texture given name %u.\n", textures->tex_rect);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures->tex_rect);
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0,
|
2012-07-24 11:32:27 +02:00
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
2016-10-03 00:38:37 +02:00
|
|
|
}
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2016-10-03 00:38:37 +02:00
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_3d);
|
|
|
|
TRACE("Dummy 3D texture given name %u.\n", textures->tex_3d);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, textures->tex_3d);
|
2016-10-03 00:38:37 +02:00
|
|
|
GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0,
|
2016-05-23 00:41:51 +02:00
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
|
2016-10-03 00:38:37 +02:00
|
|
|
}
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2016-10-03 00:38:37 +02:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_cube);
|
|
|
|
TRACE("Dummy cube texture given name %u.\n", textures->tex_cube);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, textures->tex_cube);
|
2016-10-03 00:38:37 +02:00
|
|
|
for (i = GL_TEXTURE_CUBE_MAP_POSITIVE_X; i <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++i)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(i, 0, GL_RGBA8, 1, 1, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
2011-08-26 01:12:27 +02:00
|
|
|
}
|
2016-10-03 00:38:37 +02:00
|
|
|
}
|
2016-04-19 00:01:26 +02:00
|
|
|
|
2017-03-08 12:07:20 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP_ARRAY])
|
|
|
|
{
|
|
|
|
DWORD cube_array_data[6];
|
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_cube_array);
|
|
|
|
TRACE("Dummy cube array texture given name %u.\n", textures->tex_cube_array);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textures->tex_cube_array);
|
2017-03-08 12:07:20 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(cube_array_data); ++i)
|
|
|
|
cube_array_data[i] = color;
|
|
|
|
GL_EXTCALL(glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, GL_RGBA8, 1, 1, 6, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, cube_array_data));
|
|
|
|
}
|
|
|
|
|
2016-10-03 00:38:37 +02:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_ARRAY])
|
|
|
|
{
|
2018-04-02 22:58:23 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_1d_array);
|
|
|
|
TRACE("Dummy 1D array texture given name %u.\n", textures->tex_1d_array);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D_ARRAY, textures->tex_1d_array);
|
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA8, 1, 1, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_2d_array);
|
|
|
|
TRACE("Dummy 2D array texture given name %u.\n", textures->tex_2d_array);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, textures->tex_2d_array);
|
2016-10-03 00:38:37 +02:00
|
|
|
GL_EXTCALL(glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 1, 1, 1, 0,
|
2016-05-23 00:41:51 +02:00
|
|
|
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
|
2008-02-15 15:54:37 +01:00
|
|
|
}
|
2016-10-03 00:38:37 +02:00
|
|
|
|
2017-01-26 13:07:30 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
|
|
|
|
{
|
|
|
|
GLuint buffer;
|
|
|
|
|
|
|
|
GL_EXTCALL(glGenBuffers(1, &buffer));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_TEXTURE_BUFFER, buffer));
|
|
|
|
GL_EXTCALL(glBufferData(GL_TEXTURE_BUFFER, sizeof(color), &color, GL_STATIC_DRAW));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_TEXTURE_BUFFER, 0));
|
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_buffer);
|
|
|
|
TRACE("Dummy buffer texture given name %u.\n", textures->tex_buffer);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, textures->tex_buffer);
|
2017-01-26 13:07:30 +01:00
|
|
|
GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA8, buffer));
|
|
|
|
GL_EXTCALL(glDeleteBuffers(1, &buffer));
|
|
|
|
}
|
|
|
|
|
2018-02-15 13:49:35 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_2d_ms);
|
|
|
|
TRACE("Dummy multisample texture given name %u.\n", textures->tex_2d_ms);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textures->tex_2d_ms);
|
2018-02-15 13:49:35 +01:00
|
|
|
GL_EXTCALL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, GL_TRUE));
|
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &textures->tex_2d_ms_array);
|
|
|
|
TRACE("Dummy multisample array texture given name %u.\n", textures->tex_2d_ms_array);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, textures->tex_2d_ms_array);
|
2018-02-15 13:49:35 +01:00
|
|
|
GL_EXTCALL(glTexImage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, GL_RGBA8, 1, 1, 1, GL_TRUE));
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_CLEAR_TEXTURE])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
GL_EXTCALL(glClearTexImage(textures->tex_2d_ms, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
|
|
|
|
GL_EXTCALL(glClearTexImage(textures->tex_2d_ms_array, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
|
2018-02-15 13:49:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("ARB_clear_texture is currently required to clear dummy multisample textures.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
checkGLcall("create dummy textures");
|
|
|
|
|
2019-06-07 14:52:29 +02:00
|
|
|
wined3d_context_gl_bind_dummy_textures(context_gl);
|
2008-02-15 15:54:37 +01:00
|
|
|
}
|
|
|
|
|
2009-12-17 19:14:34 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2016-10-05 11:17:09 +02:00
|
|
|
static void destroy_dummy_textures(struct wined3d_device *device, struct wined3d_context *context)
|
2009-12-17 19:14:34 +01:00
|
|
|
{
|
2018-10-26 15:13:06 +02:00
|
|
|
struct wined3d_dummy_textures *dummy_textures = &wined3d_device_gl(device)->dummy_textures;
|
2016-10-05 11:17:09 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
2018-02-15 13:49:35 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_2d_ms);
|
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_2d_ms_array);
|
2018-02-15 13:49:35 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 13:07:30 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_buffer);
|
2017-01-26 13:07:30 +01:00
|
|
|
|
2016-04-19 00:01:26 +02:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_ARRAY])
|
2018-04-02 22:58:23 +02:00
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_2d_array);
|
2018-04-02 22:58:23 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_1d_array);
|
|
|
|
}
|
2016-04-19 00:01:26 +02:00
|
|
|
|
2017-03-08 12:07:20 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP_ARRAY])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_cube_array);
|
2017-03-08 12:07:20 +01:00
|
|
|
|
2011-08-26 01:12:27 +02:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_cube);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_3d);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_rect);
|
2016-10-03 00:38:37 +02:00
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_2d);
|
2018-04-02 22:58:23 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &dummy_textures->tex_1d);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
checkGLcall("delete dummy textures");
|
2009-12-17 19:14:34 +01:00
|
|
|
|
2018-02-15 13:49:36 +01:00
|
|
|
memset(dummy_textures, 0, sizeof(*dummy_textures));
|
2009-12-17 19:14:34 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 21:52:30 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2016-10-03 00:38:40 +02:00
|
|
|
static void create_default_samplers(struct wined3d_device *device, struct wined3d_context *context)
|
2016-01-05 21:52:30 +01:00
|
|
|
{
|
2017-03-20 12:13:04 +01:00
|
|
|
struct wined3d_sampler_desc desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
desc.address_u = WINED3D_TADDRESS_WRAP;
|
|
|
|
desc.address_v = WINED3D_TADDRESS_WRAP;
|
|
|
|
desc.address_w = WINED3D_TADDRESS_WRAP;
|
|
|
|
memset(desc.border_color, 0, sizeof(desc.border_color));
|
|
|
|
desc.mag_filter = WINED3D_TEXF_POINT;
|
|
|
|
desc.min_filter = WINED3D_TEXF_POINT;
|
|
|
|
desc.mip_filter = WINED3D_TEXF_NONE;
|
|
|
|
desc.lod_bias = 0.0f;
|
|
|
|
desc.min_lod = -1000.0f;
|
|
|
|
desc.max_lod = 1000.0f;
|
2017-03-20 12:13:08 +01:00
|
|
|
desc.mip_base_level = 0;
|
2017-03-20 12:13:04 +01:00
|
|
|
desc.max_anisotropy = 1;
|
|
|
|
desc.compare = FALSE;
|
|
|
|
desc.comparison_func = WINED3D_CMP_NEVER;
|
|
|
|
desc.srgb_decode = TRUE;
|
|
|
|
|
|
|
|
/* In SM4+ shaders there is a separation between resources and samplers. Some shader
|
|
|
|
* instructions allow access to resources without using samplers.
|
|
|
|
* In GLSL, resources are always accessed through sampler or image variables. The default
|
|
|
|
* sampler object is used to emulate the direct resource access when there is no sampler state
|
|
|
|
* to use.
|
|
|
|
*/
|
2017-04-26 13:19:54 +02:00
|
|
|
if (FAILED(hr = wined3d_sampler_create(device, &desc, NULL, &wined3d_null_parent_ops, &device->default_sampler)))
|
2017-03-20 12:13:04 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to create default sampler, hr %#x.\n", hr);
|
|
|
|
device->default_sampler = NULL;
|
|
|
|
}
|
2016-01-05 21:52:30 +01:00
|
|
|
|
2017-03-20 12:13:05 +01:00
|
|
|
/* In D3D10+, a NULL sampler maps to the default sampler state. */
|
|
|
|
desc.address_u = WINED3D_TADDRESS_CLAMP;
|
|
|
|
desc.address_v = WINED3D_TADDRESS_CLAMP;
|
|
|
|
desc.address_w = WINED3D_TADDRESS_CLAMP;
|
|
|
|
desc.mag_filter = WINED3D_TEXF_LINEAR;
|
|
|
|
desc.min_filter = WINED3D_TEXF_LINEAR;
|
|
|
|
desc.mip_filter = WINED3D_TEXF_LINEAR;
|
2017-04-26 13:19:54 +02:00
|
|
|
if (FAILED(hr = wined3d_sampler_create(device, &desc, NULL, &wined3d_null_parent_ops, &device->null_sampler)))
|
2016-01-05 21:52:30 +01:00
|
|
|
{
|
2017-03-24 03:41:57 +01:00
|
|
|
ERR("Failed to create null sampler, hr %#x.\n", hr);
|
2017-03-20 12:13:05 +01:00
|
|
|
device->null_sampler = NULL;
|
2016-01-05 21:52:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2016-10-05 11:17:08 +02:00
|
|
|
static void destroy_default_samplers(struct wined3d_device *device, struct wined3d_context *context)
|
2016-01-05 21:52:30 +01:00
|
|
|
{
|
2017-03-20 12:13:04 +01:00
|
|
|
wined3d_sampler_decref(device->default_sampler);
|
|
|
|
device->default_sampler = NULL;
|
2017-03-20 12:13:05 +01:00
|
|
|
wined3d_sampler_decref(device->null_sampler);
|
|
|
|
device->null_sampler = NULL;
|
2016-01-05 21:52:30 +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;
|
|
|
|
}
|
|
|
|
|
2016-08-03 09:41:39 +02:00
|
|
|
void CDECL wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window,
|
|
|
|
const RECT *window_rect)
|
2010-11-08 11:50:31 +01:00
|
|
|
{
|
2016-08-03 09:41:39 +02:00
|
|
|
unsigned int window_pos_flags = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE;
|
2010-11-08 11:50:31 +01:00
|
|
|
BOOL filter_messages;
|
|
|
|
LONG style, exstyle;
|
2016-08-03 09:41:39 +02:00
|
|
|
RECT rect = {0};
|
2010-11-08 11:50:31 +01:00
|
|
|
|
2016-08-03 09:41:39 +02:00
|
|
|
if (!device->style && !device->exStyle)
|
|
|
|
return;
|
2010-11-08 11:50:31 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-08-03 09:41:39 +02:00
|
|
|
|
|
|
|
if (window_rect)
|
|
|
|
rect = *window_rect;
|
|
|
|
else
|
|
|
|
window_pos_flags |= (SWP_NOMOVE | SWP_NOSIZE);
|
2016-08-04 17:23:41 +02:00
|
|
|
SetWindowPos(window, 0, rect.left, rect.top,
|
|
|
|
rect.right - rect.left, rect.bottom - rect.top, window_pos_flags);
|
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
|
|
|
{
|
2017-12-06 11:00:38 +01:00
|
|
|
BOOL ds_enable = swapchain->desc.enable_auto_depth_stencil;
|
2013-09-25 09:58:13 +02:00
|
|
|
unsigned int i;
|
2013-09-23 10:26:44 +02:00
|
|
|
|
2018-08-24 15:44:03 +02:00
|
|
|
for (i = 0; i < device->adapter->d3d_info.limits.max_rt_count; ++i)
|
2013-09-25 09:58:13 +02:00
|
|
|
{
|
2018-03-01 19:36:51 +01:00
|
|
|
wined3d_device_set_rendertarget_view(device, i, NULL, FALSE);
|
2013-09-25 09:58:13 +02:00
|
|
|
}
|
2018-03-01 19:36:51 +01:00
|
|
|
if (device->back_buffer_view)
|
|
|
|
wined3d_device_set_rendertarget_view(device, 0, device->back_buffer_view, TRUE);
|
2013-09-23 10:26:44 +02:00
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
wined3d_device_set_depth_stencil_view(device, ds_enable ? device->auto_depth_stencil_view : NULL);
|
2013-09-23 10:26:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 12:30:08 +02:00
|
|
|
void wined3d_device_delete_opengl_contexts_cs(void *object)
|
2017-02-15 14:17:14 +01:00
|
|
|
{
|
|
|
|
struct wined3d_resource *resource, *cursor;
|
2017-02-16 00:58:56 +01:00
|
|
|
struct wined3d_device *device = object;
|
2017-02-15 14:17:14 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
struct wined3d_shader *shader;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Unloading resource %p.\n", resource);
|
|
|
|
wined3d_cs_emit_unload_resource(device->cs, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(shader, &device->shaders, struct wined3d_shader, shader_list_entry)
|
|
|
|
{
|
|
|
|
device->shader_backend->shader_destroy(shader);
|
|
|
|
}
|
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(device, NULL, 0);
|
2017-04-04 09:07:43 +02:00
|
|
|
device->blitter->ops->blitter_destroy(device->blitter, context);
|
2019-03-26 18:29:46 +01:00
|
|
|
device->shader_backend->shader_free_private(device, context);
|
2017-02-15 14:17:14 +01:00
|
|
|
destroy_dummy_textures(device, context);
|
|
|
|
destroy_default_samplers(device, context);
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
while (device->context_count)
|
|
|
|
{
|
|
|
|
if (device->contexts[0]->swapchain)
|
|
|
|
swapchain_destroy_contexts(device->contexts[0]->swapchain);
|
|
|
|
else
|
2019-06-05 14:24:07 +02:00
|
|
|
wined3d_context_gl_destroy(wined3d_context_gl(device->contexts[0]));
|
2017-02-15 14:17:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 12:30:08 +02:00
|
|
|
void wined3d_device_create_primary_opengl_context_cs(void *object)
|
2017-02-15 14:17:14 +01:00
|
|
|
{
|
2017-02-17 14:08:14 +01:00
|
|
|
struct wined3d_device *device = object;
|
2019-06-04 13:01:52 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2017-02-17 14:08:14 +01:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2017-02-15 14:17:14 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
struct wined3d_texture *target;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
|
|
|
|
device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate shader private data, hr %#x.\n", hr);
|
2017-02-17 14:08:14 +01:00
|
|
|
return;
|
2017-02-15 14:17:14 +01:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
if (!(device->blitter = wined3d_cpu_blitter_create()))
|
2017-02-15 14:17:14 +01:00
|
|
|
{
|
2017-04-04 09:07:43 +02:00
|
|
|
ERR("Failed to create CPU blitter.\n");
|
2019-03-26 18:29:46 +01:00
|
|
|
device->shader_backend->shader_free_private(device, NULL);
|
2017-02-17 14:08:14 +01:00
|
|
|
return;
|
2017-02-15 14:17:14 +01:00
|
|
|
}
|
2017-04-04 09:07:43 +02:00
|
|
|
wined3d_ffp_blitter_create(&device->blitter, &device->adapter->gl_info);
|
2018-05-21 20:14:45 +02:00
|
|
|
if (!wined3d_glsl_blitter_create(&device->blitter, device))
|
|
|
|
wined3d_arbfp_blitter_create(&device->blitter, device);
|
2017-04-04 09:07:43 +02:00
|
|
|
wined3d_fbo_blitter_create(&device->blitter, &device->adapter->gl_info);
|
2017-11-15 22:13:00 +01:00
|
|
|
wined3d_raw_blitter_create(&device->blitter, &device->adapter->gl_info);
|
2017-02-15 14:17:14 +01:00
|
|
|
|
2017-02-17 14:08:14 +01:00
|
|
|
swapchain = device->swapchains[0];
|
2017-02-15 14:17:14 +01:00
|
|
|
target = swapchain->back_buffers ? swapchain->back_buffers[0] : swapchain->front_buffer;
|
2017-02-15 14:17:16 +01:00
|
|
|
context = context_acquire(device, target, 0);
|
2019-06-04 13:01:52 +02:00
|
|
|
context_gl = wined3d_context_gl(context);
|
|
|
|
wined3d_device_gl_create_dummy_textures(wined3d_device_gl(device), context_gl);
|
2017-02-15 14:17:14 +01:00
|
|
|
create_default_samplers(device, context);
|
|
|
|
context_release(context);
|
2017-02-17 14:08:14 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
|
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};
|
2019-04-12 14:50:47 +02:00
|
|
|
const struct wined3d_swapchain_desc *swapchain_desc;
|
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
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
TRACE("device %p, swapchain %p.\n", device, swapchain);
|
2009-01-16 10:14:24 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
swapchain_desc = &swapchain->desc;
|
2018-10-31 10:31:48 +01:00
|
|
|
if (swapchain_desc->backbuffer_count && swapchain_desc->backbuffer_bind_flags & WINED3D_BIND_RENDER_TARGET)
|
2014-08-21 09:55:55 +02:00
|
|
|
{
|
2016-06-17 10:41:42 +02:00
|
|
|
struct wined3d_resource *back_buffer = &swapchain->back_buffers[0]->resource;
|
2016-12-05 12:04:41 +01:00
|
|
|
struct wined3d_view_desc view_desc;
|
2016-02-02 19:23:32 +01:00
|
|
|
|
2016-06-17 10:41:42 +02:00
|
|
|
view_desc.format_id = back_buffer->format->id;
|
2016-12-05 12:04:41 +01:00
|
|
|
view_desc.flags = 0;
|
2016-02-02 19:23:32 +01:00
|
|
|
view_desc.u.texture.level_idx = 0;
|
2016-12-05 12:04:41 +01:00
|
|
|
view_desc.u.texture.level_count = 1;
|
2016-02-02 19:23:32 +01:00
|
|
|
view_desc.u.texture.layer_idx = 0;
|
|
|
|
view_desc.u.texture.layer_count = 1;
|
2016-06-17 10:41:42 +02:00
|
|
|
if (FAILED(hr = wined3d_rendertarget_view_create(&view_desc, back_buffer,
|
2016-02-02 19:23:32 +01:00
|
|
|
NULL, &wined3d_null_parent_ops, &device->back_buffer_view)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
|
2019-04-12 14:50:47 +02:00
|
|
|
return hr;
|
2016-02-02 19:23:32 +01:00
|
|
|
}
|
2014-08-21 09:55:55 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchain_count = 1;
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(device->swapchains = heap_calloc(device->swapchain_count, sizeof(*device->swapchains))))
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
2019-04-12 14:50:47 +02:00
|
|
|
ERR("Failed to allocate swapchain array.\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
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;
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
memset(device->fb.render_targets, 0, sizeof(device->fb.render_targets));
|
2019-05-07 12:30:08 +02:00
|
|
|
if (FAILED(hr = device->adapter->adapter_ops->adapter_init_3d(device)))
|
|
|
|
goto err_out;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2019-05-07 12:30:07 +02:00
|
|
|
device_init_swapchain_state(device, swapchain);
|
2019-04-12 14:50:44 +02:00
|
|
|
|
2019-05-07 12:30:07 +02:00
|
|
|
TRACE("All defaults now set up.\n");
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2019-05-07 12:30:07 +02:00
|
|
|
/* Clear the screen. */
|
|
|
|
if (device->back_buffer_view)
|
|
|
|
clear_flags |= WINED3DCLEAR_TARGET;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (wined3d_settings.logo)
|
|
|
|
device_load_logo(device, wined3d_settings.logo);
|
2007-09-01 21:22:32 +02:00
|
|
|
|
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:
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(device->swapchains);
|
2019-04-12 14:50:47 +02:00
|
|
|
device->swapchains = NULL;
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchain_count = 0;
|
2014-08-21 09:55:55 +02:00
|
|
|
if (device->back_buffer_view)
|
2019-04-12 14:50:47 +02:00
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
wined3d_rendertarget_view_decref(device->back_buffer_view);
|
2019-04-12 14:50:47 +02:00
|
|
|
device->back_buffer_view = NULL;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
|
2007-10-09 22:04:18 +02:00
|
|
|
return hr;
|
2006-04-12 21:08:57 +02:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:06 +01:00
|
|
|
static void device_free_sampler(struct wine_rb_entry *entry, void *context)
|
|
|
|
{
|
|
|
|
struct wined3d_sampler *sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);
|
|
|
|
|
2015-01-19 13:44:12 +01:00
|
|
|
wined3d_sampler_decref(sampler);
|
2015-01-15 17:19:06 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
void wined3d_device_uninit_3d(struct wined3d_device *device)
|
2009-09-16 08:37:15 +02:00
|
|
|
{
|
2019-04-12 14:50:45 +02:00
|
|
|
BOOL no3d = device->wined3d->flags & WINED3D_NO3D;
|
2019-04-12 14:50:47 +02:00
|
|
|
struct wined3d_rendertarget_view *view;
|
|
|
|
struct wined3d_texture *texture;
|
2018-02-25 23:23:33 +01:00
|
|
|
unsigned int i;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
2019-04-12 14:50:45 +02:00
|
|
|
if (!device->d3d_initialized && !no3d)
|
2019-04-12 14:50:47 +02:00
|
|
|
{
|
|
|
|
ERR("Called while 3D support was not initialised.\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2018-11-29 14:33:47 +01:00
|
|
|
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
2017-05-02 11:35:30 +02:00
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
device->swapchain_count = 0;
|
|
|
|
|
|
|
|
if ((texture = device->logo_texture))
|
|
|
|
{
|
|
|
|
device->logo_texture = NULL;
|
|
|
|
wined3d_texture_decref(texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((texture = device->cursor_texture))
|
|
|
|
{
|
|
|
|
device->cursor_texture = NULL;
|
|
|
|
wined3d_texture_decref(texture);
|
|
|
|
}
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
state_unbind_resources(&device->state);
|
2019-04-12 14:50:47 +02:00
|
|
|
for (i = 0; i < device->adapter->d3d_info.limits.max_rt_count; ++i)
|
|
|
|
{
|
|
|
|
wined3d_device_set_rendertarget_view(device, i, NULL, FALSE);
|
|
|
|
}
|
2011-12-06 22:57:44 +01:00
|
|
|
|
2015-01-19 13:44:12 +01:00
|
|
|
wine_rb_clear(&device->samplers, device_free_sampler, NULL);
|
2015-01-15 17:19:06 +01:00
|
|
|
|
2019-05-07 12:30:08 +02:00
|
|
|
device->adapter->adapter_ops->adapter_uninit_3d(device);
|
2015-04-24 19:31:38 +02:00
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
if ((view = device->fb.depth_stencil))
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
TRACE("Releasing depth/stencil view %p.\n", view);
|
2010-10-05 14:32:36 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = NULL;
|
2014-08-22 12:32:01 +02:00
|
|
|
wined3d_rendertarget_view_decref(view);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
if ((view = device->auto_depth_stencil_view))
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
device->auto_depth_stencil_view = NULL;
|
|
|
|
if (wined3d_rendertarget_view_decref(view))
|
|
|
|
ERR("Something's still holding the auto depth/stencil view (%p).\n", view);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
if ((view = device->back_buffer_view))
|
2014-08-21 09:55:55 +02:00
|
|
|
{
|
|
|
|
device->back_buffer_view = NULL;
|
2019-04-12 14:50:47 +02:00
|
|
|
wined3d_rendertarget_view_decref(view);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2006-05-24 11:34:30 +02:00
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(device->swapchains);
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchains = NULL;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->d3d_initialized = FALSE;
|
2006-04-12 21:08:57 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-11-21 10:13:21 +01:00
|
|
|
const struct wined3d_driver_info *driver_info;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
2018-11-21 10:13:21 +01:00
|
|
|
driver_info = &device->adapter->driver_info;
|
|
|
|
|
2014-08-18 08:26:20 +02:00
|
|
|
TRACE("Emulating 0x%s bytes. 0x%s used, returning 0x%s left.\n",
|
2018-11-21 10:13:21 +01:00
|
|
|
wine_dbgstr_longlong(driver_info->vram_bytes),
|
2014-08-18 08:26:20 +02:00
|
|
|
wine_dbgstr_longlong(device->adapter->vram_bytes_used),
|
2018-11-21 10:13:21 +01:00
|
|
|
wine_dbgstr_longlong(driver_info->vram_bytes - device->adapter->vram_bytes_used));
|
2007-09-23 00:46:21 +02:00
|
|
|
|
2018-11-21 10:13:21 +01:00
|
|
|
return min(UINT_MAX, driver_info->vram_bytes - device->adapter->vram_bytes_used);
|
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);
|
|
|
|
|
2017-03-23 12:15:48 +01:00
|
|
|
if (idx >= WINED3D_MAX_STREAM_OUTPUT_BUFFERS)
|
2012-11-22 21:13:37 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid stream output %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-24 06:30:52 +01:00
|
|
|
stream = &device->state.stream_output[idx];
|
2013-10-10 23:49:46 +02:00
|
|
|
prev_buffer = stream->buffer;
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
stream->buffer = buffer;
|
|
|
|
stream->offset = offset;
|
2019-01-24 06:30:52 +01:00
|
|
|
wined3d_cs_emit_set_stream_output(device->cs, idx, buffer, offset);
|
2013-10-10 23:49:46 +02:00
|
|
|
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);
|
|
|
|
|
2017-03-23 12:15:48 +01:00
|
|
|
if (idx >= WINED3D_MAX_STREAM_OUTPUT_BUFFERS)
|
2012-11-22 21:13:38 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid stream output %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:41:01 +01:00
|
|
|
if (offset)
|
|
|
|
*offset = device->state.stream_output[idx].offset;
|
2013-08-27 08:44:59 +02:00
|
|
|
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
|
|
|
|
2019-02-20 21:53:56 +01:00
|
|
|
if (stream_idx >= WINED3D_MAX_STREAMS)
|
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;
|
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
|
|
|
}
|
|
|
|
|
2019-02-07 02:38:28 +01:00
|
|
|
stream = &device->state.streams[stream_idx];
|
2011-03-03 21:49:10 +01:00
|
|
|
prev_buffer = stream->buffer;
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2019-02-07 02:38:28 +01:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
if (device->update_stateblock_state->streams[stream_idx].buffer)
|
|
|
|
wined3d_buffer_decref(device->update_stateblock_state->streams[stream_idx].buffer);
|
|
|
|
device->update_stateblock_state->streams[stream_idx].buffer = buffer;
|
|
|
|
device->update_stateblock_state->streams[stream_idx].stride = stride;
|
2019-04-04 18:07:13 +02:00
|
|
|
device->update_stateblock_state->streams[stream_idx].offset = offset;
|
2019-02-07 02:38:28 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-07 02:38:28 +01:00
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.streamSource |= 1u << stream_idx;
|
2019-02-07 02:38:28 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
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;
|
2018-06-12 18:41:15 +02:00
|
|
|
stream->stride = stride;
|
|
|
|
stream->offset = offset;
|
2011-03-03 21:49:10 +01:00
|
|
|
if (buffer)
|
2015-07-28 11:04:46 +02:00
|
|
|
wined3d_buffer_incref(buffer);
|
2019-02-07 02:38:28 +01:00
|
|
|
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
|
|
|
|
2019-02-20 21:53:56 +01:00
|
|
|
if (stream_idx >= WINED3D_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;
|
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
|
|
|
{
|
2019-02-07 02:38:28 +01:00
|
|
|
UINT old_flags, old_freq, flags, freq;
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
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;
|
|
|
|
}
|
|
|
|
|
2019-02-07 02:38:28 +01:00
|
|
|
stream = &device->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
|
|
|
|
2019-02-07 02:38:28 +01:00
|
|
|
flags = divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
|
|
|
|
freq = divider & 0x7fffff;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2019-02-07 02:38:28 +01:00
|
|
|
device->update_stateblock_state->streams[stream_idx].flags = flags;
|
|
|
|
device->update_stateblock_state->streams[stream_idx].frequency = freq;
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-07 02:38:28 +01:00
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.streamFreq |= 1u << stream_idx;
|
2019-02-07 02:38:28 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->flags = flags;
|
|
|
|
stream->frequency = freq;
|
|
|
|
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);
|
2015-03-20 12:41:54 +01:00
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->_11, matrix->_12, matrix->_13, matrix->_14);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->_21, matrix->_22, matrix->_23, matrix->_24);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->_31, matrix->_32, matrix->_33, matrix->_34);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->_41, matrix->_42, matrix->_43, matrix->_44);
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
2019-02-06 06:01:04 +01:00
|
|
|
device->update_stateblock_state->transforms[d3dts] = *matrix;
|
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");
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.transform[d3dts >> 5] |= 1u << (d3dts & 0x1f);
|
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. */
|
2015-03-20 12:41:54 +01:00
|
|
|
if (!memcmp(&device->state.transforms[d3dts], 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
|
|
|
{
|
2019-01-23 02:50:24 +01:00
|
|
|
struct wined3d_matrix *mat;
|
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);
|
|
|
|
|
2019-02-22 01:53:56 +01:00
|
|
|
if (state > WINED3D_HIGHEST_TRANSFORM_STATE)
|
2011-06-11 18:05:02 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2019-01-23 02:50:24 +01:00
|
|
|
/* Tests show that stateblock recording is ignored; the change goes directly
|
|
|
|
* into the primary stateblock. */
|
|
|
|
mat = &device->state.transforms[state];
|
|
|
|
multiply_matrix(mat, mat, matrix);
|
2019-02-02 17:28:40 +01:00
|
|
|
wined3d_cs_emit_set_transform(device->cs, state, mat);
|
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
|
|
|
{
|
2009-10-14 10:55:16 +02:00
|
|
|
struct wined3d_light_info *object = NULL;
|
2019-02-12 17:45:06 +01:00
|
|
|
HRESULT hr;
|
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_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:
|
2015-04-30 23:22:18 +02:00
|
|
|
case WINED3D_LIGHT_PARALLELPOINT:
|
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;
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:45:07 +01:00
|
|
|
if (FAILED(hr = wined3d_light_state_set_light(&device->update_stateblock_state->light_state, light_idx, light, &object)))
|
|
|
|
return hr;
|
|
|
|
if (device->recording)
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
if (FAILED(hr = wined3d_light_state_set_light(&device->state.light_state, light_idx, light, &object)))
|
2019-02-12 17:45:06 +01:00
|
|
|
return hr;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Initialize the object. */
|
2016-03-15 10:52:47 +01:00
|
|
|
TRACE("Light %u setting to type %#x, diffuse %s, specular %s, ambient %s, "
|
|
|
|
"position {%.8e, %.8e, %.8e}, direction {%.8e, %.8e, %.8e}, "
|
|
|
|
"range %.8e, falloff %.8e, theta %.8e, phi %.8e.\n",
|
|
|
|
light_idx, light->type, debug_color(&light->diffuse),
|
|
|
|
debug_color(&light->specular), debug_color(&light->ambient),
|
|
|
|
light->position.x, light->position.y, light->position.z,
|
|
|
|
light->direction.x, light->direction.y, light->direction.z,
|
2011-11-20 20:27:12 +01:00
|
|
|
light->range, light->falloff, light->theta, light->phi);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
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 */
|
2015-04-27 17:39:11 +02:00
|
|
|
object->position.x = light->position.x;
|
|
|
|
object->position.y = light->position.y;
|
|
|
|
object->position.z = light->position.z;
|
|
|
|
object->position.w = 1.0f;
|
2011-05-16 23:01:21 +02:00
|
|
|
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 */
|
2015-04-27 17:39:11 +02:00
|
|
|
object->direction.x = -light->direction.x;
|
|
|
|
object->direction.y = -light->direction.y;
|
|
|
|
object->direction.z = -light->direction.z;
|
|
|
|
object->direction.w = 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 */
|
2015-04-27 17:39:11 +02:00
|
|
|
object->position.x = light->position.x;
|
|
|
|
object->position.y = light->position.y;
|
|
|
|
object->position.z = light->position.z;
|
|
|
|
object->position.w = 1.0f;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
/* Direction */
|
2015-04-27 17:39:11 +02:00
|
|
|
object->direction.x = light->direction.x;
|
|
|
|
object->direction.y = light->direction.y;
|
|
|
|
object->direction.z = light->direction.z;
|
|
|
|
object->direction.w = 0.0f;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2015-04-30 23:22:18 +02:00
|
|
|
case WINED3D_LIGHT_PARALLELPOINT:
|
|
|
|
object->position.x = light->position.x;
|
|
|
|
object->position.y = light->position.y;
|
|
|
|
object->position.z = light->position.z;
|
|
|
|
object->position.w = 1.0f;
|
|
|
|
break;
|
|
|
|
|
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
|
|
|
|
2019-02-12 17:45:07 +01:00
|
|
|
wined3d_cs_emit_set_light(device->cs, object);
|
2017-02-19 18:16:35 +01: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
|
|
|
{
|
2017-02-17 14:08:17 +01:00
|
|
|
struct wined3d_light_info *light_info;
|
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);
|
|
|
|
|
2019-02-12 17:45:05 +01:00
|
|
|
if (!(light_info = wined3d_light_state_get_light(&device->state.light_state, light_idx)))
|
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
|
|
|
{
|
2017-02-17 14:08:17 +01:00
|
|
|
struct wined3d_light_info *light_info;
|
2019-02-12 17:45:07 +01:00
|
|
|
HRESULT hr;
|
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);
|
|
|
|
|
2019-02-12 17:45:07 +01:00
|
|
|
if (!(light_info = wined3d_light_state_get_light(&device->update_stateblock_state->light_state, light_idx)))
|
|
|
|
{
|
|
|
|
if (FAILED(hr = wined3d_light_state_set_light(&device->update_stateblock_state->light_state, light_idx,
|
|
|
|
&WINED3D_default_light, &light_info)))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
wined3d_light_state_enable_light(&device->update_stateblock_state->light_state,
|
|
|
|
&device->adapter->d3d_info, light_info, enable);
|
|
|
|
|
|
|
|
if (device->recording)
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Special case - enabling an undefined light creates one with a strict set of parameters. */
|
2019-02-12 17:45:07 +01:00
|
|
|
if (!(light_info = wined3d_light_state_get_light(&device->state.light_state, light_idx)))
|
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
|
|
|
|
2019-02-12 17:45:07 +01:00
|
|
|
if (!(light_info = wined3d_light_state_get_light(&device->state.light_state, light_idx)))
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:45:07 +01:00
|
|
|
wined3d_light_state_enable_light(&device->state.light_state, &device->adapter->d3d_info, light_info, enable);
|
|
|
|
wined3d_cs_emit_set_light_enable(device->cs, light_idx, enable);
|
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
|
|
|
{
|
2017-02-17 14:08:17 +01:00
|
|
|
struct wined3d_light_info *light_info;
|
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);
|
|
|
|
|
2019-02-12 17:45:05 +01:00
|
|
|
if (!(light_info = wined3d_light_state_get_light(&device->state.light_state, light_idx)))
|
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
|
|
|
|
2018-09-20 09:02:02 +02:00
|
|
|
if (plane_idx >= device->adapter->d3d_info.limits.max_clip_distances)
|
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
|
|
|
}
|
|
|
|
|
2019-02-06 06:01:05 +01:00
|
|
|
device->update_stateblock_state->clip_planes[plane_idx] = *plane;
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-06 06:01:05 +01:00
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.clipplane |= 1u << plane_idx;
|
2019-02-06 06:01:05 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2007-02-28 14:36:36 +01:00
|
|
|
|
2019-02-06 06:01:05 +01:00
|
|
|
if (!memcmp(&device->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;
|
|
|
|
}
|
|
|
|
|
2019-02-06 06:01:05 +01:00
|
|
|
device->state.clip_planes[plane_idx] = *plane;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2019-02-06 06:01:05 +01:00
|
|
|
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
|
|
|
|
2018-09-20 09:02:02 +02:00
|
|
|
if (plane_idx >= device->adapter->d3d_info.limits.max_clip_distances)
|
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
|
|
|
|
2019-02-06 06:01:06 +01:00
|
|
|
device->update_stateblock_state->material = *material;
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-06 06:01:06 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.material = TRUE;
|
2019-02-06 06:01:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->state.material = *material;
|
|
|
|
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
|
|
|
|
2016-03-15 10:52:47 +01:00
|
|
|
TRACE("diffuse %s\n", debug_color(&material->diffuse));
|
|
|
|
TRACE("ambient %s\n", debug_color(&material->ambient));
|
|
|
|
TRACE("specular %s\n", debug_color(&material->specular));
|
|
|
|
TRACE("emissive %s\n", debug_color(&material->emissive));
|
2011-11-20 20:27:13 +01:00
|
|
|
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,
|
2016-06-02 11:14:13 +02:00
|
|
|
struct wined3d_buffer *buffer, enum wined3d_format_id format_id, unsigned int offset)
|
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;
|
2016-06-02 11:14:13 +02:00
|
|
|
unsigned int prev_offset;
|
2011-03-03 21:49:10 +01:00
|
|
|
|
2016-06-02 11:14:13 +02:00
|
|
|
TRACE("device %p, buffer %p, format %s, offset %u.\n",
|
|
|
|
device, buffer, debug_d3dformat(format_id), offset);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2019-02-07 02:38:25 +01:00
|
|
|
prev_buffer = device->state.index_buffer;
|
|
|
|
prev_format = device->state.index_format;
|
|
|
|
prev_offset = device->state.index_offset;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2019-02-07 02:38:25 +01:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
if (device->update_stateblock_state->index_buffer)
|
|
|
|
wined3d_buffer_decref(device->update_stateblock_state->index_buffer);
|
|
|
|
device->update_stateblock_state->index_buffer = buffer;
|
|
|
|
device->update_stateblock_state->index_format = format_id;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-07 02:38:25 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.indices = TRUE;
|
2019-02-07 02:38:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-10-03 08:54:12 +02:00
|
|
|
|
2016-06-02 11:14:13 +02:00
|
|
|
if (prev_buffer == buffer && prev_format == format_id && prev_offset == offset)
|
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);
|
2019-02-07 02:38:25 +01:00
|
|
|
device->state.index_buffer = buffer;
|
|
|
|
device->state.index_format = format_id;
|
|
|
|
device->state.index_offset = offset;
|
|
|
|
wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id, offset);
|
2013-10-03 08:54:12 +02:00
|
|
|
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,
|
2016-06-02 11:14:13 +02:00
|
|
|
enum wined3d_format_id *format, unsigned int *offset)
|
2009-09-25 13:31:46 +02:00
|
|
|
{
|
2016-06-02 11:14:13 +02:00
|
|
|
TRACE("device %p, format %p, offset %p.\n", device, format, offset);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-27 08:44:59 +02:00
|
|
|
*format = device->state.index_format;
|
2016-06-02 11:14:13 +02:00
|
|
|
if (offset)
|
|
|
|
*offset = device->state.index_offset;
|
2013-08-27 08:44:59 +02:00
|
|
|
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
|
|
|
|
2019-02-07 02:38:25 +01:00
|
|
|
device->update_stateblock_state->base_vertex_index = base_index;
|
|
|
|
if (!device->recording)
|
|
|
|
device->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
|
|
|
}
|
|
|
|
|
2018-04-14 11:12:38 +02:00
|
|
|
void CDECL wined3d_device_set_viewports(struct wined3d_device *device, unsigned int viewport_count,
|
|
|
|
const struct wined3d_viewport *viewports)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2018-04-14 11:12:38 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("device %p, viewport_count %u, viewports %p.\n", device, viewport_count, viewports);
|
|
|
|
|
|
|
|
for (i = 0; i < viewport_count; ++i)
|
|
|
|
{
|
|
|
|
TRACE("%u: x %.8e, y %.8e, w %.8e, h %.8e, min_z %.8e, max_z %.8e.\n", i, viewports[i].x, viewports[i].y,
|
|
|
|
viewports[i].width, viewports[i].height, viewports[i].min_z, viewports[i].max_z);
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2018-04-14 11:12:38 +02:00
|
|
|
if (viewport_count)
|
2019-02-06 22:01:49 +01:00
|
|
|
device->update_stateblock_state->viewport = viewports[0];
|
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
|
|
|
}
|
|
|
|
|
2019-02-06 22:01:49 +01:00
|
|
|
if (viewport_count)
|
|
|
|
memcpy(device->state.viewports, viewports, viewport_count * sizeof(*viewports));
|
|
|
|
else
|
|
|
|
memset(device->state.viewports, 0, sizeof(device->state.viewports));
|
|
|
|
device->state.viewport_count = viewport_count;
|
|
|
|
|
2018-04-14 11:12:38 +02:00
|
|
|
wined3d_cs_emit_set_viewports(device->cs, viewport_count, viewports);
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 11:50:45 +02:00
|
|
|
void CDECL wined3d_device_get_viewports(const struct wined3d_device *device, unsigned int *viewport_count,
|
|
|
|
struct wined3d_viewport *viewports)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2018-04-18 11:50:45 +02:00
|
|
|
unsigned int count;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2018-04-18 11:50:45 +02:00
|
|
|
TRACE("device %p, viewport_count %p, viewports %p.\n", device, viewport_count, viewports);
|
|
|
|
|
|
|
|
count = viewport_count ? min(*viewport_count, device->state.viewport_count) : 1;
|
|
|
|
if (count && viewports)
|
|
|
|
memcpy(viewports, device->state.viewports, count * sizeof(*viewports));
|
|
|
|
if (viewport_count)
|
|
|
|
*viewport_count = device->state.viewport_count;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2018-02-12 18:46:19 +01:00
|
|
|
static void resolve_depth_buffer(struct wined3d_device *device)
|
2013-02-18 13:56:23 +01:00
|
|
|
{
|
2018-02-12 18:46:19 +01:00
|
|
|
const struct wined3d_state *state = &device->state;
|
2016-02-15 18:18:04 +01:00
|
|
|
struct wined3d_rendertarget_view *src_view;
|
2018-02-12 18:46:19 +01:00
|
|
|
struct wined3d_resource *dst_resource;
|
|
|
|
struct wined3d_texture *dst_texture;
|
2013-02-18 13:56:23 +01:00
|
|
|
|
2018-02-12 18:46:19 +01:00
|
|
|
if (!(dst_texture = state->textures[0]))
|
2013-02-18 13:56:23 +01:00
|
|
|
return;
|
2018-02-12 18:46:19 +01:00
|
|
|
dst_resource = &dst_texture->resource;
|
|
|
|
if (!(dst_resource->format_flags & WINED3DFMT_FLAG_DEPTH))
|
2016-02-15 18:18:04 +01:00
|
|
|
return;
|
2018-02-12 18:46:19 +01:00
|
|
|
if (!(src_view = state->fb->depth_stencil))
|
2013-02-18 13:56:23 +01:00
|
|
|
return;
|
|
|
|
|
2018-02-12 18:46:19 +01:00
|
|
|
wined3d_device_resolve_sub_resource(device, dst_resource, 0,
|
|
|
|
src_view->resource, src_view->sub_resource_idx, dst_resource->format->id);
|
2013-02-18 13:56:23 +01:00
|
|
|
}
|
|
|
|
|
2018-10-18 00:41:13 +02:00
|
|
|
void CDECL wined3d_device_set_blend_state(struct wined3d_device *device,
|
|
|
|
struct wined3d_blend_state *blend_state, const struct wined3d_color *blend_factor)
|
2018-02-08 15:22:44 +01:00
|
|
|
{
|
2019-02-07 02:38:27 +01:00
|
|
|
struct wined3d_state *state = &device->state;
|
2018-02-08 15:22:44 +01:00
|
|
|
struct wined3d_blend_state *prev;
|
|
|
|
|
2018-10-18 00:41:13 +02:00
|
|
|
TRACE("device %p, blend_state %p, blend_factor %s.\n", device, blend_state, debug_color(blend_factor));
|
2018-02-08 15:22:44 +01:00
|
|
|
|
2019-02-07 02:38:27 +01:00
|
|
|
device->update_stateblock_state->blend_factor = *blend_factor;
|
2018-10-18 00:41:13 +02:00
|
|
|
if (device->recording)
|
2019-02-07 02:38:27 +01:00
|
|
|
{
|
2018-10-18 00:41:13 +02:00
|
|
|
device->recording->changed.blend_state = TRUE;
|
2019-02-07 02:38:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-10-18 00:41:13 +02:00
|
|
|
|
|
|
|
prev = state->blend_state;
|
|
|
|
if (prev == blend_state && !memcmp(blend_factor, &state->blend_factor, sizeof(*blend_factor)))
|
2018-02-08 15:22:44 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (blend_state)
|
|
|
|
wined3d_blend_state_incref(blend_state);
|
2018-10-18 00:41:13 +02:00
|
|
|
state->blend_state = blend_state;
|
|
|
|
state->blend_factor = *blend_factor;
|
2019-02-07 02:38:27 +01:00
|
|
|
wined3d_cs_emit_set_blend_state(device->cs, blend_state, blend_factor);
|
2018-02-08 15:22:44 +01:00
|
|
|
if (prev)
|
|
|
|
wined3d_blend_state_decref(prev);
|
|
|
|
}
|
|
|
|
|
2018-10-18 00:41:13 +02:00
|
|
|
struct wined3d_blend_state * CDECL wined3d_device_get_blend_state(const struct wined3d_device *device,
|
|
|
|
struct wined3d_color *blend_factor)
|
2018-02-08 15:22:44 +01:00
|
|
|
{
|
2018-10-18 00:41:13 +02:00
|
|
|
const struct wined3d_state *state = &device->state;
|
|
|
|
|
|
|
|
TRACE("device %p, blend_factor %p.\n", device, blend_factor);
|
2018-02-08 15:22:44 +01:00
|
|
|
|
2018-10-18 00:41:13 +02:00
|
|
|
*blend_factor = state->blend_factor;
|
|
|
|
return state->blend_state;
|
2018-02-08 15:22:44 +01:00
|
|
|
}
|
|
|
|
|
2016-07-27 23:33:41 +02:00
|
|
|
void CDECL wined3d_device_set_rasterizer_state(struct wined3d_device *device,
|
|
|
|
struct wined3d_rasterizer_state *rasterizer_state)
|
|
|
|
{
|
|
|
|
struct wined3d_rasterizer_state *prev;
|
|
|
|
|
|
|
|
TRACE("device %p, rasterizer_state %p.\n", device, rasterizer_state);
|
|
|
|
|
2019-02-15 07:38:12 +01:00
|
|
|
prev = device->state.rasterizer_state;
|
2016-07-27 23:33:41 +02:00
|
|
|
if (prev == rasterizer_state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rasterizer_state)
|
|
|
|
wined3d_rasterizer_state_incref(rasterizer_state);
|
2019-02-15 07:38:12 +01:00
|
|
|
device->state.rasterizer_state = rasterizer_state;
|
2016-07-27 23:33:41 +02:00
|
|
|
wined3d_cs_emit_set_rasterizer_state(device->cs, rasterizer_state);
|
|
|
|
if (prev)
|
|
|
|
wined3d_rasterizer_state_decref(prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wined3d_rasterizer_state * CDECL wined3d_device_get_rasterizer_state(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
return device->state.rasterizer_state;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2016-01-28 00:17:46 +01:00
|
|
|
if (state > WINEHIGHEST_RENDER_STATE)
|
|
|
|
{
|
|
|
|
WARN("Unhandled render state %#x.\n", state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-29 06:09:15 +01:00
|
|
|
device->update_stateblock_state->rs[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");
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.renderState[state >> 5] |= 1u << (state & 0x1f);
|
2012-09-11 00:27:02 +02:00
|
|
|
return;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 06:09:15 +01:00
|
|
|
if (value == device->state.render_states[state])
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
|
|
|
else
|
2019-01-29 06:09:15 +01:00
|
|
|
{
|
|
|
|
device->state.render_states[state] = value;
|
2013-10-06 17:33:04 +02:00
|
|
|
wined3d_cs_emit_set_render_state(device->cs, state, value);
|
2019-01-29 06:09:15 +01:00
|
|
|
}
|
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");
|
2018-02-12 18:46:19 +01:00
|
|
|
resolve_depth_buffer(device);
|
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
|
|
|
{
|
|
|
|
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)
|
2019-02-20 21:53:58 +01:00
|
|
|
sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
|
2006-12-19 23:17:17 +01:00
|
|
|
|
2017-10-19 10:07:29 +02:00
|
|
|
if (sampler_idx >= ARRAY_SIZE(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
|
|
|
|
2019-02-05 18:08:56 +01:00
|
|
|
device->update_stateblock_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");
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.samplerState[sampler_idx] |= 1u << state;
|
2012-09-18 22:13:57 +02:00
|
|
|
return;
|
2005-08-01 12:58:31 +02:00
|
|
|
}
|
|
|
|
|
2019-02-05 18:08:56 +01:00
|
|
|
if (value == device->state.sampler_states[sampler_idx][state])
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-05 18:08:56 +01:00
|
|
|
device->state.sampler_states[sampler_idx][state] = value;
|
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)
|
2019-02-20 21:53:58 +01:00
|
|
|
sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2017-10-19 10:07:29 +02:00
|
|
|
if (sampler_idx >= ARRAY_SIZE(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
|
|
|
}
|
|
|
|
|
2018-04-23 14:34:03 +02:00
|
|
|
void CDECL wined3d_device_set_scissor_rects(struct wined3d_device *device, unsigned int rect_count,
|
|
|
|
const RECT *rects)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2018-04-23 14:34:03 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("device %p, rect_count %u, rects %p.\n", device, rect_count, rects);
|
|
|
|
|
|
|
|
for (i = 0; i < rect_count; ++i)
|
|
|
|
{
|
|
|
|
TRACE("%u: %s\n", i, wine_dbgstr_rect(&rects[i]));
|
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2019-02-06 22:01:50 +01:00
|
|
|
if (rect_count)
|
|
|
|
device->update_stateblock_state->scissor_rect = rects[0];
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-06 22:01:50 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.scissorRect = TRUE;
|
2019-02-06 22:01:50 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-08-23 10:18:16 +02:00
|
|
|
|
2019-02-06 22:01:50 +01:00
|
|
|
if (device->state.scissor_rect_count == rect_count
|
|
|
|
&& !memcmp(device->state.scissor_rects, rects, rect_count * sizeof(*rects)))
|
2010-09-15 12:00:05 +02:00
|
|
|
{
|
2018-04-23 14:34:03 +02:00
|
|
|
TRACE("App is setting the old scissor rectangles over, nothing to do.\n");
|
2012-09-19 21:50:21 +02:00
|
|
|
return;
|
2007-02-19 15:25:16 +01:00
|
|
|
}
|
2018-04-23 14:34:03 +02:00
|
|
|
|
|
|
|
if (rect_count)
|
2019-02-06 22:01:50 +01:00
|
|
|
memcpy(device->state.scissor_rects, rects, rect_count * sizeof(*rects));
|
2018-04-23 14:34:03 +02:00
|
|
|
else
|
2019-02-06 22:01:50 +01:00
|
|
|
memset(device->state.scissor_rects, 0, sizeof(device->state.scissor_rects));
|
|
|
|
device->state.scissor_rect_count = rect_count;
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2018-04-23 14:34:03 +02:00
|
|
|
wined3d_cs_emit_set_scissor_rects(device->cs, rect_count, rects);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2018-04-26 09:58:39 +02:00
|
|
|
void CDECL wined3d_device_get_scissor_rects(const struct wined3d_device *device, unsigned int *rect_count, RECT *rects)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2018-04-26 09:58:39 +02:00
|
|
|
unsigned int count;
|
|
|
|
|
|
|
|
TRACE("device %p, rect_count %p, rects %p.\n", device, rect_count, rects);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2018-04-26 09:58:39 +02:00
|
|
|
count = rect_count ? min(*rect_count, device->state.scissor_rect_count) : 1;
|
|
|
|
if (count && rects)
|
|
|
|
memcpy(rects, device->state.scissor_rects, count * sizeof(*rects));
|
|
|
|
if (rect_count)
|
|
|
|
*rect_count = device->state.scissor_rect_count;
|
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
|
|
|
{
|
2019-02-07 02:38:26 +01:00
|
|
|
struct wined3d_vertex_declaration *prev = device->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
|
|
|
|
2019-02-07 02:38:26 +01:00
|
|
|
if (declaration)
|
|
|
|
wined3d_vertex_declaration_incref(declaration);
|
|
|
|
if (device->update_stateblock_state->vertex_declaration)
|
|
|
|
wined3d_vertex_declaration_decref(device->update_stateblock_state->vertex_declaration);
|
|
|
|
device->update_stateblock_state->vertex_declaration = declaration;
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-07 02:38:26 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.vertexDecl = TRUE;
|
2019-02-07 02:38:26 +01:00
|
|
|
return;
|
|
|
|
}
|
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);
|
2019-02-07 02:38:26 +01:00
|
|
|
device->state.vertex_declaration = declaration;
|
|
|
|
wined3d_cs_emit_set_vertex_declaration(device->cs, declaration);
|
2013-10-01 10:38:31 +02:00
|
|
|
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
|
|
|
{
|
2019-01-28 05:44:52 +01:00
|
|
|
struct wined3d_shader *prev = device->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);
|
|
|
|
|
2019-01-28 05:44:52 +01:00
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
|
|
|
if (device->update_stateblock_state->vs)
|
|
|
|
wined3d_shader_decref(device->update_stateblock_state->vs);
|
|
|
|
device->update_stateblock_state->vs = shader;
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-01-28 05:44:52 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.vertexShader = TRUE;
|
2019-01-28 05:44:52 +01:00
|
|
|
return;
|
|
|
|
}
|
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);
|
2019-01-28 05:44:52 +01:00
|
|
|
device->state.shader[WINED3D_SHADER_TYPE_VERTEX] = shader;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-29 08:39:54 +02:00
|
|
|
void CDECL wined3d_device_set_constant_buffer(struct wined3d_device *device,
|
2013-10-09 22:57:46 +02:00
|
|
|
enum wined3d_shader_type type, UINT idx, struct wined3d_buffer *buffer)
|
2012-11-29 22:44:45 +01:00
|
|
|
{
|
|
|
|
struct wined3d_buffer *prev;
|
|
|
|
|
2018-05-29 08:39:54 +02:00
|
|
|
TRACE("device %p, type %#x, idx %u, buffer %p.\n", device, type, idx, buffer);
|
|
|
|
|
2012-11-29 22:44:45 +01:00
|
|
|
if (idx >= MAX_CONSTANT_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("Invalid constant buffer index %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-24 06:30:53 +01:00
|
|
|
prev = device->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);
|
2019-01-24 06:30:53 +01:00
|
|
|
device->state.cb[type][idx] = buffer;
|
|
|
|
wined3d_cs_emit_set_constant_buffer(device->cs, type, idx, buffer);
|
2013-10-10 23:49:44 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_buffer_decref(prev);
|
2012-11-29 22:44:45 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 08:39:54 +02:00
|
|
|
struct wined3d_buffer * CDECL wined3d_device_get_constant_buffer(const struct wined3d_device *device,
|
2017-03-07 09:50:20 +01:00
|
|
|
enum wined3d_shader_type shader_type, unsigned int idx)
|
2012-11-29 22:44:46 +01:00
|
|
|
{
|
2018-05-29 08:39:54 +02:00
|
|
|
TRACE("device %p, shader_type %#x, idx %u.\n", device, shader_type, idx);
|
|
|
|
|
2012-11-29 22:44:46 +01:00
|
|
|
if (idx >= MAX_CONSTANT_BUFFERS)
|
|
|
|
{
|
|
|
|
WARN("Invalid constant buffer index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:20 +01:00
|
|
|
return device->state.cb[shader_type][idx];
|
|
|
|
}
|
|
|
|
|
2014-09-16 10:44:16 +02:00
|
|
|
static void wined3d_device_set_shader_resource_view(struct wined3d_device *device,
|
|
|
|
enum wined3d_shader_type type, UINT idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
struct wined3d_shader_resource_view *prev;
|
|
|
|
|
|
|
|
if (idx >= MAX_SHADER_RESOURCE_VIEWS)
|
|
|
|
{
|
|
|
|
WARN("Invalid view index %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-24 06:30:49 +01:00
|
|
|
prev = device->state.shader_resource_view[type][idx];
|
2014-09-16 10:44:16 +02:00
|
|
|
if (view == prev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (view)
|
|
|
|
wined3d_shader_resource_view_incref(view);
|
2019-01-24 06:30:49 +01:00
|
|
|
device->state.shader_resource_view[type][idx] = view;
|
|
|
|
wined3d_cs_emit_set_shader_resource_view(device->cs, type, idx, view);
|
2014-09-16 10:44:16 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_shader_resource_view_decref(prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL wined3d_device_set_vs_resource_view(struct wined3d_device *device,
|
|
|
|
UINT idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, view %p.\n", device, idx, view);
|
|
|
|
|
|
|
|
wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_VERTEX, idx, view);
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:21 +01:00
|
|
|
static struct wined3d_shader_resource_view *wined3d_device_get_shader_resource_view(
|
|
|
|
const struct wined3d_device *device, enum wined3d_shader_type shader_type, unsigned int idx)
|
2014-09-17 10:40:27 +02:00
|
|
|
{
|
|
|
|
if (idx >= MAX_SHADER_RESOURCE_VIEWS)
|
|
|
|
{
|
|
|
|
WARN("Invalid view index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:21 +01:00
|
|
|
return device->state.shader_resource_view[shader_type][idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wined3d_shader_resource_view * CDECL wined3d_device_get_vs_resource_view(const struct wined3d_device *device,
|
|
|
|
UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_shader_resource_view(device, WINED3D_SHADER_TYPE_VERTEX, idx);
|
2014-09-17 10:40:27 +02: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;
|
|
|
|
}
|
|
|
|
|
2019-01-24 06:30:50 +01:00
|
|
|
prev = device->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);
|
2019-01-24 06:30:50 +01:00
|
|
|
device->state.sampler[type][idx] = sampler;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:22 +01:00
|
|
|
static struct wined3d_sampler *wined3d_device_get_sampler(const struct wined3d_device *device,
|
|
|
|
enum wined3d_shader_type shader_type, unsigned int idx)
|
2012-12-05 21:01:48 +01:00
|
|
|
{
|
|
|
|
if (idx >= MAX_SAMPLER_OBJECTS)
|
|
|
|
{
|
|
|
|
WARN("Invalid sampler index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:22 +01:00
|
|
|
return device->state.sampler[shader_type][idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_vs_sampler(const struct wined3d_device *device, UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_sampler(device, WINED3D_SHADER_TYPE_VERTEX, idx);
|
2012-12-05 21:01:48 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_b(struct wined3d_device *device,
|
2016-05-17 19:41:57 +02:00
|
|
|
unsigned int start_idx, unsigned int count, const BOOL *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 19:41:57 +02:00
|
|
|
unsigned int i;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-05-17 19:41:57 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-05-17 19:41:57 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_B)
|
2011-05-16 23:01:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-05-17 19:41:57 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_B - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_B - start_idx;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2019-01-28 05:44:55 +01:00
|
|
|
memcpy(&device->update_stateblock_state->vs_consts_b[start_idx], constants, count * sizeof(*constants));
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2016-05-17 19:41:57 +02:00
|
|
|
for (i = start_idx; i < count + start_idx; ++i)
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.vertexShaderConstantsB |= (1u << i);
|
2019-01-28 05:44:55 +01:00
|
|
|
return WINED3D_OK;
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2019-01-28 05:44:55 +01:00
|
|
|
|
|
|
|
memcpy(&device->state.vs_consts_b[start_idx], constants, count * sizeof(*constants));
|
|
|
|
if (TRACE_ON(d3d))
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2019-01-28 05:44:55 +01:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set BOOL constant %u to %#x.\n", start_idx + i, constants[i]);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2019-01-28 05:44:55 +01:00
|
|
|
wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_VS_B, start_idx, count, constants);
|
|
|
|
|
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,
|
2016-05-17 19:41:58 +02:00
|
|
|
unsigned int start_idx, unsigned int count, BOOL *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 19:41:58 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-05-17 19:41:58 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_B)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-05-17 19:41:58 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_B - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_B - start_idx;
|
|
|
|
memcpy(constants, &device->state.vs_consts_b[start_idx], count * sizeof(*constants));
|
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,
|
2016-05-17 14:01:50 +02:00
|
|
|
unsigned int start_idx, unsigned int count, const struct wined3d_ivec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 14:01:50 +02:00
|
|
|
unsigned int i;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2016-05-17 14:01:50 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-05-17 14:01:50 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_I)
|
2011-05-16 23:01:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-05-17 14:01:50 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_I - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_I - start_idx;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2019-01-28 05:44:54 +01:00
|
|
|
memcpy(&device->update_stateblock_state->vs_consts_i[start_idx], constants, count * sizeof(*constants));
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2016-05-17 14:01:50 +02:00
|
|
|
for (i = start_idx; i < count + start_idx; ++i)
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.vertexShaderConstantsI |= (1u << i);
|
2019-01-28 05:44:54 +01:00
|
|
|
return WINED3D_OK;
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2019-01-28 05:44:54 +01:00
|
|
|
|
|
|
|
memcpy(&device->state.vs_consts_i[start_idx], constants, count * sizeof(*constants));
|
|
|
|
if (TRACE_ON(d3d))
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2019-01-28 05:44:54 +01:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set ivec4 constant %u to %s.\n", start_idx + i, debug_ivec4(&constants[i]));
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2019-01-28 05:44:54 +01:00
|
|
|
wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_VS_I, start_idx, count, constants);
|
|
|
|
|
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,
|
2016-05-17 14:01:51 +02:00
|
|
|
unsigned int start_idx, unsigned int count, struct wined3d_ivec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 14:01:51 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-05-17 14:01:51 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_I)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-05-17 14:01:51 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_I - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_I - start_idx;
|
|
|
|
memcpy(constants, &device->state.vs_consts_i[start_idx], count * sizeof(*constants));
|
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,
|
2016-04-26 17:55:58 +02:00
|
|
|
unsigned int start_idx, unsigned int count, const struct wined3d_vec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2016-04-26 17:55:58 +02:00
|
|
|
unsigned int i;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-04-26 17:55:58 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-04-26 17:55:58 +02:00
|
|
|
if (!constants || start_idx >= d3d_info->limits.vs_uniform_count
|
|
|
|
|| count > d3d_info->limits.vs_uniform_count - start_idx)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2019-01-28 05:44:53 +01:00
|
|
|
memcpy(&device->update_stateblock_state->vs_consts_f[start_idx], constants, count * sizeof(*constants));
|
|
|
|
if (device->recording)
|
|
|
|
{
|
|
|
|
memset(&device->recording->changed.vs_consts_f[start_idx], 1,
|
|
|
|
count * sizeof(*device->recording->changed.vs_consts_f));
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&device->state.vs_consts_f[start_idx], constants, count * sizeof(*constants));
|
2011-05-16 23:01:21 +02:00
|
|
|
if (TRACE_ON(d3d))
|
|
|
|
{
|
2016-04-26 17:55:58 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set vec4 constant %u to %s.\n", start_idx + i, debug_vec4(&constants[i]));
|
2007-02-20 22:43:53 +01:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2019-01-28 05:44:53 +01:00
|
|
|
wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_VS_F, start_idx, count, constants);
|
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,
|
2016-04-26 17:55:59 +02:00
|
|
|
unsigned int start_idx, unsigned int count, struct wined3d_vec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2016-04-26 17:55:59 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2016-04-26 17:55:59 +02:00
|
|
|
if (!constants || start_idx >= d3d_info->limits.vs_uniform_count
|
|
|
|
|| count > d3d_info->limits.vs_uniform_count - start_idx)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-04-26 17:55:59 +02:00
|
|
|
memcpy(constants, &device->state.vs_consts_f[start_idx], count * sizeof(*constants));
|
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
|
|
|
{
|
2019-01-28 05:44:56 +01:00
|
|
|
struct wined3d_shader *prev = device->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);
|
|
|
|
|
2019-01-28 05:44:56 +01:00
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
|
|
|
if (device->update_stateblock_state->ps)
|
|
|
|
wined3d_shader_decref(device->update_stateblock_state->ps);
|
|
|
|
device->update_stateblock_state->ps = shader;
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-01-28 05:44:56 +01:00
|
|
|
{
|
2013-08-26 09:23:37 +02:00
|
|
|
device->recording->changed.pixelShader = TRUE;
|
2019-01-28 05:44:56 +01:00
|
|
|
return;
|
|
|
|
}
|
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);
|
2019-01-28 05:44:56 +01:00
|
|
|
device->state.shader[WINED3D_SHADER_TYPE_PIXEL] = shader;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-17 10:40:30 +02:00
|
|
|
void CDECL wined3d_device_set_ps_resource_view(struct wined3d_device *device,
|
|
|
|
UINT idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, view %p.\n", device, idx, view);
|
|
|
|
|
|
|
|
wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_PIXEL, idx, view);
|
|
|
|
}
|
|
|
|
|
2014-09-17 10:40:31 +02:00
|
|
|
struct wined3d_shader_resource_view * CDECL wined3d_device_get_ps_resource_view(const struct wined3d_device *device,
|
|
|
|
UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
2017-03-07 09:50:21 +01:00
|
|
|
return wined3d_device_get_shader_resource_view(device, WINED3D_SHADER_TYPE_PIXEL, idx);
|
2014-09-17 10:40:31 +02: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);
|
|
|
|
|
2017-03-07 09:50:22 +01:00
|
|
|
return wined3d_device_get_sampler(device, 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,
|
2016-05-17 19:41:59 +02:00
|
|
|
unsigned int start_idx, unsigned int count, const BOOL *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 19:41:59 +02:00
|
|
|
unsigned int i;
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2016-05-17 19:41:59 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2016-05-17 19:41:59 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_B)
|
2011-05-16 23:01:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2016-05-17 19:41:59 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_B - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_B - start_idx;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2019-01-29 06:09:13 +01:00
|
|
|
memcpy(&device->update_stateblock_state->ps_consts_b[start_idx], constants, count * sizeof(*constants));
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2016-05-17 19:41:59 +02:00
|
|
|
for (i = start_idx; i < count + start_idx; ++i)
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.pixelShaderConstantsB |= (1u << i);
|
2019-01-29 06:09:13 +01:00
|
|
|
return WINED3D_OK;
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2019-01-29 06:09:13 +01:00
|
|
|
|
|
|
|
memcpy(&device->state.ps_consts_b[start_idx], constants, count * sizeof(*constants));
|
|
|
|
if (TRACE_ON(d3d))
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2019-01-29 06:09:13 +01:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set BOOL constant %u to %#x.\n", start_idx + i, constants[i]);
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2019-01-29 06:09:13 +01:00
|
|
|
wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_PS_B, start_idx, count, constants);
|
|
|
|
|
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,
|
2016-05-17 19:42:00 +02:00
|
|
|
unsigned int start_idx, unsigned int count, BOOL *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 19:42:00 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u,constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2016-05-17 19:42:00 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_B)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2016-05-17 19:42:00 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_B - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_B - start_idx;
|
|
|
|
memcpy(constants, &device->state.ps_consts_b[start_idx], count * sizeof(*constants));
|
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,
|
2016-05-17 14:01:52 +02:00
|
|
|
unsigned int start_idx, unsigned int count, const struct wined3d_ivec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 14:01:52 +02:00
|
|
|
unsigned int i;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2016-05-17 14:01:52 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2016-05-17 14:01:52 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_I)
|
2011-05-16 23:01:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-05-17 14:01:52 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_I - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_I - start_idx;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2019-01-29 06:09:12 +01:00
|
|
|
memcpy(&device->update_stateblock_state->ps_consts_i[start_idx], constants, count * sizeof(*constants));
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2016-05-17 14:01:52 +02:00
|
|
|
for (i = start_idx; i < count + start_idx; ++i)
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.pixelShaderConstantsI |= (1u << i);
|
2019-01-29 06:09:12 +01:00
|
|
|
return WINED3D_OK;
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2019-01-29 06:09:12 +01:00
|
|
|
|
|
|
|
memcpy(&device->state.ps_consts_i[start_idx], constants, count * sizeof(*constants));
|
|
|
|
if (TRACE_ON(d3d))
|
2013-08-23 10:18:16 +02:00
|
|
|
{
|
2019-01-29 06:09:12 +01:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set ivec4 constant %u to %s.\n", start_idx + i, debug_ivec4(&constants[i]));
|
2013-08-23 10:18:16 +02:00
|
|
|
}
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2019-01-29 06:09:12 +01:00
|
|
|
wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_PS_I, start_idx, count, constants);
|
|
|
|
|
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,
|
2016-05-17 14:01:53 +02:00
|
|
|
unsigned int start_idx, unsigned int count, struct wined3d_ivec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2016-05-17 14:01:53 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-05-17 14:01:53 +02:00
|
|
|
if (!constants || start_idx >= WINED3D_MAX_CONSTS_I)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-05-17 14:01:53 +02:00
|
|
|
if (count > WINED3D_MAX_CONSTS_I - start_idx)
|
|
|
|
count = WINED3D_MAX_CONSTS_I - start_idx;
|
|
|
|
memcpy(constants, &device->state.ps_consts_i[start_idx], count * sizeof(*constants));
|
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,
|
2016-04-26 17:56:00 +02:00
|
|
|
unsigned int start_idx, unsigned int count, const struct wined3d_vec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2016-04-26 17:56:00 +02:00
|
|
|
unsigned int i;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-04-26 17:56:00 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2016-04-26 17:56:00 +02:00
|
|
|
if (!constants || start_idx >= d3d_info->limits.ps_uniform_count
|
|
|
|
|| count > d3d_info->limits.ps_uniform_count - start_idx)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2019-01-29 06:09:11 +01:00
|
|
|
memcpy(&device->update_stateblock_state->ps_consts_f[start_idx], constants, count * sizeof(*constants));
|
|
|
|
if (device->recording)
|
|
|
|
{
|
|
|
|
memset(&device->recording->changed.ps_consts_f[start_idx], 1,
|
|
|
|
count * sizeof(*device->recording->changed.ps_consts_f));
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&device->state.ps_consts_f[start_idx], constants, count * sizeof(*constants));
|
2011-05-16 23:01:21 +02:00
|
|
|
if (TRACE_ON(d3d))
|
|
|
|
{
|
2016-04-26 17:56:00 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set vec4 constant %u to %s.\n", start_idx + i, debug_vec4(&constants[i]));
|
2007-02-20 22:43:53 +01:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2019-01-29 06:09:11 +01:00
|
|
|
wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_PS_F, start_idx, count, constants);
|
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,
|
2016-04-26 17:56:01 +02:00
|
|
|
unsigned int start_idx, unsigned int count, struct wined3d_vec4 *constants)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2013-04-25 15:20:27 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2016-04-26 17:56:01 +02:00
|
|
|
TRACE("device %p, start_idx %u, count %u, constants %p.\n",
|
|
|
|
device, start_idx, count, constants);
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2016-04-26 17:56:01 +02:00
|
|
|
if (!constants || start_idx >= d3d_info->limits.ps_uniform_count
|
|
|
|
|| count > d3d_info->limits.ps_uniform_count - start_idx)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-04-26 17:56:01 +02:00
|
|
|
memcpy(constants, &device->state.ps_consts_f[start_idx], count * sizeof(*constants));
|
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
|
|
|
}
|
|
|
|
|
2017-04-20 11:04:13 +02:00
|
|
|
void CDECL wined3d_device_set_hull_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
|
|
|
{
|
|
|
|
struct wined3d_shader *prev;
|
|
|
|
|
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2019-02-15 07:38:12 +01:00
|
|
|
prev = device->state.shader[WINED3D_SHADER_TYPE_HULL];
|
2017-04-20 11:04:13 +02:00
|
|
|
if (shader == prev)
|
|
|
|
return;
|
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2019-02-15 07:38:12 +01:00
|
|
|
device->state.shader[WINED3D_SHADER_TYPE_HULL] = shader;
|
2017-04-20 11:04:13 +02:00
|
|
|
wined3d_cs_emit_set_shader(device->cs, WINED3D_SHADER_TYPE_HULL, shader);
|
|
|
|
if (prev)
|
|
|
|
wined3d_shader_decref(prev);
|
|
|
|
}
|
|
|
|
|
2017-04-20 11:04:17 +02:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_hull_shader(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
return device->state.shader[WINED3D_SHADER_TYPE_HULL];
|
|
|
|
}
|
|
|
|
|
2017-04-25 12:25:45 +02:00
|
|
|
void CDECL wined3d_device_set_hs_resource_view(struct wined3d_device *device,
|
|
|
|
unsigned int idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, view %p.\n", device, idx, view);
|
|
|
|
|
|
|
|
wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_HULL, idx, view);
|
|
|
|
}
|
|
|
|
|
2017-05-05 09:06:26 +02:00
|
|
|
struct wined3d_shader_resource_view * CDECL wined3d_device_get_hs_resource_view(const struct wined3d_device *device,
|
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_shader_resource_view(device, WINED3D_SHADER_TYPE_HULL, idx);
|
|
|
|
}
|
|
|
|
|
2017-04-26 13:19:50 +02:00
|
|
|
void CDECL wined3d_device_set_hs_sampler(struct wined3d_device *device,
|
|
|
|
unsigned int idx, struct wined3d_sampler *sampler)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
|
|
|
|
|
|
|
|
wined3d_device_set_sampler(device, WINED3D_SHADER_TYPE_HULL, idx, sampler);
|
|
|
|
}
|
|
|
|
|
2017-05-05 09:06:30 +02:00
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_hs_sampler(const struct wined3d_device *device, unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_sampler(device, WINED3D_SHADER_TYPE_HULL, idx);
|
|
|
|
}
|
|
|
|
|
2017-04-20 11:04:15 +02:00
|
|
|
void CDECL wined3d_device_set_domain_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
|
|
|
{
|
|
|
|
struct wined3d_shader *prev;
|
|
|
|
|
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2019-02-15 07:38:12 +01:00
|
|
|
prev = device->state.shader[WINED3D_SHADER_TYPE_DOMAIN];
|
2017-04-20 11:04:15 +02:00
|
|
|
if (shader == prev)
|
|
|
|
return;
|
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2019-02-15 07:38:12 +01:00
|
|
|
device->state.shader[WINED3D_SHADER_TYPE_DOMAIN] = shader;
|
2017-04-20 11:04:15 +02:00
|
|
|
wined3d_cs_emit_set_shader(device->cs, WINED3D_SHADER_TYPE_DOMAIN, shader);
|
|
|
|
if (prev)
|
|
|
|
wined3d_shader_decref(prev);
|
|
|
|
}
|
|
|
|
|
2017-04-20 11:04:19 +02:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_domain_shader(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
return device->state.shader[WINED3D_SHADER_TYPE_DOMAIN];
|
|
|
|
}
|
|
|
|
|
2017-04-25 12:25:47 +02:00
|
|
|
void CDECL wined3d_device_set_ds_resource_view(struct wined3d_device *device,
|
|
|
|
unsigned int idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, view %p.\n", device, idx, view);
|
|
|
|
|
|
|
|
wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_DOMAIN, idx, view);
|
|
|
|
}
|
|
|
|
|
2017-05-05 09:06:28 +02:00
|
|
|
struct wined3d_shader_resource_view * CDECL wined3d_device_get_ds_resource_view(const struct wined3d_device *device,
|
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_shader_resource_view(device, WINED3D_SHADER_TYPE_DOMAIN, idx);
|
|
|
|
}
|
|
|
|
|
2017-04-26 13:19:52 +02:00
|
|
|
void CDECL wined3d_device_set_ds_sampler(struct wined3d_device *device,
|
|
|
|
unsigned int idx, struct wined3d_sampler *sampler)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
|
|
|
|
|
|
|
|
wined3d_device_set_sampler(device, WINED3D_SHADER_TYPE_DOMAIN, idx, sampler);
|
|
|
|
}
|
|
|
|
|
2017-05-08 09:47:59 +02:00
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_ds_sampler(const struct wined3d_device *device, unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_sampler(device, WINED3D_SHADER_TYPE_DOMAIN, idx);
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:24:22 +01:00
|
|
|
void CDECL wined3d_device_set_geometry_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
|
|
|
{
|
2019-01-25 06:06:07 +01:00
|
|
|
struct wined3d_shader *prev = device->state.shader[WINED3D_SHADER_TYPE_GEOMETRY];
|
2012-11-13 21:24:22 +01:00
|
|
|
|
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2019-01-25 06:06:07 +01:00
|
|
|
if (shader == prev)
|
2013-10-03 23:31:45 +02:00
|
|
|
return;
|
2012-11-13 21:24:22 +01:00
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2019-01-25 06:06:07 +01:00
|
|
|
device->state.shader[WINED3D_SHADER_TYPE_GEOMETRY] = shader;
|
2013-10-09 22:57:45 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-17 10:40:28 +02:00
|
|
|
void CDECL wined3d_device_set_gs_resource_view(struct wined3d_device *device,
|
|
|
|
UINT idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, view %p.\n", device, idx, view);
|
|
|
|
|
|
|
|
wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_GEOMETRY, idx, view);
|
|
|
|
}
|
|
|
|
|
2014-09-17 10:40:29 +02:00
|
|
|
struct wined3d_shader_resource_view * CDECL wined3d_device_get_gs_resource_view(const struct wined3d_device *device,
|
|
|
|
UINT idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
2017-03-07 09:50:21 +01:00
|
|
|
return wined3d_device_get_shader_resource_view(device, WINED3D_SHADER_TYPE_GEOMETRY, idx);
|
2014-09-17 10:40:29 +02: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);
|
|
|
|
|
2017-03-07 09:50:22 +01:00
|
|
|
return wined3d_device_get_sampler(device, WINED3D_SHADER_TYPE_GEOMETRY, idx);
|
2012-12-07 00:07:08 +01:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:17:58 +01:00
|
|
|
void CDECL wined3d_device_set_compute_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
|
|
|
{
|
|
|
|
struct wined3d_shader *prev;
|
|
|
|
|
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2019-01-25 06:06:08 +01:00
|
|
|
prev = device->state.shader[WINED3D_SHADER_TYPE_COMPUTE];
|
|
|
|
if (shader == prev)
|
2017-01-25 11:17:58 +01:00
|
|
|
return;
|
|
|
|
if (shader)
|
|
|
|
wined3d_shader_incref(shader);
|
2019-01-25 06:06:08 +01:00
|
|
|
device->state.shader[WINED3D_SHADER_TYPE_COMPUTE] = shader;
|
2017-01-25 11:17:58 +01:00
|
|
|
wined3d_cs_emit_set_shader(device->cs, WINED3D_SHADER_TYPE_COMPUTE, shader);
|
|
|
|
if (prev)
|
|
|
|
wined3d_shader_decref(prev);
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:12 +01:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_compute_shader(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
return device->state.shader[WINED3D_SHADER_TYPE_COMPUTE];
|
|
|
|
}
|
|
|
|
|
2017-02-22 13:19:30 +01:00
|
|
|
void CDECL wined3d_device_set_cs_resource_view(struct wined3d_device *device,
|
|
|
|
unsigned int idx, struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, view %p.\n", device, idx, view);
|
|
|
|
|
|
|
|
wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_COMPUTE, idx, view);
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:16 +01:00
|
|
|
struct wined3d_shader_resource_view * CDECL wined3d_device_get_cs_resource_view(const struct wined3d_device *device,
|
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
2017-03-07 09:50:21 +01:00
|
|
|
return wined3d_device_get_shader_resource_view(device, WINED3D_SHADER_TYPE_COMPUTE, idx);
|
2017-03-07 09:50:16 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 13:19:32 +01:00
|
|
|
void CDECL wined3d_device_set_cs_sampler(struct wined3d_device *device,
|
|
|
|
unsigned int idx, struct wined3d_sampler *sampler)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
|
|
|
|
|
|
|
|
wined3d_device_set_sampler(device, WINED3D_SHADER_TYPE_COMPUTE, idx, sampler);
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:50:18 +01:00
|
|
|
struct wined3d_sampler * CDECL wined3d_device_get_cs_sampler(const struct wined3d_device *device, unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
2017-03-07 09:50:22 +01:00
|
|
|
return wined3d_device_get_sampler(device, WINED3D_SHADER_TYPE_COMPUTE, idx);
|
2017-03-07 09:50:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:00:36 +01:00
|
|
|
static void wined3d_device_set_pipeline_unordered_access_view(struct wined3d_device *device,
|
2017-08-04 19:53:50 +02:00
|
|
|
enum wined3d_pipeline pipeline, unsigned int idx, struct wined3d_unordered_access_view *uav,
|
|
|
|
unsigned int initial_count)
|
2017-02-09 12:00:29 +01:00
|
|
|
{
|
|
|
|
struct wined3d_unordered_access_view *prev;
|
|
|
|
|
|
|
|
if (idx >= MAX_UNORDERED_ACCESS_VIEWS)
|
|
|
|
{
|
|
|
|
WARN("Invalid UAV index %u.\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-24 06:30:51 +01:00
|
|
|
prev = device->state.unordered_access_view[pipeline][idx];
|
2017-08-04 19:53:50 +02:00
|
|
|
if (uav == prev && initial_count == ~0u)
|
2017-02-09 12:00:29 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (uav)
|
|
|
|
wined3d_unordered_access_view_incref(uav);
|
2019-01-24 06:30:51 +01:00
|
|
|
device->state.unordered_access_view[pipeline][idx] = uav;
|
|
|
|
wined3d_cs_emit_set_unordered_access_view(device->cs, pipeline, idx, uav, initial_count);
|
2017-02-09 12:00:29 +01:00
|
|
|
if (prev)
|
|
|
|
wined3d_unordered_access_view_decref(prev);
|
|
|
|
}
|
|
|
|
|
2017-04-24 12:02:30 +02:00
|
|
|
static struct wined3d_unordered_access_view *wined3d_device_get_pipeline_unordered_access_view(
|
|
|
|
const struct wined3d_device *device, enum wined3d_pipeline pipeline, unsigned int idx)
|
|
|
|
{
|
|
|
|
if (idx >= MAX_UNORDERED_ACCESS_VIEWS)
|
|
|
|
{
|
|
|
|
WARN("Invalid UAV index %u.\n", idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device->state.unordered_access_view[pipeline][idx];
|
|
|
|
}
|
|
|
|
|
2017-02-09 12:00:36 +01:00
|
|
|
void CDECL wined3d_device_set_cs_uav(struct wined3d_device *device, unsigned int idx,
|
2017-08-04 19:53:50 +02:00
|
|
|
struct wined3d_unordered_access_view *uav, unsigned int initial_count)
|
2016-11-23 14:36:05 +01:00
|
|
|
{
|
2017-08-04 19:53:50 +02:00
|
|
|
TRACE("device %p, idx %u, uav %p, initial_count %#x.\n", device, idx, uav, initial_count);
|
2016-11-23 14:36:05 +01:00
|
|
|
|
2017-08-04 19:53:50 +02:00
|
|
|
wined3d_device_set_pipeline_unordered_access_view(device, WINED3D_PIPELINE_COMPUTE, idx, uav, initial_count);
|
2017-02-09 12:00:36 +01:00
|
|
|
}
|
2016-11-23 14:36:05 +01:00
|
|
|
|
2017-04-24 12:02:30 +02:00
|
|
|
struct wined3d_unordered_access_view * CDECL wined3d_device_get_cs_uav(const struct wined3d_device *device,
|
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_pipeline_unordered_access_view(device, WINED3D_PIPELINE_COMPUTE, idx);
|
|
|
|
}
|
|
|
|
|
2017-02-09 12:00:36 +01:00
|
|
|
void CDECL wined3d_device_set_unordered_access_view(struct wined3d_device *device,
|
2017-08-04 19:53:50 +02:00
|
|
|
unsigned int idx, struct wined3d_unordered_access_view *uav, unsigned int initial_count)
|
2017-02-09 12:00:36 +01:00
|
|
|
{
|
2017-08-04 19:53:50 +02:00
|
|
|
TRACE("device %p, idx %u, uav %p, initial_count %#x.\n", device, idx, uav, initial_count);
|
2016-11-23 14:36:05 +01:00
|
|
|
|
2017-08-04 19:53:50 +02:00
|
|
|
wined3d_device_set_pipeline_unordered_access_view(device, WINED3D_PIPELINE_GRAPHICS, idx, uav, initial_count);
|
2016-11-23 14:36:05 +01:00
|
|
|
}
|
|
|
|
|
2017-04-24 12:02:32 +02:00
|
|
|
struct wined3d_unordered_access_view * CDECL wined3d_device_get_unordered_access_view(
|
|
|
|
const struct wined3d_device *device, unsigned int idx)
|
|
|
|
{
|
|
|
|
TRACE("device %p, idx %u.\n", device, idx);
|
|
|
|
|
|
|
|
return wined3d_device_get_pipeline_unordered_access_view(device, WINED3D_PIPELINE_GRAPHICS, idx);
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:15:01 +02:00
|
|
|
void CDECL wined3d_device_set_max_frame_latency(struct wined3d_device *device, unsigned int latency)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!latency)
|
|
|
|
latency = 3;
|
|
|
|
|
|
|
|
device->max_frame_latency = latency;
|
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
|
|
|
swapchain_set_max_frame_latency(device->swapchains[i], device);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CDECL wined3d_device_get_max_frame_latency(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
return device->max_frame_latency;
|
|
|
|
}
|
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
static unsigned int wined3d_get_flexible_vertex_size(DWORD fvf)
|
2018-09-17 11:06:27 +02:00
|
|
|
{
|
2018-09-17 11:06:28 +02:00
|
|
|
unsigned int texcoord_count = (fvf & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
|
|
|
|
unsigned int i, size = 0;
|
2018-09-17 11:06:27 +02:00
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if (fvf & WINED3DFVF_NORMAL) size += 3 * sizeof(float);
|
|
|
|
if (fvf & WINED3DFVF_DIFFUSE) size += sizeof(DWORD);
|
|
|
|
if (fvf & WINED3DFVF_SPECULAR) size += sizeof(DWORD);
|
|
|
|
if (fvf & WINED3DFVF_PSIZE) size += sizeof(DWORD);
|
|
|
|
switch (fvf & WINED3DFVF_POSITION_MASK)
|
2018-09-17 11:06:27 +02:00
|
|
|
{
|
|
|
|
case WINED3DFVF_XYZ: size += 3 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZRHW: size += 4 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZB1: size += 4 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZB2: size += 5 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZB3: size += 6 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZB4: size += 7 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZB5: size += 8 * sizeof(float); break;
|
|
|
|
case WINED3DFVF_XYZW: size += 4 * sizeof(float); break;
|
2018-09-17 11:06:28 +02:00
|
|
|
default: FIXME("Unexpected position mask %#x.\n", fvf & WINED3DFVF_POSITION_MASK);
|
2018-09-17 11:06:27 +02:00
|
|
|
}
|
2018-09-17 11:06:28 +02:00
|
|
|
for (i = 0; i < texcoord_count; ++i)
|
2018-09-17 11:06:27 +02:00
|
|
|
{
|
2018-09-17 11:06:28 +02:00
|
|
|
size += GET_TEXCOORD_SIZE_FROM_FVF(fvf, i) * sizeof(float);
|
2018-09-17 11:06:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
static void wined3d_format_get_colour(const struct wined3d_format *format,
|
|
|
|
const void *data, struct wined3d_color *colour)
|
|
|
|
{
|
|
|
|
float *output = &colour->r;
|
|
|
|
const uint32_t *u32_data;
|
|
|
|
const uint16_t *u16_data;
|
|
|
|
const float *f32_data;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
static const struct wined3d_color default_colour = {0.0f, 0.0f, 0.0f, 1.0f};
|
|
|
|
static unsigned int warned;
|
|
|
|
|
|
|
|
switch (format->id)
|
|
|
|
{
|
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
|
|
|
u32_data = data;
|
|
|
|
wined3d_color_from_d3dcolor(colour, *u32_data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_R8G8B8A8_UNORM:
|
|
|
|
u32_data = data;
|
|
|
|
colour->r = (*u32_data & 0xffu) / 255.0f;
|
|
|
|
colour->g = ((*u32_data >> 8) & 0xffu) / 255.0f;
|
|
|
|
colour->b = ((*u32_data >> 16) & 0xffu) / 255.0f;
|
|
|
|
colour->a = ((*u32_data >> 24) & 0xffu) / 255.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_R16G16_UNORM:
|
|
|
|
case WINED3DFMT_R16G16B16A16_UNORM:
|
|
|
|
u16_data = data;
|
|
|
|
*colour = default_colour;
|
|
|
|
for (i = 0; i < format->component_count; ++i)
|
|
|
|
output[i] = u16_data[i] / 65535.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFMT_R32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
|
|
|
f32_data = data;
|
|
|
|
*colour = default_colour;
|
|
|
|
for (i = 0; i < format->component_count; ++i)
|
|
|
|
output[i] = f32_data[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*colour = default_colour;
|
|
|
|
if (!warned++)
|
|
|
|
FIXME("Unhandled colour format conversion, format %s.\n", debug_d3dformat(format->id));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_colour_from_mcs(struct wined3d_color *colour, enum wined3d_material_color_source mcs,
|
|
|
|
const struct wined3d_color *material_colour, unsigned int index,
|
|
|
|
const struct wined3d_stream_info *stream_info)
|
|
|
|
{
|
|
|
|
const struct wined3d_stream_info_element *element = NULL;
|
|
|
|
|
|
|
|
switch (mcs)
|
|
|
|
{
|
|
|
|
case WINED3D_MCS_MATERIAL:
|
|
|
|
*colour = *material_colour;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case WINED3D_MCS_COLOR1:
|
|
|
|
if (!(stream_info->use_map & (1u << WINED3D_FFP_DIFFUSE)))
|
|
|
|
{
|
|
|
|
colour->r = colour->g = colour->b = colour->a = 1.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
element = &stream_info->elements[WINED3D_FFP_DIFFUSE];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_MCS_COLOR2:
|
|
|
|
if (!(stream_info->use_map & (1u << WINED3D_FFP_SPECULAR)))
|
|
|
|
{
|
2019-05-22 11:39:27 +02:00
|
|
|
colour->r = colour->g = colour->b = colour->a = 0.0f;
|
2019-05-20 22:57:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
element = &stream_info->elements[WINED3D_FFP_SPECULAR];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
colour->r = colour->g = colour->b = colour->a = 0.0f;
|
|
|
|
ERR("Invalid material colour source %#x.\n", mcs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_format_get_colour(element->format, &element->data.addr[index * element->stride], colour);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float wined3d_clamp(float value, float min_value, float max_value)
|
|
|
|
{
|
|
|
|
return value < min_value ? min_value : value > max_value ? max_value : value;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
static float wined3d_vec3_dot(const struct wined3d_vec3 *v0, const struct wined3d_vec3 *v1)
|
|
|
|
{
|
|
|
|
return v0->x * v1->x + v0->y * v1->y + v0->z * v1->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_vec3_subtract(struct wined3d_vec3 *v0, const struct wined3d_vec3 *v1)
|
|
|
|
{
|
|
|
|
v0->x -= v1->x;
|
|
|
|
v0->y -= v1->y;
|
|
|
|
v0->z -= v1->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_vec3_scale(struct wined3d_vec3 *v, float s)
|
|
|
|
{
|
|
|
|
v->x *= s;
|
|
|
|
v->y *= s;
|
|
|
|
v->z *= s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_vec3_normalise(struct wined3d_vec3 *v)
|
|
|
|
{
|
|
|
|
float rnorm = 1.0f / sqrtf(wined3d_vec3_dot(v, v));
|
|
|
|
|
|
|
|
if (isfinite(rnorm))
|
|
|
|
wined3d_vec3_scale(v, rnorm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_vec3_transform(struct wined3d_vec3 *dst,
|
|
|
|
const struct wined3d_vec3 *v, const struct wined3d_matrix_3x3 *m)
|
|
|
|
{
|
|
|
|
struct wined3d_vec3 tmp;
|
|
|
|
|
|
|
|
tmp.x = v->x * m->_11 + v->y * m->_21 + v->z * m->_31;
|
|
|
|
tmp.y = v->x * m->_12 + v->y * m->_22 + v->z * m->_32;
|
|
|
|
tmp.z = v->x * m->_13 + v->y * m->_23 + v->z * m->_33;
|
|
|
|
|
|
|
|
*dst = tmp;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
static void wined3d_color_clamp(struct wined3d_color *dst, const struct wined3d_color *src,
|
|
|
|
float min_value, float max_value)
|
|
|
|
{
|
|
|
|
dst->r = wined3d_clamp(src->r, min_value, max_value);
|
|
|
|
dst->g = wined3d_clamp(src->g, min_value, max_value);
|
|
|
|
dst->b = wined3d_clamp(src->b, min_value, max_value);
|
|
|
|
dst->a = wined3d_clamp(src->a, min_value, max_value);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
static void wined3d_color_rgb_mul_add(struct wined3d_color *dst, const struct wined3d_color *src, float c)
|
|
|
|
{
|
|
|
|
dst->r += src->r * c;
|
|
|
|
dst->g += src->g * c;
|
|
|
|
dst->b += src->b * c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_transformed_lights(struct lights_settings *ls,
|
2019-06-10 12:11:49 +02:00
|
|
|
const struct wined3d_state *state, BOOL legacy_lighting, BOOL compute_lighting)
|
2019-05-20 22:57:34 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_light_info *lights[WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS];
|
|
|
|
const struct wined3d_light_info *light_info;
|
|
|
|
struct light_transformed *light;
|
|
|
|
struct wined3d_vec4 vec4;
|
|
|
|
unsigned int light_count;
|
|
|
|
unsigned int i, index;
|
|
|
|
|
|
|
|
memset(ls, 0, sizeof(*ls));
|
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
ls->lighting = !!compute_lighting;
|
|
|
|
ls->fog_mode = state->render_states[WINED3D_RS_FOGVERTEXMODE];
|
|
|
|
ls->fog_coord_mode = state->render_states[WINED3D_RS_RANGEFOGENABLE]
|
|
|
|
? WINED3D_FFP_VS_FOG_RANGE : WINED3D_FFP_VS_FOG_DEPTH;
|
|
|
|
ls->fog_start = wined3d_get_float_state(state, WINED3D_RS_FOGSTART);
|
|
|
|
ls->fog_end = wined3d_get_float_state(state, WINED3D_RS_FOGEND);
|
|
|
|
ls->fog_density = wined3d_get_float_state(state, WINED3D_RS_FOGDENSITY);
|
|
|
|
|
|
|
|
if (ls->fog_mode == WINED3D_FOG_NONE && !compute_lighting)
|
|
|
|
return;
|
2019-05-20 22:57:34 +02:00
|
|
|
|
|
|
|
multiply_matrix(&ls->modelview_matrix, &state->transforms[WINED3D_TS_VIEW],
|
|
|
|
&state->transforms[WINED3D_TS_WORLD_MATRIX(0)]);
|
2019-06-10 12:11:49 +02:00
|
|
|
|
|
|
|
if (!compute_lighting)
|
|
|
|
return;
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
compute_normal_matrix(&ls->normal_matrix._11, legacy_lighting, &ls->modelview_matrix);
|
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
wined3d_color_from_d3dcolor(&ls->ambient_light, state->render_states[WINED3D_RS_AMBIENT]);
|
|
|
|
ls->legacy_lighting = !!legacy_lighting;
|
|
|
|
ls->normalise = !!state->render_states[WINED3D_RS_NORMALIZENORMALS];
|
|
|
|
ls->localviewer = !!state->render_states[WINED3D_RS_LOCALVIEWER];
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
for (i = 0, index = 0; i < LIGHTMAP_SIZE && index < ARRAY_SIZE(lights); ++i)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY(light_info, &state->light_state.light_map[i], struct wined3d_light_info, entry)
|
|
|
|
{
|
|
|
|
if (!light_info->enabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (light_info->OriginalParms.type)
|
|
|
|
{
|
|
|
|
case WINED3D_LIGHT_DIRECTIONAL:
|
|
|
|
++ls->directional_light_count;
|
|
|
|
break;
|
|
|
|
|
2019-05-20 22:57:36 +02:00
|
|
|
case WINED3D_LIGHT_POINT:
|
|
|
|
++ls->point_light_count;
|
|
|
|
break;
|
|
|
|
|
2019-05-20 22:57:37 +02:00
|
|
|
case WINED3D_LIGHT_SPOT:
|
|
|
|
++ls->spot_light_count;
|
|
|
|
break;
|
|
|
|
|
2019-05-20 22:57:38 +02:00
|
|
|
case WINED3D_LIGHT_PARALLELPOINT:
|
|
|
|
++ls->parallel_point_light_count;
|
|
|
|
break;
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled light type %#x.\n", light_info->OriginalParms.type);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lights[index++] = light_info;
|
|
|
|
if (index == WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
light_count = index;
|
|
|
|
for (i = 0, index = 0; i < light_count; ++i)
|
|
|
|
{
|
|
|
|
light_info = lights[i];
|
|
|
|
if (light_info->OriginalParms.type != WINED3D_LIGHT_DIRECTIONAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
light = &ls->lights[index];
|
|
|
|
wined3d_vec4_transform(&vec4, &light_info->direction, &state->transforms[WINED3D_TS_VIEW]);
|
|
|
|
light->direction = *(struct wined3d_vec3 *)&vec4;
|
|
|
|
wined3d_vec3_normalise(&light->direction);
|
|
|
|
|
|
|
|
light->diffuse = light_info->OriginalParms.diffuse;
|
|
|
|
light->ambient = light_info->OriginalParms.ambient;
|
|
|
|
light->specular = light_info->OriginalParms.specular;
|
|
|
|
++index;
|
|
|
|
}
|
2019-05-20 22:57:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < light_count; ++i)
|
|
|
|
{
|
|
|
|
light_info = lights[i];
|
|
|
|
if (light_info->OriginalParms.type != WINED3D_LIGHT_POINT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
light = &ls->lights[index];
|
|
|
|
|
|
|
|
wined3d_vec4_transform(&light->position, &light_info->position, &state->transforms[WINED3D_TS_VIEW]);
|
|
|
|
light->range = light_info->OriginalParms.range;
|
|
|
|
light->c_att = light_info->OriginalParms.attenuation0;
|
|
|
|
light->l_att = light_info->OriginalParms.attenuation1;
|
|
|
|
light->q_att = light_info->OriginalParms.attenuation2;
|
|
|
|
|
|
|
|
light->diffuse = light_info->OriginalParms.diffuse;
|
|
|
|
light->ambient = light_info->OriginalParms.ambient;
|
|
|
|
light->specular = light_info->OriginalParms.specular;
|
|
|
|
++index;
|
|
|
|
}
|
2019-05-20 22:57:37 +02:00
|
|
|
|
|
|
|
for (i = 0; i < light_count; ++i)
|
|
|
|
{
|
|
|
|
light_info = lights[i];
|
|
|
|
if (light_info->OriginalParms.type != WINED3D_LIGHT_SPOT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
light = &ls->lights[index];
|
|
|
|
|
|
|
|
wined3d_vec4_transform(&light->position, &light_info->position, &state->transforms[WINED3D_TS_VIEW]);
|
|
|
|
wined3d_vec4_transform(&vec4, &light_info->direction, &state->transforms[WINED3D_TS_VIEW]);
|
|
|
|
light->direction = *(struct wined3d_vec3 *)&vec4;
|
|
|
|
wined3d_vec3_normalise(&light->direction);
|
|
|
|
light->range = light_info->OriginalParms.range;
|
|
|
|
light->falloff = light_info->OriginalParms.falloff;
|
|
|
|
light->c_att = light_info->OriginalParms.attenuation0;
|
|
|
|
light->l_att = light_info->OriginalParms.attenuation1;
|
|
|
|
light->q_att = light_info->OriginalParms.attenuation2;
|
|
|
|
light->cos_htheta = cosf(light_info->OriginalParms.theta / 2.0f);
|
|
|
|
light->cos_hphi = cosf(light_info->OriginalParms.phi / 2.0f);
|
|
|
|
|
|
|
|
light->diffuse = light_info->OriginalParms.diffuse;
|
|
|
|
light->ambient = light_info->OriginalParms.ambient;
|
|
|
|
light->specular = light_info->OriginalParms.specular;
|
|
|
|
++index;
|
|
|
|
}
|
2019-05-20 22:57:38 +02:00
|
|
|
|
|
|
|
for (i = 0; i < light_count; ++i)
|
|
|
|
{
|
|
|
|
light_info = lights[i];
|
|
|
|
if (light_info->OriginalParms.type != WINED3D_LIGHT_PARALLELPOINT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
light = &ls->lights[index];
|
|
|
|
|
|
|
|
wined3d_vec4_transform(&vec4, &light_info->position, &state->transforms[WINED3D_TS_VIEW]);
|
|
|
|
*(struct wined3d_vec3 *)&light->position = *(struct wined3d_vec3 *)&vec4;
|
|
|
|
wined3d_vec3_normalise((struct wined3d_vec3 *)&light->position);
|
|
|
|
light->diffuse = light_info->OriginalParms.diffuse;
|
|
|
|
light->ambient = light_info->OriginalParms.ambient;
|
|
|
|
light->specular = light_info->OriginalParms.specular;
|
|
|
|
++index;
|
|
|
|
}
|
2019-05-20 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_light_diffuse_specular(struct wined3d_color *diffuse, struct wined3d_color *specular,
|
|
|
|
const struct wined3d_vec3 *dir, float att, float material_shininess,
|
|
|
|
const struct wined3d_vec3 *normal_transformed,
|
|
|
|
const struct wined3d_vec3 *position_transformed_normalised,
|
|
|
|
const struct light_transformed *light, const struct lights_settings *ls)
|
|
|
|
{
|
|
|
|
struct wined3d_vec3 vec3;
|
|
|
|
float t, c;
|
|
|
|
|
|
|
|
c = wined3d_clamp(wined3d_vec3_dot(dir, normal_transformed), 0.0f, 1.0f);
|
|
|
|
wined3d_color_rgb_mul_add(diffuse, &light->diffuse, c * att);
|
|
|
|
|
|
|
|
vec3 = *dir;
|
|
|
|
if (ls->localviewer)
|
|
|
|
wined3d_vec3_subtract(&vec3, position_transformed_normalised);
|
|
|
|
else
|
|
|
|
vec3.z -= 1.0f;
|
|
|
|
wined3d_vec3_normalise(&vec3);
|
|
|
|
t = wined3d_vec3_dot(normal_transformed, &vec3);
|
|
|
|
if (t > 0.0f && (!ls->legacy_lighting || material_shininess > 0.0f)
|
|
|
|
&& wined3d_vec3_dot(dir, normal_transformed) > 0.0f)
|
|
|
|
wined3d_color_rgb_mul_add(specular, &light->specular, att * powf(t, material_shininess));
|
|
|
|
}
|
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
static void light_set_vertex_data(struct lights_settings *ls,
|
|
|
|
const struct wined3d_vec4 *position)
|
|
|
|
{
|
|
|
|
if (ls->fog_mode == WINED3D_FOG_NONE && !ls->lighting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wined3d_vec4_transform(&ls->position_transformed, position, &ls->modelview_matrix);
|
|
|
|
wined3d_vec3_scale((struct wined3d_vec3 *)&ls->position_transformed, 1.0f / ls->position_transformed.w);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
static void compute_light(struct wined3d_color *ambient, struct wined3d_color *diffuse,
|
2019-06-10 12:11:49 +02:00
|
|
|
struct wined3d_color *specular, struct lights_settings *ls, const struct wined3d_vec3 *normal,
|
|
|
|
float material_shininess)
|
2019-05-20 22:57:34 +02:00
|
|
|
{
|
|
|
|
struct wined3d_vec3 position_transformed_normalised;
|
|
|
|
struct wined3d_vec3 normal_transformed = {0.0f};
|
|
|
|
const struct light_transformed *light;
|
2019-05-20 22:57:36 +02:00
|
|
|
struct wined3d_vec3 dir, dst;
|
2019-05-20 22:57:34 +02:00
|
|
|
unsigned int i, index;
|
2019-05-20 22:57:36 +02:00
|
|
|
float att;
|
2019-05-20 22:57:34 +02:00
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
position_transformed_normalised = *(const struct wined3d_vec3 *)&ls->position_transformed;
|
2019-05-20 22:57:34 +02:00
|
|
|
wined3d_vec3_normalise(&position_transformed_normalised);
|
|
|
|
|
|
|
|
if (normal)
|
|
|
|
{
|
|
|
|
wined3d_vec3_transform(&normal_transformed, normal, &ls->normal_matrix);
|
|
|
|
if (ls->normalise)
|
|
|
|
wined3d_vec3_normalise(&normal_transformed);
|
|
|
|
}
|
|
|
|
|
|
|
|
diffuse->r = diffuse->g = diffuse->b = diffuse->a = 0.0f;
|
|
|
|
*specular = *diffuse;
|
|
|
|
*ambient = ls->ambient_light;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
for (i = 0; i < ls->directional_light_count; ++i, ++index)
|
|
|
|
{
|
|
|
|
light = &ls->lights[index];
|
|
|
|
|
|
|
|
wined3d_color_rgb_mul_add(ambient, &light->ambient, 1.0f);
|
|
|
|
if (normal)
|
|
|
|
update_light_diffuse_specular(diffuse, specular, &light->direction, 1.0f, material_shininess,
|
|
|
|
&normal_transformed, &position_transformed_normalised, light, ls);
|
|
|
|
}
|
2019-05-20 22:57:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ls->point_light_count; ++i, ++index)
|
|
|
|
{
|
|
|
|
light = &ls->lights[index];
|
2019-06-10 12:11:49 +02:00
|
|
|
dir.x = light->position.x - ls->position_transformed.x;
|
|
|
|
dir.y = light->position.y - ls->position_transformed.y;
|
|
|
|
dir.z = light->position.z - ls->position_transformed.z;
|
2019-05-20 22:57:36 +02:00
|
|
|
|
|
|
|
dst.z = wined3d_vec3_dot(&dir, &dir);
|
|
|
|
dst.y = sqrtf(dst.z);
|
|
|
|
dst.x = 1.0f;
|
|
|
|
if (ls->legacy_lighting)
|
|
|
|
{
|
|
|
|
dst.y = (light->range - dst.y) / light->range;
|
|
|
|
if (!(dst.y > 0.0f))
|
|
|
|
continue;
|
|
|
|
dst.z = dst.y * dst.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(dst.y <= light->range))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
att = dst.x * light->c_att + dst.y * light->l_att + dst.z * light->q_att;
|
|
|
|
if (!ls->legacy_lighting)
|
|
|
|
att = 1.0f / att;
|
|
|
|
|
|
|
|
wined3d_color_rgb_mul_add(ambient, &light->ambient, att);
|
|
|
|
if (normal)
|
|
|
|
{
|
|
|
|
wined3d_vec3_normalise(&dir);
|
|
|
|
update_light_diffuse_specular(diffuse, specular, &dir, att, material_shininess,
|
|
|
|
&normal_transformed, &position_transformed_normalised, light, ls);
|
|
|
|
}
|
|
|
|
}
|
2019-05-20 22:57:37 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ls->spot_light_count; ++i, ++index)
|
|
|
|
{
|
|
|
|
float t;
|
|
|
|
|
|
|
|
light = &ls->lights[index];
|
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
dir.x = light->position.x - ls->position_transformed.x;
|
|
|
|
dir.y = light->position.y - ls->position_transformed.y;
|
|
|
|
dir.z = light->position.z - ls->position_transformed.z;
|
2019-05-20 22:57:37 +02:00
|
|
|
|
|
|
|
dst.z = wined3d_vec3_dot(&dir, &dir);
|
|
|
|
dst.y = sqrtf(dst.z);
|
|
|
|
dst.x = 1.0f;
|
|
|
|
|
|
|
|
if (ls->legacy_lighting)
|
|
|
|
{
|
|
|
|
dst.y = (light->range - dst.y) / light->range;
|
|
|
|
if (!(dst.y > 0.0f))
|
|
|
|
continue;
|
|
|
|
dst.z = dst.y * dst.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(dst.y <= light->range))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wined3d_vec3_normalise(&dir);
|
|
|
|
t = -wined3d_vec3_dot(&dir, &light->direction);
|
|
|
|
if (t > light->cos_htheta)
|
|
|
|
att = 1.0f;
|
|
|
|
else if (t <= light->cos_hphi)
|
|
|
|
att = 0.0f;
|
|
|
|
else
|
|
|
|
att = powf((t - light->cos_hphi) / (light->cos_htheta - light->cos_hphi), light->falloff);
|
|
|
|
|
|
|
|
t = dst.x * light->c_att + dst.y * light->l_att + dst.z * light->q_att;
|
|
|
|
if (ls->legacy_lighting)
|
|
|
|
att *= t;
|
|
|
|
else
|
|
|
|
att /= t;
|
|
|
|
|
|
|
|
wined3d_color_rgb_mul_add(ambient, &light->ambient, att);
|
|
|
|
|
|
|
|
if (normal)
|
|
|
|
update_light_diffuse_specular(diffuse, specular, &dir, att, material_shininess,
|
|
|
|
&normal_transformed, &position_transformed_normalised, light, ls);
|
|
|
|
}
|
2019-05-20 22:57:38 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ls->parallel_point_light_count; ++i, ++index)
|
|
|
|
{
|
|
|
|
light = &ls->lights[index];
|
|
|
|
|
|
|
|
wined3d_color_rgb_mul_add(ambient, &light->ambient, 1.0f);
|
|
|
|
if (normal)
|
|
|
|
update_light_diffuse_specular(diffuse, specular, (const struct wined3d_vec3 *)&light->position,
|
|
|
|
1.0f, material_shininess, &normal_transformed, &position_transformed_normalised, light, ls);
|
|
|
|
}
|
2019-05-20 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
static float wined3d_calculate_fog_factor(float fog_coord, const struct lights_settings *ls)
|
|
|
|
{
|
|
|
|
switch (ls->fog_mode)
|
|
|
|
{
|
|
|
|
case WINED3D_FOG_NONE:
|
|
|
|
return fog_coord;
|
|
|
|
case WINED3D_FOG_LINEAR:
|
|
|
|
return (ls->fog_end - fog_coord) / (ls->fog_end - ls->fog_start);
|
|
|
|
case WINED3D_FOG_EXP:
|
|
|
|
return expf(-fog_coord * ls->fog_density);
|
|
|
|
case WINED3D_FOG_EXP2:
|
|
|
|
return expf(-fog_coord * fog_coord * ls->fog_density * ls->fog_density);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_fog_factor(float *fog_factor, struct lights_settings *ls)
|
|
|
|
{
|
|
|
|
float fog_coord;
|
|
|
|
|
|
|
|
if (ls->fog_mode == WINED3D_FOG_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (ls->fog_coord_mode)
|
|
|
|
{
|
|
|
|
case WINED3D_FFP_VS_FOG_RANGE:
|
|
|
|
fog_coord = sqrtf(wined3d_vec3_dot((const struct wined3d_vec3 *)&ls->position_transformed,
|
|
|
|
(const struct wined3d_vec3 *)&ls->position_transformed));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_FFP_VS_FOG_DEPTH:
|
|
|
|
fog_coord = fabsf(ls->position_transformed.z);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Unhandled fog coordinate mode %#x.\n", ls->fog_coord_mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*fog_factor = wined3d_calculate_fog_factor(fog_coord, ls);
|
|
|
|
}
|
|
|
|
|
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,
|
2018-09-17 11:06:28 +02:00
|
|
|
const struct wined3d_stream_info *stream_info, struct wined3d_buffer *dest, DWORD flags, DWORD dst_fvf)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2019-05-20 22:57:32 +02:00
|
|
|
enum wined3d_material_color_source diffuse_source, specular_source, ambient_source, emissive_source;
|
|
|
|
const struct wined3d_color *material_specular_state_colour;
|
2011-11-17 20:11:41 +01:00
|
|
|
struct wined3d_matrix mat, proj_mat, view_mat, world_mat;
|
2019-05-20 22:57:32 +02:00
|
|
|
const struct wined3d_state *state = &device->state;
|
|
|
|
const struct wined3d_format *output_colour_format;
|
|
|
|
static const struct wined3d_color black;
|
2016-08-31 11:27:52 +02:00
|
|
|
struct wined3d_map_desc map_desc;
|
|
|
|
struct wined3d_box box = {0};
|
2011-11-21 18:48:40 +01:00
|
|
|
struct wined3d_viewport vp;
|
2019-05-20 22:57:32 +02:00
|
|
|
unsigned int texture_count;
|
2019-05-20 22:57:34 +02:00
|
|
|
struct lights_settings ls;
|
2018-09-17 11:06:28 +02:00
|
|
|
unsigned int vertex_size;
|
2019-05-20 22:57:34 +02:00
|
|
|
BOOL do_clip, lighting;
|
2006-05-12 22:21:31 +02:00
|
|
|
unsigned int i;
|
2012-01-23 20:33:33 +01:00
|
|
|
BYTE *dest_ptr;
|
|
|
|
HRESULT hr;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (!(stream_info->use_map & (1u << WINED3D_FFP_POSITION)))
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2019-05-20 22:57:32 +02:00
|
|
|
ERR("Source has no position mask.\n");
|
2006-05-12 22:21:31 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
if (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)
|
2019-05-20 22:57:34 +02:00
|
|
|
do_clip = TRUE;
|
2006-05-12 22:21:31 +02:00
|
|
|
*/
|
2019-05-20 22:57:34 +02:00
|
|
|
do_clip = FALSE;
|
|
|
|
if (!warned)
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
warned = TRUE;
|
|
|
|
FIXME("Clipping is broken and disabled for now\n");
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
}
|
|
|
|
else
|
2019-05-20 22:57:34 +02:00
|
|
|
do_clip = FALSE;
|
2012-01-23 20:33:33 +01:00
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
vertex_size = wined3d_get_flexible_vertex_size(dst_fvf);
|
2016-08-31 11:27:52 +02:00
|
|
|
box.left = dwDestIndex * vertex_size;
|
|
|
|
box.right = box.left + dwCount * vertex_size;
|
2018-02-18 19:08:34 +01:00
|
|
|
if (FAILED(hr = wined3d_resource_map(&dest->resource, 0, &map_desc, &box, WINED3D_MAP_WRITE)))
|
2012-01-23 20:33:33 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to map buffer, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2016-08-31 11:27:52 +02:00
|
|
|
dest_ptr = map_desc.data;
|
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");
|
2015-03-20 12:41:54 +01:00
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", view_mat._11, view_mat._12, view_mat._13, view_mat._14);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", view_mat._21, view_mat._22, view_mat._23, view_mat._24);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", view_mat._31, view_mat._32, view_mat._33, view_mat._34);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", view_mat._41, view_mat._42, view_mat._43, view_mat._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("Proj mat:\n");
|
2015-03-20 12:41:54 +01:00
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", proj_mat._11, proj_mat._12, proj_mat._13, proj_mat._14);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", proj_mat._21, proj_mat._22, proj_mat._23, proj_mat._24);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", proj_mat._31, proj_mat._32, proj_mat._33, proj_mat._34);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", proj_mat._41, proj_mat._42, proj_mat._43, proj_mat._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("World mat:\n");
|
2015-03-20 12:41:54 +01:00
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", world_mat._11, world_mat._12, world_mat._13, world_mat._14);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", world_mat._21, world_mat._22, world_mat._23, world_mat._24);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", world_mat._31, world_mat._32, world_mat._33, world_mat._34);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", world_mat._41, world_mat._42, world_mat._43, world_mat._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
/* Get the viewport */
|
2018-04-18 11:50:45 +02:00
|
|
|
wined3d_device_get_viewports(device, NULL, &vp);
|
2018-04-26 23:30:11 +02:00
|
|
|
TRACE("viewport x %.8e, y %.8e, width %.8e, height %.8e, min_z %.8e, max_z %.8e.\n",
|
2011-11-21 18:48:40 +01:00
|
|
|
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);
|
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
texture_count = (dst_fvf & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
lighting = state->render_states[WINED3D_RS_LIGHTING]
|
|
|
|
&& (dst_fvf & (WINED3DFVF_DIFFUSE | WINED3DFVF_SPECULAR));
|
2019-05-20 22:57:32 +02:00
|
|
|
wined3d_get_material_colour_source(&diffuse_source, &emissive_source,
|
|
|
|
&ambient_source, &specular_source, state, stream_info);
|
|
|
|
output_colour_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, 0);
|
|
|
|
material_specular_state_colour = state->render_states[WINED3D_RS_SPECULARENABLE]
|
|
|
|
? &state->material.specular : &black;
|
2019-06-10 12:11:49 +02:00
|
|
|
init_transformed_lights(&ls, state, device->adapter->d3d_info.wined3d_creation_flags
|
|
|
|
& WINED3D_LEGACY_FFP_LIGHTING, lighting);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
for (i = 0; i < dwCount; ++i)
|
|
|
|
{
|
|
|
|
const struct wined3d_stream_info_element *position_element = &stream_info->elements[WINED3D_FFP_POSITION];
|
|
|
|
const float *p = (const float *)&position_element->data.addr[i * position_element->stride];
|
|
|
|
struct wined3d_color ambient, diffuse, specular;
|
2019-06-10 12:11:49 +02:00
|
|
|
struct wined3d_vec4 position;
|
2006-05-12 22:21:31 +02:00
|
|
|
unsigned int tex_index;
|
|
|
|
|
2019-06-10 12:11:49 +02:00
|
|
|
position.x = p[0];
|
|
|
|
position.y = p[1];
|
|
|
|
position.z = p[2];
|
|
|
|
position.w = 1.0f;
|
|
|
|
|
|
|
|
light_set_vertex_data(&ls, &position);
|
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if ( ((dst_fvf & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZ ) ||
|
|
|
|
((dst_fvf & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW ) ) {
|
2006-05-12 22:21:31 +02:00
|
|
|
/* The position first */
|
|
|
|
float x, y, z, rhw;
|
|
|
|
TRACE("In: ( %06.2f %06.2f %06.2f )\n", p[0], p[1], p[2]);
|
|
|
|
|
2015-03-20 12:41:54 +01:00
|
|
|
/* Multiplication with world, view and projection matrix. */
|
|
|
|
x = (p[0] * mat._11) + (p[1] * mat._21) + (p[2] * mat._31) + mat._41;
|
|
|
|
y = (p[0] * mat._12) + (p[1] * mat._22) + (p[2] * mat._32) + mat._42;
|
|
|
|
z = (p[0] * mat._13) + (p[1] * mat._23) + (p[2] * mat._33) + mat._43;
|
|
|
|
rhw = (p[0] * mat._14) + (p[1] * mat._24) + (p[2] * mat._34) + mat._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)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
if (!do_clip || (-rhw - eps < x && -rhw - eps < y && -eps < z && x <= rhw + eps
|
|
|
|
&& y <= rhw + eps && z <= rhw + eps && rhw > eps))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
/* "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);
|
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if ((dst_fvf & 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
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if (dst_fvf & WINED3DFVF_PSIZE)
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
2012-01-23 20:33:33 +01:00
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if (dst_fvf & WINED3DFVF_NORMAL)
|
2011-07-11 01:06:46 +02:00
|
|
|
{
|
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));
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:34 +02:00
|
|
|
if (lighting)
|
|
|
|
{
|
|
|
|
const struct wined3d_stream_info_element *element;
|
|
|
|
struct wined3d_vec3 *normal;
|
|
|
|
|
|
|
|
if (stream_info->use_map & (1u << WINED3D_FFP_NORMAL))
|
|
|
|
{
|
|
|
|
element = &stream_info->elements[WINED3D_FFP_NORMAL];
|
|
|
|
normal = (struct wined3d_vec3 *)&element->data.addr[i * element->stride];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
normal = NULL;
|
|
|
|
}
|
2019-06-10 12:11:49 +02:00
|
|
|
compute_light(&ambient, &diffuse, &specular, &ls, normal,
|
2019-05-20 22:57:34 +02:00
|
|
|
state->render_states[WINED3D_RS_SPECULARENABLE] ? state->material.power : 0.0f);
|
|
|
|
}
|
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if (dst_fvf & WINED3DFVF_DIFFUSE)
|
2011-07-11 01:06:46 +02:00
|
|
|
{
|
2019-05-20 22:57:34 +02:00
|
|
|
struct wined3d_color material_diffuse, material_ambient, material_emissive, diffuse_colour;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
wined3d_colour_from_mcs(&material_diffuse, diffuse_source,
|
|
|
|
&state->material.diffuse, i, stream_info);
|
2019-05-20 22:57:34 +02:00
|
|
|
|
|
|
|
if (lighting)
|
|
|
|
{
|
|
|
|
wined3d_colour_from_mcs(&material_ambient, ambient_source,
|
|
|
|
&state->material.ambient, i, stream_info);
|
|
|
|
wined3d_colour_from_mcs(&material_emissive, emissive_source,
|
|
|
|
&state->material.emissive, i, stream_info);
|
|
|
|
|
|
|
|
diffuse_colour.r = ambient.r * material_ambient.r
|
|
|
|
+ diffuse.r * material_diffuse.r + material_emissive.r;
|
|
|
|
diffuse_colour.g = ambient.g * material_ambient.g
|
|
|
|
+ diffuse.g * material_diffuse.g + material_emissive.g;
|
|
|
|
diffuse_colour.b = ambient.b * material_ambient.b
|
|
|
|
+ diffuse.b * material_diffuse.b + material_emissive.b;
|
|
|
|
diffuse_colour.a = material_diffuse.a;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
diffuse_colour = material_diffuse;
|
|
|
|
}
|
|
|
|
wined3d_color_clamp(&diffuse_colour, &diffuse_colour, 0.0f, 1.0f);
|
|
|
|
*((DWORD *)dest_ptr) = wined3d_format_convert_from_float(output_colour_format, &diffuse_colour);
|
2019-05-20 22:57:32 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 11:06:28 +02:00
|
|
|
if (dst_fvf & WINED3DFVF_SPECULAR)
|
2009-08-27 10:04:56 +02:00
|
|
|
{
|
2019-05-20 22:57:34 +02:00
|
|
|
struct wined3d_color material_specular, specular_colour;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
wined3d_colour_from_mcs(&material_specular, specular_source,
|
|
|
|
material_specular_state_colour, i, stream_info);
|
2019-05-20 22:57:34 +02:00
|
|
|
|
|
|
|
if (lighting)
|
|
|
|
{
|
|
|
|
specular_colour.r = specular.r * material_specular.r;
|
|
|
|
specular_colour.g = specular.g * material_specular.g;
|
|
|
|
specular_colour.b = specular.b * material_specular.b;
|
2019-05-22 11:39:27 +02:00
|
|
|
specular_colour.a = ls.legacy_lighting ? 0.0f : material_specular.a;
|
2019-05-20 22:57:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
specular_colour = material_specular;
|
|
|
|
}
|
2019-06-10 12:11:49 +02:00
|
|
|
update_fog_factor(&specular_colour.a, &ls);
|
2019-05-20 22:57:34 +02:00
|
|
|
wined3d_color_clamp(&specular_colour, &specular_colour, 0.0f, 1.0f);
|
|
|
|
*((DWORD *)dest_ptr) = wined3d_format_convert_from_float(output_colour_format, &specular_colour);
|
2019-05-20 22:57:32 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:57:32 +02:00
|
|
|
for (tex_index = 0; tex_index < texture_count; ++tex_index)
|
2011-07-11 01:06:46 +02:00
|
|
|
{
|
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);
|
2015-08-26 12:46:47 +02:00
|
|
|
if (!(stream_info->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + tex_index))))
|
2009-08-21 09:12:29 +02:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No source texture, but destination requests one\n");
|
2018-09-17 11:06:28 +02:00
|
|
|
dest_ptr += GET_TEXCOORD_SIZE_FROM_FVF(dst_fvf, tex_index) * sizeof(float);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2018-09-17 11:06:28 +02:00
|
|
|
copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(dst_fvf, tex_index) * sizeof(float));
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 11:27:52 +02:00
|
|
|
wined3d_resource_unmap(&dest->resource, 0);
|
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;
|
2017-03-06 10:45:22 +01:00
|
|
|
struct wined3d_resource *resource;
|
|
|
|
struct wined3d_box box = {0};
|
2011-07-26 19:52:43 +02:00
|
|
|
struct wined3d_shader *vs;
|
2018-12-25 13:24:36 +01:00
|
|
|
unsigned int i, j;
|
2009-10-28 11:00:11 +01:00
|
|
|
HRESULT hr;
|
2014-07-14 10:04:22 +02:00
|
|
|
WORD map;
|
2009-10-28 11:00:11 +01:00
|
|
|
|
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
|
|
|
|
2013-10-09 22:57:45 +02:00
|
|
|
vs = state->shader[WINED3D_SHADER_TYPE_VERTEX];
|
|
|
|
state->shader[WINED3D_SHADER_TYPE_VERTEX] = NULL;
|
2019-03-13 14:48:15 +01:00
|
|
|
wined3d_stream_info_from_declaration(&stream_info, state, &device->adapter->d3d_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. */
|
2014-07-14 10:04:22 +02:00
|
|
|
for (i = 0, map = stream_info.use_map; map; map >>= 1, ++i)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2012-03-28 20:22:36 +02:00
|
|
|
struct wined3d_stream_info_element *e;
|
2017-03-06 10:45:22 +01:00
|
|
|
struct wined3d_map_desc map_desc;
|
2009-08-21 09:12:29 +02:00
|
|
|
|
2014-07-14 10:04:22 +02:00
|
|
|
if (!(map & 1))
|
2012-03-28 20:22:36 +02:00
|
|
|
continue;
|
2009-08-21 09:12:29 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
e = &stream_info.elements[i];
|
2017-03-06 10:45:22 +01:00
|
|
|
resource = &state->streams[e->stream_idx].buffer->resource;
|
|
|
|
box.left = src_start_idx * e->stride;
|
|
|
|
box.right = box.left + vertex_count * e->stride;
|
2018-02-18 19:08:34 +01:00
|
|
|
if (FAILED(wined3d_resource_map(resource, 0, &map_desc, &box, WINED3D_MAP_READ)))
|
2018-12-25 13:24:36 +01:00
|
|
|
{
|
2017-03-06 10:45:22 +01:00
|
|
|
ERR("Failed to map resource.\n");
|
2018-12-25 13:24:36 +01:00
|
|
|
for (j = 0, map = stream_info.use_map; map && j < i; map >>= 1, ++j)
|
|
|
|
{
|
|
|
|
if (!(map & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
e = &stream_info.elements[j];
|
|
|
|
resource = &state->streams[e->stream_idx].buffer->resource;
|
|
|
|
if (FAILED(wined3d_resource_unmap(resource, 0)))
|
|
|
|
ERR("Failed to unmap resource.\n");
|
|
|
|
}
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2014-07-14 10:04:22 +02:00
|
|
|
e->data.buffer_object = 0;
|
2017-03-06 10:45:22 +01:00
|
|
|
e->data.addr += (ULONG_PTR)map_desc.data;
|
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
|
|
|
|
2017-03-06 10:45:22 +01:00
|
|
|
for (i = 0, map = stream_info.use_map; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(map & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
resource = &state->streams[stream_info.elements[i].stream_idx].buffer->resource;
|
|
|
|
if (FAILED(wined3d_resource_unmap(resource, 0)))
|
|
|
|
ERR("Failed to unmap resource.\n");
|
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
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;
|
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
|
|
|
}
|
|
|
|
|
2019-02-05 18:08:53 +01:00
|
|
|
device->update_stateblock_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");
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.textureState[stage] |= 1u << state;
|
2012-09-26 10:12:13 +02:00
|
|
|
return;
|
2006-12-19 23:00:58 +01:00
|
|
|
}
|
|
|
|
|
2019-02-05 18:08:53 +01:00
|
|
|
if (value == device->state.texture_states[stage][state])
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-05 18:08:53 +01:00
|
|
|
device->state.texture_states[stage][state] = value;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-03-22 15:47:06 +01:00
|
|
|
void 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)
|
2019-02-20 21:53:58 +01:00
|
|
|
stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_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. */
|
2017-10-19 10:07:29 +02:00
|
|
|
if (stage >= ARRAY_SIZE(device->state.textures))
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
WARN("Ignoring invalid stage %u.\n", stage);
|
2019-03-22 15:47:06 +01:00
|
|
|
return;
|
2008-01-15 08:06:37 +01:00
|
|
|
}
|
|
|
|
|
2019-02-05 18:08:54 +01:00
|
|
|
if (texture)
|
|
|
|
wined3d_texture_incref(texture);
|
|
|
|
if (device->update_stateblock_state->textures[stage])
|
|
|
|
wined3d_texture_decref(device->update_stateblock_state->textures[stage]);
|
|
|
|
device->update_stateblock_state->textures[stage] = texture;
|
|
|
|
|
2013-08-26 09:23:37 +02:00
|
|
|
if (device->recording)
|
2019-02-05 18:08:54 +01:00
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
device->recording->changed.textures |= 1u << stage;
|
2019-03-22 15:47:06 +01:00
|
|
|
return;
|
2019-02-05 18:08:54 +01:00
|
|
|
}
|
2009-09-28 10:04:59 +02:00
|
|
|
|
2019-02-05 18:08:54 +01:00
|
|
|
prev = device->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");
|
2019-03-22 15:47:06 +01:00
|
|
|
return;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
TRACE("Setting new texture to %p.\n", texture);
|
2019-02-05 18:08:54 +01:00
|
|
|
device->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);
|
2019-02-05 18:08:54 +01:00
|
|
|
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
|
|
|
|
2019-03-22 15:47:06 +01:00
|
|
|
return;
|
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)
|
2019-02-20 21:53:58 +01:00
|
|
|
stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2017-10-19 10:07:29 +02:00
|
|
|
if (stage >= ARRAY_SIZE(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
|
|
|
}
|
|
|
|
|
2018-06-13 12:23:59 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, struct wined3d_caps *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;
|
2019-01-28 05:44:52 +01:00
|
|
|
device->update_stateblock_state = &stateblock->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;
|
2019-01-28 05:44:52 +01:00
|
|
|
device->update_stateblock_state = &device->stateblock_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
|
|
|
{
|
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
|
|
|
device->inScene = FALSE;
|
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
|
|
|
{
|
2016-03-15 10:52:47 +01:00
|
|
|
TRACE("device %p, rect_count %u, rects %p, flags %#x, color %s, depth %.8e, stencil %u.\n",
|
|
|
|
device, rect_count, rects, flags, debug_color(color), 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
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
struct wined3d_rendertarget_view *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)
|
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
if (ds->width < device->fb.render_targets[0]->width
|
|
|
|
|| ds->height < device->fb.render_targets[0]->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
|
|
|
}
|
|
|
|
|
2014-09-19 10:41:46 +02:00
|
|
|
void CDECL wined3d_device_set_predication(struct wined3d_device *device,
|
|
|
|
struct wined3d_query *predicate, BOOL value)
|
|
|
|
{
|
|
|
|
struct wined3d_query *prev;
|
|
|
|
|
|
|
|
TRACE("device %p, predicate %p, value %#x.\n", device, predicate, value);
|
|
|
|
|
2019-01-25 06:06:09 +01:00
|
|
|
prev = device->state.predicate;
|
2014-09-19 10:41:46 +02:00
|
|
|
if (predicate)
|
|
|
|
{
|
|
|
|
FIXME("Predicated rendering not implemented.\n");
|
|
|
|
wined3d_query_incref(predicate);
|
|
|
|
}
|
2019-01-25 06:06:09 +01:00
|
|
|
device->state.predicate = predicate;
|
|
|
|
device->state.predicate_value = value;
|
|
|
|
wined3d_cs_emit_set_predication(device->cs, predicate, value);
|
2014-09-19 10:41:46 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_query_decref(prev);
|
|
|
|
}
|
|
|
|
|
2014-09-19 10:41:47 +02:00
|
|
|
struct wined3d_query * CDECL wined3d_device_get_predication(struct wined3d_device *device, BOOL *value)
|
|
|
|
{
|
|
|
|
TRACE("device %p, value %p.\n", device, value);
|
|
|
|
|
2017-05-10 15:54:06 +02:00
|
|
|
if (value)
|
|
|
|
*value = device->state.predicate_value;
|
2014-09-19 10:41:47 +02:00
|
|
|
return device->state.predicate;
|
|
|
|
}
|
|
|
|
|
2017-02-02 12:43:40 +01:00
|
|
|
void CDECL wined3d_device_dispatch_compute(struct wined3d_device *device,
|
|
|
|
unsigned int group_count_x, unsigned int group_count_y, unsigned int group_count_z)
|
|
|
|
{
|
|
|
|
TRACE("device %p, group_count_x %u, group_count_y %u, group_count_z %u.\n",
|
|
|
|
device, group_count_x, group_count_y, group_count_z);
|
|
|
|
|
|
|
|
wined3d_cs_emit_dispatch(device->cs, group_count_x, group_count_y, group_count_z);
|
|
|
|
}
|
|
|
|
|
2017-08-14 23:47:41 +02:00
|
|
|
void CDECL wined3d_device_dispatch_compute_indirect(struct wined3d_device *device,
|
|
|
|
struct wined3d_buffer *buffer, unsigned int offset)
|
|
|
|
{
|
|
|
|
TRACE("device %p, buffer %p, offset %u.\n", device, buffer, offset);
|
|
|
|
|
|
|
|
wined3d_cs_emit_dispatch_indirect(device->cs, buffer, offset);
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_set_primitive_type(struct wined3d_device *device,
|
2017-05-18 15:20:01 +02:00
|
|
|
enum wined3d_primitive_type primitive_type, unsigned int patch_vertex_count)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2017-05-18 15:20:01 +02:00
|
|
|
TRACE("device %p, primitive_type %s, patch_vertex_count %u.\n",
|
|
|
|
device, debug_d3dprimitivetype(primitive_type), patch_vertex_count);
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2017-02-26 07:46:33 +01:00
|
|
|
device->state.gl_primitive_type = gl_primitive_type_from_d3d(primitive_type);
|
2017-05-18 15:20:01 +02:00
|
|
|
device->state.gl_patch_vertices = patch_vertex_count;
|
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,
|
2017-05-18 15:20:01 +02:00
|
|
|
enum wined3d_primitive_type *primitive_type, unsigned int *patch_vertex_count)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2017-05-18 15:20:01 +02:00
|
|
|
TRACE("device %p, primitive_type %p, patch_vertex_count %p.\n",
|
|
|
|
device, primitive_type, patch_vertex_count);
|
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);
|
2017-05-18 15:20:01 +02:00
|
|
|
if (patch_vertex_count)
|
|
|
|
*patch_vertex_count = device->state.gl_patch_vertices;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2017-05-18 15:20:01 +02:00
|
|
|
TRACE("Returning %s.\n", debug_d3dprimitivetype(*primitive_type));
|
2009-03-05 12:30:43 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-05-18 15:20:01 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, device->state.gl_primitive_type, device->state.gl_patch_vertices,
|
|
|
|
0, start_vertex, vertex_count, 0, 0, FALSE);
|
2013-09-27 00:15:15 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 09:38:26 +01:00
|
|
|
void CDECL wined3d_device_draw_primitive_instanced(struct wined3d_device *device,
|
|
|
|
UINT start_vertex, UINT vertex_count, UINT start_instance, UINT instance_count)
|
|
|
|
{
|
|
|
|
TRACE("device %p, start_vertex %u, vertex_count %u, start_instance %u, instance_count %u.\n",
|
|
|
|
device, start_vertex, vertex_count, start_instance, instance_count);
|
|
|
|
|
2017-05-18 15:20:01 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, device->state.gl_primitive_type, device->state.gl_patch_vertices,
|
|
|
|
0, start_vertex, vertex_count, start_instance, instance_count, FALSE);
|
2015-03-24 09:38:26 +01:00
|
|
|
}
|
|
|
|
|
2017-11-01 22:08:42 +01:00
|
|
|
void CDECL wined3d_device_draw_primitive_instanced_indirect(struct wined3d_device *device,
|
|
|
|
struct wined3d_buffer *buffer, unsigned int offset)
|
|
|
|
{
|
|
|
|
TRACE("device %p, buffer %p, offset %u.\n", device, buffer, offset);
|
|
|
|
|
|
|
|
wined3d_cs_emit_draw_indirect(device->cs, device->state.gl_primitive_type, device->state.gl_patch_vertices,
|
|
|
|
buffer, offset, FALSE);
|
|
|
|
}
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
2017-05-18 15:20:01 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, device->state.gl_primitive_type, device->state.gl_patch_vertices,
|
2017-02-26 07:46:33 +01:00
|
|
|
device->state.base_vertex_index, 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)
|
|
|
|
{
|
2015-03-20 12:41:55 +01:00
|
|
|
TRACE("device %p, start_idx %u, index_count %u, start_instance %u, instance_count %u.\n",
|
|
|
|
device, start_idx, index_count, start_instance, instance_count);
|
2012-11-26 22:52:41 +01:00
|
|
|
|
2017-05-18 15:20:01 +02:00
|
|
|
wined3d_cs_emit_draw(device->cs, device->state.gl_primitive_type, device->state.gl_patch_vertices,
|
|
|
|
device->state.base_vertex_index, start_idx, index_count, start_instance, instance_count, TRUE);
|
2012-11-26 22:52:41 +01:00
|
|
|
}
|
|
|
|
|
2017-11-01 22:08:42 +01:00
|
|
|
void CDECL wined3d_device_draw_indexed_primitive_instanced_indirect(struct wined3d_device *device,
|
|
|
|
struct wined3d_buffer *buffer, unsigned int offset)
|
|
|
|
{
|
|
|
|
TRACE("device %p, buffer %p, offset %u.\n", device, buffer, offset);
|
|
|
|
|
|
|
|
wined3d_cs_emit_draw_indirect(device->cs, device->state.gl_primitive_type, device->state.gl_patch_vertices,
|
|
|
|
buffer, offset, TRUE);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-01-27 00:06:23 +01:00
|
|
|
unsigned int src_size, dst_size, src_skip_levels = 0;
|
2017-04-10 23:47:32 +02:00
|
|
|
unsigned int src_level_count, dst_level_count;
|
2016-01-27 00:06:23 +01:00
|
|
|
unsigned int layer_count, level_count, i, j;
|
2012-01-17 21:13:36 +01:00
|
|
|
enum wined3d_resource_type type;
|
2017-04-10 23:47:33 +02:00
|
|
|
struct wined3d_box box;
|
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
|
|
|
|
2018-01-30 13:24:37 +01:00
|
|
|
if (src_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU
|
|
|
|
|| src_texture->resource.usage & WINED3DUSAGE_SCRATCH)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2018-01-30 13:24:37 +01:00
|
|
|
WARN("Source resource is GPU accessible or a scratch resource.\n");
|
2013-08-26 02:01:30 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2018-01-30 13:24:37 +01:00
|
|
|
if (dst_texture->resource.access & WINED3D_RESOURCE_ACCESS_CPU)
|
2013-08-26 02:01:30 +02:00
|
|
|
{
|
2018-01-30 13:24:37 +01:00
|
|
|
WARN("Destination resource is CPU accessible.\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
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
layer_count = src_texture->layer_count;
|
|
|
|
if (layer_count != dst_texture->layer_count)
|
|
|
|
{
|
|
|
|
WARN("Source and destination have different layer counts.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2017-04-06 23:44:32 +02:00
|
|
|
if (src_texture->resource.format != dst_texture->resource.format)
|
|
|
|
{
|
|
|
|
WARN("Source and destination formats do not match.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2017-04-10 23:47:32 +02:00
|
|
|
src_level_count = src_texture->level_count;
|
|
|
|
dst_level_count = dst_texture->level_count;
|
|
|
|
level_count = min(src_level_count, dst_level_count);
|
2015-04-29 23:34:27 +02:00
|
|
|
|
|
|
|
src_size = max(src_texture->resource.width, src_texture->resource.height);
|
2018-03-26 11:30:37 +02:00
|
|
|
src_size = max(src_size, src_texture->resource.depth);
|
2015-04-29 23:34:27 +02:00
|
|
|
dst_size = max(dst_texture->resource.width, dst_texture->resource.height);
|
2018-03-26 11:30:37 +02:00
|
|
|
dst_size = max(dst_size, dst_texture->resource.depth);
|
2015-04-29 23:34:27 +02:00
|
|
|
while (src_size > dst_size)
|
|
|
|
{
|
|
|
|
src_size >>= 1;
|
|
|
|
++src_skip_levels;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2005-11-04 13:39:17 +01:00
|
|
|
|
2017-04-09 22:36:39 +02:00
|
|
|
if (wined3d_texture_get_level_width(src_texture, src_skip_levels) != dst_texture->resource.width
|
|
|
|
|| wined3d_texture_get_level_height(src_texture, src_skip_levels) != dst_texture->resource.height
|
|
|
|
|| wined3d_texture_get_level_depth(src_texture, src_skip_levels) != dst_texture->resource.depth)
|
|
|
|
{
|
|
|
|
WARN("Source and destination dimensions do not match.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Update every surface level of the texture. */
|
2017-04-10 23:47:32 +02:00
|
|
|
for (i = 0; i < level_count; ++i)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2019-05-17 13:45:17 +02:00
|
|
|
wined3d_texture_get_level_box(dst_texture, i, &box);
|
2017-04-10 23:47:32 +02:00
|
|
|
for (j = 0; j < layer_count; ++j)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2017-04-10 23:47:33 +02:00
|
|
|
wined3d_cs_emit_blt_sub_resource(device->cs,
|
|
|
|
&dst_texture->resource, j * dst_level_count + i, &box,
|
|
|
|
&src_texture->resource, j * src_level_count + i + src_skip_levels, &box,
|
|
|
|
0, NULL, WINED3D_TEXF_POINT);
|
2017-04-10 23:47:32 +02:00
|
|
|
}
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2017-04-10 23:47:32 +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: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
|
|
|
|
2019-02-20 21:54:00 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_COMBINED_SAMPLERS; ++i)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
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];
|
2015-04-22 11:30:15 +02: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
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_rendertarget_view *rt = device->fb.render_targets[0];
|
2014-08-22 12:32:01 +02:00
|
|
|
struct wined3d_rendertarget_view *ds = device->fb.depth_stencil;
|
2011-03-11 11:49:01 +01:00
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
if (ds && rt && (ds->width < rt->width || ds->height < rt->height))
|
2011-03-11 11:49:01 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-08-04 19:53:48 +02:00
|
|
|
void CDECL wined3d_device_copy_uav_counter(struct wined3d_device *device,
|
|
|
|
struct wined3d_buffer *dst_buffer, unsigned int offset, struct wined3d_unordered_access_view *uav)
|
|
|
|
{
|
|
|
|
TRACE("device %p, dst_buffer %p, offset %u, uav %p.\n",
|
|
|
|
device, dst_buffer, offset, uav);
|
|
|
|
|
|
|
|
wined3d_cs_emit_copy_uav_counter(device->cs, dst_buffer, offset, uav);
|
|
|
|
}
|
|
|
|
|
2014-08-04 12:17:24 +02:00
|
|
|
void CDECL wined3d_device_copy_resource(struct wined3d_device *device,
|
|
|
|
struct wined3d_resource *dst_resource, struct wined3d_resource *src_resource)
|
|
|
|
{
|
|
|
|
struct wined3d_texture *dst_texture, *src_texture;
|
2017-03-08 10:53:04 +01:00
|
|
|
struct wined3d_box box;
|
2016-03-25 17:52:27 +01:00
|
|
|
unsigned int i, j;
|
2014-08-04 12:17:24 +02:00
|
|
|
|
|
|
|
TRACE("device %p, dst_resource %p, src_resource %p.\n", device, dst_resource, src_resource);
|
|
|
|
|
|
|
|
if (src_resource == dst_resource)
|
|
|
|
{
|
|
|
|
WARN("Source and destination are the same resource.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_resource->type != dst_resource->type)
|
|
|
|
{
|
|
|
|
WARN("Resource types (%s / %s) don't match.\n",
|
|
|
|
debug_d3dresourcetype(dst_resource->type),
|
|
|
|
debug_d3dresourcetype(src_resource->type));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_resource->width != dst_resource->width
|
|
|
|
|| src_resource->height != dst_resource->height
|
|
|
|
|| src_resource->depth != dst_resource->depth)
|
|
|
|
{
|
|
|
|
WARN("Resource dimensions (%ux%ux%u / %ux%ux%u) don't match.\n",
|
|
|
|
dst_resource->width, dst_resource->height, dst_resource->depth,
|
|
|
|
src_resource->width, src_resource->height, src_resource->depth);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-15 22:13:03 +01:00
|
|
|
if (src_resource->format->typeless_id != dst_resource->format->typeless_id
|
|
|
|
|| (!src_resource->format->typeless_id && src_resource->format->id != dst_resource->format->id))
|
2014-08-04 12:17:24 +02:00
|
|
|
{
|
2017-11-15 22:13:03 +01:00
|
|
|
WARN("Resource formats %s and %s are incompatible.\n",
|
2014-08-04 12:17:24 +02:00
|
|
|
debug_d3dformat(dst_resource->format->id),
|
|
|
|
debug_d3dformat(src_resource->format->id));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-20 23:15:26 +01:00
|
|
|
if (dst_resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
2017-04-06 23:44:30 +02:00
|
|
|
wined3d_box_set(&box, 0, 0, src_resource->size, 1, 0, 1);
|
2017-03-08 10:53:04 +01:00
|
|
|
wined3d_cs_emit_blt_sub_resource(device->cs, dst_resource, 0, &box,
|
2017-11-15 22:13:01 +01:00
|
|
|
src_resource, 0, &box, WINED3D_BLT_RAW, NULL, WINED3D_TEXF_POINT);
|
2016-03-20 23:15:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
dst_texture = texture_from_resource(dst_resource);
|
|
|
|
src_texture = texture_from_resource(src_resource);
|
2014-08-04 12:17:24 +02:00
|
|
|
|
|
|
|
if (src_texture->layer_count != dst_texture->layer_count
|
|
|
|
|| src_texture->level_count != dst_texture->level_count)
|
|
|
|
{
|
|
|
|
WARN("Subresource layouts (%ux%u / %ux%u) don't match.\n",
|
|
|
|
dst_texture->layer_count, dst_texture->level_count,
|
|
|
|
src_texture->layer_count, src_texture->level_count);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:52:27 +01:00
|
|
|
for (i = 0; i < dst_texture->level_count; ++i)
|
2014-08-04 12:17:24 +02:00
|
|
|
{
|
2019-06-04 13:01:54 +02:00
|
|
|
wined3d_texture_get_level_box(dst_texture, i, &box);
|
2016-03-25 17:52:27 +01:00
|
|
|
for (j = 0; j < dst_texture->layer_count; ++j)
|
|
|
|
{
|
|
|
|
unsigned int idx = j * dst_texture->level_count + i;
|
2014-08-04 12:17:24 +02:00
|
|
|
|
2017-03-08 10:53:04 +01:00
|
|
|
wined3d_cs_emit_blt_sub_resource(device->cs, dst_resource, idx, &box,
|
2017-11-15 22:13:01 +01:00
|
|
|
src_resource, idx, &box, WINED3D_BLT_RAW, NULL, WINED3D_TEXF_POINT);
|
2016-03-25 17:52:27 +01:00
|
|
|
}
|
2014-08-04 12:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 16:49:28 +01:00
|
|
|
HRESULT CDECL wined3d_device_copy_sub_resource_region(struct wined3d_device *device,
|
2015-07-20 11:07:30 +02:00
|
|
|
struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx, unsigned int dst_x,
|
|
|
|
unsigned int dst_y, unsigned int dst_z, struct wined3d_resource *src_resource,
|
2018-05-18 16:08:45 +02:00
|
|
|
unsigned int src_sub_resource_idx, const struct wined3d_box *src_box, unsigned int flags)
|
2015-07-20 11:07:30 +02:00
|
|
|
{
|
2017-03-08 10:53:03 +01:00
|
|
|
struct wined3d_box dst_box, b;
|
2015-07-20 11:07:30 +02:00
|
|
|
|
|
|
|
TRACE("device %p, dst_resource %p, dst_sub_resource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
|
2018-05-18 16:08:45 +02:00
|
|
|
"src_resource %p, src_sub_resource_idx %u, src_box %s, flags %#x.\n",
|
2015-07-20 11:07:30 +02:00
|
|
|
device, dst_resource, dst_sub_resource_idx, dst_x, dst_y, dst_z,
|
2018-05-18 16:08:45 +02:00
|
|
|
src_resource, src_sub_resource_idx, debug_box(src_box), flags);
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
2015-07-20 11:07:30 +02:00
|
|
|
|
|
|
|
if (src_resource == dst_resource && src_sub_resource_idx == dst_sub_resource_idx)
|
|
|
|
{
|
|
|
|
WARN("Source and destination are the same sub-resource.\n");
|
2015-10-29 16:49:28 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2015-07-20 11:07:30 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 22:13:04 +01:00
|
|
|
if (src_resource->format->typeless_id != dst_resource->format->typeless_id
|
|
|
|
|| (!src_resource->format->typeless_id && src_resource->format->id != dst_resource->format->id))
|
2015-07-20 11:07:30 +02:00
|
|
|
{
|
2017-11-15 22:13:04 +01:00
|
|
|
WARN("Resource formats %s and %s are incompatible.\n",
|
2015-07-20 11:07:30 +02:00
|
|
|
debug_d3dformat(dst_resource->format->id),
|
|
|
|
debug_d3dformat(src_resource->format->id));
|
2015-10-29 16:49:28 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2015-07-20 11:07:30 +02:00
|
|
|
}
|
|
|
|
|
2016-03-20 23:15:27 +01:00
|
|
|
if (dst_resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
2018-08-15 11:09:51 +02:00
|
|
|
if (src_resource->type != WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
WARN("Resource types (%s / %s) don't match.\n",
|
|
|
|
debug_d3dresourcetype(dst_resource->type),
|
|
|
|
debug_d3dresourcetype(src_resource->type));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-03-20 23:15:27 +01:00
|
|
|
if (dst_sub_resource_idx)
|
|
|
|
{
|
|
|
|
WARN("Invalid dst_sub_resource_idx %u.\n", dst_sub_resource_idx);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2017-03-08 10:53:03 +01:00
|
|
|
|
2016-03-20 23:15:27 +01:00
|
|
|
if (src_sub_resource_idx)
|
|
|
|
{
|
|
|
|
WARN("Invalid src_sub_resource_idx %u.\n", src_sub_resource_idx);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2017-03-08 10:53:03 +01:00
|
|
|
if (!src_box)
|
2016-03-20 23:15:27 +01:00
|
|
|
{
|
2017-11-15 22:13:05 +01:00
|
|
|
unsigned int dst_w;
|
|
|
|
|
|
|
|
dst_w = dst_resource->size - dst_x;
|
|
|
|
wined3d_box_set(&b, 0, 0, min(src_resource->size, dst_w), 1, 0, 1);
|
2017-03-08 10:53:03 +01:00
|
|
|
src_box = &b;
|
2016-03-20 23:15:27 +01:00
|
|
|
}
|
2017-03-08 10:53:03 +01:00
|
|
|
else if ((src_box->left >= src_box->right
|
|
|
|
|| src_box->top >= src_box->bottom
|
|
|
|
|| src_box->front >= src_box->back))
|
2016-03-20 23:15:27 +01:00
|
|
|
{
|
2017-03-08 10:53:03 +01:00
|
|
|
WARN("Invalid box %s specified.\n", debug_box(src_box));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2016-03-20 23:15:27 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 10:53:03 +01:00
|
|
|
if (src_box->right > src_resource->size || dst_x >= dst_resource->size
|
|
|
|
|| src_box->right - src_box->left > dst_resource->size - dst_x)
|
2016-03-20 23:15:27 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid range specified, dst_offset %u, src_offset %u, size %u.\n",
|
2017-03-08 10:53:03 +01:00
|
|
|
dst_x, src_box->left, src_box->right - src_box->left);
|
2016-03-20 23:15:27 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2017-04-06 23:44:30 +02:00
|
|
|
wined3d_box_set(&dst_box, dst_x, 0, dst_x + (src_box->right - src_box->left), 1, 0, 1);
|
2016-03-20 23:15:27 +01:00
|
|
|
}
|
2018-03-26 11:30:38 +02:00
|
|
|
else
|
2015-07-20 11:07:30 +02:00
|
|
|
{
|
2017-03-08 10:53:03 +01:00
|
|
|
struct wined3d_texture *dst_texture = texture_from_resource(dst_resource);
|
|
|
|
struct wined3d_texture *src_texture = texture_from_resource(src_resource);
|
|
|
|
unsigned int src_level = src_sub_resource_idx % src_texture->level_count;
|
2015-07-20 11:07:30 +02:00
|
|
|
|
2017-03-08 10:53:03 +01:00
|
|
|
if (dst_sub_resource_idx >= dst_texture->level_count * dst_texture->layer_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid destination sub-resource %u.\n", dst_sub_resource_idx);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2015-07-20 11:07:30 +02:00
|
|
|
|
2017-03-08 10:53:03 +01:00
|
|
|
if (src_sub_resource_idx >= src_texture->level_count * src_texture->layer_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid source sub-resource %u.\n", src_sub_resource_idx);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst_texture->sub_resources[dst_sub_resource_idx].map_count)
|
|
|
|
{
|
|
|
|
WARN("Destination sub-resource %u is mapped.\n", dst_sub_resource_idx);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_texture->sub_resources[src_sub_resource_idx].map_count)
|
|
|
|
{
|
|
|
|
WARN("Source sub-resource %u is mapped.\n", src_sub_resource_idx);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!src_box)
|
|
|
|
{
|
2018-03-26 11:30:38 +02:00
|
|
|
unsigned int src_w, src_h, src_d, dst_w, dst_h, dst_d, dst_level;
|
2017-11-15 22:13:05 +01:00
|
|
|
|
|
|
|
src_w = wined3d_texture_get_level_width(src_texture, src_level);
|
|
|
|
src_h = wined3d_texture_get_level_height(src_texture, src_level);
|
2018-03-26 11:30:38 +02:00
|
|
|
src_d = wined3d_texture_get_level_depth(src_texture, src_level);
|
2017-11-15 22:13:05 +01:00
|
|
|
|
|
|
|
dst_level = dst_sub_resource_idx % dst_texture->level_count;
|
|
|
|
dst_w = wined3d_texture_get_level_width(dst_texture, dst_level) - dst_x;
|
|
|
|
dst_h = wined3d_texture_get_level_height(dst_texture, dst_level) - dst_y;
|
2018-03-26 11:30:38 +02:00
|
|
|
dst_d = wined3d_texture_get_level_depth(dst_texture, dst_level) - dst_z;
|
2017-11-15 22:13:05 +01:00
|
|
|
|
2018-03-26 11:30:38 +02:00
|
|
|
wined3d_box_set(&b, 0, 0, min(src_w, dst_w), min(src_h, dst_h), 0, min(src_d, dst_d));
|
2017-03-08 10:53:03 +01:00
|
|
|
src_box = &b;
|
|
|
|
}
|
|
|
|
else if (FAILED(wined3d_texture_check_box_dimensions(src_texture, src_level, src_box)))
|
|
|
|
{
|
|
|
|
WARN("Invalid source box %s.\n", debug_box(src_box));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2017-04-06 23:44:30 +02:00
|
|
|
wined3d_box_set(&dst_box, dst_x, dst_y, dst_x + (src_box->right - src_box->left),
|
2018-03-26 11:30:38 +02:00
|
|
|
dst_y + (src_box->bottom - src_box->top), dst_z, dst_z + (src_box->back - src_box->front));
|
2017-03-08 10:53:03 +01:00
|
|
|
if (FAILED(wined3d_texture_check_box_dimensions(dst_texture,
|
|
|
|
dst_sub_resource_idx % dst_texture->level_count, &dst_box)))
|
|
|
|
{
|
|
|
|
WARN("Invalid destination box %s.\n", debug_box(&dst_box));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2016-03-25 17:52:28 +01:00
|
|
|
}
|
2016-01-19 22:28:08 +01:00
|
|
|
|
2017-03-08 10:53:03 +01:00
|
|
|
wined3d_cs_emit_blt_sub_resource(device->cs, dst_resource, dst_sub_resource_idx, &dst_box,
|
2017-11-15 22:13:02 +01:00
|
|
|
src_resource, src_sub_resource_idx, src_box, WINED3D_BLT_RAW, NULL, WINED3D_TEXF_POINT);
|
2015-07-20 11:07:30 +02:00
|
|
|
|
2017-03-08 10:53:03 +01:00
|
|
|
return WINED3D_OK;
|
2015-07-20 11:07:30 +02:00
|
|
|
}
|
|
|
|
|
2015-08-18 11:24:11 +02:00
|
|
|
void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, struct wined3d_resource *resource,
|
|
|
|
unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch,
|
2018-05-22 14:37:49 +02:00
|
|
|
unsigned int depth_pitch, unsigned int flags)
|
2015-08-18 11:24:11 +02:00
|
|
|
{
|
2017-03-06 10:45:24 +01:00
|
|
|
unsigned int width, height, depth;
|
|
|
|
struct wined3d_box b;
|
2015-08-18 11:24:11 +02:00
|
|
|
|
2018-05-22 14:37:49 +02:00
|
|
|
TRACE("device %p, resource %p, sub_resource_idx %u, box %s, data %p, row_pitch %u, depth_pitch %u, "
|
|
|
|
"flags %#x.\n",
|
|
|
|
device, resource, sub_resource_idx, debug_box(box), data, row_pitch, depth_pitch, flags);
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
2015-08-18 11:24:11 +02:00
|
|
|
|
2018-09-06 22:01:57 +02:00
|
|
|
if (!(resource->access & WINED3D_RESOURCE_ACCESS_GPU))
|
|
|
|
{
|
|
|
|
WARN("Resource %p is not GPU accessible.\n", resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-04 13:03:36 +01:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
if (sub_resource_idx > 0)
|
|
|
|
{
|
|
|
|
WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-06 10:45:24 +01:00
|
|
|
width = resource->size;
|
|
|
|
height = 1;
|
|
|
|
depth = 1;
|
|
|
|
}
|
2018-03-26 11:30:39 +02:00
|
|
|
else
|
2017-03-06 10:45:24 +01:00
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
|
|
|
unsigned int level;
|
|
|
|
|
|
|
|
if (sub_resource_idx >= texture->level_count * texture->layer_count)
|
2017-01-31 15:47:12 +01:00
|
|
|
{
|
2017-03-06 10:45:24 +01:00
|
|
|
WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
|
2017-01-31 15:47:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-06 10:45:24 +01:00
|
|
|
level = sub_resource_idx % texture->level_count;
|
|
|
|
width = wined3d_texture_get_level_width(texture, level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, level);
|
|
|
|
depth = wined3d_texture_get_level_depth(texture, level);
|
2016-01-04 13:03:36 +01:00
|
|
|
}
|
2015-08-18 11:24:11 +02:00
|
|
|
|
2017-03-06 10:45:24 +01:00
|
|
|
if (!box)
|
2015-08-18 11:24:11 +02:00
|
|
|
{
|
2017-04-06 23:44:30 +02:00
|
|
|
wined3d_box_set(&b, 0, 0, width, height, 0, depth);
|
2017-03-06 10:45:24 +01:00
|
|
|
box = &b;
|
2015-08-18 11:24:11 +02:00
|
|
|
}
|
2017-03-06 10:45:24 +01:00
|
|
|
else if (box->left >= box->right || box->right > width
|
2016-11-14 17:31:17 +01:00
|
|
|
|| box->top >= box->bottom || box->bottom > height
|
2017-03-06 10:45:24 +01:00
|
|
|
|| box->front >= box->back || box->back > depth)
|
2015-08-18 11:24:11 +02:00
|
|
|
{
|
2016-11-14 17:31:17 +01:00
|
|
|
WARN("Invalid box %s specified.\n", debug_box(box));
|
|
|
|
return;
|
2015-08-18 11:24:11 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 21:31:54 +02:00
|
|
|
wined3d_resource_wait_idle(resource);
|
|
|
|
|
2017-03-06 10:45:24 +01:00
|
|
|
wined3d_cs_emit_update_sub_resource(device->cs, resource, sub_resource_idx, box, data, row_pitch, depth_pitch);
|
2015-08-18 11:24:11 +02:00
|
|
|
}
|
|
|
|
|
2018-02-12 18:46:19 +01:00
|
|
|
void CDECL wined3d_device_resolve_sub_resource(struct wined3d_device *device,
|
|
|
|
struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx,
|
|
|
|
struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx,
|
|
|
|
enum wined3d_format_id format_id)
|
|
|
|
{
|
|
|
|
struct wined3d_texture *dst_texture, *src_texture;
|
|
|
|
unsigned int dst_level, src_level;
|
|
|
|
RECT dst_rect, src_rect;
|
|
|
|
|
|
|
|
TRACE("device %p, dst_resource %p, dst_sub_resource_idx %u, "
|
|
|
|
"src_resource %p, src_sub_resource_idx %u, format %s.\n",
|
|
|
|
device, dst_resource, dst_sub_resource_idx,
|
|
|
|
src_resource, src_sub_resource_idx, debug_d3dformat(format_id));
|
|
|
|
|
|
|
|
if (wined3d_format_is_typeless(dst_resource->format)
|
|
|
|
|| wined3d_format_is_typeless(src_resource->format))
|
|
|
|
{
|
2018-08-20 13:09:25 +02:00
|
|
|
FIXME("Multisample resolve is not fully supported for typeless formats "
|
|
|
|
"(dst_format %s, src_format %s, format %s).\n",
|
2018-02-12 18:46:19 +01:00
|
|
|
debug_d3dformat(dst_resource->format->id), debug_d3dformat(src_resource->format->id),
|
|
|
|
debug_d3dformat(format_id));
|
|
|
|
}
|
|
|
|
if (dst_resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
WARN("Invalid destination resource type %s.\n", debug_d3dresourcetype(dst_resource->type));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (src_resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
WARN("Invalid source resource type %s.\n", debug_d3dresourcetype(src_resource->type));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_texture = texture_from_resource(dst_resource);
|
|
|
|
src_texture = texture_from_resource(src_resource);
|
|
|
|
|
|
|
|
dst_level = dst_sub_resource_idx % dst_texture->level_count;
|
|
|
|
SetRect(&dst_rect, 0, 0, wined3d_texture_get_level_width(dst_texture, dst_level),
|
|
|
|
wined3d_texture_get_level_height(dst_texture, dst_level));
|
|
|
|
src_level = src_sub_resource_idx % src_texture->level_count;
|
|
|
|
SetRect(&src_rect, 0, 0, wined3d_texture_get_level_width(src_texture, src_level),
|
|
|
|
wined3d_texture_get_level_height(src_texture, src_level));
|
|
|
|
wined3d_texture_blt(dst_texture, dst_sub_resource_idx, &dst_rect,
|
|
|
|
src_texture, src_sub_resource_idx, &src_rect, 0, NULL, WINED3D_TEXF_POINT);
|
|
|
|
}
|
|
|
|
|
2014-08-22 12:32:02 +02:00
|
|
|
HRESULT CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
|
2016-03-15 10:52:48 +01:00
|
|
|
struct wined3d_rendertarget_view *view, const RECT *rect, DWORD flags,
|
|
|
|
const struct wined3d_color *color, float depth, DWORD stencil)
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2017-04-05 10:21:25 +02:00
|
|
|
RECT r;
|
2009-02-25 08:39:01 +01:00
|
|
|
|
2016-03-15 10:52:48 +01:00
|
|
|
TRACE("device %p, view %p, rect %s, flags %#x, color %s, depth %.8e, stencil %u.\n",
|
|
|
|
device, view, wine_dbgstr_rect(rect), flags, debug_color(color), depth, stencil);
|
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
2014-08-21 09:55:54 +02:00
|
|
|
resource = view->resource;
|
2018-05-28 11:33:16 +02:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
2014-08-21 09:55:54 +02:00
|
|
|
{
|
|
|
|
FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
|
2014-08-22 12:32:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2014-08-21 09:55:54 +02:00
|
|
|
}
|
|
|
|
|
2018-05-28 11:33:16 +02:00
|
|
|
if (view->layer_count != max(1, resource->depth >> view->desc.u.texture.level_idx))
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
2014-08-21 09:55:54 +02:00
|
|
|
FIXME("Layered clears not implemented.\n");
|
2014-08-22 12:32:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rect)
|
|
|
|
{
|
|
|
|
SetRect(&r, 0, 0, view->width, view->height);
|
|
|
|
rect = &r;
|
2009-02-25 08:39:01 +01:00
|
|
|
}
|
2017-03-28 23:37:39 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_box b = {rect->left, rect->top, rect->right, rect->bottom, 0, 1};
|
|
|
|
struct wined3d_texture *texture = texture_from_resource(view->resource);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = wined3d_texture_check_box_dimensions(texture,
|
|
|
|
view->sub_resource_idx % texture->level_count, &b)))
|
|
|
|
return hr;
|
|
|
|
}
|
2009-02-25 08:39:01 +01:00
|
|
|
|
2017-04-05 10:21:25 +02:00
|
|
|
wined3d_cs_emit_clear_rendertarget_view(device->cs, view, rect, flags, color, depth, stencil);
|
2017-04-03 07:39:43 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2009-02-25 08:39:01 +01:00
|
|
|
}
|
|
|
|
|
2017-05-12 15:09:20 +02:00
|
|
|
void CDECL wined3d_device_clear_unordered_access_view_uint(struct wined3d_device *device,
|
|
|
|
struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value)
|
|
|
|
{
|
|
|
|
TRACE("device %p, view %p, clear_value %s.\n", device, view, debug_uvec4(clear_value));
|
|
|
|
|
|
|
|
wined3d_cs_emit_clear_unordered_access_view_uint(device->cs, view, clear_value);
|
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_rendertarget_view * CDECL wined3d_device_get_rendertarget_view(const struct wined3d_device *device,
|
|
|
|
unsigned int view_idx)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2018-08-24 15:44:03 +02:00
|
|
|
unsigned int max_rt_count;
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
TRACE("device %p, view_idx %u.\n", device, view_idx);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
2018-08-24 15:44:03 +02:00
|
|
|
max_rt_count = device->adapter->d3d_info.limits.max_rt_count;
|
|
|
|
if (view_idx >= max_rt_count)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2018-08-24 15:44:03 +02:00
|
|
|
WARN("Only %u render targets are supported.\n", max_rt_count);
|
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
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
return device->fb.render_targets[view_idx];
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-12 20:50:22 +01:00
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
struct wined3d_rendertarget_view * CDECL wined3d_device_get_depth_stencil_view(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
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_rendertarget_view(struct wined3d_device *device,
|
|
|
|
unsigned int view_idx, struct wined3d_rendertarget_view *view, BOOL set_viewport)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_rendertarget_view *prev;
|
2018-08-24 15:44:03 +02:00
|
|
|
unsigned int max_rt_count;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
TRACE("device %p, view_idx %u, view %p, set_viewport %#x.\n",
|
|
|
|
device, view_idx, view, set_viewport);
|
2006-12-19 19:25:42 +01:00
|
|
|
|
2018-08-24 15:44:03 +02:00
|
|
|
max_rt_count = device->adapter->d3d_info.limits.max_rt_count;
|
|
|
|
if (view_idx >= max_rt_count)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2018-08-24 15:44:03 +02:00
|
|
|
WARN("Only %u render targets are supported.\n", max_rt_count);
|
2006-12-19 19:25:42 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 12:43:53 +01:00
|
|
|
if (view && !(view->resource->bind_flags & WINED3D_BIND_RENDER_TARGET))
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2018-11-05 12:43:53 +01:00
|
|
|
WARN("View resource %p doesn't have render target bind flags.\n", view->resource);
|
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. */
|
2014-08-21 09:55:55 +02:00
|
|
|
if (!view_idx && set_viewport)
|
2012-11-19 00:15:49 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
struct wined3d_state *state = &device->state;
|
2012-11-19 00:15:49 +01:00
|
|
|
|
2018-04-14 11:12:38 +02:00
|
|
|
state->viewports[0].x = 0;
|
|
|
|
state->viewports[0].y = 0;
|
|
|
|
state->viewports[0].width = view->width;
|
|
|
|
state->viewports[0].height = view->height;
|
|
|
|
state->viewports[0].min_z = 0.0f;
|
|
|
|
state->viewports[0].max_z = 1.0f;
|
|
|
|
state->viewport_count = 1;
|
|
|
|
wined3d_cs_emit_set_viewports(device->cs, 1, state->viewports);
|
2019-02-06 22:01:49 +01:00
|
|
|
device->stateblock_state.viewport = state->viewports[0];
|
2012-11-19 00:15:49 +01:00
|
|
|
|
2018-04-23 14:34:03 +02:00
|
|
|
SetRect(&state->scissor_rects[0], 0, 0, view->width, view->height);
|
|
|
|
state->scissor_rect_count = 1;
|
|
|
|
wined3d_cs_emit_set_scissor_rects(device->cs, 1, state->scissor_rects);
|
2019-02-06 22:01:50 +01:00
|
|
|
device->stateblock_state.scissor_rect = state->scissor_rects[0];
|
2012-11-19 00:15:49 +01:00
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
prev = device->fb.render_targets[view_idx];
|
|
|
|
if (view == prev)
|
2012-11-19 00:15:49 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
if (view)
|
|
|
|
wined3d_rendertarget_view_incref(view);
|
|
|
|
device->fb.render_targets[view_idx] = view;
|
|
|
|
wined3d_cs_emit_set_rendertarget_view(device->cs, view_idx, view);
|
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)
|
2014-08-21 09:55:55 +02:00
|
|
|
wined3d_rendertarget_view_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
|
|
|
}
|
|
|
|
|
2018-11-18 19:39:14 +01:00
|
|
|
HRESULT CDECL wined3d_device_set_depth_stencil_view(struct wined3d_device *device,
|
|
|
|
struct wined3d_rendertarget_view *view)
|
2010-08-04 11:10:25 +02:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
struct wined3d_rendertarget_view *prev;
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
TRACE("device %p, view %p.\n", device, view);
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2018-11-18 19:39:14 +01:00
|
|
|
if (view && !(view->resource->bind_flags & WINED3D_BIND_DEPTH_STENCIL))
|
|
|
|
{
|
|
|
|
WARN("View resource %p has incompatible %s bind flags.\n",
|
|
|
|
view->resource, wined3d_debug_bind_flags(view->resource->bind_flags));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
prev = device->fb.depth_stencil;
|
|
|
|
if (prev == view)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
|
|
|
TRACE("Trying to do a NOP SetRenderTarget operation.\n");
|
2018-11-18 19:39:14 +01:00
|
|
|
return WINED3D_OK;
|
2010-04-19 20:47:01 +02:00
|
|
|
}
|
2010-04-19 20:47:03 +02:00
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
if ((device->fb.depth_stencil = view))
|
|
|
|
wined3d_rendertarget_view_incref(view);
|
|
|
|
wined3d_cs_emit_set_depth_stencil_view(device->cs, view);
|
2011-08-12 08:21:51 +02:00
|
|
|
if (prev)
|
2014-08-22 12:32:01 +02:00
|
|
|
wined3d_rendertarget_view_decref(prev);
|
2018-11-18 19:39:14 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
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,
|
2016-03-07 17:05:51 +01:00
|
|
|
struct wined3d_texture *cursor_image, unsigned int sub_resource_idx)
|
2013-11-18 10:46:16 +01:00
|
|
|
{
|
2016-04-03 15:30:53 +02:00
|
|
|
unsigned int texture_level = sub_resource_idx % cursor_image->level_count;
|
2015-01-05 13:24:59 +01:00
|
|
|
struct wined3d_sub_resource_data data;
|
2013-11-18 10:46:16 +01:00
|
|
|
struct wined3d_resource_desc desc;
|
|
|
|
struct wined3d_map_desc map_desc;
|
|
|
|
struct wined3d_texture *texture;
|
2015-01-05 13:24:59 +01:00
|
|
|
HRESULT hr;
|
2013-11-18 10:46:16 +01:00
|
|
|
|
2018-02-18 19:08:34 +01:00
|
|
|
if (FAILED(wined3d_resource_map(&cursor_image->resource, sub_resource_idx, &map_desc, NULL, WINED3D_MAP_READ)))
|
2013-11-18 10:46:16 +01:00
|
|
|
{
|
2016-03-07 17:05:51 +01:00
|
|
|
ERR("Failed to map source texture.\n");
|
2013-11-18 10:46:16 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-05 13:24:59 +01:00
|
|
|
data.data = map_desc.data;
|
|
|
|
data.row_pitch = map_desc.row_pitch;
|
|
|
|
data.slice_pitch = map_desc.slice_pitch;
|
2013-11-18 10:46:16 +01:00
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2013-11-18 10:46:16 +01:00
|
|
|
desc.format = WINED3DFMT_B8G8R8A8_UNORM;
|
|
|
|
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
|
|
|
|
desc.multisample_quality = 0;
|
2014-01-10 10:43:02 +01:00
|
|
|
desc.usage = WINED3DUSAGE_DYNAMIC;
|
2018-10-31 10:31:47 +01:00
|
|
|
desc.bind_flags = 0;
|
2018-02-02 17:58:54 +01:00
|
|
|
desc.access = WINED3D_RESOURCE_ACCESS_GPU;
|
2016-04-03 15:30:53 +02:00
|
|
|
desc.width = wined3d_texture_get_level_width(cursor_image, texture_level);
|
|
|
|
desc.height = wined3d_texture_get_level_height(cursor_image, texture_level);
|
2013-11-18 10:46:16 +01:00
|
|
|
desc.depth = 1;
|
|
|
|
desc.size = 0;
|
|
|
|
|
2018-11-26 19:40:14 +01:00
|
|
|
hr = wined3d_texture_create(device, &desc, 1, 1, 0, &data, NULL, &wined3d_null_parent_ops, &texture);
|
2016-03-07 17:05:51 +01:00
|
|
|
wined3d_resource_unmap(&cursor_image->resource, sub_resource_idx);
|
2015-01-05 13:24:59 +01:00
|
|
|
if (FAILED(hr))
|
2013-11-18 10:46:16 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to create cursor texture.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device,
|
2015-10-16 13:59:18 +02:00
|
|
|
UINT x_hotspot, UINT y_hotspot, struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2016-04-03 15:30:54 +02:00
|
|
|
unsigned int texture_level = sub_resource_idx % texture->level_count;
|
|
|
|
unsigned int cursor_width, cursor_height;
|
2015-10-16 10:35:09 +02:00
|
|
|
struct wined3d_display_mode mode;
|
|
|
|
struct wined3d_map_desc map_desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-10-16 13:59:18 +02:00
|
|
|
TRACE("device %p, x_hotspot %u, y_hotspot %u, texture %p, sub_resource_idx %u.\n",
|
|
|
|
device, x_hotspot, y_hotspot, texture, sub_resource_idx);
|
|
|
|
|
2016-04-03 15:30:54 +02:00
|
|
|
if (sub_resource_idx >= texture->level_count * texture->layer_count
|
|
|
|
|| texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
|
2015-10-16 13:59:18 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-06 20:59:46 +01:00
|
|
|
if (texture->resource.format->id != WINED3DFMT_B8G8R8A8_UNORM)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2016-03-06 20:59:46 +01:00
|
|
|
WARN("Texture %p has invalid format %s.\n",
|
|
|
|
texture, debug_d3dformat(texture->resource.format->id));
|
2015-10-16 10:35:09 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2007-03-13 03:44:22 +01:00
|
|
|
|
2015-10-16 10:35:09 +02:00
|
|
|
if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d, device->adapter->ordinal, &mode, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get display mode, hr %#x.\n", hr);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2006-07-23 00:03:33 +02:00
|
|
|
|
2016-04-03 15:30:54 +02:00
|
|
|
cursor_width = wined3d_texture_get_level_width(texture, texture_level);
|
|
|
|
cursor_height = wined3d_texture_get_level_height(texture, texture_level);
|
|
|
|
if (cursor_width > mode.width || cursor_height > mode.height)
|
2015-10-16 10:35:09 +02:00
|
|
|
{
|
2016-04-03 15:30:54 +02:00
|
|
|
WARN("Texture %p, sub-resource %u dimensions are %ux%u, but screen dimensions are %ux%u.\n",
|
|
|
|
texture, sub_resource_idx, cursor_width, cursor_height, mode.width, mode.height);
|
2015-10-16 10:35:09 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2012-06-22 15:57:29 +02:00
|
|
|
|
2015-10-16 10:35:09 +02:00
|
|
|
/* TODO: MSDN: Cursor sizes must be a power of 2 */
|
2006-07-23 00:03:33 +02:00
|
|
|
|
2015-10-16 10:35:09 +02:00
|
|
|
/* 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
|
|
|
|
* creating circular refcount dependencies. */
|
2016-03-07 17:05:51 +01:00
|
|
|
if (!(device->cursor_texture = wined3d_device_create_cursor_texture(device, texture, sub_resource_idx)))
|
2015-10-16 10:35:09 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to create cursor texture.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 20:18:33 +02:00
|
|
|
|
2016-04-03 15:30:54 +02:00
|
|
|
if (cursor_width == 32 && cursor_height == 32)
|
2015-10-16 10:35:09 +02:00
|
|
|
{
|
2016-04-03 15:30:54 +02:00
|
|
|
UINT mask_size = cursor_width * cursor_height / 8;
|
2015-10-16 10:35:09 +02:00
|
|
|
ICONINFO cursor_info;
|
|
|
|
DWORD *mask_bits;
|
|
|
|
HCURSOR cursor;
|
2011-05-16 20:18:33 +02:00
|
|
|
|
2015-10-16 10:35:09 +02: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. */
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(mask_bits = heap_alloc(mask_size)))
|
2015-10-16 10:35:09 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memset(mask_bits, 0xff, mask_size);
|
|
|
|
|
2016-03-07 17:05:52 +01:00
|
|
|
wined3d_resource_map(&texture->resource, sub_resource_idx, &map_desc, NULL,
|
2018-02-18 19:08:34 +01:00
|
|
|
WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READ);
|
2015-10-16 10:35:09 +02:00
|
|
|
cursor_info.fIcon = FALSE;
|
|
|
|
cursor_info.xHotspot = x_hotspot;
|
|
|
|
cursor_info.yHotspot = y_hotspot;
|
2016-04-03 15:30:54 +02:00
|
|
|
cursor_info.hbmMask = CreateBitmap(cursor_width, cursor_height, 1, 1, mask_bits);
|
|
|
|
cursor_info.hbmColor = CreateBitmap(cursor_width, cursor_height, 1, 32, map_desc.data);
|
2016-03-07 17:05:52 +01:00
|
|
|
wined3d_resource_unmap(&texture->resource, sub_resource_idx);
|
2015-10-16 10:35:09 +02:00
|
|
|
|
|
|
|
/* Create our cursor and clean up. */
|
|
|
|
cursor = CreateIconIndirect(&cursor_info);
|
|
|
|
if (cursor_info.hbmMask)
|
|
|
|
DeleteObject(cursor_info.hbmMask);
|
|
|
|
if (cursor_info.hbmColor)
|
|
|
|
DeleteObject(cursor_info.hbmColor);
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
DestroyCursor(device->hardwareCursor);
|
|
|
|
device->hardwareCursor = cursor;
|
|
|
|
if (device->bCursorVisible)
|
|
|
|
SetCursor(cursor);
|
2013-11-18 10:46:16 +01:00
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(mask_bits);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2016-04-03 15:30:54 +02:00
|
|
|
TRACE("New cursor dimensions are %ux%u.\n", cursor_width, cursor_height);
|
|
|
|
device->cursorWidth = cursor_width;
|
|
|
|
device->cursorHeight = cursor_height;
|
2011-05-16 23:01:23 +02:00
|
|
|
device->xHotSpot = x_hotspot;
|
|
|
|
device->yHotSpot = y_hotspot;
|
2015-10-16 10:35:09 +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
|
|
|
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
|
|
|
|
2018-01-30 13:24:38 +01:00
|
|
|
if (wined3d_resource_access_is_managed(resource->access) && !resource->map_count)
|
2011-07-25 20:45:07 +02:00
|
|
|
{
|
|
|
|
TRACE("Evicting %p.\n", resource);
|
2016-08-05 12:39:01 +02:00
|
|
|
wined3d_cs_emit_unload_resource(device->cs, resource);
|
2011-07-25 20:45:07 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 09:01:16 +01:00
|
|
|
static void update_swapchain_flags(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
unsigned int flags = texture->swapchain->desc.flags;
|
|
|
|
|
2018-11-08 18:59:02 +01:00
|
|
|
if (flags & WINED3D_SWAPCHAIN_LOCKABLE_BACKBUFFER)
|
|
|
|
texture->resource.access |= WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
|
|
|
|
else
|
|
|
|
texture->resource.access &= ~(WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W);
|
|
|
|
|
2018-11-07 09:01:16 +01:00
|
|
|
if (flags & WINED3D_SWAPCHAIN_GDI_COMPATIBLE)
|
|
|
|
texture->flags |= WINED3D_TEXTURE_GET_DC;
|
|
|
|
else
|
|
|
|
texture->flags &= ~WINED3D_TEXTURE_GET_DC;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-08-24 15:44:03 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2011-07-25 20:45:06 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2019-04-12 14:50:47 +02:00
|
|
|
struct wined3d_rendertarget_view *view;
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2016-12-05 12:04:41 +01:00
|
|
|
struct wined3d_view_desc view_desc;
|
2016-08-15 16:00:15 +02:00
|
|
|
BOOL backbuffer_resized;
|
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
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("device %p, swapchain_desc %p, mode %p, callback %p, reset_state %#x.\n",
|
|
|
|
device, swapchain_desc, mode, callback, reset_state);
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2018-11-29 14:33:47 +01:00
|
|
|
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
2017-05-02 11:35:30 +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)
|
2014-01-30 17:32:04 +01:00
|
|
|
{
|
|
|
|
if (device->logo_texture)
|
|
|
|
{
|
|
|
|
wined3d_texture_decref(device->logo_texture);
|
|
|
|
device->logo_texture = NULL;
|
|
|
|
}
|
|
|
|
if (device->cursor_texture)
|
|
|
|
{
|
|
|
|
wined3d_texture_decref(device->cursor_texture);
|
|
|
|
device->cursor_texture = NULL;
|
|
|
|
}
|
2019-02-11 18:21:03 +01:00
|
|
|
wined3d_stateblock_state_cleanup(&device->stateblock_state);
|
2013-08-27 08:44:59 +02:00
|
|
|
state_unbind_resources(&device->state);
|
2014-01-30 17:32:04 +01:00
|
|
|
}
|
2012-11-19 22:04:12 +01:00
|
|
|
|
2018-08-24 15:44:03 +02:00
|
|
|
for (i = 0; i < d3d_info->limits.max_rt_count; ++i)
|
2012-06-18 17:19:39 +02:00
|
|
|
{
|
2018-02-25 23:23:33 +01:00
|
|
|
wined3d_device_set_rendertarget_view(device, i, NULL, FALSE);
|
2012-06-18 17:19:39 +02:00
|
|
|
}
|
2014-08-22 12:32:01 +02:00
|
|
|
wined3d_device_set_depth_stencil_view(device, NULL);
|
2011-12-06 22:57:44 +01: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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
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
|
|
|
|
2018-10-31 10:31:48 +01:00
|
|
|
if (swapchain_desc->backbuffer_bind_flags && swapchain_desc->backbuffer_bind_flags != WINED3D_BIND_RENDER_TARGET)
|
|
|
|
FIXME("Got unexpected backbuffer bind flags %#x.\n", swapchain_desc->backbuffer_bind_flags);
|
2018-01-25 10:33:27 +01:00
|
|
|
|
2018-02-15 07:05:15 +01:00
|
|
|
if (swapchain_desc->swap_effect != WINED3D_SWAP_EFFECT_DISCARD
|
|
|
|
&& swapchain_desc->swap_effect != WINED3D_SWAP_EFFECT_SEQUENTIAL
|
|
|
|
&& swapchain_desc->swap_effect != WINED3D_SWAP_EFFECT_COPY)
|
|
|
|
FIXME("Unimplemented swap effect %#x.\n", swapchain_desc->swap_effect);
|
|
|
|
|
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.refresh_rate = swapchain_desc->refresh_rate;
|
2013-09-23 10:26:45 +02:00
|
|
|
swapchain->desc.auto_restore_display_mode = swapchain_desc->auto_restore_display_mode;
|
2006-12-08 16:13:15 +01: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
|
|
|
|
2016-08-15 16:00:15 +02:00
|
|
|
backbuffer_resized = swapchain_desc->backbuffer_width != swapchain->desc.backbuffer_width
|
|
|
|
|| swapchain_desc->backbuffer_height != swapchain->desc.backbuffer_height;
|
|
|
|
|
2015-08-07 10:01:33 +02:00
|
|
|
if (!swapchain_desc->windowed != !swapchain->desc.windowed
|
2016-08-01 22:28:35 +02:00
|
|
|
|| swapchain->reapply_mode || mode
|
2016-08-15 16:00:15 +02:00
|
|
|
|| (!swapchain_desc->windowed && backbuffer_resized))
|
2013-04-09 08:48:43 +02:00
|
|
|
{
|
2016-08-01 22:28:35 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_set_fullscreen(swapchain, swapchain_desc, mode)))
|
|
|
|
return hr;
|
2011-11-24 22:52:34 +01:00
|
|
|
}
|
2015-08-07 10:01:33 +02:00
|
|
|
else if (!swapchain_desc->windowed)
|
2011-08-25 21:05:03 +02:00
|
|
|
{
|
2015-08-07 10:01:33 +02:00
|
|
|
DWORD style = device->style;
|
|
|
|
DWORD exStyle = device->exStyle;
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
device->style = 0;
|
|
|
|
device->exStyle = 0;
|
|
|
|
wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
|
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height);
|
|
|
|
device->style = style;
|
|
|
|
device->exStyle = exStyle;
|
2011-08-25 21:05:03 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 10:01:33 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_resize_buffers(swapchain, swapchain_desc->backbuffer_count,
|
|
|
|
swapchain_desc->backbuffer_width, swapchain_desc->backbuffer_height, swapchain_desc->backbuffer_format,
|
|
|
|
swapchain_desc->multisample_type, swapchain_desc->multisample_quality)))
|
|
|
|
return hr;
|
2014-08-22 12:32:01 +02:00
|
|
|
|
2018-11-07 09:01:16 +01:00
|
|
|
if (swapchain_desc->flags != swapchain->desc.flags)
|
|
|
|
{
|
|
|
|
swapchain->desc.flags = swapchain_desc->flags;
|
|
|
|
|
|
|
|
update_swapchain_flags(swapchain->front_buffer);
|
|
|
|
for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
|
|
|
|
{
|
|
|
|
update_swapchain_flags(swapchain->back_buffers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
if ((view = device->auto_depth_stencil_view))
|
2014-08-22 12:32:01 +02:00
|
|
|
{
|
|
|
|
device->auto_depth_stencil_view = NULL;
|
2019-04-12 14:50:47 +02:00
|
|
|
wined3d_rendertarget_view_decref(view);
|
2014-08-22 12:32:01 +02:00
|
|
|
}
|
|
|
|
if (swapchain->desc.enable_auto_depth_stencil)
|
|
|
|
{
|
2015-09-03 20:56:26 +02:00
|
|
|
struct wined3d_resource_desc texture_desc;
|
|
|
|
struct wined3d_texture *texture;
|
2014-08-22 12:32:01 +02:00
|
|
|
|
2016-08-01 22:28:35 +02:00
|
|
|
TRACE("Creating the depth stencil buffer.\n");
|
2014-08-22 12:32:01 +02:00
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.format = swapchain->desc.auto_depth_stencil_format;
|
|
|
|
texture_desc.multisample_type = swapchain->desc.multisample_type;
|
|
|
|
texture_desc.multisample_quality = swapchain->desc.multisample_quality;
|
2018-11-06 11:12:58 +01:00
|
|
|
texture_desc.usage = 0;
|
2018-10-31 10:31:47 +01:00
|
|
|
texture_desc.bind_flags = WINED3D_BIND_DEPTH_STENCIL;
|
2018-02-02 17:58:54 +01:00
|
|
|
texture_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.width = swapchain->desc.backbuffer_width;
|
|
|
|
texture_desc.height = swapchain->desc.backbuffer_height;
|
|
|
|
texture_desc.depth = 1;
|
|
|
|
texture_desc.size = 0;
|
|
|
|
|
|
|
|
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
|
2018-11-07 09:01:15 +01:00
|
|
|
device->device_parent, &texture_desc, 0, &texture)))
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
ERR("Failed to create the auto depth/stencil surface, hr %#x.\n", hr);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2008-01-25 18:04:05 +01:00
|
|
|
}
|
2014-08-22 12:32:01 +02:00
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
view_desc.format_id = texture->resource.format->id;
|
2016-12-05 12:04:41 +01:00
|
|
|
view_desc.flags = 0;
|
2015-09-03 20:56:26 +02:00
|
|
|
view_desc.u.texture.level_idx = 0;
|
2016-12-05 12:04:41 +01:00
|
|
|
view_desc.u.texture.level_count = 1;
|
2015-09-03 20:56:26 +02:00
|
|
|
view_desc.u.texture.layer_idx = 0;
|
|
|
|
view_desc.u.texture.layer_count = 1;
|
|
|
|
hr = wined3d_rendertarget_view_create(&view_desc, &texture->resource,
|
2014-08-22 12:32:01 +02:00
|
|
|
NULL, &wined3d_null_parent_ops, &device->auto_depth_stencil_view);
|
2015-09-03 20:56:26 +02:00
|
|
|
wined3d_texture_decref(texture);
|
2014-08-22 12:32:01 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_device_set_depth_stencil_view(device, device->auto_depth_stencil_view);
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
if ((view = device->back_buffer_view))
|
2014-08-21 09:55:55 +02:00
|
|
|
{
|
|
|
|
device->back_buffer_view = NULL;
|
2019-04-12 14:50:47 +02:00
|
|
|
wined3d_rendertarget_view_decref(view);
|
2014-08-21 09:55:55 +02:00
|
|
|
}
|
2018-10-31 10:31:48 +01:00
|
|
|
if (swapchain->desc.backbuffer_count && swapchain->desc.backbuffer_bind_flags & WINED3D_BIND_RENDER_TARGET)
|
2014-08-21 09:55:55 +02:00
|
|
|
{
|
2016-06-17 10:41:42 +02:00
|
|
|
struct wined3d_resource *back_buffer = &swapchain->back_buffers[0]->resource;
|
|
|
|
|
|
|
|
view_desc.format_id = back_buffer->format->id;
|
2016-12-05 12:04:41 +01:00
|
|
|
view_desc.flags = 0;
|
2016-02-02 19:23:33 +01:00
|
|
|
view_desc.u.texture.level_idx = 0;
|
2016-12-05 12:04:41 +01:00
|
|
|
view_desc.u.texture.level_count = 1;
|
2016-02-02 19:23:33 +01:00
|
|
|
view_desc.u.texture.layer_idx = 0;
|
|
|
|
view_desc.u.texture.layer_count = 1;
|
2016-06-17 10:41:42 +02:00
|
|
|
if (FAILED(hr = wined3d_rendertarget_view_create(&view_desc, back_buffer,
|
2016-02-02 19:23:33 +01:00
|
|
|
NULL, &wined3d_null_parent_ops, &device->back_buffer_view)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2014-08-21 09:55:55 +02:00
|
|
|
}
|
|
|
|
|
2015-01-19 13:44:12 +01:00
|
|
|
wine_rb_clear(&device->samplers, device_free_sampler, NULL);
|
|
|
|
|
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;
|
|
|
|
}
|
2014-01-09 12:16:58 +01:00
|
|
|
wined3d_cs_emit_reset_state(device->cs);
|
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)
|
2019-05-07 12:30:08 +02:00
|
|
|
device->adapter->adapter_ops->adapter_uninit_3d(device);
|
2012-06-26 15:32:10 +02:00
|
|
|
|
2017-02-28 15:22:31 +01:00
|
|
|
memset(&device->state, 0, sizeof(device->state));
|
2018-08-23 14:34:04 +02:00
|
|
|
state_init(&device->state, &device->fb, &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
|
2019-01-28 05:44:52 +01:00
|
|
|
memset(&device->stateblock_state, 0, sizeof(device->stateblock_state));
|
2019-01-29 06:09:15 +01:00
|
|
|
wined3d_stateblock_state_init(&device->stateblock_state, device, WINED3D_STATE_INIT_DEFAULT);
|
2019-01-28 05:44:52 +01:00
|
|
|
device->update_stateblock_state = &device->stateblock_state;
|
2013-09-25 09:58:13 +02:00
|
|
|
|
|
|
|
device_init_swapchain_state(device, swapchain);
|
2017-03-28 23:37:36 +02:00
|
|
|
if (wined3d_settings.logo)
|
|
|
|
device_load_logo(device, wined3d_settings.logo);
|
2012-11-19 22:04:12 +01:00
|
|
|
}
|
2019-04-12 14:50:47 +02:00
|
|
|
else if ((view = device->back_buffer_view))
|
2012-11-19 22:04:12 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
struct wined3d_state *state = &device->state;
|
2008-12-19 19:21:55 +01:00
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
wined3d_device_set_rendertarget_view(device, 0, view, FALSE);
|
|
|
|
|
2012-11-19 22:04:12 +01:00
|
|
|
/* Note the min_z / max_z is not reset. */
|
2018-04-14 11:12:38 +02:00
|
|
|
state->viewports[0].x = 0;
|
|
|
|
state->viewports[0].y = 0;
|
|
|
|
state->viewports[0].width = view->width;
|
|
|
|
state->viewports[0].height = view->height;
|
|
|
|
state->viewport_count = 1;
|
|
|
|
wined3d_cs_emit_set_viewports(device->cs, 1, state->viewports);
|
2012-11-19 22:04:12 +01:00
|
|
|
|
2018-04-23 14:34:03 +02:00
|
|
|
SetRect(&state->scissor_rects[0], 0, 0, view->width, view->height);
|
|
|
|
state->scissor_rect_count = 1;
|
|
|
|
wined3d_cs_emit_set_scissor_rects(device->cs, 1, state->scissor_rects);
|
2012-11-19 22:04:12 +01:00
|
|
|
}
|
2008-03-18 19:31:24 +01:00
|
|
|
|
2019-05-07 12:30:08 +02:00
|
|
|
if (device->d3d_initialized && reset_state)
|
|
|
|
hr = device->adapter->adapter_ops->adapter_init_3d(device);
|
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
|
|
|
}
|
|
|
|
|
2016-02-04 20:10:43 +01:00
|
|
|
struct wined3d * CDECL wined3d_device_get_wined3d(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
return device->wined3d;
|
|
|
|
}
|
|
|
|
|
2018-09-24 01:09:32 +02:00
|
|
|
enum wined3d_feature_level CDECL wined3d_device_get_feature_level(const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
return device->feature_level;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-04-13 00:11:01 +02:00
|
|
|
wined3d_not_from_cs(device->cs);
|
|
|
|
|
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
|
|
|
|
2017-04-13 00:11:01 +02:00
|
|
|
wined3d_not_from_cs(device->cs);
|
|
|
|
|
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;
|
2016-03-29 16:45:33 +02:00
|
|
|
struct wined3d_rendertarget_view *rtv;
|
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
|
|
|
|
2017-01-04 00:04:48 +01:00
|
|
|
if (device->d3d_initialized)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-08-24 15:44:03 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(device->fb.render_targets); ++i)
|
2017-01-04 00:04:48 +01:00
|
|
|
{
|
|
|
|
if ((rtv = device->fb.render_targets[i]) && rtv->resource == resource)
|
|
|
|
ERR("Resource %p is still in use as render target %u.\n", resource, i);
|
|
|
|
}
|
2007-04-09 01:53:27 +02:00
|
|
|
|
2017-01-04 00:04:48 +01:00
|
|
|
if ((rtv = device->fb.depth_stencil) && rtv->resource == resource)
|
|
|
|
ERR("Resource %p is still in use as depth/stencil buffer.\n", resource);
|
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2016-03-29 16:45:33 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2018-04-02 22:58:23 +02:00
|
|
|
case WINED3D_RTYPE_TEXTURE_1D:
|
2016-01-27 00:06:23 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE_2D:
|
2016-01-27 00:06:24 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE_3D:
|
2019-02-20 21:54:00 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_COMBINED_SAMPLERS; ++i)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-03-22 10:52:45 +01:00
|
|
|
if (&device->state.textures[i]->resource == resource)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-03-22 10:52:45 +01:00
|
|
|
ERR("Texture resource %p is still in use, stage %u.\n", resource, i);
|
2013-08-27 08:44:59 +02:00
|
|
|
device->state.textures[i] = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2019-02-05 18:08:54 +01:00
|
|
|
if (device->recording && &device->update_stateblock_state->textures[i]->resource == resource)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-03-22 10:52:45 +01:00
|
|
|
ERR("Texture resource %p is still in use by recording stateblock %p, stage %u.\n",
|
|
|
|
resource, device->recording, i);
|
2019-02-05 18:08:54 +01:00
|
|
|
device->update_stateblock_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:
|
2019-02-20 21:53:56 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_STREAMS; ++i)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-03-22 10:52:45 +01:00
|
|
|
if (&device->state.streams[i].buffer->resource == resource)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-03-22 10:52:45 +01:00
|
|
|
ERR("Buffer resource %p is still in use, stream %u.\n", resource, i);
|
|
|
|
device->state.streams[i].buffer = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2019-02-07 02:38:28 +01:00
|
|
|
if (device->recording && &device->update_stateblock_state->streams[i].buffer->resource == resource)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2018-03-22 10:52:45 +01:00
|
|
|
ERR("Buffer resource %p is still in use by stateblock %p, stream %u.\n",
|
|
|
|
resource, device->recording, i);
|
2019-02-07 02:38:28 +01:00
|
|
|
device->update_stateblock_state->streams[i].buffer = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2018-03-22 10:52:45 +01:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2018-03-22 10:52:45 +01:00
|
|
|
if (&device->state.index_buffer->resource == resource)
|
|
|
|
{
|
|
|
|
ERR("Buffer resource %p is still in use as index buffer.\n", resource);
|
|
|
|
device->state.index_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-07 02:38:25 +01:00
|
|
|
if (device->recording && &device->update_stateblock_state->index_buffer->resource == resource)
|
2018-03-22 10:52:45 +01:00
|
|
|
{
|
|
|
|
ERR("Buffer resource %p is still in use by stateblock %p as index buffer.\n",
|
|
|
|
resource, device->recording);
|
2019-02-07 02:38:25 +01:00
|
|
|
device->update_stateblock_state->index_buffer = NULL;
|
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
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:06 +01:00
|
|
|
static int wined3d_sampler_compare(const void *key, const struct wine_rb_entry *entry)
|
|
|
|
{
|
|
|
|
const struct wined3d_sampler *sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);
|
|
|
|
|
|
|
|
return memcmp(&sampler->desc, key, sizeof(sampler->desc));
|
|
|
|
}
|
|
|
|
|
2018-09-24 01:09:31 +02:00
|
|
|
static BOOL wined3d_select_feature_level(const struct wined3d_adapter *adapter,
|
|
|
|
const enum wined3d_feature_level *levels, unsigned int level_count,
|
|
|
|
enum wined3d_feature_level *selected_level)
|
|
|
|
{
|
|
|
|
const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < level_count; ++i)
|
|
|
|
{
|
|
|
|
if (levels[i] && d3d_info->feature_level >= levels[i])
|
|
|
|
{
|
|
|
|
*selected_level = levels[i];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME_(winediag)("None of the requested D3D feature levels is supported on this GPU "
|
|
|
|
"with the current shader backend.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-18 11:00:20 +02:00
|
|
|
HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
|
|
|
|
unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
|
2018-09-24 01:09:31 +02:00
|
|
|
BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
|
|
|
|
struct wined3d_device_parent *device_parent)
|
2009-11-18 10:45:53 +01:00
|
|
|
{
|
2019-03-22 09:42:05 +01:00
|
|
|
struct wined3d_adapter *adapter = wined3d->adapters[adapter_idx];
|
2013-04-25 12:16:47 +02:00
|
|
|
const struct wined3d_vertex_pipe_ops *vertex_pipeline;
|
2018-09-24 01:09:31 +02:00
|
|
|
const struct fragment_pipeline *fragment_pipeline;
|
2009-11-18 10:45:53 +01:00
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-09-24 01:09:31 +02:00
|
|
|
if (!wined3d_select_feature_level(adapter, levels, level_count, &device->feature_level))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
TRACE("Device feature level %s.\n", wined3d_debug_feature_level(device->feature_level));
|
|
|
|
|
2009-11-18 10:45:53 +01:00
|
|
|
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);
|
2019-02-20 19:26:52 +01:00
|
|
|
device->adapter = adapter;
|
2009-11-18 10:45:53 +01:00
|
|
|
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
|
|
|
|
2016-09-01 10:55:49 +02:00
|
|
|
wine_rb_init(&device->samplers, wined3d_sampler_compare);
|
2015-01-15 17:19:06 +01:00
|
|
|
|
2013-04-25 12:16:47 +02:00
|
|
|
if (vertex_pipeline->vp_states && fragment_pipeline->states
|
2019-03-03 19:55:26 +01:00
|
|
|
&& FAILED(hr = compile_state_table(device->state_table, device->multistate_funcs,
|
2019-03-03 19:55:25 +01:00
|
|
|
&adapter->d3d_info, adapter->gl_info.supported, vertex_pipeline,
|
2013-04-25 15:20:30 +02:00
|
|
|
fragment_pipeline, misc_state_template)))
|
2013-01-16 08:51:47 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to compile state table, hr %#x.\n", hr);
|
2015-01-15 17:19:06 +01:00
|
|
|
wine_rb_destroy(&device->samplers, NULL, NULL);
|
2013-01-16 08:51:47 +01:00
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
return hr;
|
2010-05-06 14:57:21 +02:00
|
|
|
}
|
2013-01-16 08:51:47 +01:00
|
|
|
|
2018-08-23 14:34:04 +02:00
|
|
|
state_init(&device->state, &device->fb, &adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
|
2019-01-29 06:09:15 +01:00
|
|
|
wined3d_stateblock_state_init(&device->stateblock_state, device, WINED3D_STATE_INIT_DEFAULT);
|
2019-01-28 05:44:52 +01:00
|
|
|
device->update_stateblock_state = &device->stateblock_state;
|
2011-12-04 15:50:12 +01:00
|
|
|
|
2018-04-30 20:15:01 +02:00
|
|
|
device->max_frame_latency = 3;
|
|
|
|
|
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);
|
2019-01-28 05:44:52 +01:00
|
|
|
wined3d_stateblock_state_cleanup(&device->stateblock_state);
|
2013-09-27 00:15:13 +02:00
|
|
|
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:
|
2017-10-31 12:10:29 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(device->multistate_funcs); ++i)
|
2013-09-27 00:15:13 +02:00
|
|
|
{
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(device->multistate_funcs[i]);
|
2013-09-27 00:15:13 +02:00
|
|
|
}
|
2015-01-15 17:19:06 +01:00
|
|
|
wine_rb_destroy(&device->samplers, NULL, NULL);
|
2013-09-27 00:15:13 +02:00
|
|
|
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
|
|
|
{
|
2019-03-03 19:55:26 +01:00
|
|
|
DWORD rep = device->state_table[state].representative;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2019-03-03 19:55:26 +01:00
|
|
|
unsigned int i, idx, shift;
|
2006-12-19 13:00:03 +01:00
|
|
|
|
2017-04-13 00:11:01 +02:00
|
|
|
wined3d_from_cs(device->cs);
|
|
|
|
|
2017-02-06 14:12:16 +01:00
|
|
|
if (STATE_IS_COMPUTE(state))
|
|
|
|
{
|
|
|
|
for (i = 0; i < device->context_count; ++i)
|
|
|
|
context_invalidate_compute_state(device->contexts[i], state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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];
|
2019-03-03 19:55:26 +01:00
|
|
|
if (isStateDirty(context, rep)) continue;
|
2007-02-12 19:18:31 +01:00
|
|
|
|
|
|
|
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);
|
2015-08-26 12:46:47 +02:00
|
|
|
context->isStateDirty[idx] |= (1u << shift);
|
2007-02-12 19:18:31 +01:00
|
|
|
}
|
2006-12-19 13:00:03 +01:00
|
|
|
}
|
2007-11-30 20:22:33 +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)
|
|
|
|
{
|
2014-12-04 21:51:49 +01:00
|
|
|
if (device->filter_messages && message != WM_DISPLAYCHANGE)
|
2009-12-22 18:32:13 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2014-06-27 08:26:59 +02:00
|
|
|
else if (message == WM_ACTIVATEAPP)
|
|
|
|
{
|
2018-10-16 19:16:11 +02:00
|
|
|
unsigned int i = device->swapchain_count;
|
2014-11-13 20:39:25 +01:00
|
|
|
|
2018-10-16 19:16:11 +02:00
|
|
|
/* Deactivating the implicit swapchain may cause the application
|
|
|
|
* (e.g. Deus Ex: GOTY) to destroy the device, so take care to
|
|
|
|
* deactivate the implicit swapchain last, and to avoid accessing the
|
|
|
|
* "device" pointer afterwards. */
|
|
|
|
while (i--)
|
2014-11-13 20:39:25 +01:00
|
|
|
wined3d_swapchain_activate(device->swapchains[i], wparam);
|
2014-06-27 08:26:59 +02:00
|
|
|
}
|
2015-01-26 16:03:56 +01:00
|
|
|
else if (message == WM_SYSCOMMAND)
|
|
|
|
{
|
|
|
|
if (wparam == SC_RESTORE && device->wined3d->flags & WINED3D_HANDLE_RESTORE)
|
|
|
|
{
|
|
|
|
if (unicode)
|
|
|
|
DefWindowProcW(window, message, wparam, lparam);
|
|
|
|
else
|
|
|
|
DefWindowProcA(window, message, wparam, lparam);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|