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"
|
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
|
2004-10-07 06:22:21 +02:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
/* Define the default light parameters as specified by MSDN. */
|
|
|
|
const struct wined3d_light WINED3D_default_light =
|
|
|
|
{
|
2011-12-11 21:43:31 +01:00
|
|
|
WINED3D_LIGHT_DIRECTIONAL, /* Type */
|
2009-07-07 11:08:01 +02:00
|
|
|
{ 1.0f, 1.0f, 1.0f, 0.0f }, /* Diffuse r,g,b,a */
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 0.0f }, /* Specular r,g,b,a */
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 0.0f }, /* Ambient r,g,b,a, */
|
|
|
|
{ 0.0f, 0.0f, 0.0f }, /* Position x,y,z */
|
|
|
|
{ 0.0f, 0.0f, 1.0f }, /* Direction x,y,z */
|
|
|
|
0.0f, /* Range */
|
|
|
|
0.0f, /* Falloff */
|
|
|
|
0.0f, 0.0f, 0.0f, /* Attenuation 0,1,2 */
|
|
|
|
0.0f, /* Theta */
|
|
|
|
0.0f /* Phi */
|
2006-06-07 05:37:05 +02:00
|
|
|
};
|
|
|
|
|
2004-10-07 06:22:21 +02:00
|
|
|
/**********************************************************
|
2004-11-28 16:04:41 +01:00
|
|
|
* Global variable / Constants follow
|
2004-10-07 06:22:21 +02:00
|
|
|
**********************************************************/
|
2012-05-03 21:49:38 +02:00
|
|
|
const struct wined3d_matrix identity =
|
|
|
|
{{{
|
2009-07-07 11:08:01 +02:00
|
|
|
1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
2012-05-03 21:49:38 +02:00
|
|
|
}}}; /* When needed for comparisons */
|
2004-10-07 06:22:21 +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. */
|
2011-12-11 21:43:32 +01:00
|
|
|
static GLenum gl_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
|
|
|
switch(primitive_type)
|
|
|
|
{
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_POINTLIST:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_POINTS;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINELIST:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINES;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINESTRIP:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINE_STRIP;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLELIST:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLES;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLESTRIP:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLEFAN:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLE_FAN;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINELIST_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINES_ADJACENCY_ARB;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_LINESTRIP_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_LINE_STRIP_ADJACENCY_ARB;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLELIST_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLES_ADJACENCY_ARB;
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
case WINED3D_PT_TRIANGLESTRIP_ADJ:
|
2009-03-05 12:30:43 +01:00
|
|
|
return GL_TRIANGLE_STRIP_ADJACENCY_ARB;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 21:43:32 +01:00
|
|
|
static enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
|
|
|
switch(primitive_type)
|
|
|
|
{
|
|
|
|
case GL_POINTS:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_POINTLIST;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINES:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINELIST;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINE_STRIP:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINESTRIP;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLES:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLELIST;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLE_STRIP:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLESTRIP;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLE_FAN:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLEFAN;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINES_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINELIST_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_LINE_STRIP_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_LINESTRIP_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLES_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLELIST_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
case GL_TRIANGLE_STRIP_ADJACENCY_ARB:
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_TRIANGLESTRIP_ADJ;
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
|
2011-12-11 21:43:32 +01:00
|
|
|
return WINED3D_PT_UNDEFINED;
|
2009-03-05 12:30:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 10:25:55 +01:00
|
|
|
static BOOL fixed_get_input(BYTE usage, BYTE usage_idx, unsigned int *regnum)
|
|
|
|
{
|
2012-01-18 21:46:22 +01:00
|
|
|
if ((usage == WINED3D_DECL_USAGE_POSITION || usage == WINED3D_DECL_USAGE_POSITIONT) && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_POSITION;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_BLEND_WEIGHT && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_BLENDWEIGHT;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_BLEND_INDICES && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_BLENDINDICES;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_NORMAL && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_NORMAL;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_PSIZE && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_PSIZE;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_COLOR && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_DIFFUSE;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_COLOR && usage_idx == 1)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_SPECULAR;
|
2012-01-18 21:46:22 +01:00
|
|
|
else if (usage == WINED3D_DECL_USAGE_TEXCOORD && usage_idx < WINED3DDP_MAXTEXCOORD)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_TEXCOORD0 + usage_idx;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported input stream [usage=%s, usage_idx=%u]\n", debug_d3ddeclusage(usage), usage_idx);
|
|
|
|
*regnum = ~0U;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2012-04-30 21:30:21 +02:00
|
|
|
void device_stream_info_from_declaration(struct wined3d_device *device, struct wined3d_stream_info *stream_info)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2011-07-26 19:52:42 +02:00
|
|
|
const struct wined3d_state *state = &device->stateBlock->state;
|
2009-03-27 10:25:55 +01:00
|
|
|
/* We need to deal with frequency data! */
|
2011-07-26 19:52:42 +02:00
|
|
|
struct wined3d_vertex_declaration *declaration = state->vertex_declaration;
|
2011-07-26 19:52:43 +02:00
|
|
|
BOOL use_vshader;
|
2009-03-27 10:25:55 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2009-08-27 10:04:53 +02:00
|
|
|
stream_info->use_map = 0;
|
|
|
|
stream_info->swizzle_map = 0;
|
2009-03-27 10:25:55 +01:00
|
|
|
|
|
|
|
/* Check for transformed vertices, disable vertex shader if present. */
|
|
|
|
stream_info->position_transformed = declaration->position_transformed;
|
2011-07-26 19:52:43 +02:00
|
|
|
use_vshader = state->vertex_shader && !declaration->position_transformed;
|
2009-03-27 10:25:55 +01:00
|
|
|
|
|
|
|
/* Translate the declaration into strided data. */
|
2009-03-27 10:25:56 +01:00
|
|
|
for (i = 0; i < declaration->element_count; ++i)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
const struct wined3d_vertex_declaration_element *element = &declaration->elements[i];
|
2011-07-26 19:52:42 +02:00
|
|
|
const struct wined3d_stream_state *stream = &state->streams[element->input_slot];
|
2011-07-15 01:14:50 +02:00
|
|
|
struct wined3d_buffer *buffer = stream->buffer;
|
2011-07-11 01:06:44 +02:00
|
|
|
struct wined3d_bo_address data;
|
2009-03-27 10:25:55 +01:00
|
|
|
BOOL stride_used;
|
|
|
|
unsigned int idx;
|
|
|
|
DWORD stride;
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
TRACE("%p Element %p (%u of %u)\n", declaration->elements,
|
|
|
|
element, i + 1, declaration->element_count);
|
2009-03-27 10:25:55 +01:00
|
|
|
|
2010-09-14 13:38:41 +02:00
|
|
|
if (!buffer) continue;
|
2009-03-27 10:25:55 +01:00
|
|
|
|
2011-07-11 01:06:44 +02:00
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = NULL;
|
|
|
|
|
2011-07-15 01:14:50 +02:00
|
|
|
stride = stream->stride;
|
2011-07-26 19:52:42 +02:00
|
|
|
if (state->user_stream)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
TRACE("Stream %u is UP, %p\n", element->input_slot, buffer);
|
2011-07-11 01:06:44 +02:00
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = (BYTE *)buffer;
|
2009-03-27 10:25:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
TRACE("Stream %u isn't UP, %p\n", element->input_slot, buffer);
|
2011-07-11 01:06:45 +02:00
|
|
|
buffer_get_memory(buffer, &device->adapter->gl_info, &data);
|
2009-03-27 10:25:55 +01:00
|
|
|
|
|
|
|
/* Can't use vbo's if the base vertex index is negative. OpenGL doesn't accept negative offsets
|
|
|
|
* (or rather offsets bigger than the vbo, because the pointer is unsigned), so use system memory
|
|
|
|
* sources. In most sane cases the pointer - offset will still be > 0, otherwise it will wrap
|
|
|
|
* around to some big value. Hope that with the indices, the driver wraps it back internally. If
|
|
|
|
* not, drawStridedSlow is needed, including a vertex buffer path. */
|
2011-07-26 19:52:42 +02:00
|
|
|
if (state->load_base_vertex_index < 0)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2010-09-20 19:41:24 +02:00
|
|
|
WARN("load_base_vertex_index is < 0 (%d), not using VBOs.\n",
|
2011-07-26 19:52:42 +02:00
|
|
|
state->load_base_vertex_index);
|
2011-07-11 01:06:44 +02:00
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info);
|
2011-07-26 19:52:42 +02:00
|
|
|
if ((UINT_PTR)data.addr < -state->load_base_vertex_index * stride)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
|
|
|
FIXME("System memory vertex data load offset is negative!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-11 01:06:44 +02:00
|
|
|
data.addr += element->offset;
|
2009-03-27 10:25:55 +01:00
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
TRACE("offset %u input_slot %u usage_idx %d\n", element->offset, element->input_slot, element->usage_idx);
|
2009-03-27 10:25:55 +01:00
|
|
|
|
|
|
|
if (use_vshader)
|
|
|
|
{
|
2009-03-30 11:24:54 +02:00
|
|
|
if (element->output_slot == ~0U)
|
|
|
|
{
|
|
|
|
/* TODO: Assuming vertexdeclarations are usually used with the
|
|
|
|
* same or a similar shader, it might be worth it to store the
|
|
|
|
* last used output slot and try that one first. */
|
2011-07-26 19:52:42 +02:00
|
|
|
stride_used = vshader_get_input(state->vertex_shader,
|
2009-03-30 11:24:54 +02:00
|
|
|
element->usage, element->usage_idx, &idx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = element->output_slot;
|
|
|
|
stride_used = TRUE;
|
|
|
|
}
|
2009-03-27 10:25:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
if (!element->ffp_valid)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
WARN("Skipping unsupported fixed function element of format %s and usage %s\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
debug_d3dformat(element->format->id), debug_d3ddeclusage(element->usage));
|
2009-03-27 10:25:55 +01:00
|
|
|
stride_used = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-27 10:25:56 +01:00
|
|
|
stride_used = fixed_get_input(element->usage, element->usage_idx, &idx);
|
2009-03-27 10:25:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stride_used)
|
|
|
|
{
|
|
|
|
TRACE("Load %s array %u [usage %s, usage_idx %u, "
|
2009-03-27 10:25:56 +01:00
|
|
|
"input_slot %u, offset %u, stride %u, format %s, buffer_object %u]\n",
|
2009-03-27 10:25:55 +01:00
|
|
|
use_vshader ? "shader": "fixed function", idx,
|
2009-03-27 10:25:56 +01:00
|
|
|
debug_d3ddeclusage(element->usage), element->usage_idx, element->input_slot,
|
2011-07-11 01:06:44 +02:00
|
|
|
element->offset, stride, debug_d3dformat(element->format->id), data.buffer_object);
|
2009-03-27 10:25:56 +01:00
|
|
|
|
2011-07-15 01:14:50 +02:00
|
|
|
data.addr += stream->offset;
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
stream_info->elements[idx].format = element->format;
|
2011-07-11 01:06:46 +02:00
|
|
|
stream_info->elements[idx].data = data;
|
2009-03-27 10:25:55 +01:00
|
|
|
stream_info->elements[idx].stride = stride;
|
2009-03-27 10:25:56 +01:00
|
|
|
stream_info->elements[idx].stream_idx = element->input_slot;
|
2009-03-27 10:25:55 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->adapter->gl_info.supported[ARB_VERTEX_ARRAY_BGRA]
|
2010-08-30 20:29:49 +02:00
|
|
|
&& element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
|
|
|
stream_info->swizzle_map |= 1 << idx;
|
|
|
|
}
|
|
|
|
stream_info->use_map |= 1 << idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->num_buffer_queries = 0;
|
2011-07-26 19:52:42 +02:00
|
|
|
if (!state->user_stream)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2010-02-16 09:50:39 +01:00
|
|
|
WORD map = stream_info->use_map;
|
2012-04-30 21:30:21 +02:00
|
|
|
stream_info->all_vbo = 1;
|
2010-02-16 09:50:39 +01:00
|
|
|
|
|
|
|
/* PreLoad all the vertex buffers. */
|
|
|
|
for (i = 0; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_stream_info_element *element;
|
|
|
|
struct wined3d_buffer *buffer;
|
|
|
|
|
|
|
|
if (!(map & 1)) continue;
|
|
|
|
|
|
|
|
element = &stream_info->elements[i];
|
2011-07-26 19:52:42 +02:00
|
|
|
buffer = state->streams[element->stream_idx].buffer;
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_preload(buffer);
|
2010-02-16 09:50:39 +01:00
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
/* If the preload dropped the buffer object, update the stream info. */
|
|
|
|
if (buffer->buffer_object != element->data.buffer_object)
|
2010-02-16 09:50:39 +01:00
|
|
|
{
|
2011-07-11 01:06:46 +02:00
|
|
|
element->data.buffer_object = 0;
|
|
|
|
element->data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info)
|
|
|
|
+ (ptrdiff_t)element->data.addr;
|
2010-02-16 09:50:39 +01:00
|
|
|
}
|
2010-03-21 13:26:36 +01:00
|
|
|
|
2012-04-30 21:30:21 +02:00
|
|
|
if (!buffer->buffer_object)
|
|
|
|
stream_info->all_vbo = 0;
|
2012-03-28 20:22:38 +02:00
|
|
|
|
2010-09-14 13:38:41 +02:00
|
|
|
if (buffer->query)
|
2011-05-16 23:01:23 +02:00
|
|
|
device->buffer_queries[device->num_buffer_queries++] = buffer->query;
|
2010-02-16 09:50:39 +01:00
|
|
|
}
|
2009-03-27 10:25:55 +01:00
|
|
|
}
|
2012-04-30 21:30:21 +02:00
|
|
|
else
|
2012-03-28 20:22:38 +02:00
|
|
|
{
|
2012-04-30 21:30:21 +02:00
|
|
|
stream_info->all_vbo = 0;
|
2012-03-28 20:22:38 +02:00
|
|
|
}
|
2009-03-27 10:25:55 +01:00
|
|
|
}
|
|
|
|
|
2009-10-29 10:37:12 +01:00
|
|
|
static void stream_info_element_from_strided(const struct wined3d_gl_info *gl_info,
|
2011-12-06 22:57:48 +01:00
|
|
|
const struct wined3d_strided_element *strided, struct wined3d_stream_info_element *e)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2011-12-06 22:57:48 +01:00
|
|
|
e->data.addr = strided->data;
|
2011-07-11 01:06:46 +02:00
|
|
|
e->data.buffer_object = 0;
|
2010-08-30 20:29:49 +02:00
|
|
|
e->format = wined3d_get_format(gl_info, strided->format);
|
2011-12-06 22:57:48 +01:00
|
|
|
e->stride = strided->stride;
|
2009-03-27 10:25:55 +01:00
|
|
|
e->stream_idx = 0;
|
|
|
|
}
|
|
|
|
|
2010-02-03 11:02:22 +01:00
|
|
|
static void device_stream_info_from_strided(const struct wined3d_gl_info *gl_info,
|
2011-12-07 22:08:58 +01:00
|
|
|
const struct wined3d_strided_data *strided, struct wined3d_stream_info *stream_info)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
memset(stream_info, 0, sizeof(*stream_info));
|
|
|
|
|
2011-12-06 22:57:48 +01:00
|
|
|
if (strided->position.data)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->position, &stream_info->elements[WINED3D_FFP_POSITION]);
|
2011-12-06 22:57:48 +01:00
|
|
|
if (strided->normal.data)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->normal, &stream_info->elements[WINED3D_FFP_NORMAL]);
|
2011-12-06 22:57:48 +01:00
|
|
|
if (strided->diffuse.data)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->diffuse, &stream_info->elements[WINED3D_FFP_DIFFUSE]);
|
2011-12-06 22:57:48 +01:00
|
|
|
if (strided->specular.data)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->specular, &stream_info->elements[WINED3D_FFP_SPECULAR]);
|
2009-03-27 10:25:55 +01:00
|
|
|
|
|
|
|
for (i = 0; i < WINED3DDP_MAXTEXCOORD; ++i)
|
|
|
|
{
|
2011-12-07 22:08:58 +01:00
|
|
|
if (strided->tex_coords[i].data)
|
|
|
|
stream_info_element_from_strided(gl_info, &strided->tex_coords[i],
|
2009-03-27 10:25:55 +01:00
|
|
|
&stream_info->elements[WINED3D_FFP_TEXCOORD0 + i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_info->position_transformed = strided->position_transformed;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(stream_info->elements) / sizeof(*stream_info->elements); ++i)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
if (!stream_info->elements[i].format) continue;
|
2009-04-09 09:58:27 +02:00
|
|
|
|
2010-01-25 19:51:31 +01:00
|
|
|
if (!gl_info->supported[ARB_VERTEX_ARRAY_BGRA]
|
2010-08-30 20:29:49 +02:00
|
|
|
&& stream_info->elements[i].format->id == WINED3DFMT_B8G8R8A8_UNORM)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
|
|
|
stream_info->swizzle_map |= 1 << i;
|
|
|
|
}
|
|
|
|
stream_info->use_map |= 1 << i;
|
|
|
|
}
|
|
|
|
}
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2010-02-03 11:02:22 +01:00
|
|
|
static void device_trace_strided_stream_info(const struct wined3d_stream_info *stream_info)
|
|
|
|
{
|
|
|
|
TRACE("Strided Data:\n");
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_POSITION);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_BLENDWEIGHT);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_BLENDINDICES);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_NORMAL);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_PSIZE);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_DIFFUSE);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_SPECULAR);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD0);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD1);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD2);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD3);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD4);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD5);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD6);
|
|
|
|
TRACE_STRIDED(stream_info, WINED3D_FFP_TEXCOORD7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_update_stream_info(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
|
2010-02-03 11:02:22 +01:00
|
|
|
{
|
|
|
|
struct wined3d_stream_info *stream_info = &device->strided_streams;
|
2010-09-28 12:00:22 +02:00
|
|
|
const struct wined3d_state *state = &device->stateBlock->state;
|
2012-05-02 21:47:58 +02:00
|
|
|
DWORD prev_all_vbo = stream_info->all_vbo;
|
2010-02-03 11:02:22 +01:00
|
|
|
|
|
|
|
if (device->up_strided)
|
|
|
|
{
|
|
|
|
/* Note: this is a ddraw fixed-function code path. */
|
|
|
|
TRACE("=============================== Strided Input ================================\n");
|
|
|
|
device_stream_info_from_strided(gl_info, device->up_strided, stream_info);
|
|
|
|
if (TRACE_ON(d3d)) device_trace_strided_stream_info(stream_info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("============================= Vertex Declaration =============================\n");
|
2012-04-30 21:30:21 +02:00
|
|
|
device_stream_info_from_declaration(device, stream_info);
|
2010-02-03 11:02:22 +01:00
|
|
|
}
|
|
|
|
|
2010-09-28 12:00:22 +02:00
|
|
|
if (state->vertex_shader && !stream_info->position_transformed)
|
2010-02-03 11:02:22 +01:00
|
|
|
{
|
2012-04-30 21:30:21 +02:00
|
|
|
if (state->vertex_declaration->half_float_conv_needed && !stream_info->all_vbo)
|
2010-02-03 11:02:22 +01:00
|
|
|
{
|
|
|
|
TRACE("Using drawStridedSlow with vertex shaders for FLOAT16 conversion.\n");
|
|
|
|
device->useDrawStridedSlow = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device->useDrawStridedSlow = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WORD slow_mask = (1 << WINED3D_FFP_PSIZE);
|
|
|
|
slow_mask |= -!gl_info->supported[ARB_VERTEX_ARRAY_BGRA]
|
|
|
|
& ((1 << WINED3D_FFP_DIFFUSE) | (1 << WINED3D_FFP_SPECULAR));
|
|
|
|
|
2012-04-30 21:30:21 +02:00
|
|
|
if ((stream_info->position_transformed || (stream_info->use_map & slow_mask)) && !stream_info->all_vbo)
|
2010-02-03 11:02:22 +01:00
|
|
|
{
|
|
|
|
device->useDrawStridedSlow = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device->useDrawStridedSlow = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-05-02 21:47:58 +02:00
|
|
|
|
|
|
|
if (state->index_buffer && !state->user_stream)
|
|
|
|
{
|
|
|
|
if (prev_all_vbo != stream_info->all_vbo)
|
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
|
|
|
if (stream_info->all_vbo)
|
|
|
|
wined3d_buffer_preload(state->index_buffer);
|
|
|
|
else
|
|
|
|
buffer_get_sysmem(state->index_buffer, gl_info);
|
|
|
|
}
|
2010-02-03 11:02:22 +01:00
|
|
|
}
|
|
|
|
|
2010-09-30 11:44:27 +02:00
|
|
|
static void device_preload_texture(const struct wined3d_state *state, unsigned int idx)
|
2010-02-03 11:02:21 +01:00
|
|
|
{
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *texture;
|
2010-02-03 11:02:21 +01:00
|
|
|
enum WINED3DSRGB srgb;
|
|
|
|
|
2010-09-30 11:44:27 +02:00
|
|
|
if (!(texture = state->textures[idx])) return;
|
2012-01-08 21:14:59 +01:00
|
|
|
srgb = state->sampler_states[idx][WINED3D_SAMP_SRGB_TEXTURE] ? SRGB_SRGB : SRGB_RGB;
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_ops->texture_preload(texture, srgb);
|
2010-02-03 11:02:21 +01:00
|
|
|
}
|
|
|
|
|
2011-07-06 23:14:24 +02:00
|
|
|
void device_preload_textures(const struct wined3d_device *device)
|
2010-02-03 11:02:21 +01:00
|
|
|
{
|
2010-09-30 11:44:27 +02:00
|
|
|
const struct wined3d_state *state = &device->stateBlock->state;
|
2010-02-03 11:02:21 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2010-09-28 12:00:23 +02:00
|
|
|
if (use_vs(state))
|
2010-02-03 11:02:21 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
|
|
|
|
{
|
2011-03-30 20:49:24 +02:00
|
|
|
if (state->vertex_shader->reg_maps.sampler_type[i])
|
2010-09-30 11:44:27 +02:00
|
|
|
device_preload_texture(state, MAX_FRAGMENT_SAMPLERS + i);
|
2010-02-03 11:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-28 12:00:24 +02:00
|
|
|
if (use_ps(state))
|
2010-02-03 11:02:21 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
|
|
|
|
{
|
2011-03-30 20:49:24 +02:00
|
|
|
if (state->pixel_shader->reg_maps.sampler_type[i])
|
2010-09-30 11:44:27 +02:00
|
|
|
device_preload_texture(state, i);
|
2010-02-03 11:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WORD ffu_map = device->fixed_function_usage_map;
|
|
|
|
|
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (ffu_map & 1)
|
2010-09-30 11:44:27 +02:00
|
|
|
device_preload_texture(state, i);
|
2010-02-03 11:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context **new_array;
|
|
|
|
|
|
|
|
TRACE("Adding context %p.\n", context);
|
|
|
|
|
|
|
|
if (!device->contexts) new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
|
2011-03-30 20:49:27 +02:00
|
|
|
else new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts,
|
|
|
|
sizeof(*new_array) * (device->context_count + 1));
|
2010-03-14 21:53:25 +01:00
|
|
|
|
|
|
|
if (!new_array)
|
|
|
|
{
|
|
|
|
ERR("Failed to grow the context array.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
new_array[device->context_count++] = context;
|
2010-03-14 21:53:25 +01:00
|
|
|
device->contexts = new_array;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_context_remove(struct wined3d_device *device, struct wined3d_context *context)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context **new_array;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("Removing context %p.\n", context);
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
if (device->contexts[i] == context)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
ERR("Context %p doesn't exist in context array.\n", context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
if (!--device->context_count)
|
2010-03-14 21:53:25 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->contexts);
|
|
|
|
device->contexts = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
memmove(&device->contexts[i], &device->contexts[i + 1], (device->context_count - i) * sizeof(*device->contexts));
|
|
|
|
new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts, device->context_count * sizeof(*device->contexts));
|
2010-03-14 21:53:25 +01:00
|
|
|
if (!new_array)
|
|
|
|
{
|
|
|
|
ERR("Failed to shrink context array. Oh well.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->contexts = new_array;
|
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_switch_onscreen_ds(struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_context *context, struct wined3d_surface *depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
|
|
|
if (device->onscreen_depth_stencil)
|
|
|
|
{
|
2012-01-09 15:52:44 +01:00
|
|
|
surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_INTEXTURE);
|
|
|
|
|
|
|
|
surface_modify_ds_location(device->onscreen_depth_stencil, SFLAG_INTEXTURE,
|
2010-04-29 00:08:59 +02:00
|
|
|
device->onscreen_depth_stencil->ds_current_size.cx,
|
|
|
|
device->onscreen_depth_stencil->ds_current_size.cy);
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_decref(device->onscreen_depth_stencil);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
|
|
|
device->onscreen_depth_stencil = depth_stencil;
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_incref(device->onscreen_depth_stencil);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
2010-03-14 21:53:25 +01:00
|
|
|
|
2011-08-28 23:27:46 +02:00
|
|
|
static BOOL is_full_clear(const struct wined3d_surface *target, const RECT *draw_rect, const RECT *clear_rect)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
/* partial draw rect */
|
|
|
|
if (draw_rect->left || draw_rect->top
|
2011-03-08 19:41:07 +01:00
|
|
|
|| draw_rect->right < target->resource.width
|
|
|
|
|| draw_rect->bottom < target->resource.height)
|
2010-07-23 11:31:03 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* partial clear rect */
|
|
|
|
if (clear_rect && (clear_rect->left > 0 || clear_rect->top > 0
|
2011-03-08 19:41:07 +01:00
|
|
|
|| clear_rect->right < target->resource.width
|
|
|
|
|| clear_rect->bottom < target->resource.height))
|
2010-07-23 11:31:03 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
static void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context *context,
|
2012-01-12 17:05:19 +01:00
|
|
|
DWORD location, const RECT *draw_rect, UINT rect_count, const RECT *clear_rect, RECT *out_rect)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
RECT current_rect, r;
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (ds->flags & location)
|
2010-07-23 11:31:03 +02:00
|
|
|
SetRect(¤t_rect, 0, 0,
|
|
|
|
ds->ds_current_size.cx,
|
|
|
|
ds->ds_current_size.cy);
|
|
|
|
else
|
|
|
|
SetRectEmpty(¤t_rect);
|
|
|
|
|
|
|
|
IntersectRect(&r, draw_rect, ¤t_rect);
|
|
|
|
if (EqualRect(&r, draw_rect))
|
|
|
|
{
|
|
|
|
/* current_rect ⊇ draw_rect, modify only. */
|
2012-01-12 17:05:19 +01:00
|
|
|
SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
2010-07-23 11:31:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EqualRect(&r, ¤t_rect))
|
|
|
|
{
|
|
|
|
/* draw_rect ⊇ current_rect, test if we're doing a full clear. */
|
|
|
|
|
|
|
|
if (!clear_rect)
|
|
|
|
{
|
|
|
|
/* Full clear, modify only. */
|
2012-01-12 17:05:19 +01:00
|
|
|
*out_rect = *draw_rect;
|
2010-07-23 11:31:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntersectRect(&r, draw_rect, clear_rect);
|
|
|
|
if (EqualRect(&r, draw_rect))
|
|
|
|
{
|
|
|
|
/* clear_rect ⊇ draw_rect, modify only. */
|
2012-01-12 17:05:19 +01:00
|
|
|
*out_rect = *draw_rect;
|
2010-07-23 11:31:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Full load. */
|
|
|
|
surface_load_ds_location(ds, context, location);
|
2012-01-12 17:05:19 +01:00
|
|
|
SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2012-04-15 18:57:14 +02:00
|
|
|
void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb,
|
2011-11-15 21:18:27 +01:00
|
|
|
UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags, const struct wined3d_color *color,
|
2011-06-27 18:23:13 +02:00
|
|
|
float depth, DWORD stencil)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
const RECT *clear_rect = (rect_count > 0 && rects) ? (const RECT *)rects : NULL;
|
2011-06-27 18:23:13 +02:00
|
|
|
struct wined3d_surface *target = rt_count ? fb->render_targets[0] : NULL;
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT drawable_width, drawable_height;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
GLbitfield clear_mask = 0;
|
2011-04-05 19:01:30 +02:00
|
|
|
BOOL render_offscreen;
|
2010-07-23 11:31:03 +02:00
|
|
|
unsigned int i;
|
2012-01-12 17:05:19 +01:00
|
|
|
RECT ds_rect;
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
/* When we're clearing parts of the drawable, make sure that the target surface is well up to date in the
|
|
|
|
* drawable. After the clear we'll mark the drawable up to date, so we have to make sure that this is true
|
|
|
|
* for the cleared parts, and the untouched parts.
|
|
|
|
*
|
|
|
|
* If we're clearing the whole target there is no need to copy it into the drawable, it will be overwritten
|
|
|
|
* anyway. If we're not clearing the color buffer we don't have to copy either since we're not going to set
|
|
|
|
* the drawable up to date. We have to check all settings that limit the clear area though. Do not bother
|
|
|
|
* checking all this if the dest surface is in the drawable anyway. */
|
2010-08-23 18:28:06 +02:00
|
|
|
if (flags & WINED3DCLEAR_TARGET && !is_full_clear(target, draw_rect, clear_rect))
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2011-08-23 20:08:10 +02:00
|
|
|
struct wined3d_surface *rt = fb->render_targets[i];
|
|
|
|
if (rt)
|
|
|
|
surface_load_location(rt, rt->draw_binding, NULL);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context = context_acquire(device, target);
|
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping clear.\n");
|
2012-04-15 18:57:14 +02:00
|
|
|
return;
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
render_offscreen = context->render_offscreen;
|
|
|
|
target->get_drawable_size(context, &drawable_width, &drawable_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-11 20:55:13 +02:00
|
|
|
render_offscreen = TRUE;
|
2011-06-27 18:23:13 +02:00
|
|
|
drawable_width = fb->depth_stencil->pow2Width;
|
|
|
|
drawable_height = fb->depth_stencil->pow2Height;
|
2011-04-05 19:01:30 +02:00
|
|
|
}
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2011-07-31 17:33:41 +02:00
|
|
|
if (flags & WINED3DCLEAR_ZBUFFER)
|
|
|
|
{
|
2012-01-09 15:52:44 +01:00
|
|
|
DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
|
2011-07-31 17:33:41 +02:00
|
|
|
|
2012-01-09 15:52:44 +01:00
|
|
|
if (!render_offscreen && fb->depth_stencil != device->onscreen_depth_stencil)
|
2011-07-31 17:33:41 +02:00
|
|
|
device_switch_onscreen_ds(device, context, fb->depth_stencil);
|
2012-01-12 17:05:19 +01:00
|
|
|
prepare_ds_clear(fb->depth_stencil, context, location,
|
|
|
|
draw_rect, rect_count, clear_rect, &ds_rect);
|
2011-07-31 17:33:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!context_apply_clear_state(context, device, rt_count, fb))
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Failed to apply clear state, skipping clear.\n");
|
2012-04-15 18:57:14 +02:00
|
|
|
return;
|
2011-07-31 17:33:41 +02:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:31:03 +02:00
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
/* Only set the values up once, as they are not changing. */
|
|
|
|
if (flags & WINED3DCLEAR_STENCIL)
|
|
|
|
{
|
|
|
|
if (context->gl_info->supported[EXT_STENCIL_TWO_SIDE])
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
glStencilMask(~0U);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
|
2010-07-23 11:31:03 +02:00
|
|
|
glClearStencil(stencil);
|
|
|
|
checkGLcall("glClearStencil");
|
|
|
|
clear_mask = clear_mask | GL_STENCIL_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3DCLEAR_ZBUFFER)
|
|
|
|
{
|
2012-01-09 15:52:44 +01:00
|
|
|
DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
|
|
|
|
|
2012-01-12 17:05:19 +01:00
|
|
|
surface_modify_ds_location(fb->depth_stencil, location, ds_rect.right, ds_rect.bottom);
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
glDepthMask(GL_TRUE);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE));
|
2010-07-23 11:31:03 +02:00
|
|
|
glClearDepth(depth);
|
|
|
|
checkGLcall("glClearDepth");
|
|
|
|
clear_mask = clear_mask | GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3DCLEAR_TARGET)
|
|
|
|
{
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2011-08-23 20:08:10 +02:00
|
|
|
struct wined3d_surface *rt = fb->render_targets[i];
|
|
|
|
|
|
|
|
if (rt)
|
|
|
|
surface_modify_location(rt, rt->draw_binding, TRUE);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2010-08-22 23:35:41 +02:00
|
|
|
glClearColor(color->r, color->g, color->b, color->a);
|
2010-07-23 11:31:03 +02:00
|
|
|
checkGLcall("glClearColor");
|
|
|
|
clear_mask = clear_mask | GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clear_rect)
|
|
|
|
{
|
2011-04-05 19:01:30 +02:00
|
|
|
if (render_offscreen)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2010-08-23 18:28:06 +02:00
|
|
|
glScissor(draw_rect->left, draw_rect->top,
|
|
|
|
draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-23 18:28:06 +02:00
|
|
|
glScissor(draw_rect->left, drawable_height - draw_rect->bottom,
|
|
|
|
draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
checkGLcall("glScissor");
|
|
|
|
glClear(clear_mask);
|
|
|
|
checkGLcall("glClear");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT current_rect;
|
|
|
|
|
|
|
|
/* Now process each rect in turn. */
|
|
|
|
for (i = 0; i < rect_count; ++i)
|
|
|
|
{
|
|
|
|
/* Note that GL uses lower left, width/height. */
|
2010-08-23 18:28:06 +02:00
|
|
|
IntersectRect(¤t_rect, draw_rect, &clear_rect[i]);
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
TRACE("clear_rect[%u] %s, current_rect %s.\n", i,
|
|
|
|
wine_dbgstr_rect(&clear_rect[i]),
|
|
|
|
wine_dbgstr_rect(¤t_rect));
|
|
|
|
|
|
|
|
/* Tests show that rectangles where x1 > x2 or y1 > y2 are ignored silently.
|
2011-08-02 22:20:32 +02:00
|
|
|
* The rectangle is not cleared, no error is returned, but further rectangles are
|
2010-07-23 11:31:03 +02:00
|
|
|
* still cleared if they are valid. */
|
|
|
|
if (current_rect.left > current_rect.right || current_rect.top > current_rect.bottom)
|
|
|
|
{
|
|
|
|
TRACE("Rectangle with negative dimensions, ignoring.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (render_offscreen)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
|
|
|
glScissor(current_rect.left, current_rect.top,
|
|
|
|
current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glScissor(current_rect.left, drawable_height - current_rect.bottom,
|
|
|
|
current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
|
|
|
|
}
|
|
|
|
checkGLcall("glScissor");
|
|
|
|
|
|
|
|
glClear(clear_mask);
|
|
|
|
checkGLcall("glClear");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2011-04-05 19:01:30 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering || (flags & WINED3DCLEAR_TARGET
|
|
|
|
&& target->container.type == WINED3D_CONTAINER_SWAPCHAIN
|
2010-08-16 20:00:25 +02:00
|
|
|
&& target->container.u.swapchain->front_buffer == target))
|
2010-07-23 11:31:03 +02:00
|
|
|
wglFlush(); /* Flush to ensure ordering across contexts. */
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG CDECL wined3d_device_incref(struct wined3d_device *device)
|
2005-03-02 13:16:10 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&device->ref);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", device, refcount);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
return refcount;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&device->ref);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", device, refcount);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!refcount)
|
|
|
|
{
|
2011-12-04 15:50:12 +01:00
|
|
|
struct wined3d_stateblock *stateblock;
|
2009-01-07 02:20:08 +01:00
|
|
|
UINT i;
|
|
|
|
|
2011-12-04 15:50:12 +01:00
|
|
|
if (wined3d_stateblock_decref(device->updateStateBlock)
|
|
|
|
&& device->updateStateBlock != device->stateBlock)
|
|
|
|
FIXME("Something's still holding the update stateblock.\n");
|
|
|
|
device->updateStateBlock = NULL;
|
|
|
|
|
|
|
|
stateblock = device->stateBlock;
|
|
|
|
device->stateBlock = NULL;
|
|
|
|
if (wined3d_stateblock_decref(stateblock))
|
|
|
|
FIXME("Something's still holding the stateblock.\n");
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
|
|
|
|
device->multistate_funcs[i] = NULL;
|
2009-01-07 02:20:08 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!list_empty(&device->resources))
|
2010-04-04 19:51:38 +02:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2010-04-04 19:51:38 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
FIXME("Device released with resources still bound, acceptable but unexpected.\n");
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
|
2010-04-04 19:51:38 +02:00
|
|
|
{
|
|
|
|
FIXME("Leftover resource %p with type %s (%#x).\n",
|
2012-01-17 21:13:36 +01:00
|
|
|
resource, debug_d3dresourcetype(resource->type), resource->type);
|
2010-04-04 19:51:38 +02:00
|
|
|
}
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->contexts)
|
|
|
|
ERR("Context array not freed!\n");
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
DestroyCursor(device->hardwareCursor);
|
2011-05-16 20:13:13 +02:00
|
|
|
device->hardwareCursor = 0;
|
2005-09-23 12:07:46 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
device->wined3d = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, device);
|
|
|
|
TRACE("Freed device %p.\n", device);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
|
|
|
|
return refcount;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-08-28 23:27:47 +02:00
|
|
|
UINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *device)
|
2011-04-06 19:17:53 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-04-06 19:17:53 +02:00
|
|
|
|
|
|
|
return device->swapchain_count;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-08-28 23:27:48 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_swapchain(const struct wined3d_device *device,
|
2011-04-13 19:14:32 +02:00
|
|
|
UINT swapchain_idx, struct wined3d_swapchain **swapchain)
|
2011-04-06 19:17:53 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, swapchain %p.\n",
|
|
|
|
device, swapchain_idx, swapchain);
|
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);
|
|
|
|
*swapchain = NULL;
|
|
|
|
|
2006-05-24 11:34:30 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-27 17:33:17 +02:00
|
|
|
}
|
2011-04-13 19:14:32 +02:00
|
|
|
|
|
|
|
*swapchain = device->swapchains[swapchain_idx];
|
|
|
|
wined3d_swapchain_incref(*swapchain);
|
|
|
|
TRACE("Returning %p.\n", *swapchain);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
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;
|
2007-09-01 21:22:32 +02:00
|
|
|
HBITMAP hbm;
|
|
|
|
BITMAP bm;
|
|
|
|
HRESULT hr;
|
|
|
|
HDC dcb = NULL, dcs = NULL;
|
|
|
|
|
2009-02-03 09:36:07 +01:00
|
|
|
hbm = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
|
2007-09-01 21:22:32 +02:00
|
|
|
if(hbm)
|
|
|
|
{
|
|
|
|
GetObjectA(hbm, sizeof(BITMAP), &bm);
|
|
|
|
dcb = CreateCompatibleDC(NULL);
|
|
|
|
if(!dcb) goto out;
|
|
|
|
SelectObject(dcb, hbm);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Create a 32x32 white surface to indicate that wined3d is used, but the specified image
|
|
|
|
* couldn't be loaded
|
|
|
|
*/
|
|
|
|
memset(&bm, 0, sizeof(bm));
|
|
|
|
bm.bmWidth = 32;
|
|
|
|
bm.bmHeight = 32;
|
|
|
|
}
|
|
|
|
|
2011-11-30 06:01:45 +01:00
|
|
|
hr = wined3d_surface_create(device, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, 0, 0,
|
2012-01-20 00:36:28 +01:00
|
|
|
WINED3D_POOL_DEFAULT, WINED3D_MULTISAMPLE_NONE, 0, WINED3D_SURFACE_TYPE_OPENGL, WINED3D_SURFACE_MAPPABLE,
|
2011-11-30 06:01:45 +01:00
|
|
|
NULL, &wined3d_null_parent_ops, &device->logo_surface);
|
2010-08-31 18:41:40 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Wine logo requested, but failed to create surface, hr %#x.\n", hr);
|
2007-09-01 21:22:32 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
if (dcb)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr = wined3d_surface_getdc(device->logo_surface, &dcs)))
|
2011-04-29 13:03:41 +02:00
|
|
|
goto out;
|
2007-09-01 21:22:32 +02:00
|
|
|
BitBlt(dcs, 0, 0, bm.bmWidth, bm.bmHeight, dcb, 0, 0, SRCCOPY);
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_surface_releasedc(device->logo_surface, dcs);
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2011-12-07 22:08:59 +01:00
|
|
|
color_key.color_space_low_value = 0;
|
|
|
|
color_key.color_space_high_value = 0;
|
|
|
|
wined3d_surface_set_color_key(device->logo_surface, WINEDDCKEY_SRCBLT, &color_key);
|
2010-08-23 18:28:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-15 21:18:27 +01:00
|
|
|
const struct wined3d_color c = {1.0f, 1.0f, 1.0f, 1.0f};
|
2007-09-01 21:22:32 +02:00
|
|
|
/* Fill the surface with a white color to show that wined3d is there */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_color_fill(device, device->logo_surface, NULL, &c);
|
2007-09-01 21:22:32 +02:00
|
|
|
}
|
|
|
|
|
2009-12-29 17:10:20 +01:00
|
|
|
out:
|
|
|
|
if (dcb) DeleteDC(dcb);
|
|
|
|
if (hbm) DeleteObject(hbm);
|
2007-09-01 21:22:32 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-08-03 01:34:15 +02:00
|
|
|
static void create_dummy_textures(struct wined3d_device *device, struct wined3d_context *context)
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-08-26 01:12:27 +02:00
|
|
|
unsigned int i, j, count;
|
2011-06-30 15:01:07 +02:00
|
|
|
/* Under DirectX you can sample even if no texture is bound, whereas
|
|
|
|
* OpenGL will only allow that when a valid texture is bound.
|
|
|
|
* We emulate this by creating dummy textures and binding them
|
|
|
|
* to each texture stage when the currently set D3D texture is NULL. */
|
2008-02-15 15:54:37 +01:00
|
|
|
ENTER_GL();
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
|
|
|
{
|
2008-02-15 15:54:37 +01:00
|
|
|
/* The dummy texture does not have client storage backing */
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
|
|
|
|
}
|
2009-10-22 10:09:54 +02:00
|
|
|
|
2011-08-26 01:12:27 +02:00
|
|
|
count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
|
|
|
|
for (i = 0; i < count; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-06-30 15:01:07 +02:00
|
|
|
DWORD color = 0x000000ff;
|
2008-02-15 15:54:37 +01:00
|
|
|
|
|
|
|
/* Make appropriate texture active */
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(context, gl_info, i);
|
2008-02-15 15:54:37 +01:00
|
|
|
|
2011-08-26 01:12:29 +02:00
|
|
|
glGenTextures(1, &device->dummy_texture_2d[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glGenTextures");
|
2011-08-26 01:12:29 +02:00
|
|
|
TRACE("Dummy 2D texture %u given name %u.\n", i, device->dummy_texture_2d[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
|
2011-08-26 01:12:29 +02:00
|
|
|
glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
2011-06-30 15:01:07 +02:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glTexImage2D");
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
|
|
|
glGenTextures(1, &device->dummy_texture_rect[i]);
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Dummy rectangle texture %u given name %u.\n", i, device->dummy_texture_rect[i]);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]);
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
|
|
|
glGenTextures(1, &device->dummy_texture_3d[i]);
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Dummy 3D texture %u given name %u.\n", i, device->dummy_texture_3d[i]);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]);
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
|
|
|
|
checkGLcall("glTexImage3D");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
|
|
|
glGenTextures(1, &device->dummy_texture_cube[i]);
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Dummy cube texture %u given name %u.\n", i, device->dummy_texture_cube[i]);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]);
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++j)
|
|
|
|
{
|
|
|
|
glTexImage2D(j, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
|
|
|
}
|
2008-02-15 15:54:37 +01:00
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
|
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
|
|
|
{
|
2012-05-15 10:15:32 +02:00
|
|
|
/* Re-enable because if supported it is enabled by default */
|
2008-02-15 15:54:37 +01:00
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
|
|
|
|
}
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:14:34 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-05-16 23:01:23 +02:00
|
|
|
static void destroy_dummy_textures(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
|
2009-12-17 19:14:34 +01:00
|
|
|
{
|
2011-08-26 01:12:27 +02:00
|
|
|
unsigned int count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
|
|
|
|
|
2009-12-17 19:14:34 +01:00
|
|
|
ENTER_GL();
|
2011-08-26 01:12:27 +02:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
|
|
|
glDeleteTextures(count, device->dummy_texture_cube);
|
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_cube)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
|
|
|
glDeleteTextures(count, device->dummy_texture_3d);
|
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_3d)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
|
|
|
glDeleteTextures(count, device->dummy_texture_rect);
|
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_rect)");
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:12:29 +02:00
|
|
|
glDeleteTextures(count, device->dummy_texture_2d);
|
|
|
|
checkGLcall("glDeleteTextures(count, device->dummy_texture_2d)");
|
2009-12-17 19:14:34 +01:00
|
|
|
LEAVE_GL();
|
|
|
|
|
2011-08-26 01:12:27 +02:00
|
|
|
memset(device->dummy_texture_cube, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_cube));
|
|
|
|
memset(device->dummy_texture_3d, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_3d));
|
|
|
|
memset(device->dummy_texture_rect, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_rect));
|
2011-08-26 01:12:29 +02:00
|
|
|
memset(device->dummy_texture_2d, 0, gl_info->limits.textures * sizeof(*device->dummy_texture_2d));
|
2009-12-17 19:14:34 +01:00
|
|
|
}
|
|
|
|
|
2010-11-08 11:50:31 +01:00
|
|
|
static LONG fullscreen_style(LONG style)
|
|
|
|
{
|
|
|
|
/* Make sure the window is managed, otherwise we won't get keyboard input. */
|
|
|
|
style |= WS_POPUP | WS_SYSMENU;
|
|
|
|
style &= ~(WS_CAPTION | WS_THICKFRAME);
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG fullscreen_exstyle(LONG exstyle)
|
|
|
|
{
|
|
|
|
/* Filter out window decorations. */
|
|
|
|
exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
|
|
|
|
|
|
|
|
return exstyle;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_setup_fullscreen_window(struct wined3d_device *device, HWND window, UINT w, UINT h)
|
2010-11-08 11:50:31 +01:00
|
|
|
{
|
|
|
|
BOOL filter_messages;
|
|
|
|
LONG style, exstyle;
|
|
|
|
|
|
|
|
TRACE("Setting up window %p for fullscreen mode.\n", window);
|
|
|
|
|
|
|
|
if (device->style || device->exStyle)
|
|
|
|
{
|
|
|
|
ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
|
|
|
|
window, device->style, device->exStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
device->style = GetWindowLongW(window, GWL_STYLE);
|
|
|
|
device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
|
|
|
|
|
|
|
|
style = fullscreen_style(device->style);
|
|
|
|
exstyle = fullscreen_exstyle(device->exStyle);
|
|
|
|
|
|
|
|
TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
|
|
|
|
device->style, device->exStyle, style, exstyle);
|
|
|
|
|
|
|
|
filter_messages = device->filter_messages;
|
|
|
|
device->filter_messages = TRUE;
|
|
|
|
|
|
|
|
SetWindowLongW(window, GWL_STYLE, style);
|
|
|
|
SetWindowLongW(window, GWL_EXSTYLE, exstyle);
|
|
|
|
SetWindowPos(window, HWND_TOP, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
|
|
|
|
|
|
|
|
device->filter_messages = filter_messages;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window)
|
2010-11-08 11:50:31 +01:00
|
|
|
{
|
|
|
|
BOOL filter_messages;
|
|
|
|
LONG style, exstyle;
|
|
|
|
|
|
|
|
if (!device->style && !device->exStyle) return;
|
|
|
|
|
|
|
|
TRACE("Restoring window style of window %p to %08x, %08x.\n",
|
|
|
|
window, device->style, device->exStyle);
|
|
|
|
|
|
|
|
style = GetWindowLongW(window, GWL_STYLE);
|
|
|
|
exstyle = GetWindowLongW(window, GWL_EXSTYLE);
|
|
|
|
|
|
|
|
filter_messages = device->filter_messages;
|
|
|
|
device->filter_messages = TRUE;
|
|
|
|
|
|
|
|
/* Only restore the style if the application didn't modify it during the
|
|
|
|
* fullscreen phase. Some applications change it before calling Reset()
|
|
|
|
* when switching between windowed and fullscreen modes (HL2), some
|
|
|
|
* depend on the original style (Eve Online). */
|
|
|
|
if (style == fullscreen_style(device->style) && exstyle == fullscreen_exstyle(device->exStyle))
|
|
|
|
{
|
|
|
|
SetWindowLongW(window, GWL_STYLE, device->style);
|
|
|
|
SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
|
|
|
|
}
|
2010-11-08 11:50:32 +01:00
|
|
|
SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
2010-11-08 11:50:31 +01:00
|
|
|
|
|
|
|
device->filter_messages = filter_messages;
|
|
|
|
|
|
|
|
/* Delete the old values. */
|
|
|
|
device->style = 0;
|
|
|
|
device->exStyle = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window)
|
2010-03-17 21:59:49 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p, window %p.\n", device, window);
|
2010-10-11 13:06:20 +02:00
|
|
|
|
2010-03-17 21:59:49 +01:00
|
|
|
if (!wined3d_register_window(window, device))
|
|
|
|
{
|
|
|
|
ERR("Failed to register window %p.\n", window);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-01-24 21:47:45 +01:00
|
|
|
InterlockedExchangePointer((void **)&device->focus_window, window);
|
2010-11-05 14:11:38 +01:00
|
|
|
SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
2010-03-17 21:59:49 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
|
2010-03-17 21:59:49 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2010-10-11 13:06:20 +02:00
|
|
|
|
2010-03-17 21:59:49 +01:00
|
|
|
if (device->focus_window) wined3d_unregister_window(device->focus_window);
|
2012-01-24 21:47:45 +01:00
|
|
|
InterlockedExchangePointer((void **)&device->focus_window, NULL);
|
2010-03-17 21:59:49 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
|
2011-12-02 08:15:52 +01:00
|
|
|
struct wined3d_swapchain_desc *swapchain_desc)
|
2009-01-16 10:14:24 +01:00
|
|
|
{
|
2011-11-15 21:18:28 +01:00
|
|
|
static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f};
|
2011-05-16 23:01:22 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain = NULL;
|
2009-10-28 11:00:12 +01:00
|
|
|
struct wined3d_context *context;
|
2007-06-12 17:49:58 +02:00
|
|
|
HRESULT hr;
|
2006-12-15 19:16:36 +01:00
|
|
|
DWORD state;
|
2008-03-26 23:23:04 +01:00
|
|
|
unsigned int i;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
|
2009-01-16 10:14:24 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
if (!device->adapter->opengl)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-24 22:24:12 +02:00
|
|
|
device->valid_rt_mask = 0;
|
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
|
|
|
device->valid_rt_mask |= (1 << i);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(*device->fb.render_targets) * gl_info->limits.buffers);
|
2007-07-16 19:49:34 +02:00
|
|
|
|
2006-12-19 23:33:34 +01:00
|
|
|
/* Initialize the texture unit mapping to a 1:1 mapping */
|
2009-10-22 10:09:54 +02:00
|
|
|
for (state = 0; state < MAX_COMBINED_SAMPLERS; ++state)
|
|
|
|
{
|
2009-10-29 10:37:10 +01:00
|
|
|
if (state < gl_info->limits.fragment_samplers)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
device->texUnitMap[state] = state;
|
|
|
|
device->rev_tex_unit_map[state] = state;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device->texUnitMap[state] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
device->rev_tex_unit_map[state] = WINED3D_UNMAPPED_STAGE;
|
2007-06-22 20:43:19 +02:00
|
|
|
}
|
2006-12-19 23:33:34 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Setup the implicit swapchain. This also initializes a context. */
|
2006-04-18 22:38:30 +02:00
|
|
|
TRACE("Creating implicit swapchain\n");
|
2011-05-18 22:30:13 +02:00
|
|
|
hr = device->device_parent->ops->create_swapchain(device->device_parent,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc, &swapchain);
|
2009-01-16 10:14:24 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2006-04-18 22:38:30 +02:00
|
|
|
WARN("Failed to create implicit swapchain\n");
|
2007-10-09 22:04:18 +02:00
|
|
|
goto err_out;
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchain_count = 1;
|
|
|
|
device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
|
|
|
|
if (!device->swapchains)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
2006-05-24 11:34:30 +02:00
|
|
|
ERR("Out of memory!\n");
|
2007-10-09 22:04:18 +02:00
|
|
|
goto err_out;
|
2006-05-24 11:34:30 +02:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchains[0] = swapchain;
|
2006-05-24 11:34:30 +02:00
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers && swapchain->back_buffers[0])
|
|
|
|
{
|
|
|
|
TRACE("Setting rendertarget to %p.\n", swapchain->back_buffers);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[0] = swapchain->back_buffers[0];
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2010-04-26 21:33:00 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Setting rendertarget to %p.\n", swapchain->front_buffer);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[0] = swapchain->front_buffer;
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2011-05-18 22:30:15 +02:00
|
|
|
wined3d_surface_incref(device->fb.render_targets[0]);
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
/* Depth Stencil support */
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = device->auto_depth_stencil;
|
|
|
|
if (device->fb.depth_stencil)
|
|
|
|
wined3d_surface_incref(device->fb.depth_stencil);
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = device->shader_backend->shader_alloc_private(device);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2008-03-18 19:49:05 +01:00
|
|
|
TRACE("Shader private data couldn't be allocated\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = device->frag_pipe->alloc_private(device);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2008-07-11 16:41:28 +02:00
|
|
|
TRACE("Fragment pipeline private data couldn't be allocated\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = device->blitter->alloc_private(device);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2008-08-01 20:21:10 +02:00
|
|
|
TRACE("Blitter private data couldn't be allocated\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2008-03-18 19:49:05 +01:00
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
/* Set up some starting GL setup */
|
|
|
|
|
|
|
|
/* Setup all the devices defaults */
|
2011-05-16 23:01:22 +02:00
|
|
|
stateblock_init_default_state(device->stateBlock);
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
context = context_acquire(device, swapchain->front_buffer);
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2011-08-03 01:34:15 +02:00
|
|
|
create_dummy_textures(device, context);
|
2008-04-06 23:06:22 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
/* Initialize the current view state */
|
2011-05-16 23:01:22 +02:00
|
|
|
device->view_ident = 1;
|
|
|
|
device->contexts[0]->last_was_rhw = 0;
|
2007-02-27 21:32:15 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
switch (wined3d_settings.offscreen_rendering_mode)
|
|
|
|
{
|
2007-02-27 21:32:15 +01:00
|
|
|
case ORM_FBO:
|
2011-05-16 23:01:22 +02:00
|
|
|
device->offscreenBuffer = GL_COLOR_ATTACHMENT0;
|
2009-12-04 10:21:01 +01:00
|
|
|
break;
|
|
|
|
|
2007-02-27 21:32:15 +01:00
|
|
|
case ORM_BACKBUFFER:
|
|
|
|
{
|
2009-07-24 10:44:17 +02:00
|
|
|
if (context_get_current()->aux_buffers > 0)
|
|
|
|
{
|
2011-08-02 22:20:32 +02:00
|
|
|
TRACE("Using auxiliary buffer for offscreen rendering\n");
|
2011-05-16 23:01:22 +02:00
|
|
|
device->offscreenBuffer = GL_AUX0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-27 21:32:15 +01:00
|
|
|
TRACE("Using back buffer for offscreen rendering\n");
|
2011-05-16 23:01:22 +02:00
|
|
|
device->offscreenBuffer = GL_BACK;
|
2007-02-27 21:32:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("All defaults now set up, leaving 3D init.\n");
|
2007-02-12 19:22:41 +01:00
|
|
|
LEAVE_GL();
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2009-10-28 11:00:12 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
/* Clear the screen */
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_clear(device, 0, NULL, WINED3DCLEAR_TARGET
|
2011-12-02 08:15:52 +01:00
|
|
|
| (swapchain_desc->enable_auto_depth_stencil ? WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL : 0),
|
2011-11-15 21:18:28 +01:00
|
|
|
&black, 1.0f, 0);
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->d3d_initialized = TRUE;
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (wined3d_settings.logo)
|
2011-06-07 19:44:49 +02:00
|
|
|
device_load_logo(device, wined3d_settings.logo);
|
2006-04-18 22:38:30 +02:00
|
|
|
return WINED3D_OK;
|
2007-10-09 22:04:18 +02:00
|
|
|
|
2008-01-22 09:27:00 +01:00
|
|
|
err_out:
|
2011-05-18 22:30:15 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
|
2011-05-16 23:01:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->swapchains);
|
|
|
|
device->swapchain_count = 0;
|
2011-04-06 19:17:52 +02:00
|
|
|
if (swapchain)
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->blit_priv)
|
|
|
|
device->blitter->free_private(device);
|
|
|
|
if (device->fragment_priv)
|
|
|
|
device->frag_pipe->free_private(device);
|
|
|
|
if (device->shader_priv)
|
|
|
|
device->shader_backend->shader_free_private(device);
|
|
|
|
|
2007-10-09 22:04:18 +02:00
|
|
|
return hr;
|
2006-04-12 21:08:57 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device,
|
2011-12-02 08:15:52 +01:00
|
|
|
struct wined3d_swapchain_desc *swapchain_desc)
|
2009-01-16 10:14:24 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain = NULL;
|
2008-08-05 21:23:00 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
|
2011-05-16 23:01:22 +02:00
|
|
|
|
2008-08-05 21:23:00 +02:00
|
|
|
/* Setup the implicit swapchain */
|
|
|
|
TRACE("Creating implicit swapchain\n");
|
2011-05-18 22:30:13 +02:00
|
|
|
hr = device->device_parent->ops->create_swapchain(device->device_parent,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc, &swapchain);
|
2009-01-16 10:14:24 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
WARN("Failed to create implicit swapchain\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchain_count = 1;
|
|
|
|
device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
|
|
|
|
if (!device->swapchains)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
ERR("Out of memory!\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->swapchains[0] = swapchain;
|
2008-08-05 21:23:00 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
err_out:
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2008-08-05 21:23:00 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
|
2009-09-16 08:37:15 +02:00
|
|
|
{
|
2011-07-25 20:45:07 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2009-09-23 10:05:55 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2011-04-29 13:03:41 +02:00
|
|
|
struct wined3d_surface *surface;
|
2007-08-06 16:38:00 +02:00
|
|
|
UINT i;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
if (!device->d3d_initialized)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-03-18 19:18:40 +01:00
|
|
|
/* Force making the context current again, to verify it is still valid
|
|
|
|
* (workaround for broken drivers) */
|
|
|
|
context_set_current(NULL);
|
2008-01-09 20:37:05 +01:00
|
|
|
/* I don't think that the interface guarantees that the device is destroyed from the same thread
|
2007-03-17 23:00:39 +01:00
|
|
|
* it was created. Thus make sure a context is active for the glDelete* calls
|
|
|
|
*/
|
2011-05-16 23:01:22 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info = context->gl_info;
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->logo_surface)
|
|
|
|
wined3d_surface_decref(device->logo_surface);
|
2007-09-01 21:22:32 +02:00
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
stateblock_unbind_resources(device->stateBlock);
|
|
|
|
|
2009-03-23 13:54:34 +01:00
|
|
|
/* Unload resources */
|
2011-07-25 20:45:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Unloading resource %p.\n", resource);
|
|
|
|
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
|
|
|
}
|
2009-03-23 13:54:34 +01:00
|
|
|
|
2007-07-04 17:57:45 +02:00
|
|
|
TRACE("Deleting high order patches\n");
|
2012-01-20 00:36:29 +01:00
|
|
|
for (i = 0; i < PATCHMAP_SIZE; ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_rect_patch *patch;
|
2007-07-04 17:57:45 +02:00
|
|
|
struct list *e1, *e2;
|
2012-01-20 00:36:29 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &device->patches[i])
|
|
|
|
{
|
2012-01-20 00:36:29 +01:00
|
|
|
patch = LIST_ENTRY(e1, struct wined3d_rect_patch, entry);
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_delete_patch(device, patch->Handle);
|
2007-07-04 17:57:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-27 17:39:03 +02:00
|
|
|
/* Delete the mouse cursor texture */
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->cursorTexture)
|
|
|
|
{
|
2006-07-27 17:39:03 +02:00
|
|
|
ENTER_GL();
|
2011-05-16 23:01:22 +02:00
|
|
|
glDeleteTextures(1, &device->cursorTexture);
|
2006-07-27 17:39:03 +02:00
|
|
|
LEAVE_GL();
|
2011-05-16 23:01:22 +02:00
|
|
|
device->cursorTexture = 0;
|
2006-07-27 17:39:03 +02:00
|
|
|
}
|
|
|
|
|
2008-03-18 19:49:05 +01:00
|
|
|
/* Destroy the depth blt resources, they will be invalid after the reset. Also free shader
|
|
|
|
* private data, it might contain opengl pointers
|
|
|
|
*/
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->depth_blt_texture)
|
|
|
|
{
|
2009-05-13 18:22:55 +02:00
|
|
|
ENTER_GL();
|
2011-05-16 23:01:22 +02:00
|
|
|
glDeleteTextures(1, &device->depth_blt_texture);
|
2009-05-13 18:22:55 +02:00
|
|
|
LEAVE_GL();
|
2011-05-16 23:01:22 +02:00
|
|
|
device->depth_blt_texture = 0;
|
2008-06-27 00:52:13 +02:00
|
|
|
}
|
2008-03-18 19:49:05 +01:00
|
|
|
|
2008-07-10 23:26:10 +02:00
|
|
|
/* Destroy the shader backend. Note that this has to happen after all shaders are destroyed. */
|
2011-05-16 23:01:22 +02:00
|
|
|
device->blitter->free_private(device);
|
|
|
|
device->frag_pipe->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
2008-07-10 23:26:10 +02:00
|
|
|
|
2006-05-24 11:34:30 +02:00
|
|
|
/* Release the buffers (with sanity checks)*/
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->onscreen_depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
surface = device->onscreen_depth_stencil;
|
|
|
|
device->onscreen_depth_stencil = NULL;
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_decref(surface);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
surface = device->fb.depth_stencil;
|
2010-10-05 14:32:36 +02:00
|
|
|
|
2011-01-28 20:05:40 +01:00
|
|
|
TRACE("Releasing depth/stencil buffer %p.\n", surface);
|
2010-10-05 14:32:36 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = NULL;
|
2012-01-17 21:13:30 +01:00
|
|
|
wined3d_surface_decref(surface);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->auto_depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
surface = device->auto_depth_stencil;
|
|
|
|
device->auto_depth_stencil = NULL;
|
2011-04-29 13:03:41 +02:00
|
|
|
if (wined3d_surface_decref(surface))
|
2011-05-16 23:01:22 +02:00
|
|
|
FIXME("Something's still holding the auto depth stencil buffer (%p).\n", surface);
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:05:40 +01:00
|
|
|
for (i = 1; i < gl_info->limits.buffers; ++i)
|
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_set_render_target(device, i, NULL, FALSE);
|
2011-01-28 20:05:40 +01:00
|
|
|
}
|
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
surface = device->fb.render_targets[0];
|
2011-01-28 20:05:40 +01:00
|
|
|
TRACE("Setting rendertarget 0 to NULL\n");
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[0] = NULL;
|
2011-01-28 20:05:40 +01:00
|
|
|
TRACE("Releasing the render target at %p\n", surface);
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_decref(surface);
|
2011-01-28 20:05:40 +01:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
|
|
|
TRACE("Releasing the implicit swapchain %u.\n", i);
|
2011-05-16 23:01:22 +02:00
|
|
|
if (wined3d_swapchain_decref(device->swapchains[i]))
|
2011-04-13 19:14:31 +02:00
|
|
|
FIXME("Something's still holding the implicit swapchain.\n");
|
2006-04-18 22:38:30 +02:00
|
|
|
}
|
2006-05-24 11:34:30 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->swapchains);
|
|
|
|
device->swapchains = NULL;
|
|
|
|
device->swapchain_count = 0;
|
2006-04-18 22:38:30 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
|
|
|
|
device->fb.render_targets = NULL;
|
2007-07-16 19:49:34 +02:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->d3d_initialized = FALSE;
|
2009-12-22 18:32:13 +01:00
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
return WINED3D_OK;
|
2006-04-12 21:08:57 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_uninit_gdi(struct wined3d_device *device)
|
2011-04-12 18:28:39 +02:00
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
2011-01-19 19:20:12 +01:00
|
|
|
{
|
|
|
|
TRACE("Releasing the implicit swapchain %u.\n", i);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (wined3d_swapchain_decref(device->swapchains[i]))
|
2011-04-13 19:14:31 +02:00
|
|
|
FIXME("Something's still holding the implicit swapchain.\n");
|
2008-08-05 21:23:00 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->swapchains);
|
|
|
|
device->swapchains = NULL;
|
|
|
|
device->swapchain_count = 0;
|
2008-08-05 21:23:00 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-19 05:40:40 +02:00
|
|
|
/* Enables thread safety in the wined3d device and its resources. Called by DirectDraw
|
|
|
|
* from SetCooperativeLevel if DDSCL_MULTITHREADED is specified, and by d3d8/9 from
|
2007-03-04 17:03:03 +01:00
|
|
|
* CreateDevice if D3DCREATE_MULTITHREADED is passed.
|
|
|
|
*
|
2007-10-19 05:40:40 +02:00
|
|
|
* There is no way to deactivate thread safety once it is enabled.
|
2007-03-04 17:03:03 +01:00
|
|
|
*/
|
2011-05-16 23:01:22 +02:00
|
|
|
void CDECL wined3d_device_set_multithreaded(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
TRACE("device %p.\n", device);
|
2007-03-04 17:03:03 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
/* For now just store the flag (needed in case of ddraw). */
|
2011-11-27 21:34:48 +01:00
|
|
|
device->create_parms.flags |= WINED3DCREATE_MULTITHREADED;
|
2007-03-04 17:03:03 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_display_mode(struct wined3d_device *device,
|
2011-11-16 20:08:06 +01:00
|
|
|
UINT swapchain_idx, const struct wined3d_display_mode *mode)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-08-29 18:58:56 +02:00
|
|
|
struct wined3d_adapter *adapter = device->adapter;
|
2011-11-16 20:08:06 +01:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(&adapter->gl_info, mode->format_id);
|
2006-05-18 22:42:22 +02:00
|
|
|
DEVMODEW devmode;
|
|
|
|
LONG ret;
|
2006-12-14 23:51:23 +01:00
|
|
|
RECT clip_rc;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, mode %p (%ux%u@%u %s).\n", device, swapchain_idx, mode,
|
2011-11-16 20:08:06 +01:00
|
|
|
mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id));
|
2006-05-18 22:42:22 +02:00
|
|
|
|
|
|
|
/* Resize the screen even without a window:
|
|
|
|
* The app could have unset it with SetCooperativeLevel, but not called
|
|
|
|
* RestoreDisplayMode first. Then the release will call RestoreDisplayMode,
|
|
|
|
* but we don't have any hwnd
|
|
|
|
*/
|
|
|
|
|
2007-08-05 20:23:42 +02:00
|
|
|
memset(&devmode, 0, sizeof(devmode));
|
|
|
|
devmode.dmSize = sizeof(devmode);
|
2006-05-18 22:42:22 +02:00
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
2010-08-30 20:29:49 +02:00
|
|
|
devmode.dmBitsPerPel = format->byte_count * CHAR_BIT;
|
2011-11-16 20:08:06 +01:00
|
|
|
devmode.dmPelsWidth = mode->width;
|
|
|
|
devmode.dmPelsHeight = mode->height;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2011-11-16 20:08:06 +01:00
|
|
|
devmode.dmDisplayFrequency = mode->refresh_rate;
|
|
|
|
if (mode->refresh_rate)
|
2006-05-18 22:42:22 +02:00
|
|
|
devmode.dmFields |= DM_DISPLAYFREQUENCY;
|
|
|
|
|
|
|
|
/* Only change the mode if necessary */
|
2011-11-16 20:08:06 +01:00
|
|
|
if (adapter->screen_size.cx == mode->width && adapter->screen_size.cy == mode->height
|
|
|
|
&& adapter->screen_format == mode->format_id && !mode->refresh_rate)
|
2007-02-14 23:30:40 +01:00
|
|
|
return WINED3D_OK;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
|
|
|
ret = ChangeDisplaySettingsExW(NULL, &devmode, NULL, CDS_FULLSCREEN, NULL);
|
2010-09-14 13:38:39 +02:00
|
|
|
if (ret != DISP_CHANGE_SUCCESSFUL)
|
|
|
|
{
|
|
|
|
if (devmode.dmDisplayFrequency)
|
|
|
|
{
|
2006-05-18 22:42:22 +02:00
|
|
|
WARN("ChangeDisplaySettingsExW failed, trying without the refresh rate\n");
|
|
|
|
devmode.dmFields &= ~DM_DISPLAYFREQUENCY;
|
|
|
|
devmode.dmDisplayFrequency = 0;
|
|
|
|
ret = ChangeDisplaySettingsExW(NULL, &devmode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
if(ret != DISP_CHANGE_SUCCESSFUL) {
|
2007-04-14 22:44:55 +02:00
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
2006-05-18 22:42:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the new values */
|
2011-11-16 20:08:06 +01:00
|
|
|
adapter->screen_size.cx = mode->width;
|
|
|
|
adapter->screen_size.cy = mode->height;
|
|
|
|
adapter->screen_format = mode->format_id;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2006-12-14 23:51:23 +01:00
|
|
|
/* And finally clip mouse to our screen */
|
2011-11-16 20:08:06 +01:00
|
|
|
SetRect(&clip_rc, 0, 0, mode->width, mode->height);
|
2006-12-14 23:51:23 +01:00
|
|
|
ClipCursor(&clip_rc);
|
|
|
|
|
2006-05-18 22:42:22 +02:00
|
|
|
return WINED3D_OK;
|
2006-04-17 17:51:21 +02:00
|
|
|
}
|
|
|
|
|
2011-08-28 23:27:49 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_wined3d(const struct wined3d_device *device, struct wined3d **wined3d)
|
2011-02-01 19:39:53 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, wined3d %p.\n", device, wined3d);
|
2011-02-01 19:39:53 +01:00
|
|
|
|
|
|
|
*wined3d = device->wined3d;
|
|
|
|
wined3d_incref(*wined3d);
|
|
|
|
|
|
|
|
TRACE("Returning %p.\n", *wined3d);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-08-29 18:58:55 +02:00
|
|
|
UINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
|
|
|
|
|
|
|
TRACE("Emulating %d MB, returning %d MB left.\n",
|
|
|
|
device->adapter->TextureRam / (1024 * 1024),
|
|
|
|
(device->adapter->TextureRam - device->adapter->UsedTextureRam) / (1024 * 1024));
|
2007-09-23 00:46:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
return device->adapter->TextureRam - device->adapter->UsedTextureRam;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_stream_source(struct wined3d_device *device, UINT stream_idx,
|
2011-05-16 23:01:21 +02:00
|
|
|
struct wined3d_buffer *buffer, UINT offset, UINT stride)
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
2011-03-03 21:49:10 +01:00
|
|
|
struct wined3d_buffer *prev_buffer;
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
|
|
|
|
device, stream_idx, buffer, offset, stride);
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stream_idx >= MAX_STREAMS)
|
|
|
|
{
|
|
|
|
WARN("Stream index %u out of range.\n", stream_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-05-16 23:01:21 +02:00
|
|
|
}
|
|
|
|
else if (offset & 0x3)
|
|
|
|
{
|
|
|
|
WARN("Offset %u is not 4 byte aligned.\n", offset);
|
2007-12-20 22:14:53 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-02 13:17:17 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
stream = &device->updateStateBlock->state.streams[stream_idx];
|
2011-03-03 21:49:10 +01:00
|
|
|
prev_buffer = stream->buffer;
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.streamSource |= 1 << stream_idx;
|
2007-01-04 00:08:20 +01:00
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
if (prev_buffer == buffer
|
2011-05-16 23:01:21 +02:00
|
|
|
&& stream->stride == stride
|
|
|
|
&& stream->offset == offset)
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application is setting the old values over, nothing to do.\n");
|
2007-01-04 00:08:20 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
stream->buffer = buffer;
|
|
|
|
if (buffer)
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
stream->stride = stride;
|
|
|
|
stream->offset = offset;
|
2006-12-24 10:00:05 +01:00
|
|
|
}
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2011-03-03 21:49:10 +01:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
if (prev_buffer)
|
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-23 14:52:46 +01:00
|
|
|
}
|
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
if (buffer)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2012-04-25 21:24:22 +02:00
|
|
|
InterlockedIncrement(&buffer->resource.bind_count);
|
2011-03-03 21:49:10 +01:00
|
|
|
wined3d_buffer_incref(buffer);
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
2011-03-03 21:49:10 +01:00
|
|
|
if (prev_buffer)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2012-04-25 21:24:22 +02:00
|
|
|
InterlockedDecrement(&prev_buffer->resource.bind_count);
|
2011-03-03 21:49:10 +01:00
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
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
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
|
|
|
|
device, stream_idx, buffer, offset, stride);
|
2004-11-23 14:52:46 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stream_idx >= MAX_STREAMS)
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Stream index %u out of range.\n", stream_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-02 13:17:17 +02:00
|
|
|
}
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
stream = &device->stateBlock->state.streams[stream_idx];
|
2011-03-03 21:49:10 +01:00
|
|
|
*buffer = stream->buffer;
|
|
|
|
if (*buffer)
|
|
|
|
wined3d_buffer_incref(*buffer);
|
2011-05-16 23:01:21 +02:00
|
|
|
if (offset)
|
|
|
|
*offset = stream->offset;
|
|
|
|
*stride = stream->stride;
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-23 14:52:46 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT divider)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT old_flags, old_freq;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stream_idx %u, divider %#x.\n", device, stream_idx, divider);
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Verify input. At least in d3d9 this is invalid. */
|
|
|
|
if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && (divider & WINED3DSTREAMSOURCE_INDEXEDDATA))
|
2010-09-14 13:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("INSTANCEDATA and INDEXEDDATA were set, returning D3DERR_INVALIDCALL.\n");
|
2008-04-06 18:50:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && !stream_idx)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("INSTANCEDATA used on stream 0, returning D3DERR_INVALIDCALL.\n");
|
2008-04-06 18:50:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!divider)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Divider is 0, returning D3DERR_INVALIDCALL.\n");
|
2008-04-06 18:50:02 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
stream = &device->updateStateBlock->state.streams[stream_idx];
|
2010-11-18 20:50:40 +01:00
|
|
|
old_flags = stream->flags;
|
2011-05-16 23:01:21 +02:00
|
|
|
old_freq = stream->frequency;
|
2010-09-14 13:38:41 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
stream->flags = divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
|
|
|
|
stream->frequency = divider & 0x7fffff;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.streamFreq |= 1 << stream_idx;
|
2005-09-02 13:17:17 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stream->frequency != old_freq || stream->flags != old_flags)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
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
|
|
|
{
|
2010-09-14 13:38:41 +02:00
|
|
|
struct wined3d_stream_state *stream;
|
|
|
|
|
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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
stream = &device->updateStateBlock->state.streams[stream_idx];
|
|
|
|
*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
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_transform(struct wined3d_device *device,
|
2012-01-11 21:27:32 +01:00
|
|
|
enum wined3d_transform_state d3dts, const struct wined3d_matrix *matrix)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, state %s, matrix %p.\n",
|
|
|
|
device, debug_d3dtstype(d3dts), matrix);
|
2012-05-22 18:01:05 +02:00
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._11, matrix->u.s._12, matrix->u.s._13, matrix->u.s._14);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._21, matrix->u.s._22, matrix->u.s._23, matrix->u.s._24);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._31, matrix->u.s._32, matrix->u.s._33, matrix->u.s._34);
|
|
|
|
TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._41, matrix->u.s._42, matrix->u.s._43, matrix->u.s._44);
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
|
|
|
device->updateStateBlock->changed.transform[d3dts >> 5] |= 1 << (d3dts & 0x1f);
|
|
|
|
device->updateStateBlock->state.transforms[d3dts] = *matrix;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
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. */
|
|
|
|
if (!memcmp(&device->stateBlock->state.transforms[d3dts].u.m[0][0], matrix, sizeof(*matrix)))
|
2010-09-16 11:19:56 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("The application is setting the same matrix over again.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2010-09-16 11:19:56 +02:00
|
|
|
}
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2012-05-22 18:01:05 +02:00
|
|
|
device->stateBlock->state.transforms[d3dts] = *matrix;
|
2012-01-11 21:27:32 +01:00
|
|
|
if (d3dts == WINED3D_TS_VIEW)
|
2012-05-03 21:49:38 +02:00
|
|
|
device->view_ident = !memcmp(matrix, &identity, sizeof(identity));
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2012-01-11 21:27:32 +01:00
|
|
|
if (d3dts < WINED3D_TS_WORLD_MATRIX(device->adapter->gl_info.limits.blends))
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TRANSFORM(d3dts));
|
2010-09-02 19:25:02 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-28 16:04:41 +01:00
|
|
|
|
|
|
|
}
|
2010-09-16 11:19:56 +02:00
|
|
|
|
2011-08-31 20:40:44 +02:00
|
|
|
HRESULT 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
|
|
|
|
|
|
|
*matrix = device->stateBlock->state.transforms[state];
|
|
|
|
|
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_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
|
|
|
{
|
2011-11-17 20:11:41 +01:00
|
|
|
const struct wined3d_matrix *mat = NULL;
|
|
|
|
struct wined3d_matrix temp;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
|
|
|
|
|
2004-12-20 20:27:06 +01:00
|
|
|
/* Note: Using 'updateStateBlock' rather than 'stateblock' in the code
|
|
|
|
* below means it will be recorded in a state block change, but it
|
2005-07-13 16:15:54 +02:00
|
|
|
* works regardless where it is recorded.
|
2011-05-16 23:01:23 +02:00
|
|
|
* If this is found to be wrong, change to StateBlock. */
|
2011-06-11 18:05:02 +02:00
|
|
|
if (state > HIGHEST_TRANSFORMSTATE)
|
|
|
|
{
|
|
|
|
WARN("Unhandled transform state %#x.\n", state);
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-06-11 18:05:02 +02:00
|
|
|
mat = &device->updateStateBlock->state.transforms[state];
|
2011-05-16 23:01:23 +02:00
|
|
|
multiply_matrix(&temp, mat, matrix);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Apply change via set transform - will reapply to eg. lights this way. */
|
2011-05-16 23:01:23 +02:00
|
|
|
return wined3d_device_set_transform(device, state, &temp);
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Note lights are real special cases. Although the device caps state only
|
|
|
|
* e.g. 8 are supported, you can reference any indexes you want as long as
|
|
|
|
* that number max are enabled at any one point in time. Therefore since the
|
|
|
|
* indices can be anything, we need a hashmap of them. However, this causes
|
|
|
|
* stateblock problems. When capturing the state block, I duplicate the
|
|
|
|
* hashmap, but when recording, just build a chain pretty much of commands to
|
|
|
|
* be replayed. */
|
2011-11-20 20:27:12 +01:00
|
|
|
HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device,
|
|
|
|
UINT light_idx, const struct wined3d_light *light)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
2009-10-14 10:55:16 +02:00
|
|
|
struct wined3d_light_info *object = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2011-05-16 23:01:21 +02:00
|
|
|
float rho;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Check the parameter range. Need for speed most wanted sets junk lights
|
|
|
|
* which confuse the GL driver. */
|
|
|
|
if (!light)
|
2007-02-20 22:43:13 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
switch (light->type)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_POINT:
|
|
|
|
case WINED3D_LIGHT_SPOT:
|
|
|
|
case WINED3D_LIGHT_PARALLELPOINT:
|
|
|
|
case WINED3D_LIGHT_GLSPOT:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Incorrect attenuation values can cause the gl driver to crash.
|
|
|
|
* Happens with Need for speed most wanted. */
|
2011-11-20 20:27:12 +01:00
|
|
|
if (light->attenuation0 < 0.0f || light->attenuation1 < 0.0f || light->attenuation2 < 0.0f)
|
2009-07-07 11:08:01 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Attenuation is negative, returning WINED3DERR_INVALIDCALL.\n");
|
2007-02-20 22:43:13 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_DIRECTIONAL:
|
2007-02-20 22:43:13 +01:00
|
|
|
/* Ignores attenuation */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("Light type out of range, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
|
|
|
object = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
2011-05-16 23:01:21 +02:00
|
|
|
if (object->OriginalIndex == light_idx)
|
|
|
|
break;
|
2007-02-14 17:46:54 +01:00
|
|
|
object = NULL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!object)
|
|
|
|
{
|
2007-02-14 17:46:54 +01:00
|
|
|
TRACE("Adding new light\n");
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!object)
|
|
|
|
{
|
2007-02-14 17:46:54 +01:00
|
|
|
ERR("Out of memory error when allocating a light\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
list_add_head(&device->updateStateBlock->state.light_map[hash_idx], &object->entry);
|
2004-11-29 18:53:42 +01:00
|
|
|
object->glIndex = -1;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->OriginalIndex = light_idx;
|
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Initialize the object. */
|
|
|
|
TRACE("Light %d setting to type %d, Diffuse(%f,%f,%f,%f), Specular(%f,%f,%f,%f), Ambient(%f,%f,%f,%f)\n",
|
2011-11-20 20:27:12 +01:00
|
|
|
light_idx, light->type,
|
|
|
|
light->diffuse.r, light->diffuse.g, light->diffuse.b, light->diffuse.a,
|
|
|
|
light->specular.r, light->specular.g, light->specular.b, light->specular.a,
|
|
|
|
light->ambient.r, light->ambient.g, light->ambient.b, light->ambient.a);
|
|
|
|
TRACE("... Pos(%f,%f,%f), Dir(%f,%f,%f)\n", light->position.x, light->position.y, light->position.z,
|
|
|
|
light->direction.x, light->direction.y, light->direction.z);
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("... Range(%f), Falloff(%f), Theta(%f), Phi(%f)\n",
|
2011-11-20 20:27:12 +01:00
|
|
|
light->range, light->falloff, light->theta, light->phi);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
/* Save away the information. */
|
|
|
|
object->OriginalParms = *light;
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
switch (light->type)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_POINT:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Position */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightPosn[0] = light->position.x;
|
|
|
|
object->lightPosn[1] = light->position.y;
|
|
|
|
object->lightPosn[2] = light->position.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightPosn[3] = 1.0f;
|
|
|
|
object->cutoff = 180.0f;
|
|
|
|
/* FIXME: Range */
|
|
|
|
break;
|
|
|
|
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_DIRECTIONAL:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Direction */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightPosn[0] = -light->direction.x;
|
|
|
|
object->lightPosn[1] = -light->direction.y;
|
|
|
|
object->lightPosn[2] = -light->direction.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightPosn[3] = 0.0f;
|
2009-07-07 11:08:01 +02:00
|
|
|
object->exponent = 0.0f;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->cutoff = 180.0f;
|
|
|
|
break;
|
|
|
|
|
2011-12-11 21:43:31 +01:00
|
|
|
case WINED3D_LIGHT_SPOT:
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Position */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightPosn[0] = light->position.x;
|
|
|
|
object->lightPosn[1] = light->position.y;
|
|
|
|
object->lightPosn[2] = light->position.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightPosn[3] = 1.0f;
|
|
|
|
|
|
|
|
/* Direction */
|
2011-11-20 20:27:12 +01:00
|
|
|
object->lightDirn[0] = light->direction.x;
|
|
|
|
object->lightDirn[1] = light->direction.y;
|
|
|
|
object->lightDirn[2] = light->direction.z;
|
2011-05-16 23:01:21 +02:00
|
|
|
object->lightDirn[3] = 1.0f;
|
|
|
|
|
|
|
|
/* opengl-ish and d3d-ish spot lights use too different models
|
|
|
|
* for the light "intensity" as a function of the angle towards
|
|
|
|
* the main light direction, so we only can approximate very
|
|
|
|
* roughly. However, spot lights are rather rarely used in games
|
|
|
|
* (if ever used at all). Furthermore if still used, probably
|
|
|
|
* nobody pays attention to such details. */
|
2011-11-20 20:27:12 +01:00
|
|
|
if (!light->falloff)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
/* Falloff = 0 is easy, because d3d's and opengl's spot light
|
|
|
|
* equations have the falloff resp. exponent parameter as an
|
|
|
|
* exponent, so the spot light lighting will always be 1.0 for
|
|
|
|
* both of them, and we don't have to care for the rest of the
|
|
|
|
* rather complex calculation. */
|
|
|
|
object->exponent = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-20 20:27:12 +01:00
|
|
|
rho = light->theta + (light->phi - light->theta) / (2 * light->falloff);
|
2011-05-16 23:01:21 +02:00
|
|
|
if (rho < 0.0001f)
|
|
|
|
rho = 0.0001f;
|
|
|
|
object->exponent = -0.3f / logf(cosf(rho / 2));
|
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (object->exponent > 128.0f)
|
|
|
|
object->exponent = 128.0f;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
object->cutoff = (float)(light->phi * 90 / M_PI);
|
2011-05-16 23:01:21 +02:00
|
|
|
/* FIXME: Range */
|
|
|
|
break;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
default:
|
2011-11-20 20:27:12 +01:00
|
|
|
FIXME("Unrecognized light type %#x.\n", light->type);
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
/* Update the live definitions if the light is currently assigned a glIndex. */
|
|
|
|
if (object->glIndex != -1 && !device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_ACTIVELIGHT(object->glIndex));
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-11-20 20:27:12 +01:00
|
|
|
HRESULT CDECL wined3d_device_get_light(const struct wined3d_device *device,
|
|
|
|
UINT light_idx, struct wined3d_light *light)
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
|
|
|
struct wined3d_light_info *light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
|
|
|
|
|
|
|
|
LIST_FOR_EACH(e, &device->stateBlock->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2004-11-29 18:53:42 +01:00
|
|
|
TRACE("Light information requested but light not defined\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*light = light_info->OriginalParms;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UINT light_idx, BOOL enable)
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
|
|
|
struct wined3d_light_info *light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, enable %#x.\n", device, light_idx, enable);
|
|
|
|
|
|
|
|
LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Found light %p.\n", light_info);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Special case - enabling an undefined light creates one with a strict set of parameters. */
|
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2005-07-13 16:15:54 +02:00
|
|
|
TRACE("Light enabled requested but light not defined, so defining one!\n");
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_set_light(device, light_idx, &WINED3D_default_light);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Search for it again! Should be fairly quick as near head of list. */
|
|
|
|
LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2004-11-29 18:53:42 +01:00
|
|
|
FIXME("Adding default lights has failed dismally\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!enable)
|
|
|
|
{
|
|
|
|
if (light_info->glIndex != -1)
|
|
|
|
{
|
|
|
|
if (!device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_ACTIVELIGHT(light_info->glIndex));
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.lights[light_info->glIndex] = NULL;
|
|
|
|
light_info->glIndex = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-14 17:46:54 +01:00
|
|
|
TRACE("Light already disabled, nothing to do\n");
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info->enabled = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
light_info->enabled = TRUE;
|
|
|
|
if (light_info->glIndex != -1)
|
|
|
|
{
|
2004-11-29 18:53:42 +01:00
|
|
|
TRACE("Nothing to do as light was enabled\n");
|
2011-05-16 23:01:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-18 09:12:40 +02:00
|
|
|
unsigned int i;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Find a free GL light. */
|
2011-05-18 09:12:40 +02:00
|
|
|
for (i = 0; i < gl_info->limits.lights; ++i)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->updateStateBlock->state.lights[i])
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.lights[i] = light_info;
|
|
|
|
light_info->glIndex = i;
|
2007-02-14 17:46:54 +01:00
|
|
|
break;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
if (light_info->glIndex == -1)
|
|
|
|
{
|
2007-11-29 13:22:47 +01:00
|
|
|
/* Our tests show that Windows returns D3D_OK in this situation, even with
|
|
|
|
* D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE devices. This
|
|
|
|
* is consistent among ddraw, d3d8 and d3d9. GetLightEnable returns TRUE
|
|
|
|
* as well for those lights.
|
|
|
|
*
|
2011-05-16 23:01:21 +02:00
|
|
|
* TODO: Test how this affects rendering. */
|
2008-12-29 16:31:22 +01:00
|
|
|
WARN("Too many concurrently active lights\n");
|
2007-11-29 13:22:47 +01:00
|
|
|
return WINED3D_OK;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* i == light_info->glIndex */
|
|
|
|
if (!device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_ACTIVELIGHT(i));
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
}
|
2007-02-14 17:46:54 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-09-01 20:20:56 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable)
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
|
|
|
|
struct wined3d_light_info *light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
struct list *e;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, light_idx %u, enable %p.\n", device, light_idx, enable);
|
|
|
|
|
|
|
|
LIST_FOR_EACH(e, &device->stateBlock->state.light_map[hash_idx])
|
2009-10-14 10:55:16 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
|
|
|
|
if (light_info->OriginalIndex == light_idx)
|
|
|
|
break;
|
|
|
|
light_info = NULL;
|
2007-02-14 17:46:54 +01:00
|
|
|
}
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!light_info)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Light enabled state requested but light not defined.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
2007-02-14 17:46:54 +01:00
|
|
|
/* true is 128 according to SetLightEnable */
|
2011-05-16 23:01:21 +02:00
|
|
|
*enable = light_info->enabled ? 128 : 0;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device,
|
|
|
|
UINT plane_idx, const struct wined3d_vec4 *plane)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Validate plane_idx. */
|
|
|
|
if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application has requested clipplane this device doesn't support.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.clipplane |= 1 << plane_idx;
|
2007-02-28 14:36:36 +01:00
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
if (!memcmp(&device->updateStateBlock->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;
|
|
|
|
}
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
device->updateStateBlock->state.clip_planes[plane_idx] = *plane;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_CLIPPLANE(plane_idx));
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_clip_plane(const struct wined3d_device *device,
|
|
|
|
UINT plane_idx, struct wined3d_vec4 *plane)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Validate plane_idx. */
|
|
|
|
if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application has requested clipplane this device doesn't support.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:01:06 +02:00
|
|
|
*plane = device->stateBlock->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
|
|
|
}
|
|
|
|
|
2011-11-20 20:27:13 +01:00
|
|
|
HRESULT 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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.material = TRUE;
|
|
|
|
device->updateStateBlock->state.material = *material;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
|
|
|
/* Handle recording of state blocks */
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_MATERIAL);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-29 18:53:42 +01:00
|
|
|
}
|
|
|
|
|
2011-11-20 20:27:13 +01:00
|
|
|
HRESULT 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);
|
|
|
|
|
|
|
|
*material = device->updateStateBlock->state.material;
|
|
|
|
|
2011-11-20 20:27:13 +01:00
|
|
|
TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->diffuse.r, material->diffuse.g,
|
|
|
|
material->diffuse.b, material->diffuse.a);
|
|
|
|
TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->ambient.r, material->ambient.g,
|
|
|
|
material->ambient.b, material->ambient.a);
|
|
|
|
TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->specular.r, material->specular.g,
|
|
|
|
material->specular.b, material->specular.a);
|
|
|
|
TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n",
|
|
|
|
material->emissive.r, material->emissive.g,
|
|
|
|
material->emissive.b, material->emissive.a);
|
|
|
|
TRACE("power %.8e.\n", material->power);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
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_index_buffer(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
struct wined3d_buffer *buffer, enum wined3d_format_id format_id)
|
2009-09-25 13:31:45 +02:00
|
|
|
{
|
2011-03-03 21:49:10 +01:00
|
|
|
struct wined3d_buffer *prev_buffer;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, buffer %p, format %s.\n",
|
|
|
|
device, buffer, debug_d3dformat(format_id));
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
prev_buffer = device->updateStateBlock->state.index_buffer;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.indices = TRUE;
|
|
|
|
device->updateStateBlock->state.index_buffer = buffer;
|
|
|
|
device->updateStateBlock->state.index_format = format_id;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2011-03-03 21:49:10 +01:00
|
|
|
if (buffer)
|
|
|
|
wined3d_buffer_incref(buffer);
|
|
|
|
if (prev_buffer)
|
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
if (prev_buffer != buffer)
|
|
|
|
{
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2011-03-03 21:49:10 +01:00
|
|
|
if (buffer)
|
2011-03-03 21:49:09 +01:00
|
|
|
{
|
2012-04-25 21:24:22 +02:00
|
|
|
InterlockedIncrement(&buffer->resource.bind_count);
|
2011-03-03 21:49:10 +01:00
|
|
|
wined3d_buffer_incref(buffer);
|
2009-04-06 13:38:56 +02:00
|
|
|
}
|
2011-03-03 21:49:10 +01:00
|
|
|
if (prev_buffer)
|
2011-03-03 21:49:09 +01:00
|
|
|
{
|
2012-04-25 21:24:22 +02:00
|
|
|
InterlockedDecrement(&prev_buffer->resource.bind_count);
|
2011-03-03 21:49:10 +01:00
|
|
|
wined3d_buffer_decref(prev_buffer);
|
2009-04-06 13:38:56 +02:00
|
|
|
}
|
2007-02-19 15:25:32 +01:00
|
|
|
}
|
2009-04-06 13:38:56 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:15:53 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_index_buffer(const struct wined3d_device *device, struct wined3d_buffer **buffer)
|
2009-09-25 13:31:46 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, buffer %p.\n", device, buffer);
|
2011-03-03 21:49:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*buffer = device->stateBlock->state.index_buffer;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
if (*buffer)
|
|
|
|
wined3d_buffer_incref(*buffer);
|
2011-03-03 21:49:09 +01:00
|
|
|
|
2011-03-03 21:49:10 +01:00
|
|
|
TRACE("Returning %p.\n", *buffer);
|
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
|
|
|
}
|
|
|
|
|
2007-01-02 21:07:39 +01:00
|
|
|
/* Method to offer d3d9 a simple way to set the base vertex index without messing with the index buffer */
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT 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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->updateStateBlock->state.base_vertex_index == base_index)
|
2010-09-20 19:41:24 +02:00
|
|
|
{
|
2007-01-02 21:07:39 +01:00
|
|
|
TRACE("Application is setting the old value over, nothing to do\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.base_vertex_index = base_index;
|
2007-01-02 21:07:39 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
2007-01-02 21:07:39 +01:00
|
|
|
TRACE("Recording... not performing anything\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
return device->stateBlock->state.base_vertex_index;
|
2007-06-06 18:40:02 +02:00
|
|
|
}
|
|
|
|
|
2011-11-21 18:48:40 +01:00
|
|
|
HRESULT CDECL wined3d_device_set_viewport(struct wined3d_device *device, const struct wined3d_viewport *viewport)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, viewport %p.\n", device, viewport);
|
2011-11-21 18:48:40 +01:00
|
|
|
TRACE("x %u, y %u, w %u, h %u, min_z %.8e, max_z %.8e.\n",
|
|
|
|
viewport->x, viewport->y, viewport->width, viewport->height, viewport->min_z, viewport->max_z);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
device->updateStateBlock->changed.viewport = TRUE;
|
|
|
|
device->updateStateBlock->state.viewport = *viewport;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
|
|
|
/* Handle recording of state blocks */
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
2004-12-09 12:42:34 +01:00
|
|
|
TRACE("Recording... not performing anything\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VIEWPORT);
|
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
|
|
|
}
|
|
|
|
|
2011-11-21 18:48:40 +01:00
|
|
|
HRESULT CDECL wined3d_device_get_viewport(const struct wined3d_device *device, struct wined3d_viewport *viewport)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, viewport %p.\n", device, viewport);
|
|
|
|
|
|
|
|
*viewport = device->stateBlock->state.viewport;
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_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
|
|
|
DWORD old_value = device->stateBlock->state.render_states[state];
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, state %s (%#x), value %#x.\n", device, debug_d3drenderstate(state), state, value);
|
2006-12-15 19:16:36 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.renderState[state >> 5] |= 1 << (state & 0x1f);
|
|
|
|
device->updateStateBlock->state.render_states[state] = value;
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Compared here and not before the assignment to allow proper stateblock recording. */
|
|
|
|
if (value == old_value)
|
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
|
|
|
else
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(state));
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-09-06 19:19:52 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_render_state(const 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 %p.\n", device, debug_d3drenderstate(state), state, value);
|
2010-07-26 12:06:35 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*value = device->stateBlock->state.render_states[state];
|
2010-07-26 12:06:35 +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_sampler_state(struct wined3d_device *device,
|
2012-01-08 21:14:59 +01:00
|
|
|
UINT sampler_idx, enum wined3d_sampler_state state, DWORD value)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
DWORD old_value;
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, sampler_idx %u, state %s, value %#x.\n",
|
|
|
|
device, sampler_idx, debug_d3dsamplerstate(state), value);
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2006-12-19 23:17:17 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (sampler_idx >= sizeof(device->stateBlock->state.sampler_states)
|
|
|
|
/ sizeof(*device->stateBlock->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);
|
2008-01-15 08:06:37 +01:00
|
|
|
return WINED3D_OK; /* Windows accepts overflowing this array ... we do not. */
|
|
|
|
}
|
2010-09-16 11:19:58 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
old_value = device->stateBlock->state.sampler_states[sampler_idx][state];
|
|
|
|
device->updateStateBlock->state.sampler_states[sampler_idx][state] = value;
|
|
|
|
device->updateStateBlock->changed.samplerState[sampler_idx] |= 1 << state;
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Handle recording of state blocks. */
|
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-08-01 12:58:31 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (old_value == value)
|
|
|
|
{
|
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
2006-12-19 23:17:17 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(sampler_idx));
|
2006-12-19 23:26:39 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-07 20:22:00 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_sampler_state(const 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 %p.\n",
|
|
|
|
device, sampler_idx, debug_d3dsamplerstate(state), value);
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2007-06-25 22:45:57 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (sampler_idx >= sizeof(device->stateBlock->state.sampler_states)
|
|
|
|
/ sizeof(*device->stateBlock->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);
|
2008-01-15 08:06:37 +01:00
|
|
|
return WINED3D_OK; /* Windows accepts overflowing this array ... we do not. */
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
*value = device->stateBlock->state.sampler_states[sampler_idx][state];
|
|
|
|
TRACE("Returning %#x.\n", *value);
|
2005-03-02 13:16:10 +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_set_scissor_rect(struct wined3d_device *device, const RECT *rect)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, rect %s.\n", device, wine_dbgstr_rect(rect));
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.scissorRect = TRUE;
|
|
|
|
if (EqualRect(&device->updateStateBlock->state.scissor_rect, rect))
|
2010-09-15 12:00:05 +02:00
|
|
|
{
|
|
|
|
TRACE("App is setting the old scissor rectangle over, nothing to do.\n");
|
2007-02-19 15:25:16 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
CopyRect(&device->updateStateBlock->state.scissor_rect, rect);
|
2007-01-10 11:28:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2007-01-10 11:28:42 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SCISSORRECT);
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-07 20:22:01 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, rect %p.\n", device, rect);
|
|
|
|
|
|
|
|
*rect = device->updateStateBlock->state.scissor_rect;
|
|
|
|
TRACE("Returning rect %s.\n", wine_dbgstr_rect(rect));
|
2005-03-02 13:16:10 +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_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
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
struct wined3d_vertex_declaration *prev = device->updateStateBlock->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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (declaration)
|
|
|
|
wined3d_vertex_declaration_incref(declaration);
|
|
|
|
if (prev)
|
|
|
|
wined3d_vertex_declaration_decref(prev);
|
2009-09-28 10:05:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.vertex_declaration = declaration;
|
|
|
|
device->updateStateBlock->changed.vertexDecl = TRUE;
|
2005-12-16 12:38:24 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2007-01-04 00:07:00 +01:00
|
|
|
return WINED3D_OK;
|
2011-05-16 23:01:21 +02:00
|
|
|
}
|
|
|
|
else if (declaration == prev)
|
|
|
|
{
|
|
|
|
/* Checked after the assignment to allow proper stateblock recording. */
|
|
|
|
TRACE("Application is setting the old declaration over, nothing to do.\n");
|
2007-01-04 00:07:00 +01:00
|
|
|
return WINED3D_OK;
|
2005-12-16 12:38:24 +01:00
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VDECL);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-08 23:50:38 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vertex_declaration(const 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
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, declaration %p.\n", device, declaration);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*declaration = device->stateBlock->state.vertex_declaration;
|
|
|
|
if (*declaration)
|
|
|
|
wined3d_vertex_declaration_incref(*declaration);
|
2011-02-02 20:22:50 +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_set_vertex_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
2010-09-20 12:04:27 +02:00
|
|
|
{
|
2011-03-30 20:49:26 +02:00
|
|
|
struct wined3d_shader *prev = device->updateStateBlock->state.vertex_shader;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2011-03-30 20:49:26 +02:00
|
|
|
device->updateStateBlock->state.vertex_shader = shader;
|
2011-03-29 19:21:47 +02:00
|
|
|
device->updateStateBlock->changed.vertexShader = TRUE;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-03-29 19:21:47 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
if (shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(shader);
|
2011-03-29 19:21:47 +02:00
|
|
|
if (prev)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_decref(prev);
|
2011-03-29 19:21:47 +02:00
|
|
|
TRACE("Recording... not performing anything.\n");
|
2007-01-04 00:07:45 +01:00
|
|
|
return WINED3D_OK;
|
2011-03-29 19:21:47 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
if (shader == prev)
|
2011-03-29 19:21:47 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application is setting the old shader over, nothing to do.\n");
|
2007-01-04 00:07:45 +01:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:47 +02:00
|
|
|
if (shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(shader);
|
2011-03-29 19:21:47 +02:00
|
|
|
if (prev)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_decref(prev);
|
2007-01-02 00:35:07 +01:00
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VSHADER);
|
2007-01-02 00:35:07 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
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-03-30 20:49:26 +02:00
|
|
|
struct wined3d_shader *shader;
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2011-03-30 20:49:26 +02:00
|
|
|
shader = device->stateBlock->state.vertex_shader;
|
2011-03-29 19:21:47 +02:00
|
|
|
if (shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(shader);
|
2010-09-06 22:18:55 +02:00
|
|
|
|
|
|
|
TRACE("Returning %p.\n", shader);
|
|
|
|
return shader;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_b(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
|
|
|
UINT i;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(&device->updateStateBlock->state.vs_consts_b[start_register], constants, count * sizeof(BOOL));
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set BOOL constant %u to %s.\n", start_register + i, constants[i] ? "true" : "false");
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
|
|
|
device->updateStateBlock->changed.vertexShaderConstantsB |= (1 << i);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 22:25:41 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_b(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(constants, &device->stateBlock->state.vs_consts_b[start_register], count * sizeof(BOOL));
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_i(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
|
|
|
UINT i;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(&device->updateStateBlock->state.vs_consts_i[start_register * 4], constants, count * sizeof(int) * 4);
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set INT constant %u to {%d, %d, %d, %d}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
|
|
|
device->updateStateBlock->changed.vertexShaderConstantsI |= (1 << i);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-12-20 11:46:52 +01:00
|
|
|
}
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-09-11 22:25:42 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_i(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(constants, &device->stateBlock->state.vs_consts_i[start_register * 4], count * sizeof(int) * 4);
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-12-20 11:46:52 +01:00
|
|
|
}
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const float *constants, UINT vector4f_count)
|
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
UINT i;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Specifically test start_register > limit to catch MAX_UINT overflows
|
|
|
|
* when adding start_register + vector4f_count. */
|
|
|
|
if (!constants
|
|
|
|
|| start_register + vector4f_count > device->d3d_vshader_constantF
|
|
|
|
|| start_register > device->d3d_vshader_constantF)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(&device->updateStateBlock->state.vs_consts_f[start_register * 4],
|
|
|
|
constants, vector4f_count * sizeof(float) * 4);
|
|
|
|
if (TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
for (i = 0; i < vector4f_count; ++i)
|
|
|
|
TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2007-02-20 22:43:53 +01:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->isRecordingState)
|
2008-12-17 17:07:25 +01:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
device->shader_backend->shader_update_float_vertex_constants(device, start_register, vector4f_count);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
|
2008-12-17 17:07:25 +01:00
|
|
|
}
|
2008-03-04 02:30:23 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memset(device->updateStateBlock->changed.vertexShaderConstantsF + start_register, 1,
|
|
|
|
sizeof(*device->updateStateBlock->changed.vertexShaderConstantsF) * vector4f_count);
|
2008-03-04 02:30:23 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-12 19:51:19 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_f(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, float *constants, UINT vector4f_count)
|
|
|
|
{
|
|
|
|
int count = min(vector4f_count, device->d3d_vshader_constantF - start_register);
|
2005-09-21 12:19:29 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || count < 0)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(constants, &device->stateBlock->state.vs_consts_f[start_register * 4], count * sizeof(float) * 4);
|
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-11-29 17:05:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-12 19:51:18 +02:00
|
|
|
static void device_invalidate_texture_stage(const struct wined3d_device *device, DWORD stage)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2006-12-19 23:33:34 +01:00
|
|
|
DWORD i;
|
2011-05-16 23:01:23 +02:00
|
|
|
|
|
|
|
for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i)
|
2009-01-06 11:43:45 +01:00
|
|
|
{
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, i));
|
2006-12-19 23:33:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void device_map_stage(struct wined3d_device *device, DWORD stage, DWORD unit)
|
2009-08-17 09:39:07 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
DWORD i = device->rev_tex_unit_map[unit];
|
|
|
|
DWORD j = device->texUnitMap[stage];
|
2007-06-22 20:43:19 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->texUnitMap[stage] = unit;
|
2009-08-17 09:39:07 +02:00
|
|
|
if (i != WINED3D_UNMAPPED_STAGE && i != stage)
|
2011-05-16 23:01:23 +02:00
|
|
|
device->texUnitMap[i] = WINED3D_UNMAPPED_STAGE;
|
2007-06-22 20:43:19 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->rev_tex_unit_map[unit] = stage;
|
2009-08-17 09:39:07 +02:00
|
|
|
if (j != WINED3D_UNMAPPED_STAGE && j != unit)
|
2011-05-16 23:01:23 +02:00
|
|
|
device->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
|
2007-06-22 20:43:19 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void device_update_fixed_function_usage_map(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
UINT i;
|
2007-06-22 20:43:24 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->fixed_function_usage_map = 0;
|
2010-09-16 11:19:57 +02:00
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_state *state = &device->stateBlock->state;
|
2012-01-10 20:37:01 +01:00
|
|
|
enum wined3d_texture_op color_op = state->texture_states[i][WINED3D_TSS_COLOR_OP];
|
|
|
|
enum wined3d_texture_op alpha_op = state->texture_states[i][WINED3D_TSS_ALPHA_OP];
|
2012-01-09 22:16:51 +01:00
|
|
|
DWORD color_arg1 = state->texture_states[i][WINED3D_TSS_COLOR_ARG1] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD color_arg2 = state->texture_states[i][WINED3D_TSS_COLOR_ARG2] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD color_arg3 = state->texture_states[i][WINED3D_TSS_COLOR_ARG0] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg1 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg2 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg3 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] & WINED3DTA_SELECTMASK;
|
2007-06-27 23:47:24 +02:00
|
|
|
|
2012-01-10 20:37:01 +01:00
|
|
|
/* Not used, and disable higher stages. */
|
|
|
|
if (color_op == WINED3D_TOP_DISABLE)
|
2007-06-27 23:47:24 +02:00
|
|
|
break;
|
|
|
|
|
2012-01-10 20:37:01 +01:00
|
|
|
if (((color_arg1 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG2)
|
|
|
|
|| ((color_arg2 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG1)
|
2011-05-16 23:01:23 +02:00
|
|
|
|| ((color_arg3 == WINED3DTA_TEXTURE)
|
2012-01-10 20:37:01 +01:00
|
|
|
&& (color_op == WINED3D_TOP_MULTIPLY_ADD || color_op == WINED3D_TOP_LERP))
|
|
|
|
|| ((alpha_arg1 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG2)
|
|
|
|
|| ((alpha_arg2 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG1)
|
2011-05-16 23:01:23 +02:00
|
|
|
|| ((alpha_arg3 == WINED3DTA_TEXTURE)
|
2012-01-10 20:37:01 +01:00
|
|
|
&& (alpha_op == WINED3D_TOP_MULTIPLY_ADD || alpha_op == WINED3D_TOP_LERP)))
|
2011-05-16 23:01:23 +02:00
|
|
|
device->fixed_function_usage_map |= (1 << i);
|
2007-06-27 23:47:24 +02:00
|
|
|
|
2012-01-10 20:37:01 +01:00
|
|
|
if ((color_op == WINED3D_TOP_BUMPENVMAP || color_op == WINED3D_TOP_BUMPENVMAP_LUMINANCE)
|
|
|
|
&& i < MAX_TEXTURES - 1)
|
2011-05-16 23:01:23 +02:00
|
|
|
device->fixed_function_usage_map |= (1 << (i + 1));
|
2007-06-22 20:43:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void device_map_fixed_function_samplers(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
|
2010-02-04 18:30:06 +01:00
|
|
|
{
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int i, tex;
|
2008-12-31 16:57:10 +01:00
|
|
|
WORD ffu_map;
|
2007-06-22 20:43:29 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device_update_fixed_function_usage_map(device);
|
|
|
|
ffu_map = device->fixed_function_usage_map;
|
2007-06-22 20:43:29 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->max_ffp_textures == gl_info->limits.texture_stages
|
|
|
|
|| device->stateBlock->state.lowest_disabled_stage <= device->max_ffp_textures)
|
2010-02-04 18:30:06 +01:00
|
|
|
{
|
2008-12-31 16:57:10 +01:00
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(ffu_map & 1)) continue;
|
2007-06-28 23:32:38 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->texUnitMap[i] != i)
|
|
|
|
{
|
|
|
|
device_map_stage(device, i, i);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(i));
|
2011-09-12 19:51:18 +02:00
|
|
|
device_invalidate_texture_stage(device, i);
|
2007-06-22 20:43:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-22 20:43:29 +02:00
|
|
|
/* Now work out the mapping */
|
|
|
|
tex = 0;
|
2008-12-31 16:57:10 +01:00
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(ffu_map & 1)) continue;
|
2007-06-22 20:43:29 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->texUnitMap[i] != tex)
|
|
|
|
{
|
|
|
|
device_map_stage(device, i, tex);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(i));
|
2011-09-12 19:51:18 +02:00
|
|
|
device_invalidate_texture_stage(device, i);
|
2007-06-22 20:43:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
++tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void device_map_psamplers(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
|
2010-02-04 18:30:06 +01:00
|
|
|
{
|
2011-11-08 20:48:58 +01:00
|
|
|
const enum wined3d_sampler_texture_type *sampler_type =
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.pixel_shader->reg_maps.sampler_type;
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int i;
|
2007-06-22 20:43:42 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
|
|
|
|
{
|
|
|
|
if (sampler_type[i] && device->texUnitMap[i] != i)
|
2009-04-29 09:55:06 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
device_map_stage(device, i, i);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(i));
|
2010-01-27 20:19:42 +01:00
|
|
|
if (i < gl_info->limits.texture_stages)
|
2011-09-12 19:51:18 +02:00
|
|
|
device_invalidate_texture_stage(device, i);
|
2007-06-22 20:43:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-13 20:02:26 +02:00
|
|
|
static BOOL device_unit_free_for_vs(const struct wined3d_device *device,
|
2011-11-08 20:48:58 +01:00
|
|
|
const enum wined3d_sampler_texture_type *pshader_sampler_tokens,
|
|
|
|
const enum wined3d_sampler_texture_type *vshader_sampler_tokens, DWORD unit)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
DWORD current_mapping = device->rev_tex_unit_map[unit];
|
2007-06-27 23:47:06 +02:00
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
/* Not currently used */
|
|
|
|
if (current_mapping == WINED3D_UNMAPPED_STAGE) return TRUE;
|
2007-06-27 23:47:06 +02:00
|
|
|
|
|
|
|
if (current_mapping < MAX_FRAGMENT_SAMPLERS) {
|
|
|
|
/* Used by a fragment sampler */
|
|
|
|
|
|
|
|
if (!pshader_sampler_tokens) {
|
|
|
|
/* No pixel shader, check fixed function */
|
2011-05-16 23:01:23 +02:00
|
|
|
return current_mapping >= MAX_TEXTURES || !(device->fixed_function_usage_map & (1 << current_mapping));
|
2007-06-27 23:47:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pixel shader, check the shader's sampler map */
|
|
|
|
return !pshader_sampler_tokens[current_mapping];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Used by a vertex sampler */
|
2009-08-17 09:39:06 +02:00
|
|
|
return !vshader_sampler_tokens[current_mapping - MAX_FRAGMENT_SAMPLERS];
|
2007-06-27 23:47:06 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void device_map_vsamplers(struct wined3d_device *device, BOOL ps, const struct wined3d_gl_info *gl_info)
|
2010-02-04 18:30:06 +01:00
|
|
|
{
|
2011-11-08 20:48:58 +01:00
|
|
|
const enum wined3d_sampler_texture_type *vshader_sampler_type =
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.vertex_shader->reg_maps.sampler_type;
|
2011-11-08 20:48:58 +01:00
|
|
|
const enum wined3d_sampler_texture_type *pshader_sampler_type = NULL;
|
2010-02-04 18:30:06 +01:00
|
|
|
int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1;
|
2007-06-27 23:47:06 +02:00
|
|
|
int i;
|
|
|
|
|
2010-09-20 12:04:29 +02:00
|
|
|
if (ps)
|
|
|
|
{
|
2008-12-12 09:33:51 +01:00
|
|
|
/* Note that we only care if a sampler is sampled or not, not the sampler's specific type.
|
|
|
|
* Otherwise we'd need to call shader_update_samplers() here for 1.x pixelshaders. */
|
2011-05-16 23:01:23 +02:00
|
|
|
pshader_sampler_type = device->stateBlock->state.pixel_shader->reg_maps.sampler_type;
|
2007-06-27 23:47:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD vsampler_idx = i + MAX_FRAGMENT_SAMPLERS;
|
2009-04-29 09:55:06 +02:00
|
|
|
if (vshader_sampler_type[i])
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->texUnitMap[vsampler_idx] != WINED3D_UNMAPPED_STAGE)
|
2009-03-09 14:31:28 +01:00
|
|
|
{
|
2007-06-27 23:47:06 +02:00
|
|
|
/* Already mapped somewhere */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
while (start >= 0)
|
|
|
|
{
|
|
|
|
if (device_unit_free_for_vs(device, pshader_sampler_type, vshader_sampler_type, start))
|
2009-04-29 09:55:06 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
device_map_stage(device, vsampler_idx, start);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(vsampler_idx));
|
2007-06-27 23:47:06 +02:00
|
|
|
|
|
|
|
--start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
--start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-24 21:18:51 +02:00
|
|
|
void device_update_tex_unit_map(struct wined3d_device *device)
|
2010-02-04 18:30:06 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
const struct wined3d_state *state = &device->stateBlock->state;
|
2010-09-28 12:00:24 +02:00
|
|
|
BOOL vs = use_vs(state);
|
|
|
|
BOOL ps = use_ps(state);
|
2007-07-01 23:40:57 +02:00
|
|
|
/*
|
2006-12-19 23:33:34 +01:00
|
|
|
* Rules are:
|
|
|
|
* -> Pixel shaders need a 1:1 map. In theory the shader input could be mapped too, but
|
|
|
|
* that would be really messy and require shader recompilation
|
|
|
|
* -> When the mapping of a stage is changed, sampler and ALL texture stage states have
|
|
|
|
* to be reset. Because of that try to work with a 1:1 mapping as much as possible
|
|
|
|
*/
|
2011-05-16 23:01:23 +02:00
|
|
|
if (ps)
|
|
|
|
device_map_psamplers(device, gl_info);
|
|
|
|
else
|
|
|
|
device_map_fixed_function_samplers(device, gl_info);
|
2007-06-27 23:47:06 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (vs)
|
|
|
|
device_map_vsamplers(device, ps, gl_info);
|
2006-12-19 23:33:34 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_pixel_shader(struct wined3d_device *device, struct wined3d_shader *shader)
|
2010-09-20 12:04:29 +02:00
|
|
|
{
|
2011-03-30 20:49:26 +02:00
|
|
|
struct wined3d_shader *prev = device->updateStateBlock->state.pixel_shader;
|
2011-03-29 19:21:49 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, shader %p.\n", device, shader);
|
|
|
|
|
2011-03-30 20:49:26 +02:00
|
|
|
device->updateStateBlock->state.pixel_shader = shader;
|
2011-03-29 19:21:49 +02:00
|
|
|
device->updateStateBlock->changed.pixelShader = TRUE;
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2011-03-29 19:21:49 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
if (shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(shader);
|
2011-03-29 19:21:49 +02:00
|
|
|
if (prev)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_decref(prev);
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Recording... not performing anything.\n");
|
2006-12-19 23:22:19 +01:00
|
|
|
return WINED3D_OK;
|
2005-12-15 10:25:47 +01:00
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:49 +02:00
|
|
|
if (shader == prev)
|
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Application is setting the old shader over, nothing to do.\n");
|
2006-12-19 23:22:48 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:49 +02:00
|
|
|
if (shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(shader);
|
2011-03-29 19:21:49 +02:00
|
|
|
if (prev)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_decref(prev);
|
2007-08-20 18:56:10 +02:00
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_PIXELSHADER);
|
2006-12-19 23:33:34 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
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-03-30 20:49:26 +02:00
|
|
|
struct wined3d_shader *shader;
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2011-03-30 20:49:25 +02:00
|
|
|
shader = device->stateBlock->state.pixel_shader;
|
2011-03-29 19:21:49 +02:00
|
|
|
if (shader)
|
2011-03-30 20:49:25 +02:00
|
|
|
wined3d_shader_incref(shader);
|
2010-09-06 22:18:56 +02:00
|
|
|
|
|
|
|
TRACE("Returning %p.\n", shader);
|
|
|
|
return shader;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_ps_consts_b(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
|
|
|
UINT i;
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(&device->updateStateBlock->state.ps_consts_b[start_register], constants, count * sizeof(BOOL));
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set BOOL constant %u to %s.\n", start_register + i, constants[i] ? "true" : "false");
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
|
|
|
device->updateStateBlock->changed.pixelShaderConstantsB |= (1 << i);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-09-14 20:17:31 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_b(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, BOOL *constants, UINT bool_count)
|
|
|
|
{
|
|
|
|
UINT count = min(bool_count, MAX_CONST_B - start_register);
|
2005-12-20 11:46:52 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
|
|
|
|
device, start_register, constants, bool_count);
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_B)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(constants, &device->stateBlock->state.ps_consts_b[start_register], count * sizeof(BOOL));
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_ps_consts_i(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
|
|
|
UINT i;
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(&device->updateStateBlock->state.ps_consts_i[start_register * 4], constants, count * sizeof(int) * 4);
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
TRACE("Set INT constant %u to {%d, %d, %d, %d}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = start_register; i < count + start_register; ++i)
|
|
|
|
device->updateStateBlock->changed.pixelShaderConstantsI |= (1 << i);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->isRecordingState)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
|
2007-01-06 18:17:27 +01:00
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-12-20 11:46:52 +01:00
|
|
|
}
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-09-14 20:17:32 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_i(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, int *constants, UINT vector4i_count)
|
|
|
|
{
|
|
|
|
UINT count = min(vector4i_count, MAX_CONST_I - start_register);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
|
|
|
|
device, start_register, constants, vector4i_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || start_register >= MAX_CONST_I)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(constants, &device->stateBlock->state.ps_consts_i[start_register * 4], count * sizeof(int) * 4);
|
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, const float *constants, UINT vector4f_count)
|
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
UINT i;
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Specifically test start_register > limit to catch MAX_UINT overflows
|
|
|
|
* when adding start_register + vector4f_count. */
|
|
|
|
if (!constants
|
|
|
|
|| start_register + vector4f_count > device->d3d_pshader_constantF
|
|
|
|
|| start_register > device->d3d_pshader_constantF)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(&device->updateStateBlock->state.ps_consts_f[start_register * 4],
|
|
|
|
constants, vector4f_count * sizeof(float) * 4);
|
|
|
|
if (TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
for (i = 0; i < vector4f_count; ++i)
|
|
|
|
TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
|
|
|
|
constants[i * 4], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
2007-02-20 22:43:53 +01:00
|
|
|
}
|
2006-06-06 08:46:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->isRecordingState)
|
2008-12-17 17:07:25 +01:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
device->shader_backend->shader_update_float_pixel_constants(device, start_register, vector4f_count);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
|
2008-12-17 17:07:25 +01:00
|
|
|
}
|
2008-03-04 02:30:23 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memset(device->updateStateBlock->changed.pixelShaderConstantsF + start_register, 1,
|
|
|
|
sizeof(*device->updateStateBlock->changed.pixelShaderConstantsF) * vector4f_count);
|
2008-03-04 02:30:23 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-15 20:01:52 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_f(const struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT start_register, float *constants, UINT vector4f_count)
|
|
|
|
{
|
|
|
|
int count = min(vector4f_count, device->d3d_pshader_constantF - start_register);
|
2005-09-28 12:13:00 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
|
|
|
|
device, start_register, constants, vector4f_count);
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!constants || count < 0)
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
memcpy(constants, &device->stateBlock->state.ps_consts_f[start_register * 4], count * sizeof(float) * 4);
|
|
|
|
|
2006-06-06 08:46:59 +02:00
|
|
|
return WINED3D_OK;
|
2005-11-29 17:05:54 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-09-02 19:25:01 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2006-05-12 22:21:31 +02:00
|
|
|
#define copy_and_next(dest, src, size) memcpy(dest, src, size); dest += (size)
|
2011-09-15 20:01:53 +02:00
|
|
|
static HRESULT process_vertices_strided(const struct wined3d_device *device, DWORD dwDestIndex, DWORD dwCount,
|
2010-11-18 20:50:40 +01:00
|
|
|
const struct wined3d_stream_info *stream_info, struct wined3d_buffer *dest, DWORD flags,
|
2009-04-06 14:16:59 +02:00
|
|
|
DWORD DestFVF)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2011-11-17 20:11:41 +01:00
|
|
|
struct wined3d_matrix mat, proj_mat, view_mat, world_mat;
|
2011-11-21 18:48:40 +01:00
|
|
|
struct wined3d_viewport vp;
|
2012-01-23 20:33:33 +01:00
|
|
|
UINT vertex_size;
|
2006-05-12 22:21:31 +02:00
|
|
|
unsigned int i;
|
2012-01-23 20:33:33 +01:00
|
|
|
BYTE *dest_ptr;
|
2006-05-12 22:21:31 +02:00
|
|
|
BOOL doClip;
|
2008-11-20 23:13:48 +01:00
|
|
|
DWORD numTextures;
|
2012-01-23 20:33:33 +01:00
|
|
|
HRESULT hr;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2009-08-21 09:12:29 +02:00
|
|
|
if (stream_info->use_map & (1 << WINED3D_FFP_NORMAL))
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
|
|
|
|
}
|
|
|
|
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << WINED3D_FFP_POSITION)))
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("Source has no position mask\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:00:09 +01:00
|
|
|
if (device->stateBlock->state.render_states[WINED3D_RS_CLIPPING])
|
2010-09-15 12:00:04 +02:00
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
static BOOL warned = FALSE;
|
|
|
|
/*
|
|
|
|
* The clipping code is not quite correct. Some things need
|
|
|
|
* to be checked against IDirect3DDevice3 (!), d3d8 and d3d9,
|
|
|
|
* so disable clipping for now.
|
|
|
|
* (The graphics in Half-Life are broken, and my processvertices
|
|
|
|
* test crashes with IDirect3DDevice3)
|
|
|
|
doClip = TRUE;
|
|
|
|
*/
|
|
|
|
doClip = FALSE;
|
|
|
|
if(!warned) {
|
|
|
|
warned = TRUE;
|
|
|
|
FIXME("Clipping is broken and disabled for now\n");
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
doClip = FALSE;
|
|
|
|
|
|
|
|
vertex_size = get_flexible_vertex_size(DestFVF);
|
|
|
|
if (FAILED(hr = wined3d_buffer_map(dest, dwDestIndex * vertex_size, dwCount * vertex_size, &dest_ptr, 0)))
|
|
|
|
{
|
|
|
|
WARN("Failed to map buffer, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2012-01-11 21:27:32 +01:00
|
|
|
wined3d_device_get_transform(device, WINED3D_TS_VIEW, &view_mat);
|
|
|
|
wined3d_device_get_transform(device, WINED3D_TS_PROJECTION, &proj_mat);
|
|
|
|
wined3d_device_get_transform(device, WINED3D_TS_WORLD_MATRIX(0), &world_mat);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("View mat:\n");
|
2007-01-09 00:39:30 +01:00
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._11, view_mat.u.s._12, view_mat.u.s._13, view_mat.u.s._14);
|
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._21, view_mat.u.s._22, view_mat.u.s._23, view_mat.u.s._24);
|
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._31, view_mat.u.s._32, view_mat.u.s._33, view_mat.u.s._34);
|
|
|
|
TRACE("%f %f %f %f\n", view_mat.u.s._41, view_mat.u.s._42, view_mat.u.s._43, view_mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("Proj mat:\n");
|
2007-01-09 00:39:30 +01:00
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._11, proj_mat.u.s._12, proj_mat.u.s._13, proj_mat.u.s._14);
|
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._21, proj_mat.u.s._22, proj_mat.u.s._23, proj_mat.u.s._24);
|
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._31, proj_mat.u.s._32, proj_mat.u.s._33, proj_mat.u.s._34);
|
|
|
|
TRACE("%f %f %f %f\n", proj_mat.u.s._41, proj_mat.u.s._42, proj_mat.u.s._43, proj_mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2006-06-15 17:41:17 +02:00
|
|
|
TRACE("World mat:\n");
|
2007-01-09 00:39:30 +01:00
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._11, world_mat.u.s._12, world_mat.u.s._13, world_mat.u.s._14);
|
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._21, world_mat.u.s._22, world_mat.u.s._23, world_mat.u.s._24);
|
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._31, world_mat.u.s._32, world_mat.u.s._33, world_mat.u.s._34);
|
|
|
|
TRACE("%f %f %f %f\n", world_mat.u.s._41, world_mat.u.s._42, world_mat.u.s._43, world_mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
/* Get the viewport */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_get_viewport(device, &vp);
|
2011-11-21 18:48:40 +01:00
|
|
|
TRACE("viewport x %u, y %u, width %u, height %u, min_z %.8e, max_z %.8e.\n",
|
|
|
|
vp.x, vp.y, vp.width, vp.height, vp.min_z, vp.max_z);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
multiply_matrix(&mat,&view_mat,&world_mat);
|
|
|
|
multiply_matrix(&mat,&proj_mat,&mat);
|
|
|
|
|
2006-10-31 09:16:08 +01:00
|
|
|
numTextures = (DestFVF & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
for (i = 0; i < dwCount; i+= 1) {
|
|
|
|
unsigned int tex_index;
|
|
|
|
|
2006-10-31 09:16:08 +01:00
|
|
|
if ( ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZ ) ||
|
|
|
|
((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW ) ) {
|
2006-05-12 22:21:31 +02:00
|
|
|
/* The position first */
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_POSITION];
|
2011-07-11 01:06:46 +02:00
|
|
|
const float *p = (const float *)(element->data.addr + i * element->stride);
|
2006-05-12 22:21:31 +02:00
|
|
|
float x, y, z, rhw;
|
|
|
|
TRACE("In: ( %06.2f %06.2f %06.2f )\n", p[0], p[1], p[2]);
|
|
|
|
|
|
|
|
/* Multiplication with world, view and projection matrix */
|
2009-07-07 11:08:01 +02:00
|
|
|
x = (p[0] * mat.u.s._11) + (p[1] * mat.u.s._21) + (p[2] * mat.u.s._31) + (1.0f * mat.u.s._41);
|
|
|
|
y = (p[0] * mat.u.s._12) + (p[1] * mat.u.s._22) + (p[2] * mat.u.s._32) + (1.0f * mat.u.s._42);
|
|
|
|
z = (p[0] * mat.u.s._13) + (p[1] * mat.u.s._23) + (p[2] * mat.u.s._33) + (1.0f * mat.u.s._43);
|
|
|
|
rhw = (p[0] * mat.u.s._14) + (p[1] * mat.u.s._24) + (p[2] * mat.u.s._34) + (1.0f * mat.u.s._44);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
TRACE("x=%f y=%f z=%f rhw=%f\n", x, y, z, rhw);
|
|
|
|
|
|
|
|
/* WARNING: The following things are taken from d3d7 and were not yet checked
|
|
|
|
* against d3d8 or d3d9!
|
|
|
|
*/
|
|
|
|
|
2008-03-01 05:34:39 +01:00
|
|
|
/* Clipping conditions: From msdn
|
2006-05-12 22:21:31 +02:00
|
|
|
*
|
|
|
|
* A vertex is clipped if it does not match the following requirements
|
|
|
|
* -rhw < x <= rhw
|
|
|
|
* -rhw < y <= rhw
|
|
|
|
* 0 < z <= rhw
|
|
|
|
* 0 < rhw ( Not in d3d7, but tested in d3d7)
|
|
|
|
*
|
|
|
|
* If clipping is on is determined by the D3DVOP_CLIP flag in D3D7, and
|
|
|
|
* by the D3DRS_CLIPPING in D3D9(according to the msdn, not checked)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-09-26 20:31:58 +02:00
|
|
|
if( !doClip ||
|
2006-05-12 22:21:31 +02:00
|
|
|
( (-rhw -eps < x) && (-rhw -eps < y) && ( -eps < z) &&
|
2009-08-27 10:04:56 +02:00
|
|
|
(x <= rhw + eps) && (y <= rhw + eps ) && (z <= rhw + eps) &&
|
2006-05-12 22:21:31 +02:00
|
|
|
( rhw > eps ) ) ) {
|
|
|
|
|
|
|
|
/* "Normal" viewport transformation (not clipped)
|
2006-06-15 17:38:04 +02:00
|
|
|
* 1) The values are divided by rhw
|
2006-05-12 22:21:31 +02:00
|
|
|
* 2) The y axis is negative, so multiply it with -1
|
|
|
|
* 3) Screen coordinates go from -(Width/2) to +(Width/2) and
|
|
|
|
* -(Height/2) to +(Height/2). The z range is MinZ to MaxZ
|
|
|
|
* 4) Multiply x with Width/2 and add Width/2
|
|
|
|
* 5) The same for the height
|
|
|
|
* 6) Add the viewpoint X and Y to the 2D coordinates and
|
|
|
|
* The minimum Z value to z
|
|
|
|
* 7) rhw = 1 / rhw Reciprocal of Homogeneous W....
|
|
|
|
*
|
|
|
|
* Well, basically it's simply a linear transformation into viewport
|
|
|
|
* coordinates
|
|
|
|
*/
|
|
|
|
|
|
|
|
x /= rhw;
|
|
|
|
y /= rhw;
|
|
|
|
z /= rhw;
|
|
|
|
|
|
|
|
y *= -1;
|
|
|
|
|
2011-11-21 18:48:40 +01:00
|
|
|
x *= vp.width / 2;
|
|
|
|
y *= vp.height / 2;
|
|
|
|
z *= vp.max_z - vp.min_z;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2011-11-21 18:48:40 +01:00
|
|
|
x += vp.width / 2 + vp.x;
|
|
|
|
y += vp.height / 2 + vp.y;
|
|
|
|
z += vp.min_z;
|
2006-05-12 22:21:31 +02:00
|
|
|
|
|
|
|
rhw = 1 / rhw;
|
|
|
|
} else {
|
|
|
|
/* That vertex got clipped
|
|
|
|
* Contrary to OpenGL it is not dropped completely, it just
|
|
|
|
* undergoes a different calculation.
|
|
|
|
*/
|
|
|
|
TRACE("Vertex got clipped\n");
|
|
|
|
x += rhw;
|
|
|
|
y += rhw;
|
|
|
|
|
|
|
|
x /= 2;
|
|
|
|
y /= 2;
|
|
|
|
|
2006-06-23 18:18:02 +02:00
|
|
|
/* Msdn mentions that Direct3D9 keeps a list of clipped vertices
|
2006-05-12 22:21:31 +02:00
|
|
|
* outside of the main vertex buffer memory. That needs some more
|
|
|
|
* investigation...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Writing (%f %f %f) %f\n", x, y, z, rhw);
|
|
|
|
|
|
|
|
|
|
|
|
( (float *) dest_ptr)[0] = x;
|
|
|
|
( (float *) dest_ptr)[1] = y;
|
|
|
|
( (float *) dest_ptr)[2] = z;
|
|
|
|
( (float *) dest_ptr)[3] = rhw; /* SIC, see ddraw test! */
|
|
|
|
|
|
|
|
dest_ptr += 3 * sizeof(float);
|
|
|
|
|
2012-01-23 20:33:33 +01:00
|
|
|
if ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW)
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(float);
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
|
|
|
|
if (DestFVF & WINED3DFVF_PSIZE)
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
2012-01-23 20:33:33 +01:00
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
if (DestFVF & WINED3DFVF_NORMAL)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_NORMAL];
|
2011-07-11 01:06:46 +02:00
|
|
|
const float *normal = (const float *)(element->data.addr + i * element->stride);
|
2006-05-12 22:21:31 +02:00
|
|
|
/* AFAIK this should go into the lighting information */
|
|
|
|
FIXME("Didn't expect the destination to have a normal\n");
|
|
|
|
copy_and_next(dest_ptr, normal, 3 * sizeof(float));
|
|
|
|
}
|
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
if (DestFVF & WINED3DFVF_DIFFUSE)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_DIFFUSE];
|
2011-07-11 01:06:46 +02:00
|
|
|
const DWORD *color_d = (const DWORD *)(element->data.addr + i * element->stride);
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << WINED3D_FFP_DIFFUSE)))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
static BOOL warned = FALSE;
|
|
|
|
|
2006-09-26 20:31:58 +02:00
|
|
|
if(!warned) {
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No diffuse color in source, but destination has one\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*( (DWORD *) dest_ptr) = 0xffffffff;
|
|
|
|
dest_ptr += sizeof(DWORD);
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
copy_and_next(dest_ptr, color_d, sizeof(DWORD));
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:04:56 +02:00
|
|
|
if (DestFVF & WINED3DFVF_SPECULAR)
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
/* What's the color value in the feedback buffer? */
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_SPECULAR];
|
2011-07-11 01:06:46 +02:00
|
|
|
const DWORD *color_s = (const DWORD *)(element->data.addr + i * element->stride);
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << WINED3D_FFP_SPECULAR)))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
static BOOL warned = FALSE;
|
|
|
|
|
2006-09-26 20:31:58 +02:00
|
|
|
if(!warned) {
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No specular color in source, but destination has one\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*( (DWORD *) dest_ptr) = 0xFF000000;
|
|
|
|
dest_ptr += sizeof(DWORD);
|
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
copy_and_next(dest_ptr, color_s, sizeof(DWORD));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 01:06:46 +02:00
|
|
|
for (tex_index = 0; tex_index < numTextures; ++tex_index)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_TEXCOORD0 + tex_index];
|
2011-07-11 01:06:46 +02:00
|
|
|
const float *tex_coord = (const float *)(element->data.addr + i * element->stride);
|
2009-08-21 09:12:29 +02:00
|
|
|
if (!(stream_info->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + tex_index))))
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
ERR("No source texture, but destination requests one\n");
|
2012-01-23 20:33:33 +01:00
|
|
|
dest_ptr += GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
2012-01-23 20:33:33 +01:00
|
|
|
else
|
|
|
|
{
|
2006-05-12 22:21:31 +02:00
|
|
|
copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-23 20:33:33 +01:00
|
|
|
wined3d_buffer_unmap(dest);
|
2006-06-21 15:05:38 +02:00
|
|
|
|
2006-05-12 22:21:31 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
#undef copy_and_next
|
|
|
|
|
2010-09-02 19:25:01 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
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
|
|
|
{
|
2011-07-26 19:52:43 +02:00
|
|
|
struct wined3d_state *state = &device->stateBlock->state;
|
2009-03-27 10:25:55 +01:00
|
|
|
struct wined3d_stream_info stream_info;
|
2010-05-21 09:35:24 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2012-03-28 20:22:36 +02:00
|
|
|
BOOL streamWasUP = state->user_stream;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2011-07-26 19:52:43 +02:00
|
|
|
struct wined3d_shader *vs;
|
2012-03-28 20:22:36 +02:00
|
|
|
unsigned int i;
|
2009-10-28 11:00:11 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_start_idx %u, dst_idx %u, vertex_count %u, "
|
|
|
|
"dst_buffer %p, declaration %p, flags %#x, dst_fvf %#x.\n",
|
|
|
|
device, src_start_idx, dst_idx, vertex_count,
|
|
|
|
dst_buffer, declaration, flags, dst_fvf);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (declaration)
|
|
|
|
FIXME("Output vertex declaration not implemented yet.\n");
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2008-01-02 19:51:51 +01:00
|
|
|
/* Need any context to write to the vbo. */
|
2011-05-16 23:01:23 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-05-21 09:35:24 +02:00
|
|
|
gl_info = context->gl_info;
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2011-07-26 19:52:43 +02:00
|
|
|
/* ProcessVertices reads from vertex buffers, which have to be assigned.
|
|
|
|
* DrawPrimitive and DrawPrimitiveUP control the streamIsUP flag, thus
|
|
|
|
* restore it afterwards. */
|
|
|
|
vs = state->vertex_shader;
|
|
|
|
state->vertex_shader = NULL;
|
|
|
|
state->user_stream = FALSE;
|
2012-04-30 21:30:21 +02:00
|
|
|
device_stream_info_from_declaration(device, &stream_info);
|
2011-07-26 19:52:43 +02:00
|
|
|
state->user_stream = streamWasUP;
|
|
|
|
state->vertex_shader = vs;
|
2006-06-21 15:05:38 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
/* We can't convert FROM a VBO, and vertex buffers used to source into
|
|
|
|
* process_vertices() are unlikely to ever be used for drawing. Release
|
|
|
|
* VBOs in those buffers and fix up the stream_info structure.
|
|
|
|
*
|
|
|
|
* Also apply the start index. */
|
|
|
|
for (i = 0; i < (sizeof(stream_info.elements) / sizeof(*stream_info.elements)); ++i)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2012-03-28 20:22:36 +02:00
|
|
|
struct wined3d_stream_info_element *e;
|
2009-08-21 09:12:29 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
if (!(stream_info.use_map & (1 << i)))
|
|
|
|
continue;
|
2009-08-21 09:12:29 +02:00
|
|
|
|
2012-03-28 20:22:36 +02:00
|
|
|
e = &stream_info.elements[i];
|
|
|
|
if (e->data.buffer_object)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
|
|
|
|
e->data.buffer_object = 0;
|
|
|
|
e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, gl_info));
|
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &vb->buffer_object));
|
|
|
|
vb->buffer_object = 0;
|
|
|
|
LEAVE_GL();
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
2012-03-28 20:22:36 +02:00
|
|
|
if (e->data.addr)
|
|
|
|
e->data.addr += e->stride * src_start_idx;
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = process_vertices_strided(device, dst_idx, vertex_count,
|
|
|
|
&stream_info, dst_buffer, flags, dst_fvf);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
return hr;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2004-12-13 14:35:38 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT 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
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
DWORD old_value;
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stage %u, state %s, value %#x.\n",
|
|
|
|
device, stage, debug_d3dtexturestate(state), value);
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (state > WINED3D_HIGHEST_TEXTURE_STATE)
|
2010-09-12 10:34:20 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Invalid state %#x passed.\n", state);
|
2010-09-12 10:34:20 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stage >= gl_info->limits.texture_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",
|
2011-05-16 23:01:21 +02:00
|
|
|
stage, gl_info->limits.texture_stages - 1);
|
2007-04-16 21:44:27 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
old_value = device->updateStateBlock->state.texture_states[stage][state];
|
|
|
|
device->updateStateBlock->changed.textureState[stage] |= 1 << state;
|
|
|
|
device->updateStateBlock->state.texture_states[stage][state] = value;
|
2005-08-01 12:58:31 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything.\n");
|
2006-12-19 23:00:58 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Checked after the assignments to allow proper stateblock recording. */
|
|
|
|
if (old_value == value)
|
|
|
|
{
|
|
|
|
TRACE("Application is setting the old value over, nothing to do.\n");
|
2006-12-19 23:12:26 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stage > device->stateBlock->state.lowest_disabled_stage
|
|
|
|
&& device->StateTable[STATE_TEXTURESTAGE(0, state)].representative
|
2012-01-09 22:16:51 +01:00
|
|
|
== STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP))
|
2010-09-16 11:19:57 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
/* Colorop change above lowest disabled stage? That won't change
|
|
|
|
* anything in the GL setup. Changes in other states are important on
|
|
|
|
* disabled stages too. */
|
2006-12-19 23:00:58 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-09 22:16:51 +01:00
|
|
|
if (state == WINED3D_TSS_COLOR_OP)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int i;
|
2006-12-19 23:00:58 +01:00
|
|
|
|
2012-01-10 20:37:01 +01:00
|
|
|
if (value == WINED3D_TOP_DISABLE && old_value != WINED3D_TOP_DISABLE)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
/* Previously enabled stage disabled now. Make sure to dirtify
|
|
|
|
* all enabled stages above stage, they have to be disabled.
|
2006-12-19 23:00:58 +01:00
|
|
|
*
|
2011-05-16 23:01:21 +02:00
|
|
|
* The current stage is dirtified below. */
|
|
|
|
for (i = stage + 1; i < device->stateBlock->state.lowest_disabled_stage; ++i)
|
2010-09-16 11:19:57 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Additionally dirtifying stage %u.\n", i);
|
2012-01-09 22:16:51 +01:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
|
2006-12-19 23:00:58 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
device->stateBlock->state.lowest_disabled_stage = stage;
|
|
|
|
TRACE("New lowest disabled: %u.\n", stage);
|
|
|
|
}
|
2012-01-10 20:37:01 +01:00
|
|
|
else if (value != WINED3D_TOP_DISABLE && old_value == WINED3D_TOP_DISABLE)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
/* Previously disabled stage enabled. Stages above it may need
|
|
|
|
* enabling. Stage must be lowest_disabled_stage here, if it's
|
|
|
|
* bigger success is returned above, and stages below the lowest
|
|
|
|
* disabled stage can't be enabled (because they are enabled
|
|
|
|
* already).
|
2006-12-19 23:00:58 +01:00
|
|
|
*
|
2011-05-16 23:01:21 +02:00
|
|
|
* Again stage stage doesn't need to be dirtified here, it is
|
|
|
|
* handled below. */
|
|
|
|
for (i = stage + 1; i < gl_info->limits.texture_stages; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2012-01-10 20:37:01 +01:00
|
|
|
if (device->updateStateBlock->state.texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
|
2006-12-19 23:00:58 +01:00
|
|
|
break;
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("Additionally dirtifying stage %u due to enable.\n", i);
|
2012-01-09 22:16:51 +01:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
|
2006-12-19 23:00:58 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
device->stateBlock->state.lowest_disabled_stage = i;
|
|
|
|
TRACE("New lowest disabled: %u.\n", i);
|
2006-12-19 23:00:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, state));
|
2006-12-19 23:00:58 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-09-18 21:05:31 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_texture_stage_state(const 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
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stage %u, state %s, value %p.\n",
|
|
|
|
device, stage, debug_d3dtexturestate(state), value);
|
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);
|
2010-09-12 10:34:20 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*value = device->updateStateBlock->state.texture_states[stage][state];
|
|
|
|
TRACE("Returning %#x.\n", *value);
|
2010-09-12 10:34:20 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-13 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT stage, struct wined3d_texture *texture)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *prev;
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, stage %u, texture %p.\n", device, stage, texture);
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2007-06-25 22:46:01 +02:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
/* Windows accepts overflowing this array... we do not. */
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stage >= sizeof(device->stateBlock->state.textures) / sizeof(*device->stateBlock->state.textures))
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
WARN("Ignoring invalid stage %u.\n", stage);
|
|
|
|
return WINED3D_OK;
|
2008-01-15 08:06:37 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
if (texture && texture->resource.pool == WINED3D_POOL_SCRATCH)
|
2008-12-12 09:33:51 +01:00
|
|
|
{
|
2009-09-28 10:05:02 +02:00
|
|
|
WARN("Rejecting attempt to set scratch texture.\n");
|
2008-12-12 09:33:51 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-02-06 20:57:42 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->changed.textures |= 1 << stage;
|
2009-09-28 10:04:59 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
prev = device->updateStateBlock->state.textures[stage];
|
2009-09-28 10:05:02 +02:00
|
|
|
TRACE("Previous texture %p.\n", prev);
|
2009-09-28 10:04:59 +02:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
if (texture == prev)
|
|
|
|
{
|
|
|
|
TRACE("App is setting the same texture again, nothing to do.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
TRACE("Setting new texture to %p.\n", texture);
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.textures[stage] = texture;
|
2009-09-28 10:05:02 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->isRecordingState)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
TRACE("Recording... not performing anything\n");
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
if (texture) wined3d_texture_incref(texture);
|
|
|
|
if (prev) wined3d_texture_decref(prev);
|
2009-09-28 10:05:02 +02:00
|
|
|
|
2006-12-19 23:17:17 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
if (texture)
|
|
|
|
{
|
2012-04-25 21:24:22 +02:00
|
|
|
LONG bind_count = InterlockedIncrement(&texture->resource.bind_count);
|
2006-12-19 23:26:39 +01:00
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_incref(texture);
|
2009-01-12 10:17:50 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (!prev || texture->target != prev->target)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_PIXELSHADER);
|
2009-01-12 10:17:50 +01:00
|
|
|
|
2010-01-27 20:19:42 +01:00
|
|
|
if (!prev && stage < gl_info->limits.texture_stages)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
/* The source arguments for color and alpha ops have different
|
2012-01-09 22:16:51 +01:00
|
|
|
* meanings when a NULL texture is bound, so the COLOR_OP and
|
|
|
|
* ALPHA_OP have to be dirtified. */
|
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_COLOR_OP));
|
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_ALPHA_OP));
|
2006-12-19 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:11:00 +01:00
|
|
|
if (bind_count == 1)
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->sampler = stage;
|
2005-07-26 20:49:30 +02:00
|
|
|
}
|
2005-03-14 11:12:52 +01:00
|
|
|
|
2009-09-28 10:05:02 +02:00
|
|
|
if (prev)
|
|
|
|
{
|
2012-04-25 21:24:22 +02:00
|
|
|
LONG bind_count = InterlockedDecrement(&prev->resource.bind_count);
|
2006-12-19 23:26:39 +01:00
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_decref(prev);
|
2009-09-28 10:05:02 +02:00
|
|
|
|
2010-01-27 20:19:42 +01:00
|
|
|
if (!texture && stage < gl_info->limits.texture_stages)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
2012-01-09 22:16:51 +01:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_COLOR_OP));
|
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_ALPHA_OP));
|
2006-12-19 23:00:58 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (bind_count && prev->sampler == stage)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Search for other stages the texture is bound to. Shouldn't
|
|
|
|
* happen if applications bind textures to a single stage only. */
|
|
|
|
TRACE("Searching for other stages the texture is bound to.\n");
|
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->updateStateBlock->state.textures[i] == prev)
|
2009-09-28 10:05:02 +02:00
|
|
|
{
|
|
|
|
TRACE("Texture is also bound to stage %u.\n", i);
|
2011-03-28 21:58:42 +02:00
|
|
|
prev->sampler = i;
|
2006-12-19 23:26:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-24 17:15:24 +02:00
|
|
|
}
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(stage));
|
2006-12-19 23:26:39 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-19 21:50:26 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_texture(const struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT stage, struct wined3d_texture **texture)
|
2011-03-18 19:11:00 +01:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, stage %u, texture %p.\n", device, stage, texture);
|
2007-06-25 22:46:01 +02:00
|
|
|
|
2011-03-18 19:11:00 +01:00
|
|
|
if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
|
|
|
|
stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (stage >= sizeof(device->stateBlock->state.textures) / sizeof(*device->stateBlock->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);
|
2008-01-15 08:06:37 +01:00
|
|
|
return WINED3D_OK; /* Windows accepts overflowing this array ... we do not. */
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
*texture = device->stateBlock->state.textures[stage];
|
2011-03-18 19:11:00 +01:00
|
|
|
if (*texture)
|
|
|
|
wined3d_texture_incref(*texture);
|
2006-10-29 01:54:25 +02:00
|
|
|
|
2011-03-18 19:11:00 +01:00
|
|
|
TRACE("Returning %p.\n", *texture);
|
2007-06-25 22:46:01 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-19 21:50:27 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx,
|
2012-01-06 11:20:06 +01:00
|
|
|
UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer)
|
2009-12-16 19:55:58 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-06-23 13:05:24 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
|
|
|
|
device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer);
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain);
|
2009-12-16 19:55:58 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr);
|
|
|
|
return hr;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
2009-12-16 19:55:58 +01:00
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
hr = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type, backbuffer);
|
|
|
|
wined3d_swapchain_decref(swapchain);
|
2009-12-16 19:55:58 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to get backbuffer %u, hr %#x.\n", backbuffer_idx, hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-21 21:01:46 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps)
|
2011-02-01 19:39:53 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, caps %p.\n", device, caps);
|
2011-02-01 19:39:53 +01:00
|
|
|
|
2011-11-27 21:34:49 +01:00
|
|
|
return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal,
|
|
|
|
device->create_parms.device_type, caps);
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-21 21:01:47 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_display_mode(const struct wined3d_device *device,
|
2011-11-16 20:08:06 +01:00
|
|
|
UINT swapchain_idx, struct wined3d_display_mode *mode)
|
2011-04-13 19:14:32 +02:00
|
|
|
{
|
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-06-23 13:05:24 +02:00
|
|
|
HRESULT hr;
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, mode %p.\n", device, swapchain_idx, mode);
|
2011-04-13 19:14:32 +02:00
|
|
|
|
|
|
|
if (swapchain_idx)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain);
|
2011-04-13 19:14:31 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
hr = wined3d_swapchain_get_display_mode(swapchain, mode);
|
|
|
|
wined3d_swapchain_decref(swapchain);
|
2006-05-18 22:42:22 +02:00
|
|
|
}
|
2011-04-13 19:14:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-29 18:58:56 +02:00
|
|
|
const struct wined3d_adapter *adapter = device->adapter;
|
|
|
|
|
2011-04-13 19:14:32 +02:00
|
|
|
/* Don't read the real display mode, but return the stored mode
|
|
|
|
* instead. X11 can't change the color depth, and some apps are
|
|
|
|
* pretty angry if they SetDisplayMode from 24 to 16 bpp and find out
|
|
|
|
* that GetDisplayMode still returns 24 bpp.
|
|
|
|
*
|
|
|
|
* Also don't relay to the swapchain because with ddraw it's possible
|
|
|
|
* that there isn't a swapchain at all. */
|
2011-11-16 20:08:06 +01:00
|
|
|
mode->width = adapter->screen_size.cx;
|
|
|
|
mode->height = adapter->screen_size.cy;
|
|
|
|
mode->format_id = adapter->screen_format;
|
|
|
|
mode->refresh_rate = 0;
|
2006-05-18 22:42:22 +02:00
|
|
|
hr = WINED3D_OK;
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
return hr;
|
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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->isRecordingState)
|
|
|
|
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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_stateblock_decref(device->updateStateBlock);
|
|
|
|
device->updateStateBlock = stateblock;
|
|
|
|
device->isRecordingState = TRUE;
|
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)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_stateblock *object = device->updateStateBlock;
|
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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->isRecordingState)
|
|
|
|
{
|
|
|
|
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;
|
2011-05-16 23:01:23 +02:00
|
|
|
device->isRecordingState = FALSE;
|
|
|
|
device->updateStateBlock = device->stateBlock;
|
|
|
|
wined3d_stateblock_incref(device->updateStateBlock);
|
2011-01-28 20:05:42 +01:00
|
|
|
|
|
|
|
TRACE("Returning stateblock %p.\n", *stateblock);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_begin_scene(struct wined3d_device *device)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2004-11-28 16:04:41 +01:00
|
|
|
/* At the moment we have no need for any functionality at the beginning
|
2011-05-16 23:01:23 +02:00
|
|
|
* of a scene. */
|
|
|
|
TRACE("device %p.\n", device);
|
2007-02-09 16:35:45 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->inScene)
|
|
|
|
{
|
|
|
|
WARN("Already in scene, returning WINED3DERR_INVALIDCALL.\n");
|
2007-02-09 16:35:45 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
device->inScene = TRUE;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-11-28 16:04:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_end_scene(struct wined3d_device *device)
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2007-02-09 16:35:45 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->inScene)
|
|
|
|
{
|
|
|
|
WARN("Not in scene, returning WINED3DERR_INVALIDCALL.\n");
|
2007-02-09 16:35:45 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2005-03-14 11:12:52 +01:00
|
|
|
/* We only have to do this if we need to read the, swapbuffers performs a flush for us */
|
2009-08-26 11:44:34 +02:00
|
|
|
wglFlush();
|
2008-08-04 20:34:47 +02:00
|
|
|
/* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever
|
2009-10-28 11:00:11 +01:00
|
|
|
* fails. */
|
|
|
|
context_release(context);
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->inScene = FALSE;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2011-10-03 20:22:52 +02:00
|
|
|
HRESULT CDECL wined3d_device_present(const struct wined3d_device *device, const RECT *src_rect,
|
2011-04-07 18:45:57 +02:00
|
|
|
const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-04-07 18:45:57 +02:00
|
|
|
UINT i;
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
|
|
|
|
device, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
|
2011-04-07 18:45:57 +02:00
|
|
|
dst_window_override, dirty_region);
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2011-04-07 18:45:57 +02:00
|
|
|
for (i = 0; i < device->swapchain_count; ++i)
|
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_present(device->swapchains[i], src_rect,
|
|
|
|
dst_rect, dst_window_override, dirty_region, 0);
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
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
|
|
|
{
|
2010-08-23 18:28:06 +02:00
|
|
|
RECT draw_rect;
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2011-11-15 21:18:28 +01:00
|
|
|
TRACE("device %p, rect_count %u, rects %p, flags %#x, color {%.8e, %.8e, %.8e, %.8e}, depth %.8e, stencil %u.\n",
|
|
|
|
device, rect_count, rects, flags, color->r, color->g, color->b, color->a, depth, stencil);
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2011-03-11 11:15:25 +01:00
|
|
|
if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL))
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
struct wined3d_surface *ds = device->fb.depth_stencil;
|
2011-03-11 11:15:25 +01:00
|
|
|
if (!ds)
|
|
|
|
{
|
|
|
|
WARN("Clearing depth and/or stencil without a depth stencil buffer attached, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
/* TODO: What about depth stencil buffers without stencil bits? */
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
else if (flags & WINED3DCLEAR_TARGET)
|
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
if (ds->resource.width < device->fb.render_targets[0]->resource.width
|
|
|
|
|| ds->resource.height < device->fb.render_targets[0]->resource.height)
|
2011-03-11 11:15:25 +01:00
|
|
|
{
|
|
|
|
WARN("Silently ignoring depth and target clear with mismatching sizes\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
2007-03-06 13:35:56 +01:00
|
|
|
}
|
|
|
|
|
2011-07-05 22:30:57 +02:00
|
|
|
wined3d_get_draw_rect(&device->stateBlock->state, &draw_rect);
|
2012-04-15 18:57:14 +02:00
|
|
|
device_clear_render_targets(device, device->adapter->gl_info.limits.buffers,
|
|
|
|
&device->fb, rect_count, rects, &draw_rect, flags, color, depth, stencil);
|
2010-08-23 18:28:06 +02:00
|
|
|
|
2012-04-15 18:57:14 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-14 12:54:27 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_set_primitive_type(struct wined3d_device *device,
|
2011-12-11 21:43:32 +01:00
|
|
|
enum wined3d_primitive_type primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, primitive_type %s\n", device, debug_d3dprimitivetype(primitive_type));
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->updateStateBlock->changed.primitive_type = TRUE;
|
|
|
|
device->updateStateBlock->state.gl_primitive_type = gl_primitive_type_from_d3d(primitive_type);
|
2009-03-05 12:30:43 +01:00
|
|
|
}
|
|
|
|
|
2011-10-09 19:01:22 +02:00
|
|
|
void CDECL wined3d_device_get_primitive_type(const struct wined3d_device *device,
|
2011-12-11 21:43:32 +01:00
|
|
|
enum wined3d_primitive_type *primitive_type)
|
2009-03-05 12:30:43 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, primitive_type %p\n", device, primitive_type);
|
2009-03-05 12:30:43 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
*primitive_type = d3d_primitive_type_from_gl(device->stateBlock->state.gl_primitive_type);
|
2009-03-05 12:30:43 +01:00
|
|
|
|
|
|
|
TRACE("Returning %s\n", debug_d3dprimitivetype(*primitive_type));
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_primitive(struct wined3d_device *device, UINT start_vertex, UINT vertex_count)
|
2009-03-05 12:30:42 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, start_vertex %u, vertex_count %u.\n", device, start_vertex, vertex_count);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->stateBlock->state.vertex_declaration)
|
2010-09-17 11:59:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Called without a valid vertex declaration set.\n");
|
2008-04-07 12:08:16 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2007-03-10 00:44:46 +01:00
|
|
|
/* The index buffer is not needed here, but restore it, otherwise it is hell to keep track of */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->stateBlock->state.user_stream)
|
2010-09-20 19:41:22 +02:00
|
|
|
{
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.user_stream = FALSE;
|
2007-03-10 00:44:46 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->stateBlock->state.load_base_vertex_index)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.load_base_vertex_index = 0;
|
2011-06-11 16:18:45 +02:00
|
|
|
device_invalidate_state(device, STATE_BASEVERTEXINDEX);
|
2007-01-06 18:19:55 +01:00
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
|
|
|
|
/* Account for the loading offset due to index buffers. Instead of
|
|
|
|
* reloading all sources correct it with the startvertex parameter. */
|
2012-05-01 20:25:27 +02:00
|
|
|
drawPrimitive(device, vertex_count, start_vertex, FALSE, NULL);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *device, UINT start_idx, UINT index_count)
|
2009-03-05 12:30:42 +01:00
|
|
|
{
|
2011-06-11 16:18:45 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
|
|
|
|
|
2012-05-01 20:25:28 +02:00
|
|
|
if (!device->stateBlock->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;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->stateBlock->state.vertex_declaration)
|
2010-09-17 11:59:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Called without a valid vertex declaration set.\n");
|
2008-04-07 12:08:16 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->stateBlock->state.user_stream)
|
2010-09-20 19:41:22 +02:00
|
|
|
{
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.user_stream = FALSE;
|
2007-03-10 00:44:46 +01:00
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-06-11 16:18:45 +02:00
|
|
|
if (!gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX] &&
|
|
|
|
device->stateBlock->state.load_base_vertex_index != device->stateBlock->state.base_vertex_index)
|
2010-09-20 19:41:24 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.load_base_vertex_index = device->stateBlock->state.base_vertex_index;
|
2011-06-11 16:18:45 +02:00
|
|
|
device_invalidate_state(device, STATE_BASEVERTEXINDEX);
|
2007-01-06 18:19:55 +01:00
|
|
|
}
|
|
|
|
|
2012-05-01 20:25:28 +02:00
|
|
|
drawPrimitive(device, index_count, start_idx, TRUE, NULL);
|
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
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_primitive_up(struct wined3d_device *device, UINT vertex_count,
|
|
|
|
const void *stream_data, UINT stream_stride)
|
2009-03-05 12:30:42 +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 *vb;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, vertex count %u, stream_data %p, stream_stride %u.\n",
|
|
|
|
device, vertex_count, stream_data, stream_stride);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->stateBlock->state.vertex_declaration)
|
2010-09-17 11:59:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Called without a valid vertex declaration set.\n");
|
2008-04-07 12:08:16 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2004-12-20 20:27:06 +01:00
|
|
|
/* Note in the following, it's not this type, but that's the purpose of streamIsUP */
|
2011-05-16 23:01:23 +02:00
|
|
|
stream = &device->stateBlock->state.streams[0];
|
2011-03-03 21:49:10 +01:00
|
|
|
vb = stream->buffer;
|
2011-05-16 23:01:23 +02:00
|
|
|
stream->buffer = (struct wined3d_buffer *)stream_data;
|
2011-03-03 21:49:09 +01:00
|
|
|
if (vb)
|
|
|
|
wined3d_buffer_decref(vb);
|
2010-09-14 13:38:41 +02:00
|
|
|
stream->offset = 0;
|
2011-05-16 23:01:23 +02:00
|
|
|
stream->stride = stream_stride;
|
|
|
|
device->stateBlock->state.user_stream = TRUE;
|
2011-06-11 16:18:45 +02:00
|
|
|
if (device->stateBlock->state.load_base_vertex_index)
|
|
|
|
{
|
|
|
|
device->stateBlock->state.load_base_vertex_index = 0;
|
|
|
|
device_invalidate_state(device, STATE_BASEVERTEXINDEX);
|
|
|
|
}
|
2005-08-19 12:05:00 +02:00
|
|
|
|
2007-01-04 00:14:20 +01:00
|
|
|
/* TODO: Only mark dirty if drawing from a different UP address */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2007-01-04 00:14:20 +01:00
|
|
|
|
2012-05-01 20:25:27 +02:00
|
|
|
drawPrimitive(device, vertex_count, 0, FALSE, NULL);
|
2006-05-10 19:57:49 +02:00
|
|
|
|
|
|
|
/* MSDN specifies stream zero settings must be set to NULL */
|
2010-09-14 13:38:41 +02:00
|
|
|
stream->buffer = NULL;
|
|
|
|
stream->stride = 0;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
/* stream zero settings set to null at end, as per the msdn. No need to
|
|
|
|
* mark dirty here, the app has to set the new stream sources or use UP
|
|
|
|
* drawing again. */
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_indexed_primitive_up(struct wined3d_device *device,
|
|
|
|
UINT index_count, const void *index_data, enum wined3d_format_id index_data_format_id,
|
|
|
|
const void *stream_data, UINT stream_stride)
|
2009-03-05 12:30:42 +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 *vb, *ib;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, index_count %u, index_data %p, index_data_format %s, stream_data %p, stream_stride %u.\n",
|
|
|
|
device, index_count, index_data, debug_d3dformat(index_data_format_id), stream_data, stream_stride);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!device->stateBlock->state.vertex_declaration)
|
2010-09-17 11:59:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("(%p) : Called without a valid vertex declaration set\n", device);
|
2008-04-07 12:08:16 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
stream = &device->stateBlock->state.streams[0];
|
2011-03-03 21:49:10 +01:00
|
|
|
vb = stream->buffer;
|
2011-05-16 23:01:23 +02:00
|
|
|
stream->buffer = (struct wined3d_buffer *)stream_data;
|
2011-03-03 21:49:09 +01:00
|
|
|
if (vb)
|
|
|
|
wined3d_buffer_decref(vb);
|
2010-09-14 13:38:41 +02:00
|
|
|
stream->offset = 0;
|
2011-05-16 23:01:23 +02:00
|
|
|
stream->stride = stream_stride;
|
|
|
|
device->stateBlock->state.user_stream = TRUE;
|
2012-05-01 20:25:27 +02:00
|
|
|
device->stateBlock->state.index_format = index_data_format_id;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2007-01-02 21:07:39 +01:00
|
|
|
/* Set to 0 as per msdn. Do it now due to the stream source loading during drawPrimitive */
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.base_vertex_index = 0;
|
2011-06-11 16:18:45 +02:00
|
|
|
if (device->stateBlock->state.load_base_vertex_index)
|
|
|
|
{
|
|
|
|
device->stateBlock->state.load_base_vertex_index = 0;
|
|
|
|
device_invalidate_state(device, STATE_BASEVERTEXINDEX);
|
|
|
|
}
|
2011-06-11 16:19:45 +02:00
|
|
|
/* Invalidate the state until we have nicer tracking of the stream source pointers */
|
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2007-01-02 00:35:07 +01:00
|
|
|
|
2012-05-01 20:25:27 +02:00
|
|
|
drawPrimitive(device, index_count, 0, TRUE, index_data);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2006-05-10 19:57:49 +02:00
|
|
|
/* MSDN specifies stream zero settings and index buffer must be set to NULL */
|
2010-09-14 13:38:41 +02:00
|
|
|
stream->buffer = NULL;
|
|
|
|
stream->stride = 0;
|
2011-05-16 23:01:23 +02:00
|
|
|
ib = device->stateBlock->state.index_buffer;
|
2010-09-20 19:41:23 +02:00
|
|
|
if (ib)
|
|
|
|
{
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_decref(ib);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.index_buffer = NULL;
|
2007-08-14 14:46:38 +02:00
|
|
|
}
|
2007-01-06 18:19:55 +01:00
|
|
|
/* No need to mark the stream source state dirty here. Either the app calls UP drawing again, or it has to call
|
|
|
|
* SetStreamSource to specify a vertex buffer
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_primitive_strided(struct wined3d_device *device,
|
2011-12-07 22:08:58 +01:00
|
|
|
UINT vertex_count, const struct wined3d_strided_data *strided_data)
|
2008-12-01 15:32:15 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
/* Mark the state dirty until we have nicer tracking. It's fine to change
|
|
|
|
* baseVertexIndex because that call is only called by ddraw which does
|
|
|
|
* not need that value. */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VDECL);
|
2011-08-19 00:55:14 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2011-08-19 00:55:14 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.base_vertex_index = 0;
|
|
|
|
device->up_strided = strided_data;
|
2012-05-01 20:25:27 +02:00
|
|
|
drawPrimitive(device, vertex_count, 0, FALSE, NULL);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->up_strided = NULL;
|
2011-08-19 00:55:14 +02:00
|
|
|
|
|
|
|
/* Invalidate the states again to make sure the values from the stateblock
|
|
|
|
* are properly applied in the next regular draw. Note that the application-
|
|
|
|
* provided strided data has ovwritten pretty much the entire vertex and
|
|
|
|
* and index stream related states */
|
|
|
|
device_invalidate_state(device, STATE_VDECL);
|
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2006-05-06 16:58:57 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2007-07-27 14:39:55 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_indexed_primitive_strided(struct wined3d_device *device,
|
2011-12-07 22:08:58 +01:00
|
|
|
UINT index_count, const struct wined3d_strided_data *strided_data,
|
2011-05-16 23:01:23 +02:00
|
|
|
UINT vertex_count, const void *index_data, enum wined3d_format_id index_data_format_id)
|
2008-12-01 15:32:15 +01:00
|
|
|
{
|
2012-05-01 20:25:27 +02:00
|
|
|
enum wined3d_format_id prev_idx_format;
|
2007-07-27 14:39:55 +02:00
|
|
|
|
|
|
|
/* Mark the state dirty until we have nicer tracking
|
|
|
|
* its fine to change baseVertexIndex because that call is only called by ddraw which does not need
|
|
|
|
* that value.
|
|
|
|
*/
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VDECL);
|
2011-08-19 00:55:14 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2011-08-19 00:55:14 +02:00
|
|
|
|
2012-05-01 20:25:27 +02:00
|
|
|
prev_idx_format = device->stateBlock->state.index_format;
|
|
|
|
device->stateBlock->state.index_format = index_data_format_id;
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.user_stream = TRUE;
|
|
|
|
device->stateBlock->state.base_vertex_index = 0;
|
|
|
|
device->up_strided = strided_data;
|
2012-05-01 20:25:27 +02:00
|
|
|
drawPrimitive(device, index_count, 0, TRUE, index_data);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->up_strided = NULL;
|
2012-05-01 20:25:27 +02:00
|
|
|
device->stateBlock->state.index_format = prev_idx_format;
|
2011-08-19 00:55:14 +02:00
|
|
|
|
|
|
|
device_invalidate_state(device, STATE_VDECL);
|
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2007-07-27 14:39:55 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-21 23:17:26 +01:00
|
|
|
/* This is a helper function for UpdateTexture, there is no UpdateVolume method in D3D. */
|
2011-06-09 20:40:45 +02:00
|
|
|
static HRESULT device_update_volume(struct wined3d_device *device,
|
2011-04-14 22:41:48 +02:00
|
|
|
struct wined3d_volume *src_volume, struct wined3d_volume *dst_volume)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc src;
|
|
|
|
struct wined3d_map_desc dst;
|
2007-09-01 01:54:15 +02:00
|
|
|
HRESULT hr;
|
2009-12-21 23:17:26 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_volume %p, dst_volume %p.\n",
|
|
|
|
device, src_volume, dst_volume);
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2011-04-14 22:41:48 +02:00
|
|
|
/* TODO: Implement direct loading into the gl volume instead of using
|
|
|
|
* memcpy and dirtification to improve loading performance. */
|
|
|
|
hr = wined3d_volume_map(src_volume, &src, NULL, WINED3DLOCK_READONLY);
|
2010-10-14 13:04:02 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
2011-04-14 22:41:48 +02:00
|
|
|
hr = wined3d_volume_map(dst_volume, &dst, NULL, WINED3DLOCK_DISCARD);
|
2010-10-14 13:04:02 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-04-14 22:41:48 +02:00
|
|
|
wined3d_volume_unmap(src_volume);
|
2010-10-14 13:04:02 +02:00
|
|
|
return hr;
|
2007-09-01 01:54:15 +02:00
|
|
|
}
|
|
|
|
|
2011-12-05 22:06:57 +01:00
|
|
|
memcpy(dst.data, src.data, dst_volume->resource.size);
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2011-04-14 22:41:48 +02:00
|
|
|
hr = wined3d_volume_unmap(dst_volume);
|
2010-10-14 13:04:02 +02:00
|
|
|
if (FAILED(hr))
|
2011-04-14 22:41:48 +02:00
|
|
|
wined3d_volume_unmap(src_volume);
|
2010-10-14 13:04:02 +02:00
|
|
|
else
|
2011-04-14 22:41:48 +02:00
|
|
|
hr = wined3d_volume_unmap(src_volume);
|
2010-10-14 13:04:02 +02:00
|
|
|
|
2007-09-01 01:54:15 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2007-07-27 14:39:55 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
enum wined3d_resource_type type;
|
2009-10-19 10:12:19 +02:00
|
|
|
unsigned int level_count, i;
|
|
|
|
HRESULT hr;
|
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
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
if (src_texture == dst_texture)
|
|
|
|
{
|
|
|
|
WARN("Source and destination are the same object, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Verify that the source and destination textures are the same type. */
|
2012-01-17 21:13:36 +01:00
|
|
|
type = src_texture->resource.type;
|
|
|
|
if (dst_texture->resource.type != type)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
WARN("Source and destination have different types, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Check that both textures have the identical numbers of levels. */
|
2011-03-18 19:10:59 +01:00
|
|
|
level_count = wined3d_texture_get_level_count(src_texture);
|
|
|
|
if (wined3d_texture_get_level_count(dst_texture) != level_count)
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
WARN("Source and destination have different level counts, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2005-11-04 13:39:17 +01:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Make sure that the destination texture is loaded. */
|
2011-03-28 21:58:42 +02:00
|
|
|
dst_texture->texture_ops->texture_preload(dst_texture, SRGB_RGB);
|
2005-11-04 13:39:17 +01:00
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
/* Update every surface level of the texture. */
|
|
|
|
switch (type)
|
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface;
|
|
|
|
struct wined3d_surface *dst_surface;
|
2009-10-19 10:12:19 +02:00
|
|
|
|
|
|
|
for (i = 0; i < level_count; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
|
|
|
|
dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
|
2009-10-19 10:12:19 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-07-03 22:27:21 +02:00
|
|
|
WARN("Failed to update surface, hr %#x.\n", hr);
|
2009-10-19 10:12:19 +02:00
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_CUBE_TEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface;
|
|
|
|
struct wined3d_surface *dst_surface;
|
2009-10-19 10:12:19 +02:00
|
|
|
|
2010-10-25 12:33:39 +02:00
|
|
|
for (i = 0; i < level_count * 6; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
|
|
|
|
dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
|
2010-10-25 12:33:39 +02:00
|
|
|
if (FAILED(hr))
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
2011-07-03 22:27:21 +02:00
|
|
|
WARN("Failed to update surface, hr %#x.\n", hr);
|
2010-10-25 12:33:39 +02:00
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_VOLUME_TEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < level_count; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-06-09 20:40:45 +02:00
|
|
|
hr = device_update_volume(device,
|
2011-04-14 22:41:48 +02:00
|
|
|
volume_from_resource(wined3d_texture_get_sub_resource(src_texture, i)),
|
|
|
|
volume_from_resource(wined3d_texture_get_sub_resource(dst_texture, i)));
|
2009-10-19 10:12:19 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-06-09 20:40:45 +02:00
|
|
|
WARN("Failed to update volume, hr %#x.\n", hr);
|
2009-10-19 10:12:19 +02:00
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
2007-09-01 01:54:15 +02:00
|
|
|
|
2005-11-04 13:39:17 +01:00
|
|
|
default:
|
2009-10-19 10:12:19 +02:00
|
|
|
FIXME("Unsupported texture type %#x.\n", type);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
|
|
|
|
2009-10-19 10:12:19 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-10-11 17:24:53 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_front_buffer_data(const struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
UINT swapchain_idx, struct wined3d_surface *dst_surface)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-06-23 13:05:24 +02:00
|
|
|
HRESULT hr;
|
2010-08-15 23:21:43 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, dst_surface %p.\n", device, swapchain_idx, dst_surface);
|
2010-08-15 23:21:43 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain);
|
2010-08-15 23:21:43 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
hr = wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface);
|
|
|
|
wined3d_swapchain_decref(swapchain);
|
2010-08-15 23:21:43 +02:00
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
return hr;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-10-11 17:24:54 +02:00
|
|
|
HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes)
|
2011-03-18 19:11:00 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_state *state = &device->stateBlock->state;
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *texture;
|
|
|
|
DWORD i;
|
2008-08-21 15:10:46 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, num_passes %p.\n", device, num_passes);
|
2008-08-21 15:10:46 +02:00
|
|
|
|
2010-09-16 11:19:58 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] == WINED3D_TEXF_NONE)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Sampler state %u has minfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
|
|
|
|
return WINED3DERR_UNSUPPORTEDTEXTUREFILTER;
|
|
|
|
}
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] == WINED3D_TEXF_NONE)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Sampler state %u has magfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
|
|
|
|
return WINED3DERR_UNSUPPORTEDTEXTUREFILTER;
|
|
|
|
}
|
|
|
|
|
2011-03-11 11:49:01 +01:00
|
|
|
texture = state->textures[i];
|
2010-11-12 13:12:05 +01:00
|
|
|
if (!texture || texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING) continue;
|
2008-08-21 15:10:46 +02:00
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT)
|
2010-09-16 11:19:58 +02:00
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Non-filterable texture and mag filter enabled on samper %u, returning E_FAIL\n", i);
|
|
|
|
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
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Non-filterable texture and min filter enabled on samper %u, returning E_FAIL\n", i);
|
|
|
|
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
|
|
|
{
|
2008-08-21 15:10:46 +02:00
|
|
|
WARN("Non-filterable texture and mip filter enabled on samper %u, returning E_FAIL\n", i);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:00:09 +01:00
|
|
|
if (state->render_states[WINED3D_RS_ZENABLE] || state->render_states[WINED3D_RS_ZWRITEENABLE]
|
|
|
|
|| state->render_states[WINED3D_RS_STENCILENABLE])
|
2011-03-11 11:49:01 +01:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
struct wined3d_surface *ds = device->fb.depth_stencil;
|
|
|
|
struct wined3d_surface *target = device->fb.render_targets[0];
|
2011-03-11 11:49:01 +01:00
|
|
|
|
|
|
|
if(ds && target
|
|
|
|
&& (ds->resource.width < target->resource.width || ds->resource.height < target->resource.height))
|
|
|
|
{
|
|
|
|
WARN("Depth stencil is smaller than the color buffer, returning D3DERR_CONFLICTINGRENDERSTATE\n");
|
|
|
|
return WINED3DERR_CONFLICTINGRENDERSTATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-02 13:16:10 +01:00
|
|
|
/* return a sensible default */
|
2011-05-16 23:01:23 +02:00
|
|
|
*num_passes = 1;
|
2008-08-21 15:10:46 +02:00
|
|
|
|
|
|
|
TRACE("returning D3D_OK\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT 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;
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
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-08-27 11:58:53 +02:00
|
|
|
HRESULT hr;
|
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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain);
|
2009-12-20 20:41:37 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr);
|
|
|
|
return hr;
|
2005-08-27 11:58:53 +02:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
hr = wined3d_swapchain_get_raster_status(swapchain, raster_status);
|
|
|
|
wined3d_swapchain_decref(swapchain);
|
2009-12-20 20:41:37 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to get raster status, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
static BOOL warned;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, segments %.8e.\n", device, segments);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
if (segments != 0.0f)
|
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
if (!warned)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("device %p, segments %.8e stub!\n", device, segments);
|
2008-12-01 15:32:14 +01:00
|
|
|
warned = TRUE;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-10-13 21:43:09 +02:00
|
|
|
float CDECL wined3d_device_get_npatch_mode(const struct wined3d_device *device)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2008-12-01 15:32:14 +01:00
|
|
|
static BOOL warned;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2008-12-01 15:32:14 +01:00
|
|
|
if (!warned)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("device %p stub!\n", device);
|
2008-12-01 15:32:14 +01:00
|
|
|
warned = TRUE;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2005-03-02 13:16:10 +01:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *src_surface, const RECT *src_rect,
|
|
|
|
struct wined3d_surface *dst_surface, const POINT *dst_point)
|
2010-03-31 11:28:56 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %s.\n",
|
|
|
|
device, src_surface, wine_dbgstr_rect(src_rect),
|
2010-03-31 11:28:56 +02:00
|
|
|
dst_surface, wine_dbgstr_point(dst_point));
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
if (src_surface->resource.pool != WINED3D_POOL_SYSTEM_MEM || dst_surface->resource.pool != WINED3D_POOL_DEFAULT)
|
2010-03-31 11:28:56 +02:00
|
|
|
{
|
|
|
|
WARN("source %p must be SYSTEMMEM and dest %p must be DEFAULT, returning WINED3DERR_INVALIDCALL\n",
|
|
|
|
src_surface, dst_surface);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2005-11-04 12:13:45 +01:00
|
|
|
|
2011-10-24 20:45:42 +02:00
|
|
|
return surface_upload_from_surface(dst_surface, dst_point, src_surface, src_rect);
|
2005-01-26 21:54:00 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_rect_patch(struct wined3d_device *device, UINT handle,
|
2011-11-23 08:51:45 +01:00
|
|
|
const float *num_segs, const struct wined3d_rect_patch_info *rect_patch_info)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2012-01-20 00:36:29 +01:00
|
|
|
struct wined3d_rect_patch *patch;
|
2009-03-05 12:30:43 +01:00
|
|
|
GLenum old_primitive_type;
|
2007-07-04 17:57:45 +02:00
|
|
|
unsigned int i;
|
|
|
|
struct list *e;
|
|
|
|
BOOL found;
|
2004-10-07 06:22:21 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, handle %#x, num_segs %p, rect_patch_info %p.\n",
|
|
|
|
device, handle, num_segs, rect_patch_info);
|
|
|
|
|
|
|
|
if (!(handle || rect_patch_info))
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
/* TODO: Write a test for the return value, thus the FIXME */
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("Both handle and rect_patch_info are NULL.\n");
|
2007-07-04 17:57:45 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
i = PATCHMAP_HASHFUNC(handle);
|
2007-07-04 17:57:45 +02:00
|
|
|
found = FALSE;
|
2011-05-16 23:01:23 +02:00
|
|
|
LIST_FOR_EACH(e, &device->patches[i])
|
|
|
|
{
|
2012-01-20 00:36:29 +01:00
|
|
|
patch = LIST_ENTRY(e, struct wined3d_rect_patch, entry);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (patch->Handle == handle)
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!found)
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
TRACE("Patch does not exist. Creating a new one\n");
|
|
|
|
patch = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*patch));
|
2011-05-16 23:01:23 +02:00
|
|
|
patch->Handle = handle;
|
|
|
|
list_add_head(&device->patches[i], &patch->entry);
|
2007-07-04 17:57:45 +02:00
|
|
|
} else {
|
|
|
|
TRACE("Found existing patch %p\n", patch);
|
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
/* Since opengl does not load tesselated vertex attributes into numbered vertex
|
|
|
|
* attributes we have to tesselate, read back, and draw. This needs a patch
|
|
|
|
* management structure instance. Create one.
|
|
|
|
*
|
|
|
|
* A possible improvement is to check if a vertex shader is used, and if not directly
|
|
|
|
* draw the patch.
|
|
|
|
*/
|
|
|
|
FIXME("Drawing an uncached patch. This is slow\n");
|
|
|
|
patch = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*patch));
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (num_segs[0] != patch->numSegs[0] || num_segs[1] != patch->numSegs[1]
|
|
|
|
|| num_segs[2] != patch->numSegs[2] || num_segs[3] != patch->numSegs[3]
|
2011-11-23 08:51:45 +01:00
|
|
|
|| (rect_patch_info && memcmp(rect_patch_info, &patch->rect_patch_info, sizeof(*rect_patch_info))))
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("Tesselation density or patch info changed, retesselating\n");
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (rect_patch_info)
|
2011-11-23 08:51:45 +01:00
|
|
|
patch->rect_patch_info = *rect_patch_info;
|
2011-05-16 23:01:23 +02:00
|
|
|
|
|
|
|
patch->numSegs[0] = num_segs[0];
|
|
|
|
patch->numSegs[1] = num_segs[1];
|
|
|
|
patch->numSegs[2] = num_segs[2];
|
|
|
|
patch->numSegs[3] = num_segs[3];
|
2007-07-04 17:57:45 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = tesselate_rectpatch(device, patch);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Patch tesselation failed.\n");
|
2007-07-04 17:57:45 +02:00
|
|
|
|
|
|
|
/* Do not release the handle to store the params of the patch */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!handle)
|
2007-07-04 17:57:45 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, patch);
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2007-07-04 17:57:45 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
old_primitive_type = device->stateBlock->state.gl_primitive_type;
|
|
|
|
device->stateBlock->state.gl_primitive_type = GL_TRIANGLES;
|
|
|
|
wined3d_device_draw_primitive_strided(device, patch->numSegs[0] * patch->numSegs[1] * 2 * 3, &patch->strided);
|
|
|
|
device->stateBlock->state.gl_primitive_type = old_primitive_type;
|
2007-07-04 17:57:45 +02:00
|
|
|
|
|
|
|
/* Destroy uncached patches */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!handle)
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, patch->mem);
|
|
|
|
HeapFree(GetProcessHeap(), 0, patch);
|
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
2004-10-07 06:22:21 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_draw_tri_patch(struct wined3d_device *device, UINT handle,
|
2011-11-23 21:14:56 +01:00
|
|
|
const float *segment_count, const struct wined3d_tri_patch_info *patch_info)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("device %p, handle %#x, segment_count %p, patch_info %p stub!\n",
|
|
|
|
device, handle, segment_count, patch_info);
|
2009-12-21 23:17:26 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-12 20:50:22 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_delete_patch(struct wined3d_device *device, UINT handle)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2012-01-20 00:36:29 +01:00
|
|
|
struct wined3d_rect_patch *patch;
|
2007-07-04 17:57:45 +02:00
|
|
|
struct list *e;
|
2011-05-16 23:01:23 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("device %p, handle %#x.\n", device, handle);
|
2007-07-04 17:57:45 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
i = PATCHMAP_HASHFUNC(handle);
|
|
|
|
LIST_FOR_EACH(e, &device->patches[i])
|
|
|
|
{
|
2012-01-20 00:36:29 +01:00
|
|
|
patch = LIST_ENTRY(e, struct wined3d_rect_patch, entry);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (patch->Handle == handle)
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
TRACE("Deleting patch %p\n", patch);
|
|
|
|
list_remove(&patch->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, patch->mem);
|
|
|
|
HeapFree(GetProcessHeap(), 0, patch);
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Write a test for the return value */
|
2007-12-07 21:01:34 +01:00
|
|
|
FIXME("Attempt to destroy nonexistent patch\n");
|
2007-07-04 17:57:45 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-13 16:15:54 +02:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_color_fill(struct wined3d_device *device,
|
2011-11-15 21:18:27 +01:00
|
|
|
struct wined3d_surface *surface, const RECT *rect, const struct wined3d_color *color)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-08-04 19:53:29 +02:00
|
|
|
RECT r;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, surface %p, rect %s, color {%.8e, %.8e, %.8e, %.8e}.\n",
|
|
|
|
device, surface, wine_dbgstr_rect(rect),
|
2010-08-23 18:28:09 +02:00
|
|
|
color->r, color->g, color->b, color->a);
|
2005-08-22 11:13:49 +02:00
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
if (surface->resource.pool != WINED3D_POOL_DEFAULT && surface->resource.pool != WINED3D_POOL_SYSTEM_MEM)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2012-01-17 21:13:37 +01:00
|
|
|
WARN("Color-fill not allowed on %s surfaces.\n", debug_d3dpool(surface->resource.pool));
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-18 12:32:00 +02:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-08-04 19:53:29 +02:00
|
|
|
if (!rect)
|
|
|
|
{
|
|
|
|
SetRect(&r, 0, 0, surface->resource.width, surface->resource.height);
|
|
|
|
rect = &r;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
return surface_color_fill(surface, rect, color);
|
2004-10-07 06:22:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-05 23:38:48 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
|
2011-11-15 21:18:27 +01:00
|
|
|
struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color)
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2009-02-25 08:39:01 +01:00
|
|
|
HRESULT hr;
|
2011-08-04 19:53:30 +02:00
|
|
|
RECT rect;
|
2009-02-25 08:39:01 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
resource = rendertarget_view->resource;
|
2012-01-17 21:13:36 +01:00
|
|
|
if (resource->type != WINED3D_RTYPE_SURFACE)
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
|
|
|
FIXME("Only supported on surface resources\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-04 19:53:30 +02:00
|
|
|
SetRect(&rect, 0, 0, resource->width, resource->height);
|
|
|
|
hr = surface_color_fill(surface_from_resource(resource), &rect, color);
|
2010-08-29 21:57:44 +02:00
|
|
|
if (FAILED(hr)) ERR("Color fill failed, hr %#x.\n", hr);
|
2009-02-25 08:39:01 +01:00
|
|
|
}
|
|
|
|
|
2011-10-16 21:55:32 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_render_target(const struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT render_target_idx, struct wined3d_surface **render_target)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, render_target_idx %u, render_target %p.\n",
|
|
|
|
device, render_target_idx, render_target);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
|
|
|
if (render_target_idx >= device->adapter->gl_info.limits.buffers)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2010-08-04 11:10:24 +02:00
|
|
|
WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
|
2006-12-19 19:25:42 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
*render_target = device->fb.render_targets[render_target_idx];
|
2010-08-04 11:10:24 +02:00
|
|
|
TRACE("Returning render target %p.\n", *render_target);
|
|
|
|
|
2011-10-09 19:01:18 +02:00
|
|
|
if (!*render_target)
|
|
|
|
return WINED3DERR_NOTFOUND;
|
|
|
|
|
|
|
|
wined3d_surface_incref(*render_target);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-12 20:50:22 +01:00
|
|
|
|
2011-10-16 21:55:33 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device,
|
|
|
|
struct wined3d_surface **depth_stencil)
|
2010-08-04 11:10:25 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, depth_stencil %p.\n", device, depth_stencil);
|
2010-08-04 11:10:25 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
*depth_stencil = device->fb.depth_stencil;
|
2010-08-04 11:10:25 +02:00
|
|
|
TRACE("Returning depth/stencil surface %p.\n", *depth_stencil);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
if (!*depth_stencil)
|
|
|
|
return WINED3DERR_NOTFOUND;
|
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_incref(*depth_stencil);
|
2010-08-04 11:10:25 +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_render_target(struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT render_target_idx, struct wined3d_surface *render_target, BOOL set_viewport)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *prev;
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, render_target_idx %u, render_target %p, set_viewport %#x.\n",
|
|
|
|
device, render_target_idx, render_target, set_viewport);
|
2006-12-19 19:25:42 +01:00
|
|
|
|
2010-08-04 11:10:24 +02:00
|
|
|
if (render_target_idx >= device->adapter->gl_info.limits.buffers)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2010-08-04 11:10:24 +02:00
|
|
|
WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
|
2006-12-19 19:25:42 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
prev = device->fb.render_targets[render_target_idx];
|
2011-04-29 13:03:42 +02:00
|
|
|
if (render_target == prev)
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
|
|
|
TRACE("Trying to do a NOP SetRenderTarget operation.\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-27 12:54:52 +02:00
|
|
|
/* Render target 0 can't be set to NULL. */
|
2010-08-04 11:10:24 +02:00
|
|
|
if (!render_target && !render_target_idx)
|
2010-07-27 12:54:52 +02:00
|
|
|
{
|
|
|
|
WARN("Trying to set render target 0 to NULL.\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
2010-07-27 12:54:52 +02:00
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
if (render_target && !(render_target->resource.usage & WINED3DUSAGE_RENDERTARGET))
|
2010-08-04 11:10:24 +02:00
|
|
|
{
|
|
|
|
FIXME("Surface %p doesn't have render target usage.\n", render_target);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
if (render_target)
|
|
|
|
wined3d_surface_incref(render_target);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[render_target_idx] = render_target;
|
2010-08-17 19:03:27 +02:00
|
|
|
/* Release after the assignment, to prevent device_resource_released()
|
|
|
|
* from seeing the surface as still in use. */
|
2011-04-29 13:03:41 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_surface_decref(prev);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
|
|
|
/* Render target 0 is special. */
|
|
|
|
if (!render_target_idx && set_viewport)
|
2010-04-19 20:46:59 +02:00
|
|
|
{
|
2010-08-04 11:10:24 +02:00
|
|
|
/* Set the viewport and scissor rectangles, if requested. Tests show
|
|
|
|
* that stateblock recording is ignored, the change goes directly
|
|
|
|
* into the primary stateblock. */
|
2011-11-21 18:48:40 +01:00
|
|
|
device->stateBlock->state.viewport.height = device->fb.render_targets[0]->resource.height;
|
|
|
|
device->stateBlock->state.viewport.width = device->fb.render_targets[0]->resource.width;
|
|
|
|
device->stateBlock->state.viewport.x = 0;
|
|
|
|
device->stateBlock->state.viewport.y = 0;
|
|
|
|
device->stateBlock->state.viewport.max_z = 1.0f;
|
|
|
|
device->stateBlock->state.viewport.min_z = 0.0f;
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VIEWPORT);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
2010-09-15 12:00:05 +02:00
|
|
|
device->stateBlock->state.scissor_rect.top = 0;
|
|
|
|
device->stateBlock->state.scissor_rect.left = 0;
|
2011-11-21 18:48:40 +01:00
|
|
|
device->stateBlock->state.scissor_rect.right = device->stateBlock->state.viewport.width;
|
|
|
|
device->stateBlock->state.scissor_rect.bottom = device->stateBlock->state.viewport.height;
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SCISSORRECT);
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
2010-08-04 11:10:24 +02:00
|
|
|
|
2011-06-08 00:27:15 +02:00
|
|
|
device_invalidate_state(device, STATE_FRAMEBUFFER);
|
|
|
|
|
2007-02-12 19:21:10 +01: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_depth_stencil(struct wined3d_device *device, struct wined3d_surface *depth_stencil)
|
2010-08-04 11:10:25 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
struct wined3d_surface *prev = device->fb.depth_stencil;
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, depth_stencil %p, old depth_stencil %p.\n",
|
2011-05-18 22:30:15 +02:00
|
|
|
device, depth_stencil, prev);
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (prev == depth_stencil)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
|
|
|
TRACE("Trying to do a NOP SetRenderTarget operation.\n");
|
2010-04-19 20:47:03 +02:00
|
|
|
return WINED3D_OK;
|
2010-04-19 20:47:01 +02:00
|
|
|
}
|
2010-04-19 20:47:03 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (prev)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
if (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|
2011-05-18 22:30:15 +02:00
|
|
|
|| prev->flags & SFLAG_DISCARD)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
2012-02-02 15:08:58 +01:00
|
|
|
surface_modify_ds_location(prev, SFLAG_DISCARDED,
|
2011-05-18 22:30:15 +02:00
|
|
|
prev->resource.width, prev->resource.height);
|
|
|
|
if (prev == device->onscreen_depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_surface_decref(device->onscreen_depth_stencil);
|
|
|
|
device->onscreen_depth_stencil = NULL;
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
2008-07-02 23:00:41 +02:00
|
|
|
}
|
2010-04-19 20:47:03 +02:00
|
|
|
}
|
2008-07-02 23:00:41 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = depth_stencil;
|
|
|
|
if (depth_stencil)
|
|
|
|
wined3d_surface_incref(depth_stencil);
|
2007-03-06 13:35:56 +01:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (!prev != !depth_stencil)
|
2010-04-19 20:47:03 +02:00
|
|
|
{
|
|
|
|
/* Swapping NULL / non NULL depth stencil affects the depth and tests */
|
2011-12-19 21:00:09 +01:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
|
2011-04-20 16:28:05 +02:00
|
|
|
}
|
2011-05-18 22:30:15 +02:00
|
|
|
else if (prev && prev->resource.format->depth_size != depth_stencil->resource.format->depth_size)
|
2011-04-20 16:28:05 +02:00
|
|
|
{
|
2011-12-19 21:00:09 +01:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
2011-08-12 08:21:51 +02:00
|
|
|
if (prev)
|
|
|
|
wined3d_surface_decref(prev);
|
2005-07-07 22:35:05 +02:00
|
|
|
|
2011-06-08 00:27:15 +02:00
|
|
|
device_invalidate_state(device, STATE_FRAMEBUFFER);
|
|
|
|
|
2010-04-19 20:47:02 +02:00
|
|
|
return WINED3D_OK;
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device,
|
|
|
|
UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_image)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, x_hotspot %u, y_hotspot %u, cursor_image %p.\n",
|
|
|
|
device, x_hotspot, y_hotspot, cursor_image);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2006-07-23 00:03:33 +02:00
|
|
|
/* some basic validation checks */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->cursorTexture)
|
2010-05-03 22:03:28 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_context *context = context_acquire(device, NULL);
|
2007-08-06 16:27:08 +02:00
|
|
|
ENTER_GL();
|
2011-05-16 23:01:23 +02:00
|
|
|
glDeleteTextures(1, &device->cursorTexture);
|
2006-07-27 17:39:03 +02:00
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->cursorTexture = 0;
|
2006-07-27 17:39:03 +02:00
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:43 +02:00
|
|
|
if (cursor_image)
|
|
|
|
{
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc map_desc;
|
2007-03-13 03:44:22 +01:00
|
|
|
|
2006-07-23 00:03:33 +02:00
|
|
|
/* MSDN: Cursor must be A8R8G8B8 */
|
2011-04-29 13:03:42 +02:00
|
|
|
if (cursor_image->resource.format->id != WINED3DFMT_B8G8R8A8_UNORM)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2010-08-15 23:21:43 +02:00
|
|
|
WARN("surface %p has an invalid format.\n", cursor_image);
|
2006-07-23 00:03:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MSDN: Cursor must be smaller than the display mode */
|
2011-08-29 18:58:56 +02:00
|
|
|
if (cursor_image->resource.width > device->adapter->screen_size.cx
|
|
|
|
|| cursor_image->resource.height > device->adapter->screen_size.cy)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
|
|
|
WARN("Surface %p dimensions are %ux%u, but screen dimensions are %ux%u.\n",
|
2011-04-29 13:03:42 +02:00
|
|
|
cursor_image, cursor_image->resource.width, cursor_image->resource.height,
|
2011-08-29 18:58:56 +02:00
|
|
|
device->adapter->screen_size.cx, device->adapter->screen_size.cy);
|
2006-07-23 00:03:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 20:18:33 +02:00
|
|
|
/* TODO: MSDN: Cursor sizes must be a power of 2 */
|
|
|
|
|
|
|
|
/* Do not store the surface's pointer because the application may
|
|
|
|
* release it after setting the cursor image. Windows doesn't
|
|
|
|
* addref the set surface, so we can't do this either without
|
|
|
|
* creating circular refcount dependencies. Copy out the gl texture
|
|
|
|
* instead. */
|
|
|
|
device->cursorWidth = cursor_image->resource.width;
|
|
|
|
device->cursorHeight = cursor_image->resource.height;
|
2012-04-12 22:49:04 +02:00
|
|
|
if (SUCCEEDED(wined3d_surface_map(cursor_image, &map_desc, NULL, WINED3DLOCK_READONLY)))
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2011-05-16 20:18:33 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
const struct wined3d_format *format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
|
|
|
|
struct wined3d_context *context;
|
2012-04-12 22:49:04 +02:00
|
|
|
char *mem, *bits = map_desc.data;
|
2011-05-16 20:18:33 +02:00
|
|
|
GLint intfmt = format->glInternal;
|
|
|
|
GLint gl_format = format->glFormat;
|
|
|
|
GLint type = format->glType;
|
|
|
|
INT height = device->cursorHeight;
|
|
|
|
INT width = device->cursorWidth;
|
|
|
|
INT bpp = format->byte_count;
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
/* Reformat the texture memory (pitch and width can be
|
|
|
|
* different) */
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, width * height * bpp);
|
2012-04-12 22:49:04 +02:00
|
|
|
for (i = 0; i < height; ++i)
|
|
|
|
memcpy(&mem[width * bpp * i], &bits[map_desc.row_pitch * i], width * bpp);
|
2011-05-16 20:18:33 +02:00
|
|
|
wined3d_surface_unmap(cursor_image);
|
|
|
|
|
|
|
|
context = context_acquire(device, NULL);
|
2007-04-19 22:52:11 +02:00
|
|
|
|
2011-05-16 20:18:33 +02:00
|
|
|
ENTER_GL();
|
2007-04-19 22:52:11 +02:00
|
|
|
|
2011-05-16 20:18:33 +02:00
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
|
|
|
{
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
|
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2011-07-24 00:11:07 +02:00
|
|
|
invalidate_active_texture(device, context);
|
2011-05-16 20:18:33 +02:00
|
|
|
/* Create a new cursor texture */
|
|
|
|
glGenTextures(1, &device->cursorTexture);
|
|
|
|
checkGLcall("glGenTextures");
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, GL_TEXTURE_2D, device->cursorTexture);
|
2011-05-16 20:18:33 +02:00
|
|
|
/* Copy the bitmap memory into the cursor texture */
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, intfmt, width, height, 0, gl_format, type, mem);
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
|
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
2007-05-15 00:37:53 +02:00
|
|
|
{
|
2011-05-16 20:18:33 +02:00
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
|
2007-04-19 22:52:11 +02:00
|
|
|
}
|
2011-05-16 20:18:33 +02:00
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
context_release(context);
|
2007-03-13 03:44:22 +01:00
|
|
|
}
|
|
|
|
else
|
2011-05-16 20:18:33 +02:00
|
|
|
{
|
|
|
|
FIXME("A cursor texture was not returned.\n");
|
|
|
|
device->cursorTexture = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor_image->resource.width == 32 && cursor_image->resource.height == 32)
|
2007-03-13 03:44:22 +01:00
|
|
|
{
|
2012-01-26 23:04:19 +01:00
|
|
|
UINT mask_size = cursor_image->resource.width * cursor_image->resource.height / 8;
|
2007-05-15 00:37:53 +02:00
|
|
|
ICONINFO cursorInfo;
|
2012-01-26 23:04:19 +01:00
|
|
|
DWORD *maskBits;
|
2007-05-15 00:37:53 +02:00
|
|
|
HCURSOR cursor;
|
2012-01-26 23:04:19 +01:00
|
|
|
|
|
|
|
/* 32-bit user32 cursors ignore the alpha channel if it's all
|
|
|
|
* zeroes, and use the mask instead. Fill the mask with all ones
|
|
|
|
* to ensure we still get a fully transparent cursor. */
|
|
|
|
maskBits = HeapAlloc(GetProcessHeap(), 0, mask_size);
|
|
|
|
memset(maskBits, 0xff, mask_size);
|
2012-04-12 22:49:04 +02:00
|
|
|
wined3d_surface_map(cursor_image, &map_desc, NULL,
|
2010-08-15 23:21:43 +02:00
|
|
|
WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY);
|
2011-04-29 13:03:42 +02:00
|
|
|
TRACE("width: %u height: %u.\n", cursor_image->resource.width, cursor_image->resource.height);
|
2007-05-15 00:37:53 +02:00
|
|
|
|
|
|
|
cursorInfo.fIcon = FALSE;
|
2011-05-16 23:01:23 +02:00
|
|
|
cursorInfo.xHotspot = x_hotspot;
|
|
|
|
cursorInfo.yHotspot = y_hotspot;
|
2011-04-29 13:03:42 +02:00
|
|
|
cursorInfo.hbmMask = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
|
|
|
|
1, 1, maskBits);
|
|
|
|
cursorInfo.hbmColor = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
|
2012-04-12 22:49:04 +02:00
|
|
|
1, 32, map_desc.data);
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_unmap(cursor_image);
|
2007-05-15 00:37:53 +02:00
|
|
|
/* Create our cursor and clean up. */
|
|
|
|
cursor = CreateIconIndirect(&cursorInfo);
|
|
|
|
if (cursorInfo.hbmMask) DeleteObject(cursorInfo.hbmMask);
|
|
|
|
if (cursorInfo.hbmColor) DeleteObject(cursorInfo.hbmColor);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->hardwareCursor) DestroyCursor(device->hardwareCursor);
|
|
|
|
device->hardwareCursor = cursor;
|
2011-05-16 20:22:25 +02:00
|
|
|
if (device->bCursorVisible) SetCursor( cursor );
|
2007-05-15 00:37:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, maskBits);
|
2007-03-13 03:44:22 +01:00
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->xHotSpot = x_hotspot;
|
|
|
|
device->yHotSpot = y_hotspot;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_set_cursor_position(struct wined3d_device *device,
|
|
|
|
int x_screen_space, int y_screen_space, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, x %d, y %d, flags %#x.\n",
|
|
|
|
device, x_screen_space, y_screen_space, flags);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
device->xScreenSpace = x_screen_space;
|
|
|
|
device->yScreenSpace = y_screen_space;
|
2011-05-16 20:22:25 +02:00
|
|
|
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
{
|
|
|
|
POINT pt;
|
2011-10-20 21:42:55 +02:00
|
|
|
|
|
|
|
GetCursorPos( &pt );
|
|
|
|
if (x_screen_space == pt.x && y_screen_space == pt.y)
|
|
|
|
return;
|
|
|
|
SetCursorPos( x_screen_space, y_screen_space );
|
|
|
|
|
|
|
|
/* Switch to the software cursor if position diverges from the hardware one. */
|
2011-05-16 20:22:25 +02:00
|
|
|
GetCursorPos( &pt );
|
|
|
|
if (x_screen_space != pt.x || y_screen_space != pt.y)
|
|
|
|
{
|
|
|
|
if (device->bCursorVisible) SetCursor( NULL );
|
|
|
|
DestroyCursor( device->hardwareCursor );
|
|
|
|
device->hardwareCursor = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL CDECL wined3d_device_show_cursor(struct wined3d_device *device, BOOL show)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL oldVisible = device->bCursorVisible;
|
2007-03-02 09:25:02 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, show %#x.\n", device, show);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 20:16:15 +02:00
|
|
|
/*
|
|
|
|
* When ShowCursor is first called it should make the cursor appear at the OS's last
|
|
|
|
* known cursor position.
|
|
|
|
*/
|
|
|
|
if (show && !oldVisible)
|
|
|
|
{
|
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
device->xScreenSpace = pt.x;
|
|
|
|
device->yScreenSpace = pt.y;
|
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-05-16 20:13:13 +02:00
|
|
|
if (device->hardwareCursor)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
|
|
|
device->bCursorVisible = show;
|
|
|
|
if (show)
|
|
|
|
SetCursor(device->hardwareCursor);
|
2007-05-15 00:37:53 +02:00
|
|
|
else
|
|
|
|
SetCursor(NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->cursorTexture)
|
|
|
|
device->bCursorVisible = show;
|
2007-05-15 00:37:53 +02:00
|
|
|
}
|
|
|
|
|
2006-08-09 22:23:31 +02:00
|
|
|
return oldVisible;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-07-28 22:27:54 +02:00
|
|
|
void CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
2011-07-25 20:45:07 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2011-07-25 20:45:07 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2011-07-25 20:45:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Checking resource %p for eviction.\n", resource);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2012-05-21 20:48:35 +02:00
|
|
|
if (resource->pool == WINED3D_POOL_MANAGED && !resource->map_count)
|
2011-07-25 20:45:07 +02:00
|
|
|
{
|
|
|
|
TRACE("Evicting %p.\n", resource);
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 08:06:06 +02:00
|
|
|
|
2010-07-08 12:20:57 +02:00
|
|
|
/* Invalidate stream sources, the buffer(s) may have been evicted. */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
static BOOL is_display_mode_supported(const struct wined3d_device *device,
|
|
|
|
const struct wined3d_swapchain_desc *swapchain_desc)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2011-11-16 20:08:06 +01:00
|
|
|
struct wined3d_display_mode m;
|
2008-02-06 20:16:13 +01:00
|
|
|
UINT i, count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* All Windowed modes are supported, as is leaving the current mode */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->windowed)
|
|
|
|
return TRUE;
|
|
|
|
if (!swapchain_desc->backbuffer_width)
|
|
|
|
return TRUE;
|
|
|
|
if (!swapchain_desc->backbuffer_height)
|
|
|
|
return TRUE;
|
2008-02-06 20:16:13 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
count = wined3d_get_adapter_mode_count(device->wined3d, device->adapter->ordinal, WINED3DFMT_UNKNOWN);
|
2011-02-01 19:39:53 +01:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
2008-02-06 20:16:13 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_enum_adapter_modes(device->wined3d, device->adapter->ordinal, WINED3DFMT_UNKNOWN, i, &m);
|
2011-02-01 19:39:53 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Failed to enumerate adapter mode.\n");
|
2011-12-02 08:15:52 +01:00
|
|
|
if (m.width == swapchain_desc->backbuffer_width && m.height == swapchain_desc->backbuffer_height)
|
2011-02-01 19:39:53 +01:00
|
|
|
/* Mode found, it is supported. */
|
2008-02-06 20:16:13 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* Mode not found -> not supported */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-05-16 23:01:23 +02:00
|
|
|
static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
|
2010-04-04 19:51:39 +02:00
|
|
|
{
|
2011-07-25 20:45:07 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2009-09-23 10:05:55 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2011-03-30 20:49:26 +02:00
|
|
|
struct wined3d_shader *shader;
|
2008-07-29 19:09:34 +02:00
|
|
|
|
2011-01-04 17:42:01 +01:00
|
|
|
context = context_acquire(device, NULL);
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info = context->gl_info;
|
2009-06-25 10:24:54 +02:00
|
|
|
|
2011-07-25 20:45:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
|
|
|
{
|
|
|
|
TRACE("Unloading resource %p.\n", resource);
|
|
|
|
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
|
|
|
}
|
|
|
|
|
2011-03-30 20:49:26 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(shader, &device->shaders, struct wined3d_shader, shader_list_entry)
|
2010-12-13 13:40:32 +01:00
|
|
|
{
|
2011-01-04 17:42:01 +01:00
|
|
|
device->shader_backend->shader_destroy(shader);
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ENTER_GL();
|
2011-01-04 17:42:01 +01:00
|
|
|
if (device->depth_blt_texture)
|
|
|
|
{
|
|
|
|
glDeleteTextures(1, &device->depth_blt_texture);
|
|
|
|
device->depth_blt_texture = 0;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
2011-07-05 18:55:44 +02:00
|
|
|
if (device->cursorTexture)
|
|
|
|
{
|
|
|
|
glDeleteTextures(1, &device->cursorTexture);
|
|
|
|
device->cursorTexture = 0;
|
|
|
|
}
|
2008-10-19 01:21:06 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
|
2011-01-04 17:42:01 +01:00
|
|
|
device->blitter->free_private(device);
|
|
|
|
device->frag_pipe->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
|
|
|
destroy_dummy_textures(device, gl_info);
|
2008-07-29 19:09:34 +02:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
while (device->context_count)
|
2009-10-28 11:00:14 +01:00
|
|
|
{
|
2011-06-28 02:26:20 +02:00
|
|
|
swapchain_destroy_contexts(device->contexts[0]->swapchain);
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
2011-06-28 02:26:20 +02:00
|
|
|
|
2008-07-29 19:09:34 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
swapchain->context = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT create_primary_opengl_context(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
|
2010-04-04 19:51:39 +02:00
|
|
|
{
|
2009-12-17 19:14:35 +01:00
|
|
|
struct wined3d_context *context;
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *target;
|
2008-07-29 19:09:34 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* Recreate the primary swapchain's context */
|
|
|
|
swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
|
2009-12-17 19:14:35 +01:00
|
|
|
if (!swapchain->context)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory for swapchain context array.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
target = swapchain->back_buffers ? swapchain->back_buffers[0] : swapchain->front_buffer;
|
2010-03-28 16:25:04 +02:00
|
|
|
if (!(context = context_create(swapchain, target, swapchain->ds_format)))
|
2009-12-17 19:14:35 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create context.\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-07-29 19:09:34 +02:00
|
|
|
|
2009-12-17 19:14:35 +01:00
|
|
|
swapchain->context[0] = context;
|
|
|
|
swapchain->num_contexts = 1;
|
2011-08-03 01:34:15 +02:00
|
|
|
create_dummy_textures(device, context);
|
2009-12-17 19:14:35 +01:00
|
|
|
context_release(context);
|
2009-10-28 11:00:12 +01:00
|
|
|
|
2011-01-04 17:42:02 +01:00
|
|
|
hr = device->shader_backend->shader_alloc_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate shader private data, hr %#x.\n", hr);
|
|
|
|
goto err;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
2009-12-17 19:14:35 +01:00
|
|
|
|
2011-01-04 17:42:02 +01:00
|
|
|
hr = device->frag_pipe->alloc_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate fragment pipe private data, hr %#x.\n", hr);
|
2011-01-04 17:42:02 +01:00
|
|
|
device->shader_backend->shader_free_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
goto err;
|
2008-08-01 20:21:10 +02:00
|
|
|
}
|
2009-12-17 19:14:35 +01:00
|
|
|
|
2011-01-04 17:42:02 +01:00
|
|
|
hr = device->blitter->alloc_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate blitter private data, hr %#x.\n", hr);
|
2011-01-04 17:42:02 +01:00
|
|
|
device->frag_pipe->free_private(device);
|
|
|
|
device->shader_backend->shader_free_private(device);
|
2009-12-17 19:14:35 +01:00
|
|
|
goto err;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2008-08-01 20:21:10 +02:00
|
|
|
|
2009-12-17 19:14:35 +01:00
|
|
|
err:
|
2011-01-04 17:42:02 +01:00
|
|
|
context_acquire(device, NULL);
|
|
|
|
destroy_dummy_textures(device, context->gl_info);
|
2009-12-17 19:14:35 +01:00
|
|
|
context_release(context);
|
2011-01-04 17:42:02 +01:00
|
|
|
context_destroy(device, context);
|
2009-12-17 19:14:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
swapchain->num_contexts = 0;
|
2008-08-01 20:21:10 +02:00
|
|
|
return hr;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
|
2011-12-02 08:15:52 +01:00
|
|
|
const struct wined3d_swapchain_desc *swapchain_desc,
|
2011-07-25 20:45:06 +02:00
|
|
|
wined3d_device_reset_cb callback)
|
2010-09-02 19:25:00 +02:00
|
|
|
{
|
2011-07-25 20:45:06 +02:00
|
|
|
struct wined3d_resource *resource, *cursor;
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2011-11-16 20:08:06 +01:00
|
|
|
struct wined3d_display_mode mode;
|
2006-12-08 16:13:15 +01:00
|
|
|
BOOL DisplayModeChanged = FALSE;
|
2011-08-25 21:05:03 +02:00
|
|
|
BOOL update_desc = FALSE;
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT hr;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2011-12-06 22:57:44 +01:00
|
|
|
stateblock_unbind_resources(device->stateBlock);
|
|
|
|
|
2011-07-25 20:45:10 +02:00
|
|
|
if (device->onscreen_depth_stencil)
|
|
|
|
{
|
|
|
|
wined3d_surface_decref(device->onscreen_depth_stencil);
|
|
|
|
device->onscreen_depth_stencil = NULL;
|
|
|
|
}
|
2011-07-25 20:45:08 +02:00
|
|
|
|
2011-07-25 20:45:06 +02: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;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_device_get_swapchain(device, 0, &swapchain);
|
2011-04-13 19:14:32 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2006-12-08 16:13:15 +01:00
|
|
|
ERR("Failed to get the first implicit swapchain\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!is_display_mode_supported(device, swapchain_desc))
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
WARN("Rejecting reset() call because the requested display mode is not supported.\n");
|
|
|
|
WARN("Requested mode: %ux%u.\n",
|
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height);
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2008-02-06 20:16:13 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2006-12-08 16:13:15 +01:00
|
|
|
/* Is it necessary to recreate the gl context? Actually every setting can be changed
|
|
|
|
* on an existing gl context, so there's no real need for recreation.
|
|
|
|
*
|
|
|
|
* TODO: Figure out how Reset influences resources in D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEMORY and D3DPOOL_MANAGED
|
|
|
|
*
|
|
|
|
* TODO: Figure out what happens to explicit swapchains, or if we have more than one implicit swapchain
|
|
|
|
*/
|
|
|
|
TRACE("New params:\n");
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("backbuffer_width %u\n", swapchain_desc->backbuffer_width);
|
|
|
|
TRACE("backbuffer_height %u\n", swapchain_desc->backbuffer_height);
|
|
|
|
TRACE("backbuffer_format %s\n", debug_d3dformat(swapchain_desc->backbuffer_format));
|
|
|
|
TRACE("backbuffer_count %u\n", swapchain_desc->backbuffer_count);
|
|
|
|
TRACE("multisample_type %#x\n", swapchain_desc->multisample_type);
|
|
|
|
TRACE("multisample_quality %u\n", swapchain_desc->multisample_quality);
|
|
|
|
TRACE("swap_effect %#x\n", swapchain_desc->swap_effect);
|
|
|
|
TRACE("device_window %p\n", swapchain_desc->device_window);
|
|
|
|
TRACE("windowed %#x\n", swapchain_desc->windowed);
|
|
|
|
TRACE("enable_auto_depth_stencil %#x\n", swapchain_desc->enable_auto_depth_stencil);
|
2011-12-11 21:43:30 +01:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil)
|
|
|
|
TRACE("auto_depth_stencil_format %s\n", debug_d3dformat(swapchain_desc->auto_depth_stencil_format));
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("flags %#x\n", swapchain_desc->flags);
|
|
|
|
TRACE("refresh_rate %u\n", swapchain_desc->refresh_rate);
|
|
|
|
TRACE("swap_interval %u\n", swapchain_desc->swap_interval);
|
2011-12-11 21:43:30 +01:00
|
|
|
TRACE("auto_restore_display_mode %#x\n", swapchain_desc->auto_restore_display_mode);
|
2006-12-08 16:13:15 +01:00
|
|
|
|
|
|
|
/* No special treatment of these parameters. Just store them */
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.swap_effect = swapchain_desc->swap_effect;
|
|
|
|
swapchain->desc.flags = swapchain_desc->flags;
|
|
|
|
swapchain->desc.swap_interval = swapchain_desc->swap_interval;
|
|
|
|
swapchain->desc.refresh_rate = swapchain_desc->refresh_rate;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
|
|
|
/* What to do about these? */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->backbuffer_count
|
|
|
|
&& swapchain_desc->backbuffer_count != swapchain->desc.backbuffer_count)
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("Cannot change the back buffer count yet.\n");
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->device_window
|
|
|
|
&& swapchain_desc->device_window != swapchain->desc.device_window)
|
2012-02-29 17:22:32 +01:00
|
|
|
{
|
|
|
|
TRACE("Changing the device window from %p to %p.\n",
|
|
|
|
swapchain->desc.device_window, swapchain_desc->device_window);
|
|
|
|
swapchain->desc.device_window = swapchain_desc->device_window;
|
|
|
|
swapchain->device_window = swapchain_desc->device_window;
|
|
|
|
wined3d_swapchain_set_window(swapchain, NULL);
|
|
|
|
}
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil && !device->auto_depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2009-04-23 08:33:21 +02:00
|
|
|
HRESULT hrc;
|
|
|
|
|
|
|
|
TRACE("Creating the depth stencil buffer\n");
|
|
|
|
|
2011-05-18 22:30:13 +02:00
|
|
|
hrc = device->device_parent->ops->create_depth_stencil(device->device_parent,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height,
|
|
|
|
swapchain_desc->auto_depth_stencil_format,
|
|
|
|
swapchain_desc->multisample_type,
|
|
|
|
swapchain_desc->multisample_quality,
|
2009-04-23 08:33:21 +02:00
|
|
|
FALSE,
|
2011-05-16 23:01:23 +02:00
|
|
|
&device->auto_depth_stencil);
|
2011-04-13 19:14:31 +02:00
|
|
|
if (FAILED(hrc))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the depth stencil buffer.\n");
|
|
|
|
wined3d_swapchain_decref(swapchain);
|
2009-04-23 08:33:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2008-01-08 22:34:43 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->onscreen_depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_surface_decref(device->onscreen_depth_stencil);
|
|
|
|
device->onscreen_depth_stencil = NULL;
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 11:08:58 +02:00
|
|
|
/* Reset the depth stencil */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->enable_auto_depth_stencil)
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_set_depth_stencil(device, device->auto_depth_stencil);
|
2008-09-10 11:08:58 +02:00
|
|
|
else
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_set_depth_stencil(device, NULL);
|
2008-09-10 11:08:58 +02:00
|
|
|
|
2009-09-25 13:31:50 +02:00
|
|
|
TRACE("Resetting stateblock\n");
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_stateblock_decref(device->updateStateBlock);
|
|
|
|
wined3d_stateblock_decref(device->stateBlock);
|
2009-09-25 13:31:50 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->windowed)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
2011-11-16 20:08:06 +01:00
|
|
|
mode.width = swapchain->orig_width;
|
|
|
|
mode.height = swapchain->orig_height;
|
|
|
|
mode.refresh_rate = 0;
|
2011-12-02 08:15:52 +01:00
|
|
|
mode.format_id = swapchain->desc.backbuffer_format;
|
2011-05-16 23:01:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
mode.width = swapchain_desc->backbuffer_width;
|
|
|
|
mode.height = swapchain_desc->backbuffer_height;
|
|
|
|
mode.refresh_rate = swapchain_desc->refresh_rate;
|
|
|
|
mode.format_id = swapchain_desc->backbuffer_format;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Should Width == 800 && Height == 0 set 800x600? */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->backbuffer_width && swapchain_desc->backbuffer_height
|
|
|
|
&& (swapchain_desc->backbuffer_width != swapchain->desc.backbuffer_width
|
|
|
|
|| swapchain_desc->backbuffer_height != swapchain->desc.backbuffer_height))
|
2006-12-08 16:13:15 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain_desc->windowed)
|
2006-12-08 16:13:15 +01:00
|
|
|
DisplayModeChanged = TRUE;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.backbuffer_width = swapchain_desc->backbuffer_width;
|
|
|
|
swapchain->desc.backbuffer_height = swapchain_desc->backbuffer_height;
|
2011-08-25 21:05:03 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->backbuffer_format != WINED3DFMT_UNKNOWN
|
|
|
|
&& swapchain_desc->backbuffer_format != swapchain->desc.backbuffer_format)
|
2011-11-24 22:52:34 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.backbuffer_format = swapchain_desc->backbuffer_format;
|
2011-11-24 22:52:34 +01:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain_desc->multisample_type != swapchain->desc.multisample_type
|
|
|
|
|| swapchain_desc->multisample_quality != swapchain->desc.multisample_quality)
|
2011-08-25 21:05:03 +02:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.multisample_type = swapchain_desc->multisample_type;
|
|
|
|
swapchain->desc.multisample_quality = swapchain_desc->multisample_quality;
|
2011-08-25 21:05:03 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_desc)
|
|
|
|
{
|
|
|
|
UINT i;
|
2011-05-16 23:01:23 +02:00
|
|
|
|
2012-01-12 21:43:08 +01:00
|
|
|
hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
|
|
|
|
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
|
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr))
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2009-12-04 13:07:18 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
|
2010-04-26 21:33:01 +02:00
|
|
|
{
|
2012-01-12 21:43:08 +01:00
|
|
|
hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
|
|
|
|
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
|
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr))
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2009-12-04 13:07:18 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->auto_depth_stencil)
|
2010-04-19 20:47:00 +02:00
|
|
|
{
|
2012-01-12 21:43:08 +01:00
|
|
|
hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width,
|
|
|
|
swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id,
|
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr))
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2009-12-04 13:07:18 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2008-01-25 18:04:05 +01:00
|
|
|
}
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
2011-12-04 15:50:13 +01:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
delete_opengl_contexts(device, swapchain);
|
2011-08-22 21:02:45 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain_desc->windowed != !swapchain->desc.windowed
|
2010-03-15 21:07:29 +01:00
|
|
|
|| DisplayModeChanged)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_set_display_mode(device, 0, &mode);
|
2008-08-04 21:11:22 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain_desc->windowed)
|
2010-03-15 21:07:28 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain->desc.windowed)
|
2010-10-06 12:01:29 +02:00
|
|
|
{
|
2011-11-27 21:34:48 +01:00
|
|
|
HWND focus_window = device->create_parms.focus_window;
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!focus_window)
|
2011-12-02 08:15:52 +01:00
|
|
|
focus_window = swapchain_desc->device_window;
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
|
2010-10-06 12:01:29 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to acquire focus window, hr %#x.\n", hr);
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2010-10-06 12:01:29 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-08-04 21:11:22 +02:00
|
|
|
/* switch from windowed to fs */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height);
|
2010-10-06 12:01:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-04 21:11:22 +02:00
|
|
|
/* Fullscreen -> fullscreen mode change */
|
2010-03-15 21:07:30 +01:00
|
|
|
MoveWindow(swapchain->device_window, 0, 0,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height,
|
|
|
|
TRUE);
|
2008-08-04 21:11:22 +02:00
|
|
|
}
|
2010-03-15 21:07:28 +01:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
else if (!swapchain->desc.windowed)
|
2010-03-15 21:07:28 +01:00
|
|
|
{
|
2008-08-04 21:11:22 +02:00
|
|
|
/* Fullscreen -> windowed switch */
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_restore_fullscreen_window(device, swapchain->device_window);
|
|
|
|
wined3d_device_release_focus_window(device);
|
2008-08-04 21:11:22 +02:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.windowed = swapchain_desc->windowed;
|
2010-10-06 12:01:29 +02:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
else if (!swapchain_desc->windowed)
|
2010-10-06 12:01:29 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
DWORD style = device->style;
|
|
|
|
DWORD exStyle = device->exStyle;
|
2008-02-06 22:12:06 +01:00
|
|
|
/* If we're in fullscreen, and the mode wasn't changed, we have to get the window back into
|
|
|
|
* the right position. Some applications(Battlefield 2, Guild Wars) move it and then call
|
|
|
|
* Reset to clear up their mess. Guild Wars also loses the device during that.
|
|
|
|
*/
|
2011-05-16 23:01:23 +02:00
|
|
|
device->style = 0;
|
|
|
|
device->exStyle = 0;
|
|
|
|
wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain_desc->backbuffer_width,
|
|
|
|
swapchain_desc->backbuffer_height);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->style = style;
|
|
|
|
device->exStyle = exStyle;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2008-12-19 19:21:55 +01:00
|
|
|
|
|
|
|
/* Note: No parent needed for initial internal stateblock */
|
2012-01-17 21:13:39 +01:00
|
|
|
hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock);
|
2011-05-16 23:01:23 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Resetting the stateblock failed with error %#x.\n", hr);
|
|
|
|
else
|
|
|
|
TRACE("Created stateblock %p.\n", device->stateBlock);
|
|
|
|
device->updateStateBlock = device->stateBlock;
|
|
|
|
wined3d_stateblock_incref(device->updateStateBlock);
|
2008-12-19 19:21:55 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
stateblock_init_default_state(device->stateBlock);
|
2008-03-18 19:31:24 +01:00
|
|
|
|
2011-08-22 21:02:47 +02:00
|
|
|
swapchain_update_render_to_fbo(swapchain);
|
2011-08-23 20:08:08 +02:00
|
|
|
swapchain_update_draw_bindings(swapchain);
|
2009-12-06 18:08:39 +01:00
|
|
|
|
2011-12-04 15:50:13 +01:00
|
|
|
if (device->d3d_initialized)
|
|
|
|
hr = create_primary_opengl_context(device, swapchain);
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2008-03-18 19:31:24 +01:00
|
|
|
|
2008-02-05 00:05:26 +01:00
|
|
|
/* All done. There is no need to reload resources or shaders, this will happen automatically on the
|
|
|
|
* first use
|
|
|
|
*/
|
2008-07-29 19:09:34 +02:00
|
|
|
return hr;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, enable_dialogs %#x.\n", device, enable_dialogs);
|
2009-12-21 23:17:26 +01:00
|
|
|
|
|
|
|
if (!enable_dialogs) FIXME("Dialogs cannot be disabled yet.\n");
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 20:46:15 +02:00
|
|
|
HRESULT 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;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-10-19 22:03:13 +02:00
|
|
|
void CDECL wined3d_device_set_gamma_ramp(const struct wined3d_device *device,
|
2011-11-21 18:48:41 +01:00
|
|
|
UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, swapchain_idx %u, flags %#x, ramp %p.\n",
|
|
|
|
device, swapchain_idx, flags, ramp);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (SUCCEEDED(wined3d_device_get_swapchain(device, swapchain_idx, &swapchain)))
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_swapchain_set_gamma_ramp(swapchain, flags, ramp);
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (SUCCEEDED(wined3d_device_get_swapchain(device, swapchain_idx, &swapchain)))
|
2011-04-13 19:14:31 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
wined3d_swapchain_get_gamma_ramp(swapchain, ramp);
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_decref(swapchain);
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
2004-10-07 06:22:21 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)
|
2009-05-29 09:13:21 +02:00
|
|
|
{
|
2011-01-16 23:36:45 +01:00
|
|
|
TRACE("device %p, resource %p.\n", device, resource);
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
list_add_head(&device->resources, &resource->resource_list_entry);
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
static void device_resource_remove(struct wined3d_device *device, struct wined3d_resource *resource)
|
2009-05-29 09:13:21 +02:00
|
|
|
{
|
2011-01-16 23:36:44 +01:00
|
|
|
TRACE("device %p, resource %p.\n", device, resource);
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
list_remove(&resource->resource_list_entry);
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource)
|
2009-05-29 09:13:21 +02:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
enum wined3d_resource_type type = resource->type;
|
2010-08-17 19:03:28 +02:00
|
|
|
unsigned int i;
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2010-08-17 19:03:28 +02:00
|
|
|
TRACE("device %p, resource %p, type %s.\n", device, resource, debug_d3dresourcetype(type));
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2011-01-16 23:36:47 +01:00
|
|
|
context_resource_released(device, resource, type);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-08-17 19:03:28 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_SURFACE:
|
2009-06-25 10:24:56 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface = surface_from_resource(resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
|
|
|
if (!device->d3d_initialized) break;
|
|
|
|
|
|
|
|
for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.render_targets[i] == surface)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
ERR("Surface %p is still in use as render target %u.\n", surface, i);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets[i] = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
2007-07-18 23:13:58 +02:00
|
|
|
}
|
2007-04-09 01:53:27 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.depth_stencil == surface)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
ERR("Surface %p is still in use as depth/stencil buffer.\n", surface);
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.depth_stencil = NULL;
|
2011-03-01 09:47:56 +01:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
}
|
2007-04-09 01:53:27 +02:00
|
|
|
break;
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE:
|
|
|
|
case WINED3D_RTYPE_CUBE_TEXTURE:
|
|
|
|
case WINED3D_RTYPE_VOLUME_TEXTURE:
|
2010-08-17 19:03:28 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
|
|
|
if (device->stateBlock && device->stateBlock->state.textures[i] == texture)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
|
|
|
ERR("Texture %p is still in use by stateblock %p, stage %u.\n",
|
2011-03-01 09:47:56 +01:00
|
|
|
texture, device->stateBlock, i);
|
2010-09-17 11:59:40 +02:00
|
|
|
device->stateBlock->state.textures[i] = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
|
|
|
if (device->updateStateBlock != device->stateBlock
|
2011-03-01 09:47:56 +01:00
|
|
|
&& device->updateStateBlock->state.textures[i] == texture)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
|
|
|
ERR("Texture %p is still in use by stateblock %p, stage %u.\n",
|
2011-03-01 09:47:56 +01:00
|
|
|
texture, device->updateStateBlock, i);
|
2010-09-17 11:59:40 +02:00
|
|
|
device->updateStateBlock->state.textures[i] = NULL;
|
2010-08-17 19:03:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
case WINED3D_RTYPE_BUFFER:
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_STREAMS; ++i)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
if (device->stateBlock && device->stateBlock->state.streams[i].buffer == buffer)
|
|
|
|
{
|
|
|
|
ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
|
|
|
|
buffer, device->stateBlock, i);
|
|
|
|
device->stateBlock->state.streams[i].buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device->updateStateBlock != device->stateBlock
|
|
|
|
&& device->updateStateBlock->state.streams[i].buffer == buffer)
|
|
|
|
{
|
|
|
|
ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
|
|
|
|
buffer, device->updateStateBlock, i);
|
|
|
|
device->updateStateBlock->state.streams[i].buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
if (device->stateBlock && device->stateBlock->state.index_buffer == buffer)
|
2010-08-17 19:03:28 +02:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
|
|
|
|
buffer, device->stateBlock);
|
|
|
|
device->stateBlock->state.index_buffer = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
}
|
2010-08-17 19:03:28 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
if (device->updateStateBlock != device->stateBlock
|
|
|
|
&& device->updateStateBlock->state.index_buffer == buffer)
|
|
|
|
{
|
|
|
|
ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
|
|
|
|
buffer, device->updateStateBlock);
|
|
|
|
device->updateStateBlock->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
|
|
|
}
|
|
|
|
|
2011-10-20 21:42:58 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_surface_from_dc(const struct wined3d_device *device,
|
2011-04-29 13:03:42 +02:00
|
|
|
HDC dc, struct wined3d_surface **surface)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *resource;
|
2010-03-16 19:02:21 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, dc %p, surface %p.\n", device, dc, surface);
|
|
|
|
|
2011-11-23 08:51:42 +01:00
|
|
|
if (!dc)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
if (resource->type == WINED3D_RTYPE_SURFACE)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *s = surface_from_resource(resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
|
|
|
if (s->hDC == dc)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
TRACE("Found surface %p for dc %p.\n", s, dc);
|
2011-04-29 13:03:42 +02:00
|
|
|
*surface = s;
|
2010-03-16 19:02:21 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d,
|
2011-12-12 20:53:59 +01:00
|
|
|
UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags,
|
2011-06-23 11:43:39 +02:00
|
|
|
BYTE surface_alignment, struct wined3d_device_parent *device_parent)
|
2009-11-18 10:45:53 +01:00
|
|
|
{
|
|
|
|
struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
|
|
|
|
const struct fragment_pipeline *fragment_pipeline;
|
2011-11-16 20:08:06 +01:00
|
|
|
struct wined3d_display_mode mode;
|
2009-11-18 10:45:53 +01:00
|
|
|
struct shader_caps shader_caps;
|
|
|
|
struct fragment_caps ffp_caps;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
device->ref = 1;
|
2011-02-01 19:39:54 +01:00
|
|
|
device->wined3d = wined3d;
|
2011-02-01 19:39:53 +01:00
|
|
|
wined3d_incref(device->wined3d);
|
2009-11-18 10:45:53 +01:00
|
|
|
device->adapter = wined3d->adapter_count ? adapter : NULL;
|
|
|
|
device->device_parent = device_parent;
|
|
|
|
list_init(&device->resources);
|
|
|
|
list_init(&device->shaders);
|
2011-06-23 11:43:39 +02:00
|
|
|
device->surface_alignment = surface_alignment;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
|
|
|
/* Get the initial screen setup for ddraw. */
|
2011-02-01 19:39:53 +01:00
|
|
|
hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode);
|
2009-11-18 10:45:53 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to get the adapter's display mode, hr %#x.\n", hr);
|
2011-02-01 19:39:53 +01:00
|
|
|
wined3d_decref(device->wined3d);
|
2009-11-18 10:45:53 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2011-11-16 20:08:06 +01:00
|
|
|
adapter->screen_size.cx = mode.width;
|
|
|
|
adapter->screen_size.cy = mode.height;
|
|
|
|
adapter->screen_format = mode.format_id;
|
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
|
|
|
|
|
|
|
for (i = 0; i < PATCHMAP_SIZE; ++i) list_init(&device->patches[i]);
|
|
|
|
|
|
|
|
select_shader_mode(&adapter->gl_info, &device->ps_selected_mode, &device->vs_selected_mode);
|
2010-02-02 12:06:57 +01:00
|
|
|
device->shader_backend = adapter->shader_backend;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2010-05-06 14:57:21 +02:00
|
|
|
if (device->shader_backend)
|
|
|
|
{
|
|
|
|
device->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
|
2011-10-25 16:58:47 +02:00
|
|
|
device->vshader_version = shader_caps.VertexShaderVersion;
|
|
|
|
device->pshader_version = shader_caps.PixelShaderVersion;
|
2010-05-06 14:57:21 +02:00
|
|
|
device->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
|
|
|
|
device->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
|
|
|
|
device->vs_clipping = shader_caps.VSClipping;
|
|
|
|
}
|
2010-02-02 12:06:56 +01:00
|
|
|
fragment_pipeline = adapter->fragment_pipe;
|
2009-11-18 10:45:53 +01:00
|
|
|
device->frag_pipe = fragment_pipeline;
|
2010-05-06 14:57:21 +02:00
|
|
|
if (fragment_pipeline)
|
2009-11-18 10:45:53 +01:00
|
|
|
{
|
2010-05-06 14:57:21 +02:00
|
|
|
fragment_pipeline->get_caps(&adapter->gl_info, &ffp_caps);
|
|
|
|
device->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2010-05-06 14:57:21 +02:00
|
|
|
hr = compile_state_table(device->StateTable, device->multistate_funcs, &adapter->gl_info,
|
|
|
|
ffp_vertexstate_template, fragment_pipeline, misc_state_template);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to compile state table, hr %#x.\n", hr);
|
2011-02-01 19:39:53 +01:00
|
|
|
wined3d_decref(device->wined3d);
|
2010-05-06 14:57:21 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2010-02-03 11:02:20 +01:00
|
|
|
device->blitter = adapter->blitter;
|
2009-11-18 10:45:53 +01:00
|
|
|
|
2012-01-17 21:13:39 +01:00
|
|
|
hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock);
|
2011-12-04 15:50:12 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create stateblock.\n");
|
|
|
|
for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
|
|
|
|
}
|
|
|
|
wined3d_decref(device->wined3d);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created stateblock %p.\n", device->stateBlock);
|
|
|
|
device->updateStateBlock = device->stateBlock;
|
|
|
|
wined3d_stateblock_incref(device->updateStateBlock);
|
|
|
|
|
2009-11-18 10:45:53 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 23:21:13 +02:00
|
|
|
void device_invalidate_state(const struct wined3d_device *device, DWORD state)
|
2011-05-16 23:01:23 +02:00
|
|
|
{
|
|
|
|
DWORD rep = device->StateTable[state].representative;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2006-12-19 13:00:03 +01:00
|
|
|
DWORD idx;
|
|
|
|
BYTE shift;
|
2007-02-12 19:18:31 +01:00
|
|
|
UINT i;
|
2006-12-19 13:00:03 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2011-03-30 20:49:27 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
context = device->contexts[i];
|
2007-02-12 19:18:31 +01:00
|
|
|
if(isStateDirty(context, rep)) continue;
|
|
|
|
|
|
|
|
context->dirtyArray[context->numDirtyEntries++] = rep;
|
2009-12-29 17:10:22 +01:00
|
|
|
idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
|
|
|
|
shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
|
2007-02-12 19:18:31 +01:00
|
|
|
context->isStateDirty[idx] |= (1 << shift);
|
|
|
|
}
|
2006-12-19 13:00:03 +01:00
|
|
|
}
|
2007-11-30 20:22:33 +01:00
|
|
|
|
2011-07-06 23:14:25 +02:00
|
|
|
void get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height)
|
2009-07-24 10:44:15 +02:00
|
|
|
{
|
|
|
|
/* The drawable size of a fbo target is the opengl texture size, which is the power of two size. */
|
2010-04-21 22:02:31 +02:00
|
|
|
*width = context->current_rt->pow2Width;
|
|
|
|
*height = context->current_rt->pow2Height;
|
2007-11-30 20:22:33 +01:00
|
|
|
}
|
|
|
|
|
2011-07-06 23:14:25 +02:00
|
|
|
void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height)
|
2009-07-24 10:44:15 +02:00
|
|
|
{
|
2011-07-06 23:14:25 +02:00
|
|
|
const struct wined3d_swapchain *swapchain = context->swapchain;
|
2007-11-30 20:22:33 +01:00
|
|
|
/* The drawable size of a backbuffer / aux buffer offscreen target is the size of the
|
|
|
|
* current context's drawable, which is the size of the back buffer of the swapchain
|
2010-03-15 21:07:25 +01:00
|
|
|
* the active context belongs to. */
|
2011-12-02 08:15:52 +01:00
|
|
|
*width = swapchain->desc.backbuffer_width;
|
|
|
|
*height = swapchain->desc.backbuffer_height;
|
2007-11-30 20:22:33 +01:00
|
|
|
}
|
2009-12-22 18:32:13 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
|
2009-12-22 18:32:13 +01:00
|
|
|
UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc)
|
|
|
|
{
|
|
|
|
if (device->filter_messages)
|
|
|
|
{
|
|
|
|
TRACE("Filtering message: window %p, message %#x, wparam %#lx, lparam %#lx.\n",
|
|
|
|
window, message, wparam, lparam);
|
2010-11-02 12:02:47 +01:00
|
|
|
if (unicode)
|
|
|
|
return DefWindowProcW(window, message, wparam, lparam);
|
|
|
|
else
|
|
|
|
return DefWindowProcA(window, message, wparam, lparam);
|
2009-12-22 18:32:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message == WM_DESTROY)
|
|
|
|
{
|
|
|
|
TRACE("unregister window %p.\n", window);
|
|
|
|
wined3d_unregister_window(window);
|
2009-12-28 17:38:04 +01:00
|
|
|
|
2012-01-24 21:47:45 +01:00
|
|
|
if (InterlockedCompareExchangePointer((void **)&device->focus_window, NULL, window) != window)
|
|
|
|
ERR("Window %p is not the focus window for device %p.\n", window, device);
|
2009-12-22 18:32:13 +01:00
|
|
|
}
|
2011-11-30 06:01:44 +01:00
|
|
|
else if (message == WM_DISPLAYCHANGE)
|
|
|
|
{
|
|
|
|
device->device_parent->ops->mode_changed(device->device_parent);
|
|
|
|
}
|
2009-12-22 18:32:13 +01:00
|
|
|
|
2010-11-02 12:02:47 +01:00
|
|
|
if (unicode)
|
|
|
|
return CallWindowProcW(proc, window, message, wparam, lparam);
|
|
|
|
else
|
|
|
|
return CallWindowProcA(proc, window, message, wparam, lparam);
|
2009-12-22 18:32:13 +01:00
|
|
|
}
|