2004-10-07 06:22:21 +02:00
|
|
|
/*
|
|
|
|
* IWineD3DDevice implementation
|
|
|
|
*
|
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);
|
|
|
|
|
2006-06-07 05:37:05 +02:00
|
|
|
/* Define the default light parameters as specified by MSDN */
|
|
|
|
const WINED3DLIGHT WINED3D_default_light = {
|
|
|
|
|
2009-07-07 11:08:01 +02:00
|
|
|
WINED3DLIGHT_DIRECTIONAL, /* Type */
|
|
|
|
{ 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
|
|
|
**********************************************************/
|
2009-07-07 11:08:01 +02:00
|
|
|
const float identity[] =
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
}; /* 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. */
|
|
|
|
static GLenum gl_primitive_type_from_d3d(WINED3DPRIMITIVETYPE primitive_type)
|
|
|
|
{
|
|
|
|
switch(primitive_type)
|
|
|
|
{
|
|
|
|
case WINED3DPT_POINTLIST:
|
|
|
|
return GL_POINTS;
|
|
|
|
|
|
|
|
case WINED3DPT_LINELIST:
|
|
|
|
return GL_LINES;
|
|
|
|
|
|
|
|
case WINED3DPT_LINESTRIP:
|
|
|
|
return GL_LINE_STRIP;
|
|
|
|
|
|
|
|
case WINED3DPT_TRIANGLELIST:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
|
|
|
|
case WINED3DPT_TRIANGLESTRIP:
|
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
|
|
|
|
case WINED3DPT_TRIANGLEFAN:
|
|
|
|
return GL_TRIANGLE_FAN;
|
|
|
|
|
|
|
|
case WINED3DPT_LINELIST_ADJ:
|
|
|
|
return GL_LINES_ADJACENCY_ARB;
|
|
|
|
|
|
|
|
case WINED3DPT_LINESTRIP_ADJ:
|
|
|
|
return GL_LINE_STRIP_ADJACENCY_ARB;
|
|
|
|
|
|
|
|
case WINED3DPT_TRIANGLELIST_ADJ:
|
|
|
|
return GL_TRIANGLES_ADJACENCY_ARB;
|
|
|
|
|
|
|
|
case WINED3DPT_TRIANGLESTRIP_ADJ:
|
|
|
|
return GL_TRIANGLE_STRIP_ADJACENCY_ARB;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static WINED3DPRIMITIVETYPE d3d_primitive_type_from_gl(GLenum primitive_type)
|
|
|
|
{
|
|
|
|
switch(primitive_type)
|
|
|
|
{
|
|
|
|
case GL_POINTS:
|
|
|
|
return WINED3DPT_POINTLIST;
|
|
|
|
|
|
|
|
case GL_LINES:
|
|
|
|
return WINED3DPT_LINELIST;
|
|
|
|
|
|
|
|
case GL_LINE_STRIP:
|
|
|
|
return WINED3DPT_LINESTRIP;
|
|
|
|
|
|
|
|
case GL_TRIANGLES:
|
|
|
|
return WINED3DPT_TRIANGLELIST;
|
|
|
|
|
|
|
|
case GL_TRIANGLE_STRIP:
|
|
|
|
return WINED3DPT_TRIANGLESTRIP;
|
|
|
|
|
|
|
|
case GL_TRIANGLE_FAN:
|
|
|
|
return WINED3DPT_TRIANGLEFAN;
|
|
|
|
|
|
|
|
case GL_LINES_ADJACENCY_ARB:
|
|
|
|
return WINED3DPT_LINELIST_ADJ;
|
|
|
|
|
|
|
|
case GL_LINE_STRIP_ADJACENCY_ARB:
|
|
|
|
return WINED3DPT_LINESTRIP_ADJ;
|
|
|
|
|
|
|
|
case GL_TRIANGLES_ADJACENCY_ARB:
|
|
|
|
return WINED3DPT_TRIANGLELIST_ADJ;
|
|
|
|
|
|
|
|
case GL_TRIANGLE_STRIP_ADJACENCY_ARB:
|
|
|
|
return WINED3DPT_TRIANGLESTRIP_ADJ;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
|
|
|
|
return WINED3DPT_UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 10:25:55 +01:00
|
|
|
static BOOL fixed_get_input(BYTE usage, BYTE usage_idx, unsigned int *regnum)
|
|
|
|
{
|
2010-09-14 13:38:39 +02:00
|
|
|
if ((usage == WINED3DDECLUSAGE_POSITION || usage == WINED3DDECLUSAGE_POSITIONT) && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_POSITION;
|
2010-09-14 13:38:39 +02:00
|
|
|
else if (usage == WINED3DDECLUSAGE_BLENDWEIGHT && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_BLENDWEIGHT;
|
2010-09-14 13:38:39 +02:00
|
|
|
else if (usage == WINED3DDECLUSAGE_BLENDINDICES && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_BLENDINDICES;
|
2010-09-14 13:38:39 +02:00
|
|
|
else if (usage == WINED3DDECLUSAGE_NORMAL && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_NORMAL;
|
2010-09-14 13:38:39 +02:00
|
|
|
else if (usage == WINED3DDECLUSAGE_PSIZE && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_PSIZE;
|
2010-09-14 13:38:39 +02:00
|
|
|
else if (usage == WINED3DDECLUSAGE_COLOR && !usage_idx)
|
2009-03-27 10:25:55 +01:00
|
|
|
*regnum = WINED3D_FFP_DIFFUSE;
|
|
|
|
else if (usage == WINED3DDECLUSAGE_COLOR && usage_idx == 1)
|
|
|
|
*regnum = WINED3D_FFP_SPECULAR;
|
|
|
|
else if (usage == WINED3DDECLUSAGE_TEXCOORD && usage_idx < WINED3DDP_MAXTEXCOORD)
|
|
|
|
*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. */
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_stream_info_from_declaration(struct wined3d_device *device,
|
2009-03-27 10:25:55 +01:00
|
|
|
BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup)
|
|
|
|
{
|
|
|
|
/* We need to deal with frequency data! */
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_vertex_declaration *declaration = device->stateBlock->state.vertex_declaration;
|
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;
|
|
|
|
if (declaration->position_transformed) use_vshader = FALSE;
|
|
|
|
|
|
|
|
/* 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-05-16 23:01:23 +02:00
|
|
|
struct wined3d_buffer *buffer = device->stateBlock->state.streams[element->input_slot].buffer;
|
2009-03-27 10:25:55 +01:00
|
|
|
GLuint buffer_object = 0;
|
|
|
|
const BYTE *data = NULL;
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
stride = device->stateBlock->state.streams[element->input_slot].stride;
|
|
|
|
if (device->stateBlock->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);
|
2009-03-27 10:25:55 +01:00
|
|
|
buffer_object = 0;
|
2010-09-14 13:38:41 +02:00
|
|
|
data = (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-05-16 23:01:23 +02:00
|
|
|
data = buffer_get_memory(buffer, &device->adapter->gl_info, &buffer_object);
|
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-05-16 23:01:23 +02:00
|
|
|
if (device->stateBlock->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-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.load_base_vertex_index);
|
2009-03-27 10:25:55 +01:00
|
|
|
buffer_object = 0;
|
2011-05-16 23:01:23 +02:00
|
|
|
data = buffer_get_sysmem(buffer, &device->adapter->gl_info);
|
|
|
|
if ((UINT_PTR)data < -device->stateBlock->state.load_base_vertex_index * stride)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
|
|
|
FIXME("System memory vertex data load offset is negative!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixup)
|
|
|
|
{
|
|
|
|
if (buffer_object) *fixup = TRUE;
|
|
|
|
else if (*fixup && !use_vshader
|
2009-03-27 10:25:56 +01:00
|
|
|
&& (element->usage == WINED3DDECLUSAGE_COLOR
|
|
|
|
|| element->usage == WINED3DDECLUSAGE_POSITIONT))
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
|
|
|
static BOOL warned = FALSE;
|
|
|
|
if (!warned)
|
|
|
|
{
|
|
|
|
/* This may be bad with the fixed function pipeline. */
|
|
|
|
FIXME("Missing vbo streams with unfixed colors or transformed position, expect problems\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-27 10:25:56 +01:00
|
|
|
data += 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-05-16 23:01:23 +02:00
|
|
|
stride_used = vshader_get_input(device->stateBlock->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,
|
2010-08-30 20:29:49 +02:00
|
|
|
element->offset, stride, debug_d3dformat(element->format->id), buffer_object);
|
2009-03-27 10:25:56 +01:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
stream_info->elements[idx].format = element->format;
|
2009-03-27 10:25:55 +01:00
|
|
|
stream_info->elements[idx].stride = stride;
|
|
|
|
stream_info->elements[idx].data = data;
|
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
|
|
|
stream_info->elements[idx].buffer_object = buffer_object;
|
|
|
|
|
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;
|
|
|
|
if (!device->stateBlock->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;
|
|
|
|
|
|
|
|
/* 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-05-16 23:01:23 +02:00
|
|
|
buffer = device->stateBlock->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
|
|
|
|
|
|
|
/* If PreLoad dropped the buffer object, update the stream info. */
|
|
|
|
if (buffer->buffer_object != element->buffer_object)
|
|
|
|
{
|
|
|
|
element->buffer_object = 0;
|
2011-05-16 23:01:23 +02:00
|
|
|
element->data = buffer_get_sysmem(buffer, &device->adapter->gl_info) + (ptrdiff_t)element->data;
|
2010-02-16 09:50:39 +01:00
|
|
|
}
|
2010-03-21 13:26:36 +01: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-29 10:37:12 +01:00
|
|
|
static void stream_info_element_from_strided(const struct wined3d_gl_info *gl_info,
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct WineDirect3DStridedData *strided, struct wined3d_stream_info_element *e)
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
e->format = wined3d_get_format(gl_info, strided->format);
|
2009-03-27 10:25:55 +01:00
|
|
|
e->stride = strided->dwStride;
|
|
|
|
e->data = strided->lpData;
|
|
|
|
e->stream_idx = 0;
|
|
|
|
e->buffer_object = 0;
|
|
|
|
}
|
|
|
|
|
2010-02-03 11:02:22 +01:00
|
|
|
static void device_stream_info_from_strided(const struct wined3d_gl_info *gl_info,
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
memset(stream_info, 0, sizeof(*stream_info));
|
|
|
|
|
|
|
|
if (strided->position.lpData)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->position, &stream_info->elements[WINED3D_FFP_POSITION]);
|
2009-03-27 10:25:55 +01:00
|
|
|
if (strided->normal.lpData)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->normal, &stream_info->elements[WINED3D_FFP_NORMAL]);
|
2009-03-27 10:25:55 +01:00
|
|
|
if (strided->diffuse.lpData)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->diffuse, &stream_info->elements[WINED3D_FFP_DIFFUSE]);
|
2009-03-27 10:25:55 +01:00
|
|
|
if (strided->specular.lpData)
|
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)
|
|
|
|
{
|
|
|
|
if (strided->texCoords[i].lpData)
|
2009-10-29 10:37:12 +01:00
|
|
|
stream_info_element_from_strided(gl_info, &strided->texCoords[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;
|
2010-02-03 11:02:22 +01:00
|
|
|
BOOL fixup = FALSE;
|
|
|
|
|
|
|
|
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");
|
2010-09-28 12:00:22 +02:00
|
|
|
device_stream_info_from_declaration(device, !!state->vertex_shader, stream_info, &fixup);
|
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
|
|
|
{
|
2010-09-28 12:00:22 +02:00
|
|
|
if (state->vertex_declaration->half_float_conv_needed && !fixup)
|
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));
|
|
|
|
|
|
|
|
if ((stream_info->position_transformed || (stream_info->use_map & slow_mask)) && !fixup)
|
|
|
|
{
|
|
|
|
device->useDrawStridedSlow = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device->useDrawStridedSlow = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
srgb = state->sampler_states[idx][WINED3DSAMP_SRGBTEXTURE] ? 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-05-16 23:01:23 +02:00
|
|
|
void device_preload_textures(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;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void device_get_draw_rect(struct wined3d_device *device, RECT *rect)
|
2010-04-28 00:08:50 +02:00
|
|
|
{
|
2011-01-28 20:05:43 +01:00
|
|
|
struct wined3d_stateblock *stateblock = device->stateBlock;
|
2010-09-15 12:00:06 +02:00
|
|
|
WINED3DVIEWPORT *vp = &stateblock->state.viewport;
|
2010-04-28 00:08:50 +02:00
|
|
|
|
|
|
|
SetRect(rect, vp->X, vp->Y, vp->X + vp->Width, vp->Y + vp->Height);
|
|
|
|
|
2010-09-15 12:00:04 +02:00
|
|
|
if (stateblock->state.render_states[WINED3DRS_SCISSORTESTENABLE])
|
2010-04-28 00:08:50 +02:00
|
|
|
{
|
2010-09-15 12:00:05 +02:00
|
|
|
IntersectRect(rect, rect, &stateblock->state.scissor_rect);
|
2010-04-28 00:08:50 +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 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)
|
|
|
|
{
|
|
|
|
surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_DS_OFFSCREEN);
|
2010-04-29 00:08:59 +02:00
|
|
|
surface_modify_ds_location(device->onscreen_depth_stencil, SFLAG_DS_OFFSCREEN,
|
|
|
|
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-04-29 13:03:42 +02:00
|
|
|
static BOOL is_full_clear(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,
|
2010-07-23 11:31:03 +02:00
|
|
|
DWORD location, const RECT *draw_rect, UINT rect_count, const RECT *clear_rect)
|
|
|
|
{
|
|
|
|
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. */
|
|
|
|
surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
|
|
|
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. */
|
|
|
|
surface_modify_ds_location(ds, location, draw_rect->right, draw_rect->bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntersectRect(&r, draw_rect, clear_rect);
|
|
|
|
if (EqualRect(&r, draw_rect))
|
|
|
|
{
|
|
|
|
/* clear_rect ⊇ draw_rect, modify only. */
|
|
|
|
surface_modify_ds_location(ds, location, draw_rect->right, draw_rect->bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Full load. */
|
|
|
|
surface_load_ds_location(ds, context, location);
|
|
|
|
surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
|
|
|
}
|
|
|
|
|
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 device_clear_render_targets(struct wined3d_device *device, UINT rt_count, struct wined3d_surface **rts,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *depth_stencil, UINT rect_count, const RECT *rects, const RECT *draw_rect,
|
2011-04-05 19:01:30 +02:00
|
|
|
DWORD flags, const WINED3DCOLORVALUE *color, 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-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *target = rt_count ? rts[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;
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
if (rts[i]) surface_load_location(rts[i], SFLAG_INDRAWABLE, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context = context_acquire(device, target);
|
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping clear.\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-26 19:45:02 +01:00
|
|
|
if (!context_apply_clear_state(context, device, rt_count, rts, depth_stencil))
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Failed to apply clear state, skipping clear.\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
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-04-05 19:01:30 +02:00
|
|
|
drawable_width = depth_stencil->pow2Width;
|
|
|
|
drawable_height = depth_stencil->pow2Height;
|
|
|
|
}
|
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-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_TWOSIDEDSTENCILMODE));
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
glStencilMask(~0U);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_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)
|
|
|
|
{
|
2011-04-05 19:01:30 +02:00
|
|
|
DWORD location = render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN;
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
if (location == SFLAG_DS_ONSCREEN && depth_stencil != device->onscreen_depth_stencil)
|
2010-09-05 23:38:48 +02:00
|
|
|
{
|
|
|
|
LEAVE_GL();
|
2010-07-23 11:31:03 +02:00
|
|
|
device_switch_onscreen_ds(device, context, depth_stencil);
|
2010-09-05 23:38:48 +02:00
|
|
|
ENTER_GL();
|
|
|
|
}
|
2010-08-23 18:28:06 +02:00
|
|
|
prepare_ds_clear(depth_stencil, context, location, draw_rect, rect_count, clear_rect);
|
2010-07-23 11:31:03 +02:00
|
|
|
surface_modify_location(depth_stencil, SFLAG_INDRAWABLE, TRUE);
|
|
|
|
|
|
|
|
glDepthMask(GL_TRUE);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_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)
|
|
|
|
{
|
|
|
|
if (rts[i]) surface_modify_location(rts[i], SFLAG_INDRAWABLE, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_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.
|
|
|
|
* The rectangle is not cleared, no error is returned, but further rectanlges are
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG CDECL wined3d_device_incref(struct wined3d_device *device)
|
2005-03-02 13:16:10 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&device->ref);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", device, refcount);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
return refcount;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&device->ref);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", device, refcount);
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!refcount)
|
|
|
|
{
|
2009-01-07 02:20:08 +01:00
|
|
|
UINT i;
|
|
|
|
|
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",
|
2011-03-01 09:47:56 +01:00
|
|
|
resource, debug_d3dresourcetype(resource->resourceType), resource->resourceType);
|
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-05-16 23:01:22 +02:00
|
|
|
UINT CDECL wined3d_device_get_swapchain_count(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_swapchain(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-05-16 23:01:23 +02:00
|
|
|
static void IWineD3DDeviceImpl_LoadLogo(struct wined3d_device *device, const char *filename)
|
|
|
|
{
|
2007-09-01 21:22:32 +02:00
|
|
|
HBITMAP hbm;
|
|
|
|
BITMAP bm;
|
|
|
|
HRESULT hr;
|
|
|
|
HDC dcb = NULL, dcs = NULL;
|
|
|
|
WINEDDCOLORKEY colorkey;
|
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_surface_create(device, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, TRUE,
|
2010-08-31 18:41:40 +02:00
|
|
|
FALSE, 0, 0, WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL, NULL,
|
2011-05-16 23:01:23 +02:00
|
|
|
&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
|
|
|
|
|
|
|
colorkey.dwColorSpaceLowValue = 0;
|
|
|
|
colorkey.dwColorSpaceHighValue = 0;
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_surface_set_color_key(device->logo_surface, WINEDDCKEY_SRCBLT, &colorkey);
|
2010-08-23 18:28:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const WINED3DCOLORVALUE 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-05-16 23:01:23 +02:00
|
|
|
static void create_dummy_textures(struct wined3d_device *device)
|
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;
|
2008-02-15 15:54:37 +01:00
|
|
|
unsigned int i;
|
|
|
|
/* Under DirectX you can have texture stage operations even if no texture is
|
|
|
|
bound, whereas opengl will only do texture operations when a valid texture is
|
|
|
|
bound. We emulate this by creating dummy textures and binding them to each
|
|
|
|
texture stage, but disable all stages by default. Hence if a stage is enabled
|
|
|
|
then the default texture will kick in until replaced by a SetTexture call */
|
|
|
|
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
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
for (i = 0; i < gl_info->limits.textures; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2008-02-15 15:54:37 +01:00
|
|
|
GLubyte white = 255;
|
|
|
|
|
|
|
|
/* Make appropriate texture active */
|
2008-12-16 13:18:49 +01:00
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
|
|
|
|
checkGLcall("glActiveTextureARB");
|
2008-02-15 15:54:37 +01:00
|
|
|
|
|
|
|
/* Generate an opengl texture name */
|
2011-05-16 23:01:23 +02:00
|
|
|
glGenTextures(1, &device->dummyTextureName[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glGenTextures");
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("Dummy Texture %d given name %d.\n", i, device->dummyTextureName[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
|
|
|
|
/* Generate a dummy 2d texture (not using 1d because they cause many
|
|
|
|
* DRI drivers fall back to sw) */
|
2011-05-16 23:01:23 +02:00
|
|
|
glBindTexture(GL_TEXTURE_2D, device->dummyTextureName[i]);
|
2008-02-15 15:54:37 +01:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &white);
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
|
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
|
|
|
{
|
2008-02-15 15:54:37 +01:00
|
|
|
/* Reenable because if supported it is enabled by default */
|
|
|
|
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
|
|
|
{
|
|
|
|
ENTER_GL();
|
|
|
|
glDeleteTextures(gl_info->limits.textures, device->dummyTextureName);
|
|
|
|
checkGLcall("glDeleteTextures(gl_info->limits.textures, device->dummyTextureName)");
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
memset(device->dummyTextureName, 0, gl_info->limits.textures * sizeof(*device->dummyTextureName));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
device->focus_window = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
|
|
|
|
WINED3DPRESENT_PARAMETERS *present_parameters)
|
2009-01-16 10:14:24 +01:00
|
|
|
{
|
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-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p, present_parameters %p.\n", device, present_parameters);
|
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-16 23:01:22 +02:00
|
|
|
TRACE("Creating stateblock.\n");
|
|
|
|
hr = wined3d_stateblock_create(device, WINED3DSBT_INIT, &device->stateBlock);
|
2010-07-30 10:15:25 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2007-07-22 23:09:11 +02:00
|
|
|
WARN("Failed to create stateblock\n");
|
2007-10-09 22:04:18 +02:00
|
|
|
goto err_out;
|
2007-07-22 23:09:11 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
TRACE("Created stateblock %p.\n", device->stateBlock);
|
|
|
|
device->updateStateBlock = device->stateBlock;
|
|
|
|
wined3d_stateblock_incref(device->updateStateBlock);
|
|
|
|
|
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
|
|
|
|
2011-05-16 23:01:22 +02:00
|
|
|
device->palette_count = 1;
|
|
|
|
device->palettes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PALETTEENTRY*));
|
2011-05-18 22:30:15 +02:00
|
|
|
if (!device->palettes || !device->fb.render_targets)
|
2010-07-30 10:15:26 +02:00
|
|
|
{
|
2008-03-26 23:23:04 +01:00
|
|
|
ERR("Out of memory!\n");
|
2009-12-02 10:41:20 +01:00
|
|
|
hr = E_OUTOFMEMORY;
|
2008-03-26 23:23:04 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
|
|
|
|
device->palettes[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256);
|
|
|
|
if (!device->palettes[0])
|
|
|
|
{
|
2008-03-26 23:23:04 +01:00
|
|
|
ERR("Out of memory!\n");
|
2009-12-02 10:41:20 +01:00
|
|
|
hr = E_OUTOFMEMORY;
|
2008-03-26 23:23:04 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
device->palettes[0][i].peRed = 0xff;
|
|
|
|
device->palettes[0][i].peGreen = 0xff;
|
|
|
|
device->palettes[0][i].peBlue = 0xff;
|
|
|
|
device->palettes[0][i].peFlags = 0xff;
|
2008-03-26 23:23:04 +01:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->currentPalette = 0;
|
2008-03-26 23:23:04 +01: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-05-16 23:01:22 +02:00
|
|
|
present_parameters, &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-05-16 23:01:22 +02:00
|
|
|
create_dummy_textures(device);
|
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)
|
|
|
|
{
|
2007-02-27 21:32:15 +01:00
|
|
|
TRACE("Using auxilliary 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
|
|
|
|
| (present_parameters->EnableAutoDepthStencil ? WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL : 0),
|
|
|
|
0x00, 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)
|
|
|
|
IWineD3DDeviceImpl_LoadLogo(device, wined3d_settings.logo);
|
|
|
|
device->highest_dirty_ps_const = 0;
|
|
|
|
device->highest_dirty_vs_const = 0;
|
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;
|
|
|
|
if (device->palettes)
|
2011-04-06 19:17:53 +02:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->palettes[0]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->palettes);
|
2008-03-26 23:23:04 +01:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->palette_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->stateBlock)
|
2011-01-28 20:05:41 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_stateblock_decref(device->stateBlock);
|
|
|
|
device->stateBlock = NULL;
|
2008-08-20 22:45:02 +02:00
|
|
|
}
|
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,
|
|
|
|
WINED3DPRESENT_PARAMETERS *present_parameters)
|
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-05-16 23:01:22 +02:00
|
|
|
TRACE("device %p, present_parameters %p.\n", device, present_parameters);
|
|
|
|
|
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-05-16 23:01:22 +02:00
|
|
|
present_parameters, &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-03-01 09:47:56 +01:00
|
|
|
static HRESULT WINAPI device_unload_resource(struct wined3d_resource *resource, void *data)
|
2009-03-23 13:54:34 +01:00
|
|
|
{
|
2011-02-28 08:05:38 +01:00
|
|
|
TRACE("Unloading resource %p.\n", resource);
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
resource->resource_ops->resource_unload(resource);
|
2011-02-28 08:05:38 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2009-03-23 13:54:34 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2009-03-23 13:54:34 +01:00
|
|
|
/* Unload resources */
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_enum_resources(device, device_unload_resource, NULL);
|
2009-03-23 13:54:34 +01:00
|
|
|
|
2007-07-04 17:57:45 +02:00
|
|
|
TRACE("Deleting high order patches\n");
|
|
|
|
for(i = 0; i < PATCHMAP_SIZE; i++) {
|
|
|
|
struct list *e1, *e2;
|
|
|
|
struct WineD3DRectPatch *patch;
|
2011-05-16 23:01:22 +02:00
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &device->patches[i])
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
patch = LIST_ENTRY(e1, struct WineD3DRectPatch, 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
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->depth_blt_rb)
|
|
|
|
{
|
2009-05-13 18:22:55 +02:00
|
|
|
ENTER_GL();
|
2011-05-16 23:01:22 +02:00
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &device->depth_blt_rb);
|
2009-05-13 18:22:55 +02:00
|
|
|
LEAVE_GL();
|
2011-05-16 23:01:22 +02:00
|
|
|
device->depth_blt_rb = 0;
|
|
|
|
device->depth_blt_rb_w = 0;
|
|
|
|
device->depth_blt_rb_h = 0;
|
2008-07-02 23:00:11 +02:00
|
|
|
}
|
2008-03-18 19:49:05 +01:00
|
|
|
|
2007-08-14 14:44:41 +02:00
|
|
|
/* Release the update stateblock */
|
2011-05-16 23:01:22 +02:00
|
|
|
if (wined3d_stateblock_decref(device->updateStateBlock))
|
2011-01-28 20:05:41 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
if (device->updateStateBlock != device->stateBlock)
|
2011-01-28 20:05:41 +01:00
|
|
|
FIXME("Something's still holding the update stateblock.\n");
|
2007-08-14 14:44:41 +02:00
|
|
|
}
|
2011-05-16 23:01:22 +02:00
|
|
|
device->updateStateBlock = NULL;
|
2007-08-14 14:44:41 +02:00
|
|
|
|
2011-01-28 20:05:41 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
struct wined3d_stateblock *stateblock = device->stateBlock;
|
|
|
|
device->stateBlock = NULL;
|
2007-08-14 14:44:41 +02:00
|
|
|
|
|
|
|
/* Release the stateblock */
|
2011-01-28 20:05:41 +01:00
|
|
|
if (wined3d_stateblock_decref(stateblock))
|
|
|
|
FIXME("Something's still holding the stateblock.\n");
|
2007-08-14 14:44:41 +02: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;
|
2011-04-29 13:03:41 +02:00
|
|
|
if (wined3d_surface_decref(surface)
|
2011-05-16 23:01:22 +02:00
|
|
|
&& surface != device->auto_depth_stencil)
|
2011-01-28 20:05:40 +01:00
|
|
|
ERR("Something is still holding a reference to depth/stencil buffer %p.\n", 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-16 23:01:22 +02:00
|
|
|
for (i = 0; i < device->palette_count; ++i)
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->palettes[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->palettes);
|
|
|
|
device->palettes = NULL;
|
|
|
|
device->palette_count = 0;
|
2008-03-26 23:23:04 +01: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). */
|
|
|
|
device->createParms.BehaviorFlags |= 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,
|
|
|
|
UINT swapchain_idx, const WINED3DDISPLAYMODE *mode)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(&device->adapter->gl_info, mode->Format);
|
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,
|
|
|
|
mode->Width, mode->Height, mode->RefreshRate, debug_d3dformat(mode->Format));
|
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-05-16 23:01:23 +02:00
|
|
|
devmode.dmPelsWidth = mode->Width;
|
|
|
|
devmode.dmPelsHeight = mode->Height;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
devmode.dmDisplayFrequency = mode->RefreshRate;
|
|
|
|
if (mode->RefreshRate)
|
2006-05-18 22:42:22 +02:00
|
|
|
devmode.dmFields |= DM_DISPLAYFREQUENCY;
|
|
|
|
|
|
|
|
/* Only change the mode if necessary */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->ddraw_width == mode->Width && device->ddraw_height == mode->Height
|
|
|
|
&& device->ddraw_format == mode->Format && !mode->RefreshRate)
|
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-05-16 23:01:23 +02:00
|
|
|
device->ddraw_width = mode->Width;
|
|
|
|
device->ddraw_height = mode->Height;
|
|
|
|
device->ddraw_format = mode->Format;
|
2006-05-18 22:42:22 +02:00
|
|
|
|
2006-12-14 23:51:23 +01:00
|
|
|
/* And finally clip mouse to our screen */
|
2011-05-16 23:01:23 +02: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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_wined3d(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-05-16 23:01:23 +02:00
|
|
|
UINT CDECL wined3d_device_get_available_texture_mem(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
|
|
|
{
|
2011-03-03 21:49:10 +01:00
|
|
|
InterlockedIncrement(&buffer->bind_count);
|
|
|
|
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
|
|
|
{
|
2011-03-03 21:49:10 +01:00
|
|
|
InterlockedDecrement(&prev_buffer->bind_count);
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_stream_source(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_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
|
|
|
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,
|
2011-05-16 23:01:21 +02:00
|
|
|
WINED3DTRANSFORMSTATETYPE d3dts, const WINED3DMATRIX *matrix)
|
|
|
|
{
|
|
|
|
TRACE("device %p, state %s, matrix %p.\n",
|
|
|
|
device, debug_d3dtstype(d3dts), matrix);
|
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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
conv_mat(matrix, &device->stateBlock->state.transforms[d3dts].u.m[0][0]);
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
/* ScreenCoord = ProjectionMat * ViewMat * WorldMat * ObjectCoord
|
|
|
|
* where ViewMat = Camera space, WorldMat = world space.
|
|
|
|
*
|
|
|
|
* In OpenGL, camera and world space is combined into GL_MODELVIEW
|
|
|
|
* matrix. The Projection matrix stay projection matrix. */
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (d3dts == WINED3DTS_VIEW)
|
|
|
|
device->view_ident = !memcmp(matrix, identity, 16 * sizeof(float));
|
2004-11-28 16:04:41 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (d3dts < WINED3DTS_WORLDMATRIX(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_transform(struct wined3d_device *device,
|
2010-09-16 11:19:56 +02:00
|
|
|
WINED3DTRANSFORMSTATETYPE state, WINED3DMATRIX *matrix)
|
|
|
|
{
|
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,
|
|
|
|
WINED3DTRANSFORMSTATETYPE state, const WINED3DMATRIX *matrix)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2008-11-26 16:14:39 +01:00
|
|
|
const WINED3DMATRIX *mat = NULL;
|
2006-10-12 08:21:39 +02:00
|
|
|
WINED3DMATRIX 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. */
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (state <= HIGHEST_TRANSFORMSTATE)
|
|
|
|
mat = &device->updateStateBlock->state.transforms[state];
|
2010-09-16 11:19:56 +02:00
|
|
|
else
|
2011-05-16 23:01:23 +02:00
|
|
|
FIXME("Unhandled transform state %#x.\n", state);
|
2004-11-29 18:53:42 +01:00
|
|
|
|
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-05-23 16:34:11 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device, UINT light_idx, const WINED3DLIGHT *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-05-16 23:01:21 +02:00
|
|
|
switch (light->Type)
|
|
|
|
{
|
2007-02-20 22:43:13 +01:00
|
|
|
case WINED3DLIGHT_POINT:
|
|
|
|
case WINED3DLIGHT_SPOT:
|
|
|
|
case WINED3DLIGHT_PARALLELPOINT:
|
|
|
|
case WINED3DLIGHT_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. */
|
|
|
|
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;
|
|
|
|
|
|
|
|
case WINED3DLIGHT_DIRECTIONAL:
|
|
|
|
/* 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",
|
|
|
|
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);
|
|
|
|
TRACE("... Range(%f), Falloff(%f), Theta(%f), Phi(%f)\n",
|
|
|
|
light->Range, light->Falloff, light->Theta, light->Phi);
|
|
|
|
|
|
|
|
/* Save away the information. */
|
|
|
|
object->OriginalParms = *light;
|
|
|
|
|
|
|
|
switch (light->Type)
|
|
|
|
{
|
|
|
|
case WINED3DLIGHT_POINT:
|
|
|
|
/* Position */
|
|
|
|
object->lightPosn[0] = light->Position.x;
|
|
|
|
object->lightPosn[1] = light->Position.y;
|
|
|
|
object->lightPosn[2] = light->Position.z;
|
|
|
|
object->lightPosn[3] = 1.0f;
|
|
|
|
object->cutoff = 180.0f;
|
|
|
|
/* FIXME: Range */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DLIGHT_DIRECTIONAL:
|
|
|
|
/* Direction */
|
|
|
|
object->lightPosn[0] = -light->Direction.x;
|
|
|
|
object->lightPosn[1] = -light->Direction.y;
|
|
|
|
object->lightPosn[2] = -light->Direction.z;
|
|
|
|
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;
|
|
|
|
|
|
|
|
case WINED3DLIGHT_SPOT:
|
|
|
|
/* Position */
|
|
|
|
object->lightPosn[0] = light->Position.x;
|
|
|
|
object->lightPosn[1] = light->Position.y;
|
|
|
|
object->lightPosn[2] = light->Position.z;
|
|
|
|
object->lightPosn[3] = 1.0f;
|
|
|
|
|
|
|
|
/* Direction */
|
|
|
|
object->lightDirn[0] = light->Direction.x;
|
|
|
|
object->lightDirn[1] = light->Direction.y;
|
|
|
|
object->lightDirn[2] = light->Direction.z;
|
|
|
|
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. */
|
|
|
|
if (!light->Falloff)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
{
|
|
|
|
rho = light->Theta + (light->Phi - light->Theta) / (2 * light->Falloff);
|
|
|
|
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-05-16 23:01:21 +02:00
|
|
|
object->cutoff = (float)(light->Phi * 90 / M_PI);
|
|
|
|
/* FIXME: Range */
|
|
|
|
break;
|
2004-11-29 18:53:42 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
default:
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_light(struct wined3d_device *device, UINT light_idx, WINED3DLIGHT *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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_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;
|
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
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device, UINT plane_idx, const float *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
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->updateStateBlock->state.clip_planes[plane_idx][0] == plane[0]
|
|
|
|
&& device->updateStateBlock->state.clip_planes[plane_idx][1] == plane[1]
|
|
|
|
&& device->updateStateBlock->state.clip_planes[plane_idx][2] == plane[2]
|
|
|
|
&& device->updateStateBlock->state.clip_planes[plane_idx][3] == plane[3])
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.clip_planes[plane_idx][0] = plane[0];
|
|
|
|
device->updateStateBlock->state.clip_planes[plane_idx][1] = plane[1];
|
|
|
|
device->updateStateBlock->state.clip_planes[plane_idx][2] = plane[2];
|
|
|
|
device->updateStateBlock->state.clip_planes[plane_idx][3] = plane[3];
|
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
|
|
|
}
|
|
|
|
|
2011-05-23 16:34:11 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_clip_plane(struct wined3d_device *device, UINT plane_idx, float *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
|
|
|
plane[0] = (float)device->stateBlock->state.clip_planes[plane_idx][0];
|
|
|
|
plane[1] = (float)device->stateBlock->state.clip_planes[plane_idx][1];
|
|
|
|
plane[2] = (float)device->stateBlock->state.clip_planes[plane_idx][2];
|
|
|
|
plane[3] = (float)device->stateBlock->state.clip_planes[plane_idx][3];
|
|
|
|
|
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_clip_status(struct wined3d_device *device, const WINED3DCLIPSTATUS *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;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
device->updateStateBlock->state.clip_status.ClipUnion = clip_status->ClipUnion;
|
|
|
|
device->updateStateBlock->state.clip_status.ClipIntersection = clip_status->ClipIntersection;
|
|
|
|
|
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_get_clip_status(struct wined3d_device *device, WINED3DCLIPSTATUS *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;
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
clip_status->ClipUnion = device->updateStateBlock->state.clip_status.ClipUnion;
|
|
|
|
clip_status->ClipIntersection = device->updateStateBlock->state.clip_status.ClipIntersection;
|
|
|
|
|
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_material(struct wined3d_device *device, const WINED3DMATERIAL *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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_material(struct wined3d_device *device, WINED3DMATERIAL *material)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, material %p.\n", device, material);
|
|
|
|
|
|
|
|
*material = device->updateStateBlock->state.material;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2011-03-03 21:49:10 +01:00
|
|
|
InterlockedIncrement(&buffer->bind_count);
|
|
|
|
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
|
|
|
{
|
2011-03-03 21:49:10 +01:00
|
|
|
InterlockedDecrement(&prev_buffer->bind_count);
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_index_buffer(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;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2007-06-05 18:52:21 +02:00
|
|
|
/* The base vertex index affects the stream sources */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2007-01-02 21:07:39 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
INT CDECL wined3d_device_get_base_vertex_index(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_viewport(struct wined3d_device *device, const WINED3DVIEWPORT *viewport)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, viewport %p.\n", device, viewport);
|
|
|
|
TRACE("x %u, y %u, w %u, h %u, minz %.8e, maxz %.8e.\n",
|
|
|
|
viewport->X, viewport->Y, viewport->Width, viewport->Height, viewport->MinZ, viewport->MaxZ);
|
|
|
|
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_viewport(struct wined3d_device *device, WINED3DVIEWPORT *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-05-16 23:01:21 +02:00
|
|
|
WINED3DRENDERSTATETYPE 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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_render_state(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
WINED3DRENDERSTATETYPE 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,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT sampler_idx, WINED3DSAMPLERSTATETYPE state, DWORD value)
|
|
|
|
{
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_sampler_state(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT sampler_idx, WINED3DSAMPLERSTATETYPE state, DWORD *value)
|
|
|
|
{
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_scissor_rect(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_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
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_vertex_shader(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_b(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_i(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_vs_consts_f(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-05-16 23:01:23 +02:00
|
|
|
static inline void markTextureStagesDirty(struct wined3d_device *device, DWORD stage)
|
|
|
|
{
|
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;
|
2010-09-16 11:19:57 +02:00
|
|
|
WINED3DTEXTUREOP color_op = state->texture_states[i][WINED3DTSS_COLOROP];
|
|
|
|
WINED3DTEXTUREOP alpha_op = state->texture_states[i][WINED3DTSS_ALPHAOP];
|
|
|
|
DWORD color_arg1 = state->texture_states[i][WINED3DTSS_COLORARG1] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD color_arg2 = state->texture_states[i][WINED3DTSS_COLORARG2] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD color_arg3 = state->texture_states[i][WINED3DTSS_COLORARG0] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg1 = state->texture_states[i][WINED3DTSS_ALPHAARG1] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg2 = state->texture_states[i][WINED3DTSS_ALPHAARG2] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg3 = state->texture_states[i][WINED3DTSS_ALPHAARG0] & WINED3DTA_SELECTMASK;
|
2007-06-27 23:47:24 +02:00
|
|
|
|
|
|
|
if (color_op == WINED3DTOP_DISABLE) {
|
|
|
|
/* Not used, and disable higher stages */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((color_arg1 == WINED3DTA_TEXTURE) && color_op != WINED3DTOP_SELECTARG2)
|
|
|
|
|| ((color_arg2 == WINED3DTA_TEXTURE) && color_op != WINED3DTOP_SELECTARG1)
|
2011-05-16 23:01:23 +02:00
|
|
|
|| ((color_arg3 == WINED3DTA_TEXTURE)
|
|
|
|
&& (color_op == WINED3DTOP_MULTIPLYADD || color_op == WINED3DTOP_LERP))
|
2007-06-27 23:47:24 +02:00
|
|
|
|| ((alpha_arg1 == WINED3DTA_TEXTURE) && alpha_op != WINED3DTOP_SELECTARG2)
|
|
|
|
|| ((alpha_arg2 == WINED3DTA_TEXTURE) && alpha_op != WINED3DTOP_SELECTARG1)
|
2011-05-16 23:01:23 +02:00
|
|
|
|| ((alpha_arg3 == WINED3DTA_TEXTURE)
|
|
|
|
&& (alpha_op == WINED3DTOP_MULTIPLYADD || alpha_op == WINED3DTOP_LERP)))
|
|
|
|
device->fixed_function_usage_map |= (1 << i);
|
2007-06-27 23:47:24 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if ((color_op == WINED3DTOP_BUMPENVMAP || color_op == WINED3DTOP_BUMPENVMAPLUMINANCE) && i < MAX_TEXTURES - 1)
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
markTextureStagesDirty(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-05-16 23:01:23 +02:00
|
|
|
markTextureStagesDirty(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
|
|
|
{
|
2009-04-29 09:55:06 +02:00
|
|
|
const WINED3DSAMPLER_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-05-16 23:01:23 +02:00
|
|
|
markTextureStagesDirty(device, i);
|
2007-06-22 20:43:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static BOOL device_unit_free_for_vs(struct wined3d_device *device,
|
|
|
|
const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_tokens,
|
2010-07-30 06:41:49 +02:00
|
|
|
const WINED3DSAMPLER_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
|
|
|
{
|
2009-04-29 09:55:06 +02:00
|
|
|
const WINED3DSAMPLER_TEXTURE_TYPE *vshader_sampler_type =
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.vertex_shader->reg_maps.sampler_type;
|
2009-04-29 09:55:06 +02:00
|
|
|
const WINED3DSAMPLER_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-05-16 23:01:23 +02:00
|
|
|
struct wined3d_shader * CDECL wined3d_device_get_pixel_shader(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_b(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_i(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_ps_consts_f(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-05-16 23:01:23 +02:00
|
|
|
static HRESULT process_vertices_strided(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-05-16 23:01:23 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2007-02-20 23:00:02 +01:00
|
|
|
char *dest_ptr, *dest_conv = NULL, *dest_conv_addr = NULL;
|
2006-05-12 22:21:31 +02:00
|
|
|
unsigned int i;
|
2006-10-11 03:57:25 +02:00
|
|
|
WINED3DVIEWPORT vp;
|
2006-10-12 08:21:39 +02:00
|
|
|
WINED3DMATRIX mat, proj_mat, view_mat, world_mat;
|
2006-05-12 22:21:31 +02:00
|
|
|
BOOL doClip;
|
2008-11-20 23:13:48 +01:00
|
|
|
DWORD numTextures;
|
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;
|
|
|
|
}
|
|
|
|
|
2010-05-21 09:35:24 +02:00
|
|
|
if (!dest->resource.allocatedMemory)
|
|
|
|
buffer_get_sysmem(dest, gl_info);
|
2006-06-21 15:05:38 +02:00
|
|
|
|
|
|
|
/* Get a pointer into the destination vbo(create one if none exists) and
|
|
|
|
* write correct opengl data into it. It's cheap and allows us to run drawStridedFast
|
|
|
|
*/
|
2009-10-29 10:37:11 +01:00
|
|
|
if (!dest->buffer_object && gl_info->supported[ARB_VERTEX_BUFFER_OBJECT])
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
|
|
|
dest->flags |= WINED3D_BUFFER_CREATEBO;
|
2011-03-03 21:49:09 +01:00
|
|
|
wined3d_buffer_preload(dest);
|
2006-06-21 15:05:38 +02:00
|
|
|
}
|
|
|
|
|
2009-03-06 14:56:23 +01:00
|
|
|
if (dest->buffer_object)
|
|
|
|
{
|
2007-05-06 18:39:29 +02:00
|
|
|
unsigned char extrabytes = 0;
|
|
|
|
/* If the destination vertex buffer has D3DFVF_XYZ position(non-rhw), native d3d writes RHW position, where the RHW
|
|
|
|
* gets written into the 4 bytes after the Z position. In the case of a dest buffer that only has D3DFVF_XYZ data,
|
|
|
|
* this may write 4 extra bytes beyond the area that should be written
|
|
|
|
*/
|
|
|
|
if(DestFVF == WINED3DFVF_XYZ) extrabytes = 4;
|
|
|
|
dest_conv_addr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCount * get_flexible_vertex_size(DestFVF) + extrabytes);
|
2007-02-20 23:00:02 +01:00
|
|
|
if(!dest_conv_addr) {
|
|
|
|
ERR("Out of memory\n");
|
2006-06-21 15:05:38 +02:00
|
|
|
/* Continue without storing converted vertices */
|
|
|
|
}
|
2007-02-20 23:00:02 +01:00
|
|
|
dest_conv = dest_conv_addr;
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->stateBlock->state.render_states[WINED3DRS_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");
|
|
|
|
}
|
|
|
|
} else doClip = FALSE;
|
2010-05-21 09:35:24 +02:00
|
|
|
dest_ptr = ((char *)buffer_get_sysmem(dest, gl_info)) + dwDestIndex * get_flexible_vertex_size(DestFVF);
|
2006-05-12 22:21:31 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_get_transform(device, WINED3DTS_VIEW, &view_mat);
|
|
|
|
wined3d_device_get_transform(device, WINED3DTS_PROJECTION, &proj_mat);
|
|
|
|
wined3d_device_get_transform(device, WINED3DTS_WORLDMATRIX(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);
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("Viewport: X=%d, Y=%d, Width=%d, Height=%d, MinZ=%f, MaxZ=%f\n",
|
2006-05-12 22:21:31 +02:00
|
|
|
vp.X, vp.Y, vp.Width, vp.Height, vp.MinZ, vp.MaxZ);
|
|
|
|
|
|
|
|
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];
|
|
|
|
const float *p = (const float *)(element->data + 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;
|
|
|
|
|
|
|
|
x *= vp.Width / 2;
|
|
|
|
y *= vp.Height / 2;
|
|
|
|
z *= vp.MaxZ - vp.MinZ;
|
|
|
|
|
|
|
|
x += vp.Width / 2 + vp.X;
|
|
|
|
y += vp.Height / 2 + vp.Y;
|
|
|
|
z += vp.MinZ;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2006-10-31 09:16:08 +01:00
|
|
|
if((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW) {
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(float);
|
|
|
|
}
|
2006-06-21 15:05:38 +02:00
|
|
|
|
|
|
|
if(dest_conv) {
|
|
|
|
float w = 1 / rhw;
|
|
|
|
( (float *) dest_conv)[0] = x * w;
|
|
|
|
( (float *) dest_conv)[1] = y * w;
|
|
|
|
( (float *) dest_conv)[2] = z * w;
|
|
|
|
( (float *) dest_conv)[3] = w;
|
|
|
|
|
|
|
|
dest_conv += 3 * sizeof(float);
|
|
|
|
|
2006-10-31 09:16:08 +01:00
|
|
|
if((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW) {
|
2006-06-21 15:05:38 +02:00
|
|
|
dest_conv += sizeof(float);
|
|
|
|
}
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
2006-10-31 09:16:08 +01:00
|
|
|
if (DestFVF & WINED3DFVF_PSIZE) {
|
2006-05-12 22:21:31 +02:00
|
|
|
dest_ptr += sizeof(DWORD);
|
2006-06-21 15:05:38 +02:00
|
|
|
if(dest_conv) dest_conv += sizeof(DWORD);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
2006-10-31 09:16:08 +01: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];
|
|
|
|
const float *normal = (const float *)(element->data + 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));
|
2006-06-21 15:05:38 +02:00
|
|
|
if(dest_conv) {
|
|
|
|
copy_and_next(dest_conv, normal, 3 * sizeof(float));
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
|
2006-10-31 09:16:08 +01: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];
|
|
|
|
const DWORD *color_d = (const DWORD *)(element->data + 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);
|
2006-06-21 15:05:38 +02:00
|
|
|
|
|
|
|
if(dest_conv) {
|
|
|
|
*( (DWORD *) dest_conv) = 0xffffffff;
|
|
|
|
dest_conv += sizeof(DWORD);
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
2006-06-21 15:05:38 +02: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
|
|
|
if(dest_conv) {
|
|
|
|
*( (DWORD *) dest_conv) = (*color_d & 0xff00ff00) ; /* Alpha + green */
|
|
|
|
*( (DWORD *) dest_conv) |= (*color_d & 0x00ff0000) >> 16; /* Red */
|
|
|
|
*( (DWORD *) dest_conv) |= (*color_d & 0xff0000ff) << 16; /* Blue */
|
|
|
|
dest_conv += sizeof(DWORD);
|
|
|
|
}
|
|
|
|
}
|
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];
|
|
|
|
const DWORD *color_s = (const DWORD *)(element->data + 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);
|
2006-06-21 15:05:38 +02:00
|
|
|
|
|
|
|
if(dest_conv) {
|
|
|
|
*( (DWORD *) dest_conv) = 0xFF000000;
|
|
|
|
dest_conv += sizeof(DWORD);
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_and_next(dest_ptr, color_s, sizeof(DWORD));
|
2006-06-21 15:05:38 +02:00
|
|
|
if(dest_conv) {
|
|
|
|
*( (DWORD *) dest_conv) = (*color_s & 0xff00ff00) ; /* Alpha + green */
|
|
|
|
*( (DWORD *) dest_conv) |= (*color_s & 0x00ff0000) >> 16; /* Red */
|
|
|
|
*( (DWORD *) dest_conv) |= (*color_s & 0xff0000ff) << 16; /* Blue */
|
|
|
|
dest_conv += sizeof(DWORD);
|
|
|
|
}
|
2006-05-12 22:21:31 +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];
|
|
|
|
const float *tex_coord = (const float *)(element->data + 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");
|
|
|
|
dest_ptr+=GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
|
2006-06-21 15:05:38 +02:00
|
|
|
if(dest_conv) dest_conv += GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float));
|
2006-06-21 15:05:38 +02:00
|
|
|
if(dest_conv) {
|
|
|
|
copy_and_next(dest_conv, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float));
|
|
|
|
}
|
2006-05-12 22:21:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:01 +02:00
|
|
|
if (dest_conv)
|
|
|
|
{
|
|
|
|
ENTER_GL();
|
|
|
|
|
2009-03-06 14:56:23 +01:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, dest->buffer_object));
|
2007-02-20 23:00:02 +01:00
|
|
|
checkGLcall("glBindBufferARB(GL_ARRAY_BUFFER_ARB)");
|
|
|
|
GL_EXTCALL(glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, dwDestIndex * get_flexible_vertex_size(DestFVF),
|
|
|
|
dwCount * get_flexible_vertex_size(DestFVF),
|
|
|
|
dest_conv_addr));
|
|
|
|
checkGLcall("glBufferSubDataARB(GL_ARRAY_BUFFER_ARB)");
|
2010-09-02 19:25:01 +02:00
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2007-02-20 23:00:02 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, dest_conv_addr);
|
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,
|
|
|
|
struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf)
|
2009-03-06 14:56:23 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
BOOL vbo = FALSE, streamWasUP = device->stateBlock->state.user_stream;
|
2009-03-27 10:25:55 +01:00
|
|
|
struct wined3d_stream_info stream_info;
|
2010-05-21 09:35:24 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
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
|
|
|
|
2007-04-29 17:36:35 +02:00
|
|
|
/* ProcessVertices reads from vertex buffers, which have to be assigned. DrawPrimitive and DrawPrimitiveUP
|
|
|
|
* control the streamIsUP flag, thus restore it afterwards.
|
|
|
|
*/
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.user_stream = FALSE;
|
|
|
|
device_stream_info_from_declaration(device, FALSE, &stream_info, &vbo);
|
|
|
|
device->stateBlock->state.user_stream = streamWasUP;
|
2006-06-21 15:05:38 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (vbo || src_start_idx)
|
|
|
|
{
|
2007-04-22 18:06:07 +02:00
|
|
|
unsigned int i;
|
2008-01-09 20:37:05 +01:00
|
|
|
/* ProcessVertices can't convert FROM a vbo, and vertex buffers used to source into ProcessVertices are
|
2009-03-27 10:25:55 +01:00
|
|
|
* unlikely to ever be used for drawing. Release vbos in those buffers and fix up the stream_info structure
|
2007-04-22 18:06:07 +02:00
|
|
|
*
|
|
|
|
* Also get the start index in, but only loop over all elements if there's something to add at all.
|
|
|
|
*/
|
2009-03-27 10:25:55 +01:00
|
|
|
for (i = 0; i < (sizeof(stream_info.elements) / sizeof(*stream_info.elements)); ++i)
|
2009-03-26 10:43:40 +01:00
|
|
|
{
|
2009-08-21 09:12:29 +02:00
|
|
|
struct wined3d_stream_info_element *e;
|
|
|
|
|
|
|
|
if (!(stream_info.use_map & (1 << i))) continue;
|
|
|
|
|
|
|
|
e = &stream_info.elements[i];
|
2009-03-27 10:25:55 +01:00
|
|
|
if (e->buffer_object)
|
2009-03-26 10:43:40 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_buffer *vb = device->stateBlock->state.streams[e->stream_idx].buffer;
|
2009-03-27 10:25:55 +01:00
|
|
|
e->buffer_object = 0;
|
2010-05-21 12:45:40 +02:00
|
|
|
e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, gl_info));
|
2009-03-26 10:43:40 +01:00
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &vb->buffer_object));
|
|
|
|
vb->buffer_object = 0;
|
|
|
|
LEAVE_GL();
|
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
if (e->data)
|
|
|
|
e->data += 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,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT stage, WINED3DTEXTURESTAGESTATETYPE 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
|
2010-09-16 11:19:57 +02:00
|
|
|
== STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP))
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (state == WINED3DTSS_COLOROP)
|
|
|
|
{
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int i;
|
2006-12-19 23:00:58 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (value == WINED3DTOP_DISABLE && old_value != WINED3DTOP_DISABLE)
|
|
|
|
{
|
|
|
|
/* 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);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP));
|
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);
|
|
|
|
}
|
|
|
|
else if (value != WINED3DTOP_DISABLE && old_value == WINED3DTOP_DISABLE)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
if (device->updateStateBlock->state.texture_states[i][WINED3DTSS_COLOROP] == WINED3DTOP_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);
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP));
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_texture_stage_state(struct wined3d_device *device,
|
2011-05-23 16:34:11 +02:00
|
|
|
UINT stage, WINED3DTEXTURESTAGESTATETYPE 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
|
|
|
}
|
|
|
|
|
2008-12-12 09:33:51 +01:00
|
|
|
/* SetTexture isn't allowed on textures in WINED3DPOOL_SCRATCH */
|
2011-03-18 19:11:00 +01:00
|
|
|
if (texture && texture->resource.pool == WINED3DPOOL_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)
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
LONG bind_count = InterlockedIncrement(&texture->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
|
|
|
|
* meanings when a NULL texture is bound, so the COLOROP and
|
|
|
|
* ALPHAOP have to be dirtified. */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_COLOROP));
|
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_ALPHAOP));
|
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)
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
LONG bind_count = InterlockedDecrement(&prev->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
|
|
|
{
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_COLOROP));
|
|
|
|
device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3DTSS_ALPHAOP));
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_texture(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_back_buffer(struct wined3d_device *device, UINT swapchain_idx,
|
2011-04-29 13:03:42 +02:00
|
|
|
UINT backbuffer_idx, WINED3DBACKBUFFER_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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_device_caps(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
|
|
|
|
|
|
|
return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal, device->devType, caps);
|
2005-01-18 12:42:29 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_display_mode(struct wined3d_device *device,
|
2011-04-13 19:14:32 +02:00
|
|
|
UINT swapchain_idx, WINED3DDISPLAYMODE *mode)
|
|
|
|
{
|
|
|
|
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-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. */
|
|
|
|
mode->Width = device->ddraw_width;
|
|
|
|
mode->Height = device->ddraw_height;
|
|
|
|
mode->Format = device->ddraw_format;
|
|
|
|
mode->RefreshRate = 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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_stateblock_create(device, WINED3DSBT_RECORDED, &stateblock);
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_present(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,
|
2010-08-30 20:29:47 +02:00
|
|
|
const RECT *rects, DWORD flags, WINED3DCOLOR color, float depth, DWORD stencil)
|
2010-04-19 20:46:59 +02:00
|
|
|
{
|
2010-08-22 23:35:41 +02:00
|
|
|
const WINED3DCOLORVALUE c = {D3DCOLOR_R(color), D3DCOLOR_G(color), D3DCOLOR_B(color), D3DCOLOR_A(color)};
|
2010-08-23 18:28:06 +02:00
|
|
|
RECT draw_rect;
|
2004-12-14 12:54:27 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, rect_count %u, rects %p, flags %#x, color 0x%08x, depth %.8e, stencil %u.\n",
|
|
|
|
device, rect_count, rects, flags, color, 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
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:47 +02:00
|
|
|
device_get_draw_rect(device, &draw_rect);
|
2010-08-23 18:28:06 +02:00
|
|
|
|
2010-08-30 20:29:47 +02:00
|
|
|
return device_clear_render_targets(device, device->adapter->gl_info.limits.buffers,
|
2011-05-18 22:30:15 +02:00
|
|
|
device->fb.render_targets, device->fb.depth_stencil, rect_count, rects,
|
2011-04-05 19:01:30 +02:00
|
|
|
&draw_rect, flags, &c, depth, stencil);
|
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,
|
2009-03-05 12:30:43 +01:00
|
|
|
WINED3DPRIMITIVETYPE primitive_type)
|
|
|
|
{
|
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-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_get_primitive_type(struct wined3d_device *device,
|
2009-03-05 12:30:43 +01:00
|
|
|
WINED3DPRIMITIVETYPE *primitive_type)
|
|
|
|
{
|
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-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
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. */
|
|
|
|
drawPrimitive(device, vertex_count, start_vertex, 0, 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
|
|
|
{
|
2010-09-20 19:41:23 +02:00
|
|
|
struct wined3d_buffer *index_buffer;
|
2011-05-16 23:01:23 +02:00
|
|
|
UINT index_size = 2;
|
2007-02-20 22:46:31 +01:00
|
|
|
GLuint vbo;
|
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);
|
|
|
|
|
|
|
|
index_buffer = device->stateBlock->state.index_buffer;
|
2010-09-20 19:41:23 +02:00
|
|
|
if (!index_buffer)
|
|
|
|
{
|
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
|
|
|
}
|
2010-09-20 19:41:23 +02:00
|
|
|
vbo = index_buffer->buffer_object;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (device->stateBlock->state.index_format == WINED3DFMT_R16_UINT)
|
|
|
|
index_size = 2;
|
2010-09-20 19:41:23 +02:00
|
|
|
else
|
2011-05-16 23:01:23 +02:00
|
|
|
index_size = 4;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (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-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_STREAMSRC);
|
2007-01-06 18:19:55 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
drawPrimitive(device, index_count, start_idx, index_size,
|
2010-09-20 19:41:23 +02:00
|
|
|
vbo ? NULL : index_buffer->resource.allocatedMemory);
|
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;
|
|
|
|
device->stateBlock->state.load_base_vertex_index = 0;
|
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
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
drawPrimitive(device, vertex_count, 0, 0, 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;
|
2011-05-16 23:01:23 +02:00
|
|
|
UINT index_size;
|
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
|
|
|
if (index_data_format_id == WINED3DFMT_R16_UINT)
|
|
|
|
index_size = 2;
|
|
|
|
else
|
|
|
|
index_size = 4;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
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;
|
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;
|
|
|
|
device->stateBlock->state.load_base_vertex_index = 0;
|
2007-01-06 18:19:55 +01:00
|
|
|
/* Mark the state dirty until we have nicer tracking of the stream source pointers */
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_VDECL);
|
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2007-01-02 00:35:07 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
drawPrimitive(device, index_count, 0, index_size, 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,
|
|
|
|
UINT vertex_count, const WineDirect3DVertexStridedData *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);
|
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
2011-05-16 23:01:23 +02:00
|
|
|
device->stateBlock->state.base_vertex_index = 0;
|
|
|
|
device->up_strided = strided_data;
|
|
|
|
drawPrimitive(device, vertex_count, 0, 0, NULL);
|
|
|
|
device->up_strided = NULL;
|
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,
|
|
|
|
UINT index_count, const WineDirect3DVertexStridedData *strided_data,
|
|
|
|
UINT vertex_count, const void *index_data, enum wined3d_format_id index_data_format_id)
|
2008-12-01 15:32:15 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
UINT index_size = index_data_format_id == WINED3DFMT_R32_UINT ? 4 : 2;
|
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);
|
|
|
|
device_invalidate_state(device, STATE_INDEXBUFFER);
|
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;
|
|
|
|
drawPrimitive(device, index_count, 0, index_size, index_data);
|
|
|
|
device->up_strided = NULL;
|
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-05-16 23:01:23 +02:00
|
|
|
static HRESULT IWineD3DDeviceImpl_UpdateVolume(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
|
|
|
{
|
2007-09-01 01:54:15 +02:00
|
|
|
WINED3DLOCKED_BOX src;
|
|
|
|
WINED3DLOCKED_BOX dst;
|
|
|
|
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-04-14 22:41:48 +02:00
|
|
|
memcpy(dst.pBits, src.pBits, 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
|
|
|
{
|
|
|
|
unsigned int level_count, i;
|
|
|
|
WINED3DRESOURCETYPE type;
|
|
|
|
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. */
|
2011-06-07 11:06:24 +02:00
|
|
|
type = src_texture->resource.resourceType;
|
|
|
|
if (dst_texture->resource.resourceType != 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)
|
|
|
|
{
|
2006-03-09 23:21:16 +01:00
|
|
|
case WINED3DRTYPE_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))
|
|
|
|
{
|
|
|
|
WARN("IWineD3DDevice_UpdateSurface failed, hr %#x.\n", hr);
|
|
|
|
return hr;
|
2005-11-04 13:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-19 10:12:19 +02:00
|
|
|
}
|
|
|
|
|
2006-03-09 23:21:16 +01:00
|
|
|
case WINED3DRTYPE_CUBETEXTURE:
|
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
|
|
|
{
|
2010-10-25 12:33:39 +02:00
|
|
|
WARN("IWineD3DDevice_UpdateSurface failed, hr %#x.\n", hr);
|
|
|
|
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
|
|
|
|
2006-03-09 23:21:16 +01:00
|
|
|
case WINED3DRTYPE_VOLUMETEXTURE:
|
2009-10-19 10:12:19 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < level_count; ++i)
|
2005-11-04 13:39:17 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = IWineD3DDeviceImpl_UpdateVolume(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))
|
|
|
|
{
|
|
|
|
WARN("IWineD3DDeviceImpl_UpdateVolume failed, hr %#x.\n", hr);
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_front_buffer_data(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_validate_device(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)
|
|
|
|
{
|
2011-03-11 11:49:01 +01:00
|
|
|
if (state->sampler_states[i][WINED3DSAMP_MINFILTER] == WINED3DTEXF_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;
|
|
|
|
}
|
2011-03-11 11:49:01 +01:00
|
|
|
if (state->sampler_states[i][WINED3DSAMP_MAGFILTER] == WINED3DTEXF_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
|
|
|
|
2011-03-11 11:49:01 +01:00
|
|
|
if (state->sampler_states[i][WINED3DSAMP_MAGFILTER] != WINED3DTEXF_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;
|
|
|
|
}
|
2011-03-11 11:49:01 +01:00
|
|
|
if (state->sampler_states[i][WINED3DSAMP_MINFILTER] != WINED3DTEXF_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;
|
|
|
|
}
|
2011-03-11 11:49:01 +01:00
|
|
|
if (state->sampler_states[i][WINED3DSAMP_MIPFILTER] != WINED3DTEXF_NONE
|
|
|
|
&& state->sampler_states[i][WINED3DSAMP_MIPFILTER] != WINED3DTEXF_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-03-11 11:49:01 +01:00
|
|
|
if (state->render_states[WINED3DRS_ZENABLE] || state->render_states[WINED3DRS_ZWRITEENABLE] ||
|
|
|
|
state->render_states[WINED3DRS_STENCILENABLE])
|
|
|
|
{
|
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-27 11:40:57 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static void dirtify_p8_texture_samplers(struct wined3d_device *device)
|
2008-04-02 23:12:16 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
UINT i;
|
2008-04-02 23:12:16 +02:00
|
|
|
|
2009-09-25 13:31:49 +02:00
|
|
|
for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
|
|
|
|
{
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *texture = device->stateBlock->state.textures[i];
|
2010-08-30 20:29:49 +02:00
|
|
|
if (texture && (texture->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM))
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(i));
|
2009-09-25 13:31:49 +02:00
|
|
|
}
|
2008-04-02 23:12:16 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_palette_entries(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT palette_idx, const PALETTEENTRY *entries)
|
2011-04-06 19:17:52 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT i;
|
2008-03-26 23:23:04 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, palette_idx %u, entries %p.\n", device, palette_idx, entries);
|
2008-03-26 23:23:04 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (palette_idx >= MAX_PALETTES)
|
|
|
|
{
|
|
|
|
WARN("Invalid palette index %u.\n", palette_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-08-11 12:57:20 +02:00
|
|
|
}
|
2008-03-26 23:23:04 +01:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (palette_idx >= device->palette_count)
|
2011-04-06 19:17:52 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT new_size = device->palette_count;
|
|
|
|
PALETTEENTRY **palettes;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
new_size *= 2;
|
|
|
|
} while (palette_idx >= new_size);
|
|
|
|
palettes = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, device->palettes, sizeof(*palettes) * new_size);
|
|
|
|
if (!palettes)
|
|
|
|
{
|
2008-03-26 23:23:04 +01:00
|
|
|
ERR("Out of memory!\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
device->palettes = palettes;
|
|
|
|
device->palette_count = new_size;
|
2008-03-26 23:23:04 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
if (!device->palettes[palette_idx])
|
|
|
|
{
|
|
|
|
device->palettes[palette_idx] = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256);
|
|
|
|
if (!device->palettes[palette_idx])
|
|
|
|
{
|
2008-03-26 23:23:04 +01:00
|
|
|
ERR("Out of memory!\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
device->palettes[palette_idx][i].peRed = entries[i].peRed;
|
|
|
|
device->palettes[palette_idx][i].peGreen = entries[i].peGreen;
|
|
|
|
device->palettes[palette_idx][i].peBlue = entries[i].peBlue;
|
|
|
|
device->palettes[palette_idx][i].peFlags = entries[i].peFlags;
|
2005-08-11 12:57:20 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
if (palette_idx == device->currentPalette)
|
|
|
|
dirtify_p8_texture_samplers(device);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-27 11:40:57 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_palette_entries(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT palette_idx, PALETTEENTRY *entries)
|
2011-04-06 19:17:52 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT i;
|
2011-04-06 19:17:52 +02:00
|
|
|
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, palette_idx %u, entries %p.\n", device, palette_idx, entries);
|
|
|
|
|
|
|
|
if (palette_idx >= device->palette_count || !device->palettes[palette_idx])
|
2011-04-06 19:17:52 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
/* What happens in such situation isn't documented; Native seems to
|
|
|
|
* silently abort on such conditions. */
|
|
|
|
WARN("Invalid palette index %u.\n", palette_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-08-11 12:57:20 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
entries[i].peRed = device->palettes[palette_idx][i].peRed;
|
|
|
|
entries[i].peGreen = device->palettes[palette_idx][i].peGreen;
|
|
|
|
entries[i].peBlue = device->palettes[palette_idx][i].peBlue;
|
|
|
|
entries[i].peFlags = device->palettes[palette_idx][i].peFlags;
|
2005-08-11 12:57:20 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_set_current_texture_palette(struct wined3d_device *device, UINT palette_idx)
|
2011-04-06 19:17:52 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
TRACE("device %p, palette_idx %u.\n", device, palette_idx);
|
|
|
|
|
|
|
|
/* Native appears to silently abort on attempt to make an uninitialized
|
|
|
|
* palette current and render. (tested with reference rasterizer). */
|
|
|
|
if (palette_idx >= device->palette_count || !device->palettes[palette_idx])
|
2011-04-06 19:17:52 +02:00
|
|
|
{
|
2011-05-16 23:01:21 +02:00
|
|
|
WARN("Invalid palette index %u.\n", palette_idx);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-08-11 12:57:20 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
/* TODO: stateblocks? */
|
|
|
|
if (device->currentPalette != palette_idx)
|
|
|
|
{
|
|
|
|
device->currentPalette = palette_idx;
|
|
|
|
dirtify_p8_texture_samplers(device);
|
2008-04-02 23:12:16 +02:00
|
|
|
}
|
2011-05-16 23:01:21 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
2005-01-26 21:54:00 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_current_texture_palette(struct wined3d_device *device, UINT *palette_idx)
|
2011-05-16 23:01:21 +02:00
|
|
|
{
|
|
|
|
TRACE("device %p, palette_idx %p.\n", device, palette_idx);
|
|
|
|
|
|
|
|
if (!palette_idx)
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2011-05-16 23:01:21 +02:00
|
|
|
|
|
|
|
*palette_idx = device->currentPalette;
|
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
BOOL CDECL wined3d_device_get_software_vertex_processing(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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_raster_status(struct wined3d_device *device,
|
2009-12-20 20:41:37 +01:00
|
|
|
UINT swapchain_idx, WINED3DRASTER_STATUS *raster_status)
|
|
|
|
{
|
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-05-16 23:01:23 +02:00
|
|
|
float CDECL wined3d_device_get_npatch_mode(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
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *src_format;
|
|
|
|
const struct wined3d_format *dst_format;
|
2010-05-21 09:35:25 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2010-03-30 11:24:47 +02:00
|
|
|
const unsigned char *data;
|
2010-03-31 11:28:56 +02:00
|
|
|
UINT update_w, update_h;
|
2010-03-31 11:28:58 +02:00
|
|
|
CONVERT_TYPES convert;
|
2010-03-31 11:28:56 +02:00
|
|
|
UINT src_w, src_h;
|
|
|
|
UINT dst_x, dst_y;
|
|
|
|
DWORD sampler;
|
2010-08-30 20:29:49 +02:00
|
|
|
struct wined3d_format format;
|
2005-07-12 19:02:47 +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
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
if (src_surface->resource.pool != WINED3DPOOL_SYSTEMMEM || dst_surface->resource.pool != WINED3DPOOL_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-04-29 13:03:42 +02:00
|
|
|
src_format = src_surface->resource.format;
|
|
|
|
dst_format = dst_surface->resource.format;
|
2010-03-30 11:24:48 +02:00
|
|
|
|
2010-08-25 20:46:51 +02:00
|
|
|
if (src_format->id != dst_format->id)
|
2010-03-30 11:24:45 +02:00
|
|
|
{
|
|
|
|
WARN("Source and destination surfaces should have the same format.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2010-03-31 11:28:56 +02:00
|
|
|
dst_x = dst_point ? dst_point->x : 0;
|
|
|
|
dst_y = dst_point ? dst_point->y : 0;
|
|
|
|
|
|
|
|
/* This call loads the OpenGL surface directly, instead of copying the
|
|
|
|
* surface to the destination's sysmem copy. If surface conversion is
|
|
|
|
* needed, use BltFast instead to copy in sysmem and use regular surface
|
|
|
|
* loading. */
|
2011-04-29 13:03:42 +02:00
|
|
|
d3dfmt_get_conv(dst_surface, FALSE, TRUE, &format, &convert);
|
2010-08-30 20:29:49 +02:00
|
|
|
if (convert != NO_CONVERSION || format.convert)
|
2011-04-29 13:03:41 +02:00
|
|
|
return wined3d_surface_bltfast(dst_surface, dst_x, dst_y, src_surface, src_rect, 0);
|
2007-08-11 20:02:01 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-05-21 09:35:25 +02:00
|
|
|
gl_info = context->gl_info;
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2008-12-16 13:18:49 +01:00
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
|
|
|
|
checkGLcall("glActiveTextureARB");
|
|
|
|
LEAVE_GL();
|
2007-02-20 22:44:45 +01:00
|
|
|
|
2005-11-23 20:14:43 +01:00
|
|
|
/* Make sure the surface is loaded and up to date */
|
2011-04-29 13:03:42 +02:00
|
|
|
surface_internal_preload(dst_surface, SRGB_RGB);
|
|
|
|
surface_bind(dst_surface, gl_info, FALSE);
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
src_w = src_surface->resource.width;
|
|
|
|
src_h = src_surface->resource.height;
|
2010-03-31 11:28:56 +02:00
|
|
|
update_w = src_rect ? src_rect->right - src_rect->left : src_w;
|
|
|
|
update_h = src_rect ? src_rect->bottom - src_rect->top : src_h;
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
data = src_surface->resource.allocatedMemory;
|
2010-03-30 11:24:47 +02:00
|
|
|
if (!data) ERR("Source surface has no allocated memory, but should be a sysmem surface.\n");
|
2005-11-04 12:13:45 +01:00
|
|
|
|
2008-10-19 02:05:10 +02:00
|
|
|
ENTER_GL();
|
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (dst_format->flags & WINED3DFMT_FLAG_COMPRESSED)
|
2010-03-25 22:51:26 +01:00
|
|
|
{
|
2010-08-15 23:21:48 +02:00
|
|
|
UINT row_length = wined3d_format_calculate_size(src_format, 1, update_w, 1);
|
|
|
|
UINT row_count = (update_h + src_format->block_height - 1) / src_format->block_height;
|
|
|
|
UINT src_pitch = wined3d_format_calculate_size(src_format, 1, src_w, 1);
|
2010-03-30 11:24:44 +02:00
|
|
|
|
2010-03-31 11:28:56 +02:00
|
|
|
if (src_rect)
|
2010-03-25 22:51:26 +01:00
|
|
|
{
|
2010-03-31 11:28:56 +02:00
|
|
|
data += (src_rect->top / src_format->block_height) * src_pitch;
|
|
|
|
data += (src_rect->left / src_format->block_width) * src_format->block_byte_count;
|
2010-03-30 11:24:46 +02:00
|
|
|
}
|
|
|
|
|
2010-03-30 11:24:47 +02:00
|
|
|
TRACE("glCompressedTexSubImage2DARB, target %#x, level %d, x %d, y %d, w %d, h %d, "
|
2011-04-29 13:03:42 +02:00
|
|
|
"format %#x, image_size %#x, data %p.\n", dst_surface->texture_target, dst_surface->texture_level,
|
2010-03-31 11:28:56 +02:00
|
|
|
dst_x, dst_y, update_w, update_h, dst_format->glFormat, row_count * row_length, data);
|
2010-03-30 11:24:47 +02:00
|
|
|
|
2010-03-30 11:24:46 +02:00
|
|
|
if (row_length == src_pitch)
|
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
GL_EXTCALL(glCompressedTexSubImage2DARB(dst_surface->texture_target, dst_surface->texture_level,
|
2010-03-31 11:28:56 +02:00
|
|
|
dst_x, dst_y, update_w, update_h, dst_format->glInternal, row_count * row_length, data));
|
2010-03-30 11:24:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT row, y;
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2010-03-30 11:24:46 +02:00
|
|
|
/* glCompressedTexSubImage2DARB() ignores pixel store state, so we
|
|
|
|
* can't use the unpack row length like below. */
|
2010-03-31 11:28:56 +02:00
|
|
|
for (row = 0, y = dst_y; row < row_count; ++row)
|
2010-03-25 22:51:26 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
GL_EXTCALL(glCompressedTexSubImage2DARB(dst_surface->texture_target, dst_surface->texture_level,
|
2010-03-31 11:28:56 +02:00
|
|
|
dst_x, y, update_w, src_format->block_height, dst_format->glInternal, row_length, data));
|
2010-03-30 11:24:48 +02:00
|
|
|
y += src_format->block_height;
|
2010-03-25 22:51:26 +01:00
|
|
|
data += src_pitch;
|
|
|
|
}
|
2005-07-12 19:02:47 +02:00
|
|
|
}
|
2010-03-30 11:24:44 +02:00
|
|
|
checkGLcall("glCompressedTexSubImage2DARB");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-31 11:28:56 +02:00
|
|
|
if (src_rect)
|
2010-03-30 11:24:47 +02:00
|
|
|
{
|
2010-03-31 11:28:56 +02:00
|
|
|
data += src_rect->top * src_w * src_format->byte_count;
|
|
|
|
data += src_rect->left * src_format->byte_count;
|
2010-03-30 11:24:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("glTexSubImage2D, target %#x, level %d, x %d, y %d, w %d, h %d, format %#x, type %#x, data %p.\n",
|
2011-04-29 13:03:42 +02:00
|
|
|
dst_surface->texture_target, dst_surface->texture_level, dst_x, dst_y,
|
2010-03-31 11:28:56 +02:00
|
|
|
update_w, update_h, dst_format->glFormat, dst_format->glType, data);
|
2010-03-30 11:24:44 +02:00
|
|
|
|
2010-03-31 11:28:56 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, src_w);
|
2011-04-29 13:03:42 +02:00
|
|
|
glTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level, dst_x, dst_y,
|
2010-03-31 11:28:56 +02:00
|
|
|
update_w, update_h, dst_format->glFormat, dst_format->glType, data);
|
2010-03-30 11:24:44 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
checkGLcall("glTexSubImage2D");
|
|
|
|
}
|
2005-07-12 19:02:47 +02:00
|
|
|
|
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2005-07-12 19:02:47 +02:00
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
surface_modify_location(dst_surface, SFLAG_INTEXTURE, TRUE);
|
2011-05-16 23:01:23 +02:00
|
|
|
sampler = device->rev_tex_unit_map[0];
|
2009-08-17 09:39:07 +02:00
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(sampler));
|
2007-02-20 22:44:45 +01:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
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,
|
|
|
|
const float *num_segs, const WINED3DRECTPATCH_INFO *rect_patch_info)
|
2011-05-16 23:01:22 +02:00
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
struct WineD3DRectPatch *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])
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
patch = LIST_ENTRY(e, struct WineD3DRectPatch, 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]
|
|
|
|
|| (rect_patch_info && memcmp(rect_patch_info, &patch->RectPatchInfo, 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)
|
|
|
|
patch->RectPatchInfo = *rect_patch_info;
|
|
|
|
|
|
|
|
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
|
|
|
device->currentPatch = patch;
|
|
|
|
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;
|
|
|
|
device->currentPatch = NULL;
|
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-05-16 23:01:22 +02:00
|
|
|
const float *segment_count, const WINED3DTRIPATCH_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
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
struct WineD3DRectPatch *patch;
|
|
|
|
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])
|
|
|
|
{
|
2007-07-04 17:57:45 +02:00
|
|
|
patch = LIST_ENTRY(e, struct WineD3DRectPatch, 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-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface, const RECT *rect, const WINED3DCOLORVALUE *color)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
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
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
if (surface->resource.pool != WINED3DPOOL_DEFAULT && surface->resource.pool != WINED3DPOOL_SYSTEMMEM)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
2006-05-18 22:59:33 +02:00
|
|
|
FIXME("call to colorfill with non WINED3DPOOL_DEFAULT or WINED3DPOOL_SYSTEMMEM surface\n");
|
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-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-04-05 19:01:32 +02:00
|
|
|
struct wined3d_rendertarget_view *rendertarget_view, const WINED3DCOLORVALUE *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-04-05 19:01:32 +02:00
|
|
|
resource = rendertarget_view->resource;
|
2011-03-01 09:47:56 +01:00
|
|
|
if (resource->resourceType != WINED3DRTYPE_SURFACE)
|
2009-02-25 08:39:01 +01:00
|
|
|
{
|
|
|
|
FIXME("Only supported on surface resources\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
hr = surface_color_fill(surface_from_resource(resource), NULL, 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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_render_target(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];
|
2011-04-29 13:03:41 +02:00
|
|
|
if (*render_target)
|
|
|
|
wined3d_surface_incref(*render_target);
|
2010-08-04 11:10:24 +02:00
|
|
|
|
|
|
|
TRACE("Returning render target %p.\n", *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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_depth_stencil(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-05-18 22:30:15 +02: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;
|
2010-09-15 12:00:06 +02:00
|
|
|
device->stateBlock->state.viewport.X = 0;
|
|
|
|
device->stateBlock->state.viewport.Y = 0;
|
|
|
|
device->stateBlock->state.viewport.MaxZ = 1.0f;
|
|
|
|
device->stateBlock->state.viewport.MinZ = 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;
|
2010-09-15 12:00:06 +02: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
|
|
|
|
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-05-16 23:01:21 +02:00
|
|
|
if (device->swapchains[0]->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|
2011-05-18 22:30:15 +02:00
|
|
|
|| prev->flags & SFLAG_DISCARD)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
2011-05-18 22:30:15 +02:00
|
|
|
surface_modify_ds_location(prev, SFLAG_DS_DISCARDED,
|
|
|
|
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);
|
|
|
|
if (prev)
|
|
|
|
wined3d_surface_decref(prev);
|
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-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_ZENABLE));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_STENCILENABLE));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_STENCILWRITEMASK));
|
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_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-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_RENDER(WINED3DRS_DEPTHBIAS));
|
2005-07-07 22:35:05 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-05-15 00:37:53 +02:00
|
|
|
WINED3DLOCKED_RECT lockedRect;
|
2005-03-02 13:16:10 +01: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)
|
|
|
|
{
|
2007-03-13 03:44:22 +01:00
|
|
|
WINED3DLOCKED_RECT rect;
|
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
if (cursor_image->resource.width > device->ddraw_width
|
|
|
|
|| cursor_image->resource.height > device->ddraw_height)
|
2010-08-15 23:21:43 +02:00
|
|
|
{
|
|
|
|
WARN("Surface %p dimensions are %ux%u, but screen dimensions are %ux%u.\n",
|
2011-04-29 13:03:42 +02:00
|
|
|
cursor_image, cursor_image->resource.width, cursor_image->resource.height,
|
2011-05-16 23:01:23 +02:00
|
|
|
device->ddraw_width, device->ddraw_height);
|
2006-07-23 00:03:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-05-16 20:18:33 +02:00
|
|
|
/* TODO: MSDN: Cursor sizes must be a power of 2 */
|
|
|
|
|
|
|
|
/* Do not store the surface's pointer because the application may
|
|
|
|
* release it after setting the cursor image. Windows doesn't
|
|
|
|
* addref the set surface, so we can't do this either without
|
|
|
|
* creating circular refcount dependencies. Copy out the gl texture
|
|
|
|
* instead. */
|
|
|
|
device->cursorWidth = cursor_image->resource.width;
|
|
|
|
device->cursorHeight = cursor_image->resource.height;
|
|
|
|
if (SUCCEEDED(wined3d_surface_map(cursor_image, &rect, 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;
|
|
|
|
char *mem, *bits = rect.pBits;
|
|
|
|
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;
|
|
|
|
DWORD sampler;
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
/* Reformat the texture memory (pitch and width can be
|
|
|
|
* different) */
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, width * height * bpp);
|
|
|
|
for(i = 0; i < height; i++)
|
|
|
|
memcpy(&mem[width * bpp * i], &bits[rect.Pitch * i], width * bpp);
|
|
|
|
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-05-16 20:18:33 +02:00
|
|
|
/* Make sure that a proper texture unit is selected */
|
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
|
|
|
|
checkGLcall("glActiveTextureARB");
|
|
|
|
sampler = device->rev_tex_unit_map[0];
|
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(device, STATE_SAMPLER(sampler));
|
2011-05-16 20:18:33 +02:00
|
|
|
/* Create a new cursor texture */
|
|
|
|
glGenTextures(1, &device->cursorTexture);
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
glBindTexture(GL_TEXTURE_2D, device->cursorTexture);
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
/* 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
|
|
|
{
|
2007-05-15 00:37:53 +02:00
|
|
|
/* Draw a hardware cursor */
|
|
|
|
ICONINFO cursorInfo;
|
|
|
|
HCURSOR cursor;
|
|
|
|
/* Create and clear maskBits because it is not needed for
|
|
|
|
* 32-bit cursors. 32x32 bits split into 32-bit chunks == 32
|
|
|
|
* chunks. */
|
|
|
|
DWORD *maskBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2011-04-29 13:03:42 +02:00
|
|
|
(cursor_image->resource.width * cursor_image->resource.height / 8));
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_map(cursor_image, &lockedRect, 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,
|
|
|
|
1, 32, lockedRect.pBits);
|
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
|
|
|
|
|
|
|
/* switch to the software cursor if position diverges from the hardware one */
|
|
|
|
if (device->hardwareCursor)
|
|
|
|
{
|
|
|
|
POINT pt;
|
|
|
|
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-03-01 09:47:56 +01:00
|
|
|
static HRESULT WINAPI evict_managed_resource(struct wined3d_resource *resource, void *data)
|
|
|
|
{
|
2009-06-10 08:06:06 +02:00
|
|
|
TRACE("checking resource %p for eviction\n", resource);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
|
|
|
if (resource->pool == WINED3DPOOL_MANAGED)
|
|
|
|
{
|
|
|
|
TRACE("Evicting %p.\n", resource);
|
|
|
|
resource->resource_ops->resource_unload(resource);
|
2009-06-10 08:06:06 +02:00
|
|
|
}
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2009-06-10 08:06:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2005-03-02 13:16:10 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device)
|
2009-12-21 23:17:26 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p.\n", device);
|
2009-06-10 08:06:06 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
wined3d_device_enum_resources(device, evict_managed_resource, NULL);
|
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);
|
2010-07-08 12:20:57 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-02 13:16:10 +01:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:42 +02:00
|
|
|
static HRESULT updateSurfaceDesc(struct wined3d_surface *surface,
|
|
|
|
const WINED3DPRESENT_PARAMETERS *pPresentationParameters)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = surface->resource.device;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2007-02-13 20:21:48 +01:00
|
|
|
|
2006-12-08 16:13:15 +01:00
|
|
|
/* Reallocate proper memory for the front and back buffer and adjust their sizes */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (surface->flags & SFLAG_DIBSECTION)
|
|
|
|
{
|
2006-12-08 16:13:15 +01:00
|
|
|
/* Release the DC */
|
|
|
|
SelectObject(surface->hDC, surface->dib.holdbitmap);
|
|
|
|
DeleteDC(surface->hDC);
|
|
|
|
/* Release the DIB section */
|
|
|
|
DeleteObject(surface->dib.DIBsection);
|
|
|
|
surface->dib.bitmap_data = NULL;
|
|
|
|
surface->resource.allocatedMemory = NULL;
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~SFLAG_DIBSECTION;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2011-03-08 19:41:07 +01:00
|
|
|
surface->resource.width = pPresentationParameters->BackBufferWidth;
|
|
|
|
surface->resource.height = pPresentationParameters->BackBufferHeight;
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[ARB_TEXTURE_RECTANGLE]
|
2010-07-20 18:51:54 +02:00
|
|
|
|| gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2007-02-15 22:36:50 +01:00
|
|
|
surface->pow2Width = pPresentationParameters->BackBufferWidth;
|
|
|
|
surface->pow2Height = pPresentationParameters->BackBufferHeight;
|
2006-12-08 16:13:15 +01:00
|
|
|
} else {
|
|
|
|
surface->pow2Width = surface->pow2Height = 1;
|
2007-02-15 22:36:50 +01:00
|
|
|
while (surface->pow2Width < pPresentationParameters->BackBufferWidth) surface->pow2Width <<= 1;
|
|
|
|
while (surface->pow2Height < pPresentationParameters->BackBufferHeight) surface->pow2Height <<= 1;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2008-01-27 21:26:07 +01:00
|
|
|
|
2009-07-10 10:20:13 +02:00
|
|
|
if (surface->texture_name)
|
|
|
|
{
|
2010-05-03 22:03:28 +02:00
|
|
|
struct wined3d_context *context = context_acquire(device, NULL);
|
2007-08-06 16:27:08 +02:00
|
|
|
ENTER_GL();
|
2009-07-10 10:20:13 +02:00
|
|
|
glDeleteTextures(1, &surface->texture_name);
|
2006-12-08 16:13:15 +01:00
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2009-07-10 10:20:13 +02:00
|
|
|
surface->texture_name = 0;
|
2010-11-12 13:12:04 +01:00
|
|
|
surface->flags &= ~SFLAG_CLIENT;
|
|
|
|
}
|
|
|
|
if (surface->pow2Width != pPresentationParameters->BackBufferWidth
|
|
|
|
|| surface->pow2Height != pPresentationParameters->BackBufferHeight)
|
|
|
|
{
|
|
|
|
surface->flags |= SFLAG_NONPOW2;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
surface->flags &= ~SFLAG_NONPOW2;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
2008-03-23 16:14:05 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, surface->resource.heapMemory);
|
|
|
|
surface->resource.allocatedMemory = NULL;
|
|
|
|
surface->resource.heapMemory = NULL;
|
2011-04-29 13:03:41 +02:00
|
|
|
surface->resource.size = wined3d_surface_get_pitch(surface) * surface->pow2Width;
|
2009-12-04 13:07:18 +01:00
|
|
|
|
|
|
|
/* Put all surfaces into sysmem - the drawable might disappear if the backbuffer was rendered
|
|
|
|
* to a FBO */
|
2010-04-28 00:08:48 +02:00
|
|
|
if (!surface_init_sysmem(surface))
|
2009-12-04 13:07:18 +01:00
|
|
|
{
|
|
|
|
return E_OUTOFMEMORY;
|
2008-06-02 21:12:54 +02:00
|
|
|
}
|
2009-12-04 13:07:18 +01:00
|
|
|
return WINED3D_OK;
|
2006-12-08 16:13:15 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static BOOL is_display_mode_supported(struct wined3d_device *device, const WINED3DPRESENT_PARAMETERS *pp)
|
2008-11-26 16:14:39 +01:00
|
|
|
{
|
2008-02-06 20:16:13 +01:00
|
|
|
UINT i, count;
|
|
|
|
WINED3DDISPLAYMODE m;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* All Windowed modes are supported, as is leaving the current mode */
|
|
|
|
if(pp->Windowed) return TRUE;
|
|
|
|
if(!pp->BackBufferWidth) return TRUE;
|
|
|
|
if(!pp->BackBufferHeight) return TRUE;
|
|
|
|
|
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");
|
|
|
|
if (m.Width == pp->BackBufferWidth && m.Height == pp->BackBufferHeight)
|
|
|
|
/* 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
|
|
|
{
|
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-05-16 23:01:22 +02:00
|
|
|
wined3d_device_enum_resources(device, device_unload_resource, NULL);
|
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-01-04 17:42:01 +01:00
|
|
|
if (device->depth_blt_rb)
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &device->depth_blt_rb);
|
|
|
|
device->depth_blt_rb = 0;
|
|
|
|
device->depth_blt_rb_w = 0;
|
|
|
|
device->depth_blt_rb_h = 0;
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
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-01-04 17:42:01 +01:00
|
|
|
context_destroy(device, device->contexts[0]);
|
2008-07-29 19:09:34 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
swapchain->context = NULL;
|
|
|
|
swapchain->num_contexts = 0;
|
|
|
|
}
|
|
|
|
|
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-01-04 17:42:02 +01:00
|
|
|
create_dummy_textures(device);
|
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,
|
|
|
|
WINED3DPRESENT_PARAMETERS *present_parameters)
|
2010-09-02 19:25:00 +02:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain;
|
2006-12-08 16:13:15 +01:00
|
|
|
BOOL DisplayModeChanged = FALSE;
|
|
|
|
WINED3DDISPLAYMODE mode;
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT hr;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, present_parameters %p.\n", device, present_parameters);
|
|
|
|
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
if (!is_display_mode_supported(device, present_parameters))
|
|
|
|
{
|
2008-02-06 20:16:13 +01:00
|
|
|
WARN("Rejecting Reset() call because the requested display mode is not supported\n");
|
2011-05-16 23:01:23 +02:00
|
|
|
WARN("Requested mode: %d, %d.\n",
|
|
|
|
present_parameters->BackBufferWidth,
|
|
|
|
present_parameters->BackBufferHeight);
|
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-05-16 23:01:23 +02:00
|
|
|
TRACE("BackBufferWidth = %d\n", present_parameters->BackBufferWidth);
|
|
|
|
TRACE("BackBufferHeight = %d\n", present_parameters->BackBufferHeight);
|
|
|
|
TRACE("BackBufferFormat = %s\n", debug_d3dformat(present_parameters->BackBufferFormat));
|
|
|
|
TRACE("BackBufferCount = %d\n", present_parameters->BackBufferCount);
|
|
|
|
TRACE("MultiSampleType = %d\n", present_parameters->MultiSampleType);
|
|
|
|
TRACE("MultiSampleQuality = %d\n", present_parameters->MultiSampleQuality);
|
|
|
|
TRACE("SwapEffect = %d\n", present_parameters->SwapEffect);
|
|
|
|
TRACE("hDeviceWindow = %p\n", present_parameters->hDeviceWindow);
|
|
|
|
TRACE("Windowed = %s\n", present_parameters->Windowed ? "true" : "false");
|
|
|
|
TRACE("EnableAutoDepthStencil = %s\n", present_parameters->EnableAutoDepthStencil ? "true" : "false");
|
|
|
|
TRACE("Flags = %08x\n", present_parameters->Flags);
|
|
|
|
TRACE("FullScreen_RefreshRateInHz = %d\n", present_parameters->FullScreen_RefreshRateInHz);
|
|
|
|
TRACE("PresentationInterval = %d\n", present_parameters->PresentationInterval);
|
2006-12-08 16:13:15 +01:00
|
|
|
|
|
|
|
/* No special treatment of these parameters. Just store them */
|
2011-05-16 23:01:23 +02:00
|
|
|
swapchain->presentParms.SwapEffect = present_parameters->SwapEffect;
|
|
|
|
swapchain->presentParms.Flags = present_parameters->Flags;
|
|
|
|
swapchain->presentParms.PresentationInterval = present_parameters->PresentationInterval;
|
|
|
|
swapchain->presentParms.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
|
|
|
/* What to do about these? */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->BackBufferCount
|
|
|
|
&& present_parameters->BackBufferCount != swapchain->presentParms.BackBufferCount)
|
|
|
|
FIXME("Cannot change the back buffer count yet.\n");
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->BackBufferFormat != WINED3DFMT_UNKNOWN
|
|
|
|
&& present_parameters->BackBufferFormat != swapchain->presentParms.BackBufferFormat)
|
|
|
|
FIXME("Cannot change the back buffer format yet.\n");
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->hDeviceWindow
|
|
|
|
&& present_parameters->hDeviceWindow != swapchain->presentParms.hDeviceWindow)
|
|
|
|
FIXME("Cannot change the device window yet.\n");
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->EnableAutoDepthStencil && !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-05-16 23:01:23 +02:00
|
|
|
present_parameters->BackBufferWidth,
|
|
|
|
present_parameters->BackBufferHeight,
|
|
|
|
present_parameters->AutoDepthStencilFormat,
|
|
|
|
present_parameters->MultiSampleType,
|
|
|
|
present_parameters->MultiSampleQuality,
|
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-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->EnableAutoDepthStencil)
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
delete_opengl_contexts(device, swapchain);
|
2008-02-05 00:05:26 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->Windowed)
|
|
|
|
{
|
2006-12-08 16:13:15 +01:00
|
|
|
mode.Width = swapchain->orig_width;
|
|
|
|
mode.Height = swapchain->orig_height;
|
|
|
|
mode.RefreshRate = 0;
|
|
|
|
mode.Format = swapchain->presentParms.BackBufferFormat;
|
2011-05-16 23:01:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mode.Width = present_parameters->BackBufferWidth;
|
|
|
|
mode.Height = present_parameters->BackBufferHeight;
|
|
|
|
mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz;
|
2006-12-08 16:13:15 +01:00
|
|
|
mode.Format = swapchain->presentParms.BackBufferFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Should Width == 800 && Height == 0 set 800x600? */
|
2011-05-16 23:01:23 +02:00
|
|
|
if (present_parameters->BackBufferWidth && present_parameters->BackBufferHeight
|
|
|
|
&& (present_parameters->BackBufferWidth != swapchain->presentParms.BackBufferWidth
|
|
|
|
|| present_parameters->BackBufferHeight != swapchain->presentParms.BackBufferHeight))
|
2006-12-08 16:13:15 +01:00
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
UINT i;
|
2006-12-08 16:13:15 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
if (!present_parameters->Windowed)
|
2006-12-08 16:13:15 +01:00
|
|
|
DisplayModeChanged = TRUE;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
swapchain->presentParms.BackBufferWidth = present_parameters->BackBufferWidth;
|
|
|
|
swapchain->presentParms.BackBufferHeight = present_parameters->BackBufferHeight;
|
|
|
|
|
|
|
|
hr = updateSurfaceDesc(swapchain->front_buffer, present_parameters);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = updateSurfaceDesc(swapchain->back_buffers[i], present_parameters);
|
|
|
|
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
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = updateSurfaceDesc(device->auto_depth_stencil, present_parameters);
|
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
if (!present_parameters->Windowed != !swapchain->presentParms.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-05-16 23:01:23 +02:00
|
|
|
if (!present_parameters->Windowed)
|
2010-03-15 21:07:28 +01:00
|
|
|
{
|
2010-10-06 12:01:29 +02:00
|
|
|
if (swapchain->presentParms.Windowed)
|
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
HWND focus_window = device->createParms.hFocusWindow;
|
2011-05-16 23:01:22 +02:00
|
|
|
if (!focus_window)
|
2011-05-16 23:01:23 +02:00
|
|
|
focus_window = present_parameters->hDeviceWindow;
|
|
|
|
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,
|
|
|
|
present_parameters->BackBufferWidth,
|
|
|
|
present_parameters->BackBufferHeight);
|
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-05-16 23:01:23 +02:00
|
|
|
present_parameters->BackBufferWidth, present_parameters->BackBufferHeight,
|
2008-08-04 21:16:49 +02:00
|
|
|
TRUE);
|
2008-08-04 21:11:22 +02:00
|
|
|
}
|
2010-03-15 21:07:28 +01:00
|
|
|
}
|
|
|
|
else if (!swapchain->presentParms.Windowed)
|
|
|
|
{
|
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-05-16 23:01:23 +02:00
|
|
|
swapchain->presentParms.Windowed = present_parameters->Windowed;
|
2010-10-06 12:01:29 +02:00
|
|
|
}
|
2011-05-16 23:01:23 +02:00
|
|
|
else if (!present_parameters->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,
|
|
|
|
present_parameters->BackBufferWidth,
|
|
|
|
present_parameters->BackBufferHeight);
|
|
|
|
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 */
|
2011-05-16 23:01:23 +02:00
|
|
|
hr = wined3d_stateblock_create(device, WINED3DSBT_INIT, &device->stateBlock);
|
|
|
|
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
|
|
|
|
2009-12-06 18:08:39 +01:00
|
|
|
if(wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
|
|
|
RECT client_rect;
|
|
|
|
GetClientRect(swapchain->win_handle, &client_rect);
|
|
|
|
|
2009-12-15 20:16:19 +01:00
|
|
|
if(!swapchain->presentParms.BackBufferCount)
|
|
|
|
{
|
|
|
|
TRACE("Single buffered rendering\n");
|
|
|
|
swapchain->render_to_fbo = FALSE;
|
|
|
|
}
|
|
|
|
else if(swapchain->presentParms.BackBufferWidth != client_rect.right ||
|
|
|
|
swapchain->presentParms.BackBufferHeight != client_rect.bottom )
|
2009-12-06 18:08:39 +01:00
|
|
|
{
|
|
|
|
TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u\n",
|
|
|
|
swapchain->presentParms.BackBufferWidth,
|
|
|
|
swapchain->presentParms.BackBufferHeight,
|
|
|
|
client_rect.right, client_rect.bottom);
|
|
|
|
swapchain->render_to_fbo = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Rendering directly to GL_BACK\n");
|
|
|
|
swapchain->render_to_fbo = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_creation_parameters(struct wined3d_device *device,
|
|
|
|
WINED3DDEVICE_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-05-16 23:01:23 +02:00
|
|
|
*parameters = device->createParms;
|
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_gamma_ramp(struct wined3d_device *device,
|
2011-05-16 23:01:21 +02:00
|
|
|
UINT swapchain_idx, DWORD flags, const WINED3DGAMMARAMP *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-05-16 23:01:23 +02:00
|
|
|
void CDECL wined3d_device_get_gamma_ramp(struct wined3d_device *device, UINT swapchain_idx, WINED3DGAMMARAMP *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
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
WINED3DRESOURCETYPE type = resource->resourceType;
|
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)
|
|
|
|
{
|
|
|
|
case WINED3DRTYPE_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
|
|
|
|
2006-03-09 23:21:16 +01:00
|
|
|
case WINED3DRTYPE_TEXTURE:
|
|
|
|
case WINED3DRTYPE_CUBETEXTURE:
|
|
|
|
case WINED3DRTYPE_VOLUMETEXTURE:
|
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;
|
|
|
|
|
2009-04-06 16:44:00 +02:00
|
|
|
case WINED3DRTYPE_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-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_enum_resources(struct wined3d_device *device,
|
2011-03-01 09:47:56 +01:00
|
|
|
D3DCB_ENUMRESOURCES callback, void *data)
|
|
|
|
{
|
|
|
|
struct wined3d_resource *resource, *cursor;
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
TRACE("device %p, callback %p, data %p.\n", device, callback, data);
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
|
2011-03-01 09:47:56 +01:00
|
|
|
{
|
|
|
|
TRACE("enumerating resource %p.\n", resource);
|
|
|
|
if (callback(resource, data) == S_FALSE)
|
|
|
|
{
|
|
|
|
TRACE("Canceling enumeration.\n");
|
2008-01-11 15:38:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-01 09:47:56 +01:00
|
|
|
|
2008-01-11 15:38:54 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_device_get_surface_from_dc(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);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
|
2010-03-16 19:02:21 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
if (resource->resourceType == WINED3DRTYPE_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,
|
2009-11-18 10:45:53 +01:00
|
|
|
UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags,
|
2011-05-18 22:30:13 +02:00
|
|
|
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;
|
|
|
|
struct shader_caps shader_caps;
|
|
|
|
struct fragment_caps ffp_caps;
|
|
|
|
WINED3DDISPLAYMODE mode;
|
|
|
|
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);
|
|
|
|
|
|
|
|
device->surface_alignment = wined3d->dxVersion == 7 ? DDRAW_PITCH_ALIGNMENT : D3D8_PITCH_ALIGNMENT;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
device->ddraw_width = mode.Width;
|
|
|
|
device->ddraw_height = mode.Height;
|
|
|
|
device->ddraw_format = mode.Format;
|
|
|
|
|
|
|
|
/* Save the creation parameters. */
|
|
|
|
device->createParms.AdapterOrdinal = adapter_idx;
|
|
|
|
device->createParms.DeviceType = device_type;
|
|
|
|
device->createParms.hFocusWindow = focus_window;
|
|
|
|
device->createParms.BehaviorFlags = flags;
|
|
|
|
|
|
|
|
device->devType = device_type;
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-05 22:48:51 +02:00
|
|
|
void device_invalidate_state(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
|
|
|
|
2009-08-03 08:06:51 +02:00
|
|
|
void get_drawable_size_fbo(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
|
|
|
}
|
|
|
|
|
2009-08-03 08:06:51 +02:00
|
|
|
void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height)
|
2009-07-24 10:44:15 +02:00
|
|
|
{
|
2011-04-13 19:14:32 +02:00
|
|
|
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. */
|
|
|
|
*width = swapchain->presentParms.BackBufferWidth;
|
|
|
|
*height = swapchain->presentParms.BackBufferHeight;
|
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
|
|
|
|
|
|
|
if (device->focus_window == window) device->focus_window = NULL;
|
|
|
|
else ERR("Window %p is not the focus window for device %p.\n", window, device);
|
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
|
|
|
}
|