058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002 Lionel Ulmer
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2005 Jason Edmeades
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2003-2004 Raphael Junqueira
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2004 Christian Costa
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2005 Oliver Stieber
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2006-2008 Henri Verbeet
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2007 Andrew Riedi
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2009-2011 Henri Verbeet for CodeWeavers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is free software; you can redistribute it and/or
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * modify it under the terms of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License as published by the Free Software Foundation; either
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * version 2.1 of the License, or (at your option) any later version.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is distributed in the hope that it will be useful,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Lesser General Public License for more details.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * You should have received a copy of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License along with this library; if not, write to the Free Software
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync/*
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * a choice of LGPL license versions is made available with the language indicating
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * of the LGPL is applied is otherwise unspecified.
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync */
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "config.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "wine/port.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include <stdio.h>
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef HAVE_FLOAT_H
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync# include <float.h>
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "wined3d_private.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncWINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Define the default light parameters as specified by MSDN. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncconst struct wined3d_light WINED3D_default_light =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_LIGHT_DIRECTIONAL, /* Type */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync { 1.0f, 1.0f, 1.0f, 0.0f }, /* Diffuse r,g,b,a */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync { 0.0f, 0.0f, 0.0f, 0.0f }, /* Specular r,g,b,a */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync { 0.0f, 0.0f, 0.0f, 0.0f }, /* Ambient r,g,b,a, */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync { 0.0f, 0.0f, 0.0f }, /* Position x,y,z */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync { 0.0f, 0.0f, 1.0f }, /* Direction x,y,z */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 0.0f, /* Range */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 0.0f, /* Falloff */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 0.0f, 0.0f, 0.0f, /* Attenuation 0,1,2 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 0.0f, /* Theta */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 0.0f /* Phi */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Note that except for WINED3DPT_POINTLIST and WINED3DPT_LINELIST these
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * actually have the same values in GL and D3D. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncGLenum gl_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch(primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_POINTLIST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_POINTS;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINELIST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_LINES;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINESTRIP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_LINE_STRIP;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLELIST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_TRIANGLES;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLESTRIP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_TRIANGLE_STRIP;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLEFAN:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_TRIANGLE_FAN;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINELIST_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_LINES_ADJACENCY_ARB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINESTRIP_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_LINE_STRIP_ADJACENCY_ARB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLELIST_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_TRIANGLES_ADJACENCY_ARB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLESTRIP_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_TRIANGLE_STRIP_ADJACENCY_ARB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return GL_NONE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch(primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_POINTS:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_POINTLIST;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_LINES:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_LINELIST;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_LINE_STRIP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_LINESTRIP;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TRIANGLES:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_TRIANGLELIST;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TRIANGLE_STRIP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_TRIANGLESTRIP;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TRIANGLE_FAN:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_TRIANGLEFAN;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_LINES_ADJACENCY_ARB:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_LINELIST_ADJ;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_LINE_STRIP_ADJACENCY_ARB:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_LINESTRIP_ADJ;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TRIANGLES_ADJACENCY_ARB:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_TRIANGLELIST_ADJ;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TRIANGLE_STRIP_ADJACENCY_ARB:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_TRIANGLESTRIP_ADJ;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_PT_UNDEFINED;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL fixed_get_input(BYTE usage, BYTE usage_idx, unsigned int *regnum)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((usage == WINED3D_DECL_USAGE_POSITION || usage == WINED3D_DECL_USAGE_POSITIONT) && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_POSITION;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_BLEND_WEIGHT && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_BLENDWEIGHT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_BLEND_INDICES && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_BLENDINDICES;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_NORMAL && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_NORMAL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_PSIZE && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_PSIZE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_COLOR && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_DIFFUSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_COLOR && usage_idx == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_SPECULAR;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_TEXCOORD && usage_idx < WINED3DDP_MAXTEXCOORD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = WINED3D_FFP_TEXCOORD0 + usage_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unsupported input stream [usage=%s, usage_idx=%u]\n", debug_d3ddeclusage(usage), usage_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = ~0U;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_stream_info_from_declaration(struct wined3d_device *device, struct wined3d_stream_info *stream_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We need to deal with frequency data! */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_vertex_declaration *declaration = state->vertex_declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL use_vshader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WORD map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->use_map = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->swizzle_map = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->all_vbo = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Check for transformed vertices, disable vertex shader if present. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->position_transformed = declaration->position_transformed;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync use_vshader = state->vertex_shader && !declaration->position_transformed;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Translate the declaration into strided data. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < declaration->element_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_vertex_declaration_element *element = &declaration->elements[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_state *stream = &state->streams[element->input_slot];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer = stream->buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_bo_address data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL stride_used;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p Element %p (%u of %u)\n", declaration->elements,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element, i + 1, declaration->element_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stride = stream->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Stream %u, buffer %p.\n", element->input_slot, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_get_memory(buffer, &device->adapter->gl_info, &data);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We can't use VBOs if the base vertex index is negative. OpenGL
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * doesn't accept negative offsets (or rather offsets bigger than the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * VBO, because the pointer is unsigned), so use system memory
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * sources. In most sane cases the pointer - offset will still be > 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * otherwise it will wrap around to some big value. Hope that with the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * indices, the driver wraps it back internally. If not,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * drawStridedSlow() is needed, including a vertex buffer path. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->load_base_vertex_index < 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN_(d3d_perf)("load_base_vertex_index is < 0 (%d), not using VBOs.\n", state->load_base_vertex_index);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data.buffer_object = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((UINT_PTR)data.addr < -state->load_base_vertex_index * stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("System memory vertex data load offset is negative!\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data.addr += element->offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("offset %u input_slot %u usage_idx %d\n", element->offset, element->input_slot, element->usage_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (use_vshader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (element->output_slot == ~0U)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: Assuming vertexdeclarations are usually used with the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * same or a similar shader, it might be worth it to store the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * last used output slot and try that one first. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stride_used = vshader_get_input(state->vertex_shader,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element->usage, element->usage_idx, &idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync idx = element->output_slot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stride_used = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!element->ffp_valid)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Skipping unsupported fixed function element of format %s and usage %s\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync debug_d3dformat(element->format->id), debug_d3ddeclusage(element->usage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stride_used = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stride_used = fixed_get_input(element->usage, element->usage_idx, &idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stride_used)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Load %s array %u [usage %s, usage_idx %u, "
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync "input_slot %u, offset %u, stride %u, format %s, buffer_object %u]\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync use_vshader ? "shader": "fixed function", idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync debug_d3ddeclusage(element->usage), element->usage_idx, element->input_slot,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element->offset, stride, debug_d3dformat(element->format->id), data.buffer_object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data.addr += stream->offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].format = element->format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].data = data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].offset = element->offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].stride = stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].stream_idx = element->input_slot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->adapter->gl_info.supported[ARB_VERTEX_ARRAY_BGRA]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->swizzle_map |= 1 << idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->use_map |= 1 << idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Preload the vertex buffers. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->num_buffer_queries = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0, map = stream_info->use_map; map; map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_info_element *element;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(map & 1))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element = &stream_info->elements[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer = state->streams[element->stream_idx].buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_preload(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* If the preload dropped the buffer object, update the stream info. */
a1161adeea4a93de6a9370a0a7ab1e58652b365evboxsync if (
a1161adeea4a93de6a9370a0a7ab1e58652b365evboxsync#ifdef VBOX_WITH_WINE_FIX_STRINFOBUF
a1161adeea4a93de6a9370a0a7ab1e58652b365evboxsync element->data.buffer_object &&
a1161adeea4a93de6a9370a0a7ab1e58652b365evboxsync#endif
a1161adeea4a93de6a9370a0a7ab1e58652b365evboxsync buffer->buffer_object != element->data.buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element->data.buffer_object = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element->data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info) + (ptrdiff_t)element->data.addr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->all_vbo = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->query)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->buffer_queries[device->num_buffer_queries++] = buffer->query;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_update_stream_info(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_info *stream_info = &device->stream_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD prev_all_vbo = stream_info->all_vbo;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("============================= Vertex Declaration =============================\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_stream_info_from_declaration(device, stream_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->vertex_shader && !stream_info->position_transformed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->vertex_declaration->half_float_conv_needed && !stream_info->all_vbo)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using drawStridedSlow with vertex shaders for FLOAT16 conversion.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->useDrawStridedSlow = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->useDrawStridedSlow = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WORD slow_mask = (1 << WINED3D_FFP_PSIZE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync slow_mask |= -!gl_info->supported[ARB_VERTEX_ARRAY_BGRA]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync & ((1 << WINED3D_FFP_DIFFUSE) | (1 << WINED3D_FFP_SPECULAR));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
1675f41731e9e75ac43352afd2b690c08795b032vboxsync if (((stream_info->position_transformed && !device->adapter->d3d_info.xyzrhw)
1675f41731e9e75ac43352afd2b690c08795b032vboxsync || (stream_info->use_map & slow_mask)) && !stream_info->all_vbo)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->useDrawStridedSlow = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->useDrawStridedSlow = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_all_vbo != stream_info->all_vbo)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_preload_texture(const struct wined3d_state *state, unsigned int idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *texture;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum WINED3DSRGB srgb;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(texture = state->textures[idx])) return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync srgb = state->sampler_states[idx][WINED3D_SAMP_SRGB_TEXTURE] ? SRGB_SRGB : SRGB_RGB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture->texture_ops->texture_preload(texture, srgb);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_preload_textures(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (use_vs(state))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->vertex_shader->reg_maps.sampler_type[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_preload_texture(state, MAX_FRAGMENT_SAMPLERS + i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (use_ps(state))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->pixel_shader->reg_maps.sampler_type[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_preload_texture(state, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WORD ffu_map = device->fixed_function_usage_map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; ffu_map; ffu_map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ffu_map & 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_preload_texture(state, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context **new_array;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Adding context %p.\n", context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->contexts) new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*new_array) * (device->context_count + 1));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!new_array)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to grow the context array.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync new_array[device->context_count++] = context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->contexts = new_array;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_context_remove(struct wined3d_device *device, struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context **new_array;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL found = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Removing context %p.\n", context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->context_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->contexts[i] == context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync found = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!found)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Context %p doesn't exist in context array.\n", context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!--device->context_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->contexts);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->contexts = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memmove(&device->contexts[i], &device->contexts[i + 1], (device->context_count - i) * sizeof(*device->contexts));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts, device->context_count * sizeof(*device->contexts));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!new_array)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to shrink context array. Oh well.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->contexts = new_array;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_switch_onscreen_ds(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context, struct wined3d_surface *depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->onscreen_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_INTEXTURE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_modify_ds_location(device->onscreen_depth_stencil, SFLAG_INTEXTURE,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->onscreen_depth_stencil->ds_current_size.cx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->onscreen_depth_stencil->ds_current_size.cy);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(device->onscreen_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->onscreen_depth_stencil = depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_incref(device->onscreen_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL is_full_clear(const struct wined3d_surface *target, const RECT *draw_rect, const RECT *clear_rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* partial draw rect */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (draw_rect->left || draw_rect->top
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || draw_rect->right < target->resource.width
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || draw_rect->bottom < target->resource.height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* partial clear rect */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (clear_rect && (clear_rect->left > 0 || clear_rect->top > 0
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || clear_rect->right < target->resource.width
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || clear_rect->bottom < target->resource.height))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void prepare_ds_clear(struct wined3d_surface *ds, struct wined3d_context *context,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD location, const RECT *draw_rect, UINT rect_count, const RECT *clear_rect, RECT *out_rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT current_rect, r;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ds->flags & SFLAG_DISCARDED)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Depth buffer was discarded, make it entirely current in its new location since
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * there is no other place where we would get data anyway. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(out_rect, 0, 0, ds->resource.width, ds->resource.height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ds->flags & location)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(&current_rect, 0, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ds->ds_current_size.cx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ds->ds_current_size.cy);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRectEmpty(&current_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IntersectRect(&r, draw_rect, &current_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (EqualRect(&r, draw_rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* current_rect ⊇ draw_rect, modify only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (EqualRect(&r, &current_rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* draw_rect ⊇ current_rect, test if we're doing a full clear. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!clear_rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Full clear, modify only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *out_rect = *draw_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IntersectRect(&r, draw_rect, clear_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (EqualRect(&r, draw_rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* clear_rect ⊇ draw_rect, modify only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *out_rect = *draw_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Full load. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_load_ds_location(ds, context, location);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags, const struct wined3d_color *color,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync float depth, DWORD stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const RECT *clear_rect = (rect_count > 0 && rects) ? (const RECT *)rects : NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *target = rt_count ? fb->render_targets[0] : NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT drawable_width, drawable_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLbitfield clear_mask = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL render_offscreen;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT ds_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* When we're clearing parts of the drawable, make sure that the target surface is well up to date in the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * drawable. After the clear we'll mark the drawable up to date, so we have to make sure that this is true
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * for the cleared parts, and the untouched parts.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * If we're clearing the whole target there is no need to copy it into the drawable, it will be overwritten
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * anyway. If we're not clearing the color buffer we don't have to copy either since we're not going to set
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the drawable up to date. We have to check all settings that limit the clear area though. Do not bother
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * checking all this if the dest surface is in the drawable anyway. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3DCLEAR_TARGET && !is_full_clear(target, draw_rect, clear_rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < rt_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *rt = fb->render_targets[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (rt)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_load_location(rt, rt->draw_binding, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, target);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!context->valid)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid context, skipping clear.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (target)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync render_offscreen = context->render_offscreen;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync target->get_drawable_size(context, &drawable_width, &drawable_height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync render_offscreen = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync drawable_width = fb->depth_stencil->pow2Width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync drawable_height = fb->depth_stencil->pow2Height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3DCLEAR_ZBUFFER)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!render_offscreen && fb->depth_stencil != device->onscreen_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_switch_onscreen_ds(device, context, fb->depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prepare_ds_clear(fb->depth_stencil, context, location,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_rect, rect_count, clear_rect, &ds_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!context_apply_clear_state(context, device, rt_count, fb))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to apply clear state, skipping clear.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Only set the values up once, as they are not changing. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3DCLEAR_STENCIL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glStencilMask(~0U);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glClearStencil(stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glClearStencil");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync clear_mask = clear_mask | GL_STENCIL_BUFFER_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3DCLEAR_ZBUFFER)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_modify_ds_location(fb->depth_stencil, location, ds_rect.right, ds_rect.bottom);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glClearDepth(depth);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glClearDepth");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync clear_mask = clear_mask | GL_DEPTH_BUFFER_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3DCLEAR_TARGET)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < rt_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *rt = fb->render_targets[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (rt)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_modify_location(rt, rt->draw_binding, TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glClearColor(color->r, color->g, color->b, color->a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glClearColor");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync clear_mask = clear_mask | GL_COLOR_BUFFER_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!clear_rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_offscreen)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glScissor(draw_rect->left, draw_rect->top,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glScissor(draw_rect->left, drawable_height - draw_rect->bottom,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glScissor");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glClear(clear_mask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glClear");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT current_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Now process each rect in turn. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < rect_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note that GL uses lower left, width/height. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IntersectRect(&current_rect, draw_rect, &clear_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("clear_rect[%u] %s, current_rect %s.\n", i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wine_dbgstr_rect(&clear_rect[i]),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wine_dbgstr_rect(&current_rect));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Tests show that rectangles where x1 > x2 or y1 > y2 are ignored silently.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The rectangle is not cleared, no error is returned, but further rectangles are
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * still cleared if they are valid. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (current_rect.left > current_rect.right || current_rect.top > current_rect.bottom)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Rectangle with negative dimensions, ignoring.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_offscreen)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glScissor(current_rect.left, current_rect.top,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glScissor(current_rect.left, drawable_height - current_rect.bottom,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glScissor");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glClear(clear_mask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glClear");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_settings.strict_draw_ordering || (flags & WINED3DCLEAR_TARGET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && target->swapchain && target->swapchain->front_buffer == target))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_device_incref(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&device->ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", device, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_device_decref(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&device->ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", device, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!refcount)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stateblock *stateblock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_stateblock_decref(device->updateStateBlock)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock != device->stateBlock)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the update stateblock.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stateblock = device->stateBlock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_stateblock_decref(stateblock))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the stateblock.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->multistate_funcs[i] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!list_empty(&device->resources))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Device released with resources still bound, acceptable but unexpected.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Leftover resource %p with type %s (%#x).\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource, debug_d3dresourcetype(resource->type), resource->type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->contexts)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Context array not freed!\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->hardwareCursor)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DestroyCursor(device->hardwareCursor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->hardwareCursor = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_decref(device->wined3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->wined3d = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Freed device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncUINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->swapchain_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_swapchain * CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u.\n", device, swapchain_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_idx >= device->swapchain_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("swapchain_idx %u >= swapchain_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_idx, device->swapchain_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->swapchains[swapchain_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_load_logo(struct wined3d_device *device, const char *filename)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_color_key color_key;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HBITMAP hbm;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BITMAP bm;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HDC dcb = NULL, dcs = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hbm = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(hbm)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GetObjectA(hbm, sizeof(BITMAP), &bm);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dcb = CreateCompatibleDC(NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!dcb) goto out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SelectObject(dcb, hbm);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Create a 32x32 white surface to indicate that wined3d is used, but the specified image
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * couldn't be loaded
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(&bm, 0, sizeof(bm));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync bm.bmWidth = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync bm.bmHeight = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_surface_create(device, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_POOL_SYSTEM_MEM, WINED3D_MULTISAMPLE_NONE, 0, WINED3D_SURFACE_MAPPABLE,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync NULL, &wined3d_null_parent_ops, &device->logo_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Wine logo requested, but failed to create surface, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (dcb)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_surface_getdc(device->logo_surface, &dcs)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BitBlt(dcs, 0, 0, bm.bmWidth, bm.bmHeight, dcb, 0, 0, SRCCOPY);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_releasedc(device->logo_surface, dcs);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync color_key.color_space_low_value = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync color_key.color_space_high_value = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_set_color_key(device->logo_surface, WINEDDCKEY_SRCBLT, &color_key);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_color c = {1.0f, 1.0f, 1.0f, 1.0f};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fill the surface with a white color to show that wined3d is there */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_color_fill(device, device->logo_surface, NULL, &c);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncout:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (dcb) DeleteDC(dcb);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (hbm) DeleteObject(hbm);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void create_dummy_textures(struct wined3d_device *device, struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i, j, count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Under DirectX you can sample even if no texture is bound, whereas
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * OpenGL will only allow that when a valid texture is bound.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * We emulate this by creating dummy textures and binding them
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to each texture stage when the currently set D3D texture is NULL. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[APPLE_CLIENT_STORAGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The dummy texture does not have client storage backing */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD color = 0x000000ff;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Make appropriate texture active */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_active_texture(context, gl_info, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_2d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glGenTextures");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy 2D texture %u given name %u.\n", i, device->dummy_texture_2d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBindTexture");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glTexImage2D");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glGenTextures");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy rectangle texture %u given name %u.\n", i, device->dummy_texture_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBindTexture");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glTexImage2D");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[EXT_TEXTURE3D])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_3d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glGenTextures");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy 3D texture %u given name %u.\n", i, device->dummy_texture_3d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBindTexture");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glTexImage3D");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_cube[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glGenTextures");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy cube texture %u given name %u.\n", i, device->dummy_texture_cube[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBindTexture");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++j)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(j, 0, GL_RGBA8, 1, 1, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glTexImage2D");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[APPLE_CLIENT_STORAGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Re-enable because if supported it is enabled by default */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void destroy_dummy_textures(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_cube);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_cube)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[EXT_TEXTURE3D])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_3d)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_rect)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_2d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_2d)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->dummy_texture_cube, 0, count * sizeof(*device->dummy_texture_cube));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->dummy_texture_3d, 0, count * sizeof(*device->dummy_texture_3d));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->dummy_texture_rect, 0, count * sizeof(*device->dummy_texture_rect));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->dummy_texture_2d, 0, count * sizeof(*device->dummy_texture_2d));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic LONG fullscreen_style(LONG style)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Make sure the window is managed, otherwise we won't get keyboard input. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync style |= WS_POPUP | WS_SYSMENU;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync style &= ~(WS_CAPTION | WS_THICKFRAME);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return style;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic LONG fullscreen_exstyle(LONG exstyle)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Filter out window decorations. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return exstyle;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_setup_fullscreen_window(struct wined3d_device *device, HWND window, UINT w, UINT h)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL filter_messages;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LONG style, exstyle;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting up window %p for fullscreen mode.\n", window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->style || device->exStyle)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync window, device->style, device->exStyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->style = GetWindowLongW(window, GWL_STYLE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync style = fullscreen_style(device->style);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync exstyle = fullscreen_exstyle(device->exStyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->style, device->exStyle, style, exstyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync filter_messages = device->filter_messages;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->filter_messages = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowLongW(window, GWL_STYLE, style);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowLongW(window, GWL_EXSTYLE, exstyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowPos(window, HWND_TOPMOST, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->filter_messages = filter_messages;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL filter_messages;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LONG style, exstyle;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->style && !device->exStyle) return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync style = GetWindowLongW(window, GWL_STYLE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync exstyle = GetWindowLongW(window, GWL_EXSTYLE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* These flags are set by wined3d_device_setup_fullscreen_window, not the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * application, and we want to ignore them in the test below, since it's
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * not the application's fault that they changed. Additionally, we want to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * preserve the current status of these flags (i.e. don't restore them) to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * more closely emulate the behavior of Direct3D, which leaves these flags
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * alone when returning to windowed mode. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->style ^= (device->style ^ style) & WS_VISIBLE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->exStyle ^= (device->exStyle ^ exstyle) & WS_EX_TOPMOST;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Restoring window style of window %p to %08x, %08x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync window, device->style, device->exStyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync filter_messages = device->filter_messages;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->filter_messages = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Only restore the style if the application didn't modify it during the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * fullscreen phase. Some applications change it before calling Reset()
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * when switching between windowed and fullscreen modes (HL2), some
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * depend on the original style (Eve Online). */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (style == fullscreen_style(device->style) && exstyle == fullscreen_exstyle(device->exStyle))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowLongW(window, GWL_STYLE, device->style);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->filter_messages = filter_messages;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Delete the old values. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->style = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->exStyle = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, window %p.\n", device, window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!wined3d_register_window(window, device))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to register window %p.\n", window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedExchangePointer((void **)&device->focus_window, window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("unsupported!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->focus_window) wined3d_unregister_window(device->focus_window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedExchangePointer((void **)&device->focus_window, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("unsupported!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain_desc *swapchain_desc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->d3d_initialized)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->wined3d->flags & WINED3D_NO3D)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!swapchain_desc->pHgsmi)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("hgsmi not specified!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->pHgsmi = swapchain_desc->pHgsmi;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*device->fb.render_targets) * gl_info->limits.buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Initialize the texture unit mapping to a 1:1 mapping */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (state = 0; state < MAX_COMBINED_SAMPLERS; ++state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state < gl_info->limits.fragment_samplers)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->texUnitMap[state] = state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->rev_tex_unit_map[state] = state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->texUnitMap[state] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->rev_tex_unit_map[state] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Shader private data couldn't be allocated\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto err_out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->blitter->alloc_private(device)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Blitter private data couldn't be allocated\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto err_out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Setup the implicit swapchain. This also initializes a context. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Creating implicit swapchain\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = device->device_parent->ops->create_swapchain(device->device_parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc, &swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create implicit swapchain\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto err_out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchain_count = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->swapchains)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Out of memory!\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto err_out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains[0] = swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain->back_buffers && swapchain->back_buffers[0])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting rendertarget to %p.\n", swapchain->back_buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[0] = swapchain->back_buffers[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting rendertarget to %p.\n", swapchain->front_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[0] = swapchain->front_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_incref(device->fb.render_targets[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Depth Stencil support */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.depth_stencil = device->auto_depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->fb.depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_incref(device->fb.depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Set up some starting GL setup */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Setup all the devices defaults */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stateblock_init_default_state(device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, swapchain->front_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync create_dummy_textures(device, context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->contexts[0]->last_was_rhw = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (wined3d_settings.offscreen_rendering_mode)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case ORM_FBO:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->offscreenBuffer = GL_COLOR_ATTACHMENT0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case ORM_BACKBUFFER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (context_get_current()->aux_buffers > 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using auxiliary buffer for offscreen rendering\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->offscreenBuffer = GL_AUX0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using back buffer for offscreen rendering\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->offscreenBuffer = GL_BACK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("All defaults now set up, leaving 3D init.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Clear the screen */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_clear(device, 0, NULL, WINED3DCLEAR_TARGET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync | (swapchain_desc->enable_auto_depth_stencil ? WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL : 0),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &black, 1.0f, 0);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->d3d_initialized = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_settings.logo)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_load_logo(device, wined3d_settings.logo);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncerr_out:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->swapchains);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchain_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_decref(swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->blit_priv)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->blitter->free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->shader_priv)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain_desc *swapchain_desc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Setup the implicit swapchain */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Creating implicit swapchain\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = device->device_parent->ops->create_swapchain(device->device_parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc, &swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create implicit swapchain\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto err_out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchain_count = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->swapchains)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Out of memory!\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto err_out;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains[0] = swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncerr_out:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_decref(swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource, *cursor;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *surface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->d3d_initialized)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_PROFILE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBOXWINEPROFILE_DRAWPRIM_TERM(&device->DrawPrimProfile);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Force making the context current again, to verify it is still valid
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * (workaround for broken drivers) */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_set_current(NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* I don't think that the interface guarantees that the device is destroyed from the same thread
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * it was created. Thus make sure a context is active for the glDelete* calls
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
fcded3b75bf930c68355adc3e3757e35e9cabde4vboxsync#ifdef VBOX_WITH_WINE_FIX_ZEROVERTATTR
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync zv_destroy(device);
fcded3b75bf930c68355adc3e3757e35e9cabde4vboxsync#endif
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->logo_surface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(device->logo_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stateblock_unbind_resources(device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Unload resources */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Unloading resource %p.\n", resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource->resource_ops->resource_unload(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Delete the mouse cursor texture */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->cursorTexture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->cursorTexture = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Destroy the depth blt resources, they will be invalid after the reset. Also free shader
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * private data, it might contain opengl pointers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->depth_blt_texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->depth_blt_texture = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chaches_term(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Destroy the shader backend. Note that this has to happen after all shaders are destroyed. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->blitter->free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync destroy_dummy_textures(device, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release the buffers (with sanity checks)*/
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->onscreen_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface = device->onscreen_depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->onscreen_depth_stencil = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->fb.depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface = device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Releasing depth/stencil buffer %p.\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.depth_stencil = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->auto_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface = device->auto_depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->auto_depth_stencil = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_surface_decref(surface))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the auto depth stencil buffer (%p).\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 1; i < gl_info->limits.buffers; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_render_target(device, i, NULL, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface = device->fb.render_targets[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting rendertarget 0 to NULL\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[0] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Releasing the render target at %p\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->swapchain_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Releasing the implicit swapchain %u.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_swapchain_decref(device->swapchains[i]))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the implicit swapchain.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (device->context_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_destroy(device, device->contexts[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->swapchains);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchain_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->d3d_initialized = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_uninit_gdi(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->swapchain_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Releasing the implicit swapchain %u.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_swapchain_decref(device->swapchains[i]))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the implicit swapchain.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->swapchains);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchain_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Enables thread safety in the wined3d device and its resources. Called by DirectDraw
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * from SetCooperativeLevel if DDSCL_MULTITHREADED is specified, and by d3d8/9 from
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * CreateDevice if D3DCREATE_MULTITHREADED is passed.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * There is no way to deactivate thread safety once it is enabled.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_multithreaded(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* For now just store the flag (needed in case of ddraw). */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.flags |= WINED3DCREATE_MULTITHREADED;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncUINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Emulating %d MB, returning %d MB left.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter->TextureRam / (1024 * 1024),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (device->adapter->TextureRam - device->adapter->UsedTextureRam) / (1024 * 1024));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->adapter->TextureRam - device->adapter->UsedTextureRam;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("unsupported!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ~0UL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_stream_output(struct wined3d_device *device, UINT idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer, UINT offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *prev_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p, offset %u.\n", device, idx, buffer, offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_STREAM_OUT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid stream output %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev_buffer = device->updateStateBlock->state.stream_output[idx].buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.stream_output[idx].buffer = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.stream_output[idx].offset = offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer != buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev_buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_stream_output(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT idx, UINT *offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, offset %p.\n", device, idx, offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_STREAM_OUT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid stream output %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *offset = device->stateBlock->state.stream_output[idx].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.stream_output[idx].buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_stream_source(struct wined3d_device *device, UINT stream_idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer, UINT offset, UINT stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_state *stream;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *prev_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, stream_idx, buffer, offset, stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stream_idx >= MAX_STREAMS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Stream index %u out of range.\n", stream_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (offset & 0x3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Offset %u is not 4 byte aligned.\n", offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->updateStateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev_buffer = stream->buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.streamSource |= 1 << stream_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer == buffer
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && stream->stride == stride
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && stream->offset == offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old values over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream->buffer = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream->stride = stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream->offset = offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev_buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_STREAMSRC);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_stream_source(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stream_idx, struct wined3d_buffer **buffer, UINT *offset, UINT *stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_state *stream;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, stream_idx, buffer, offset, stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stream_idx >= MAX_STREAMS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Stream index %u out of range.\n", stream_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->stateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = stream->buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (*buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(*buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *offset = stream->offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *stride = stream->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT divider)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_state *stream;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT old_flags, old_freq;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, divider %#x.\n", device, stream_idx, divider);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Verify input. At least in d3d9 this is invalid. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && (divider & WINED3DSTREAMSOURCE_INDEXEDDATA))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("INSTANCEDATA and INDEXEDDATA were set, returning D3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && !stream_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("INSTANCEDATA used on stream 0, returning D3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!divider)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Divider is 0, returning D3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->updateStateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync old_flags = stream->flags;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync old_freq = stream->frequency;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream->flags = divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream->frequency = divider & 0x7fffff;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.streamFreq |= 1 << stream_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stream->frequency != old_freq || stream->flags != old_flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_STREAMSRC);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_stream_source_freq(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stream_idx, UINT *divider)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_state *stream;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, divider %p.\n", device, stream_idx, divider);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->updateStateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *divider = stream->flags | stream->frequency;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning %#x.\n", *divider);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_transform(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_transform_state d3dts, const struct wined3d_matrix *matrix)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s, matrix %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, debug_d3dtstype(d3dts), matrix);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._11, matrix->u.s._12, matrix->u.s._13, matrix->u.s._14);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._21, matrix->u.s._22, matrix->u.s._23, matrix->u.s._24);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._31, matrix->u.s._32, matrix->u.s._33, matrix->u.s._34);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%.8e %.8e %.8e %.8e\n", matrix->u.s._41, matrix->u.s._42, matrix->u.s._43, matrix->u.s._44);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.transform[d3dts >> 5] |= 1 << (d3dts & 0x1f);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.transforms[d3dts] = *matrix;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* If the new matrix is the same as the current one,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * we cut off any further processing. this seems to be a reasonable
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * optimization because as was noticed, some apps (warcraft3 for example)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * tend towards setting the same matrix repeatedly for some reason.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * From here on we assume that the new matrix is different, wherever it matters. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!memcmp(&device->stateBlock->state.transforms[d3dts].u.m[0][0], matrix, sizeof(*matrix)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("The application is setting the same matrix over again.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.transforms[d3dts] = *matrix;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (d3dts < WINED3D_TS_WORLD_MATRIX(device->adapter->gl_info.limits.blends))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TRANSFORM(d3dts));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_transform(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_transform_state state, struct wined3d_matrix *matrix)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *matrix = device->stateBlock->state.transforms[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_multiply_transform(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_transform_state state, const struct wined3d_matrix *matrix)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_matrix *mat;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_matrix temp;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note: Using 'updateStateBlock' rather than 'stateblock' in the code
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * below means it will be recorded in a state block change, but it
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * works regardless where it is recorded.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * If this is found to be wrong, change to StateBlock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state > HIGHEST_TRANSFORMSTATE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Unhandled transform state %#x.\n", state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mat = &device->updateStateBlock->state.transforms[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync multiply_matrix(&temp, mat, matrix);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Apply change via set transform - will reapply to eg. lights this way. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_transform(device, state, &temp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Note lights are real special cases. Although the device caps state only
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * e.g. 8 are supported, you can reference any indexes you want as long as
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * that number max are enabled at any one point in time. Therefore since the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * indices can be anything, we need a hashmap of them. However, this causes
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * stateblock problems. When capturing the state block, I duplicate the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * hashmap, but when recording, just build a chain pretty much of commands to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * be replayed. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_light(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT light_idx, const struct wined3d_light *light)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_light_info *object = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct list *e;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync float rho;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Check the parameter range. Need for speed most wanted sets junk lights
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * which confuse the GL driver. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!light)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (light->type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_POINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_SPOT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_PARALLELPOINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_GLSPOT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Incorrect attenuation values can cause the gl driver to crash.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Happens with Need for speed most wanted. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light->attenuation0 < 0.0f || light->attenuation1 < 0.0f || light->attenuation2 < 0.0f)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Attenuation is negative, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_DIRECTIONAL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Ignores attenuation */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Light type out of range, returning WINED3DERR_INVALIDCALL\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (object->OriginalIndex == light_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Adding new light\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&device->updateStateBlock->state.light_map[hash_idx], &object->entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->glIndex = -1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->OriginalIndex = light_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Initialize the object. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light %d setting to type %d, Diffuse(%f,%f,%f,%f), Specular(%f,%f,%f,%f), Ambient(%f,%f,%f,%f)\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_idx, light->type,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light->diffuse.r, light->diffuse.g, light->diffuse.b, light->diffuse.a,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light->specular.r, light->specular.g, light->specular.b, light->specular.a,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light->ambient.r, light->ambient.g, light->ambient.b, light->ambient.a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("... Pos(%f,%f,%f), Dir(%f,%f,%f)\n", light->position.x, light->position.y, light->position.z,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light->direction.x, light->direction.y, light->direction.z);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("... Range(%f), Falloff(%f), Theta(%f), Phi(%f)\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light->range, light->falloff, light->theta, light->phi);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Update the live definitions if the light is currently assigned a glIndex. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (object->glIndex != -1 && !device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (object->OriginalParms.type != light->type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_LIGHT_TYPE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_ACTIVELIGHT(object->glIndex));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Save away the information. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->OriginalParms = *light;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (light->type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_POINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Position */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[0] = light->position.x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[1] = light->position.y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[2] = light->position.z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[3] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->cutoff = 180.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* FIXME: Range */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_DIRECTIONAL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Direction */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[0] = -light->direction.x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[1] = -light->direction.y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[2] = -light->direction.z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[3] = 0.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->exponent = 0.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->cutoff = 180.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_LIGHT_SPOT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Position */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[0] = light->position.x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[1] = light->position.y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[2] = light->position.z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightPosn[3] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Direction */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightDirn[0] = light->direction.x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightDirn[1] = light->direction.y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightDirn[2] = light->direction.z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->lightDirn[3] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* opengl-ish and d3d-ish spot lights use too different models
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * for the light "intensity" as a function of the angle towards
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the main light direction, so we only can approximate very
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * roughly. However, spot lights are rather rarely used in games
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * (if ever used at all). Furthermore if still used, probably
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * nobody pays attention to such details. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!light->falloff)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Falloff = 0 is easy, because d3d's and opengl's spot light
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * equations have the falloff resp. exponent parameter as an
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * exponent, so the spot light lighting will always be 1.0 for
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * both of them, and we don't have to care for the rest of the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * rather complex calculation. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->exponent = 0.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync rho = light->theta + (light->phi - light->theta) / (2 * light->falloff);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (rho < 0.0001f)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync rho = 0.0001f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIXES
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->exponent = -0.3f / log(cos(rho / 2));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->exponent = -0.3f / logf(cosf(rho / 2));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (object->exponent > 128.0f)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->exponent = 128.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->cutoff = (float)(light->phi * 90 / M_PI);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* FIXME: Range */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unrecognized light type %#x.\n", light->type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_light(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT light_idx, struct wined3d_light *light)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_light_info *light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct list *e;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->stateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->OriginalIndex == light_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!light_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light information requested but light not defined\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *light = light_info->OriginalParms;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UINT light_idx, BOOL enable)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_light_info *light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct list *e;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, enable %#x.\n", device, light_idx, enable);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->OriginalIndex == light_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Found light %p.\n", light_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Special case - enabling an undefined light creates one with a strict set of parameters. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!light_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light enabled requested but light not defined, so defining one!\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_light(device, light_idx, &WINED3D_default_light);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Search for it again! Should be fairly quick as near head of list. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->OriginalIndex == light_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!light_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Adding default lights has failed dismally\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!enable)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->glIndex != -1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_LIGHT_TYPE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_ACTIVELIGHT(light_info->glIndex));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.lights[light_info->glIndex] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info->glIndex = -1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light already disabled, nothing to do\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info->enabled = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info->enabled = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->glIndex != -1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Nothing to do as light was enabled\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Find a free GL light. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < gl_info->limits.lights; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->updateStateBlock->state.lights[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.lights[i] = light_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info->glIndex = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->glIndex == -1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Our tests show that Windows returns D3D_OK in this situation, even with
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE devices. This
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * is consistent among ddraw, d3d8 and d3d9. GetLightEnable returns TRUE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * as well for those lights.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * TODO: Test how this affects rendering. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Too many concurrently active lights\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* i == light_info->glIndex */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_LIGHT_TYPE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_ACTIVELIGHT(i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT hash_idx = LIGHTMAP_HASHFUNC(light_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_light_info *light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct list *e;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, enable %p.\n", device, light_idx, enable);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->stateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (light_info->OriginalIndex == light_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!light_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light enabled state requested but light not defined.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* true is 128 according to SetLightEnable */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *enable = light_info->enabled ? 128 : 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT plane_idx, const struct wined3d_vec4 *plane)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Validate plane_idx. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application has requested clipplane this device doesn't support.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.clipplane |= 1 << plane_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!memcmp(&device->updateStateBlock->state.clip_planes[plane_idx], plane, sizeof(*plane)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting old values over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.clip_planes[plane_idx] = *plane;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_CLIPPLANE(plane_idx));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_clip_plane(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT plane_idx, struct wined3d_vec4 *plane)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Validate plane_idx. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application has requested clipplane this device doesn't support.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *plane = device->stateBlock->state.clip_planes[plane_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_clip_status(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_clip_status *clip_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, clip_status %p stub!\n", device, clip_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!clip_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_clip_status(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_clip_status *clip_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, clip_status %p stub!\n", device, clip_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!clip_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_material(struct wined3d_device *device, const struct wined3d_material *material)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, material %p.\n", device, material);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.material = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.material = *material;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_MATERIAL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_material(const struct wined3d_device *device, struct wined3d_material *material)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, material %p.\n", device, material);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *material = device->updateStateBlock->state.material;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->diffuse.r, material->diffuse.g,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->diffuse.b, material->diffuse.a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->ambient.r, material->ambient.g,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->ambient.b, material->ambient.a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->specular.r, material->specular.g,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->specular.b, material->specular.a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->emissive.r, material->emissive.g,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync material->emissive.b, material->emissive.a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("power %.8e.\n", material->power);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_index_buffer(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer, enum wined3d_format_id format_id)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *prev_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, buffer %p, format %s.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, buffer, debug_d3dformat(format_id));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev_buffer = device->updateStateBlock->state.index_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.indices = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.index_buffer = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.index_format = format_id;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer != buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev_buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_index_buffer(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_format_id *format)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, format %p.\n", device, format);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *format = device->stateBlock->state.index_format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.index_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device, INT base_index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, base_index %d.\n", device, base_index);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.base_vertex_index = base_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncINT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.base_vertex_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_viewport(struct wined3d_device *device, const struct wined3d_viewport *viewport)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, viewport %p.\n", device, viewport);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("x %u, y %u, w %u, h %u, min_z %.8e, max_z %.8e.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync viewport->x, viewport->y, viewport->width, viewport->height, viewport->min_z, viewport->max_z);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.viewport = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.viewport = *viewport;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VIEWPORT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_viewport(const struct wined3d_device *device, struct wined3d_viewport *viewport)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, viewport %p.\n", device, viewport);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *viewport = device->stateBlock->state.viewport;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void resolve_depth_buffer(struct wined3d_state *state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *texture = state->textures[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *depth_stencil, *surface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture || texture->resource.type != WINED3D_RTYPE_TEXTURE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || !(texture->resource.format->flags & WINED3DFMT_FLAG_DEPTH))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface = surface_from_resource(texture->sub_resources[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync depth_stencil = state->fb->depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_blt(surface, NULL, depth_stencil, NULL, 0, NULL, WINED3D_TEXF_POINT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_render_state(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_render_state state, DWORD value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD old_value = device->stateBlock->state.render_states[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s (%#x), value %#x.\n", device, debug_d3drenderstate(state), state, value);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.renderState[state >> 5] |= 1 << (state & 0x1f);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.render_states[state] = value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Compared here and not before the assignment to allow proper stateblock recording. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value == old_value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old value over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state == WINED3D_RS_POINTSIZE && value == WINED3D_RESZ_CODE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("RESZ multisampled depth buffer resolve triggered.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resolve_depth_buffer(&device->stateBlock->state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_device_get_render_state(const struct wined3d_device *device, enum wined3d_render_state state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s (%#x).\n", device, debug_d3drenderstate(state), state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.render_states[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_sampler_state(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT sampler_idx, enum wined3d_sampler_state state, DWORD value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD old_value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, sampler_idx %u, state %s, value %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, sampler_idx, debug_d3dsamplerstate(state), value);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= sizeof(device->stateBlock->state.sampler_states)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync / sizeof(*device->stateBlock->state.sampler_states))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler %u.\n", sampler_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return; /* Windows accepts overflowing this array ... we do not. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync old_value = device->stateBlock->state.sampler_states[sampler_idx][state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.sampler_states[sampler_idx][state] = value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.samplerState[sampler_idx] |= 1 << state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (old_value == value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old value over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(sampler_idx));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_device_get_sampler_state(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT sampler_idx, enum wined3d_sampler_state state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, sampler_idx %u, state %s.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, sampler_idx, debug_d3dsamplerstate(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= sizeof(device->stateBlock->state.sampler_states)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync / sizeof(*device->stateBlock->state.sampler_states))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler %u.\n", sampler_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0; /* Windows accepts overflowing this array ... we do not. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.sampler_states[sampler_idx][state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_scissor_rect(struct wined3d_device *device, const RECT *rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, rect %s.\n", device, wine_dbgstr_rect(rect));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.scissorRect = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (EqualRect(&device->updateStateBlock->state.scissor_rect, rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("App is setting the old scissor rectangle over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync CopyRect(&device->updateStateBlock->state.scissor_rect, rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SCISSORRECT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, rect %p.\n", device, rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *rect = device->updateStateBlock->state.scissor_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning rect %s.\n", wine_dbgstr_rect(rect));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vertex_declaration(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_vertex_declaration *declaration)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_vertex_declaration *prev = device->updateStateBlock->state.vertex_declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, declaration %p.\n", device, declaration);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (declaration)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_vertex_declaration_incref(declaration);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_vertex_declaration_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vertex_declaration = declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexDecl = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (declaration == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Checked after the assignment to allow proper stateblock recording. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old declaration over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VDECL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_vertex_declaration * CDECL wined3d_device_get_vertex_declaration(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.vertex_declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vertex_shader(struct wined3d_device *device, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *prev = device->updateStateBlock->state.vertex_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, shader %p.\n", device, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_shader_incref(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_shader_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vertex_shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexShader = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old shader over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VSHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * CDECL wined3d_device_get_vertex_shader(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.vertex_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vs_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_CONSTANT_BUFFERS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid constant buffer index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.vs_cb[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vs_cb[idx] = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev != buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_vs_cb(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u.\n", device, idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_CONSTANT_BUFFERS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid constant buffer index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.vs_cb[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_sampler *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_SAMPLER_OBJECTS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.vs_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vs_sampler[idx] = sampler;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_sampler_incref(sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_sampler_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_sampler * CDECL wined3d_device_get_vs_sampler(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u.\n", device, idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_SAMPLER_OBJECTS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.vs_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_vs_consts_b(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, bool_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_B)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.vs_consts_b[start_register], constants, count * sizeof(BOOL));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set BOOL constant %u to %s.\n", start_register + i, constants[i] ? "true" : "false");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexShaderConstantsB |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_vs_consts_b(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, bool_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_B)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.vs_consts_b[start_register], count * sizeof(BOOL));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_vs_consts_i(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_I)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.vs_consts_i[start_register * 4], constants, count * sizeof(int) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set INT constant %u to {%d, %d, %d, %d}.\n", start_register + i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4], constants[i * 4 + 1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4 + 2], constants[i * 4 + 3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexShaderConstantsI |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_vs_consts_i(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_I)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.vs_consts_i[start_register * 4], count * sizeof(int) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const float *constants, UINT vector4f_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Specifically test start_register > limit to catch MAX_UINT overflows
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * when adding start_register + vector4f_count. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register + vector4f_count > d3d_info->limits.vs_uniform_count
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register > d3d_info->limits.vs_uniform_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.vs_consts_f[start_register * 4],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants, vector4f_count * sizeof(float) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (TRACE_ON(d3d))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < vector4f_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4], constants[i * 4 + 1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4 + 2], constants[i * 4 + 3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_update_float_vertex_constants(device, start_register, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->updateStateBlock->changed.vertexShaderConstantsF + start_register, 1,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*device->updateStateBlock->changed.vertexShaderConstantsF) * vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_vs_consts_f(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, float *constants, UINT vector4f_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int count = min(vector4f_count, d3d_info->limits.vs_uniform_count - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || count < 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.vs_consts_f[start_register * 4], count * sizeof(float) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_invalidate_texture_stage(const struct wined3d_device *device, DWORD stage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_stage(struct wined3d_device *device, DWORD stage, DWORD unit)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD i = device->rev_tex_unit_map[unit];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD j = device->texUnitMap[stage];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->texUnitMap[stage] = unit;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (i != WINED3D_UNMAPPED_STAGE && i != stage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->texUnitMap[i] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->rev_tex_unit_map[unit] = stage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (j != WINED3D_UNMAPPED_STAGE && j != unit)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_update_fixed_function_usage_map(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fixed_function_usage_map = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_TEXTURES; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_texture_op color_op = state->texture_states[i][WINED3D_TSS_COLOR_OP];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_texture_op alpha_op = state->texture_states[i][WINED3D_TSS_ALPHA_OP];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD color_arg1 = state->texture_states[i][WINED3D_TSS_COLOR_ARG1] & WINED3DTA_SELECTMASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD color_arg2 = state->texture_states[i][WINED3D_TSS_COLOR_ARG2] & WINED3DTA_SELECTMASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD color_arg3 = state->texture_states[i][WINED3D_TSS_COLOR_ARG0] & WINED3DTA_SELECTMASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD alpha_arg1 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] & WINED3DTA_SELECTMASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD alpha_arg2 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] & WINED3DTA_SELECTMASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD alpha_arg3 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] & WINED3DTA_SELECTMASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Not used, and disable higher stages. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (color_op == WINED3D_TOP_DISABLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (((color_arg1 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ((color_arg2 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ((color_arg3 == WINED3DTA_TEXTURE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (color_op == WINED3D_TOP_MULTIPLY_ADD || color_op == WINED3D_TOP_LERP))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ((alpha_arg1 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ((alpha_arg2 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ((alpha_arg3 == WINED3DTA_TEXTURE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (alpha_op == WINED3D_TOP_MULTIPLY_ADD || alpha_op == WINED3D_TOP_LERP)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fixed_function_usage_map |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((color_op == WINED3D_TOP_BUMPENVMAP || color_op == WINED3D_TOP_BUMPENVMAP_LUMINANCE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && i < MAX_TEXTURES - 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fixed_function_usage_map |= (1 << (i + 1));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_fixed_function_samplers(struct wined3d_device *device, const struct wined3d_d3d_info *d3d_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i, tex;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WORD ffu_map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_update_fixed_function_usage_map(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ffu_map = device->fixed_function_usage_map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (d3d_info->limits.ffp_textures == d3d_info->limits.ffp_blend_stages
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || device->stateBlock->state.lowest_disabled_stage <= d3d_info->limits.ffp_textures)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; ffu_map; ffu_map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(ffu_map & 1)) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->texUnitMap[i] != i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_stage(device, i, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_texture_stage(device, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Now work out the mapping */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync tex = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; ffu_map; ffu_map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(ffu_map & 1)) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->texUnitMap[i] != tex)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_stage(device, i, tex);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_texture_stage(device, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++tex;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_psamplers(struct wined3d_device *device, const struct wined3d_d3d_info *d3d_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_sampler_texture_type *sampler_type =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.pixel_shader->reg_maps.sampler_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_type[i] && device->texUnitMap[i] != i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_stage(device, i, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (i < d3d_info->limits.ffp_blend_stages)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_texture_stage(device, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL device_unit_free_for_vs(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_sampler_texture_type *pshader_sampler_tokens,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_sampler_texture_type *vshader_sampler_tokens, DWORD unit)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD current_mapping = device->rev_tex_unit_map[unit];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Not currently used */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (current_mapping == WINED3D_UNMAPPED_STAGE) return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (current_mapping < MAX_FRAGMENT_SAMPLERS) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Used by a fragment sampler */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!pshader_sampler_tokens) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No pixel shader, check fixed function */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return current_mapping >= MAX_TEXTURES || !(device->fixed_function_usage_map & (1 << current_mapping));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Pixel shader, check the shader's sampler map */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return !pshader_sampler_tokens[current_mapping];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Used by a vertex sampler */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return !vshader_sampler_tokens[current_mapping - MAX_FRAGMENT_SAMPLERS];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_vsamplers(struct wined3d_device *device, BOOL ps, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_sampler_texture_type *vshader_sampler_type =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.vertex_shader->reg_maps.sampler_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_sampler_texture_type *pshader_sampler_type = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ps)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note that we only care if a sampler is sampled or not, not the sampler's specific type.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Otherwise we'd need to call shader_update_samplers() here for 1.x pixelshaders. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync pshader_sampler_type = device->stateBlock->state.pixel_shader->reg_maps.sampler_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD vsampler_idx = i + MAX_FRAGMENT_SAMPLERS;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (vshader_sampler_type[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->texUnitMap[vsampler_idx] != WINED3D_UNMAPPED_STAGE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Already mapped somewhere */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (start >= 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device_unit_free_for_vs(device, pshader_sampler_type, vshader_sampler_type, start))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_stage(device, vsampler_idx, start);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(vsampler_idx));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync --start;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync --start;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_update_tex_unit_map(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL vs = use_vs(state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL ps = use_ps(state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Rules are:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * -> Pixel shaders need a 1:1 map. In theory the shader input could be mapped too, but
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * that would be really messy and require shader recompilation
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * -> When the mapping of a stage is changed, sampler and ALL texture stage states have
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to be reset. Because of that try to work with a 1:1 mapping as much as possible
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ps)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_psamplers(device, d3d_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_fixed_function_samplers(device, d3d_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (vs)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_map_vsamplers(device, ps, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_pixel_shader(struct wined3d_device *device, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *prev = device->updateStateBlock->state.pixel_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, shader %p.\n", device, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_shader_incref(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_shader_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.pixel_shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.pixelShader = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old shader over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * CDECL wined3d_device_get_pixel_shader(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.pixel_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_ps_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_CONSTANT_BUFFERS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid constant buffer index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.ps_cb[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.ps_cb[idx] = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev != buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_ps_cb(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u.\n", device, idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_CONSTANT_BUFFERS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid constant buffer index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.ps_cb[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_ps_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_sampler *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_SAMPLER_OBJECTS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.ps_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.ps_sampler[idx] = sampler;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_sampler_incref(sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_sampler_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_sampler * CDECL wined3d_device_get_ps_sampler(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u.\n", device, idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_SAMPLER_OBJECTS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.ps_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_ps_consts_b(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, bool_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_B)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.ps_consts_b[start_register], constants, count * sizeof(BOOL));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set BOOL constant %u to %s.\n", start_register + i, constants[i] ? "true" : "false");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.pixelShaderConstantsB |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_ps_consts_b(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, bool_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_B)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.ps_consts_b[start_register], count * sizeof(BOOL));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_ps_consts_i(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_I)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.ps_consts_i[start_register * 4], constants, count * sizeof(int) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set INT constant %u to {%d, %d, %d, %d}.\n", start_register + i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4], constants[i * 4 + 1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4 + 2], constants[i * 4 + 3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.pixelShaderConstantsI |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_ps_consts_i(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || start_register >= MAX_CONST_I)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.ps_consts_i[start_register * 4], count * sizeof(int) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const float *constants, UINT vector4f_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Specifically test start_register > limit to catch MAX_UINT overflows
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * when adding start_register + vector4f_count. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register + vector4f_count > d3d_info->limits.ps_uniform_count
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register > d3d_info->limits.ps_uniform_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.ps_consts_f[start_register * 4],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants, vector4f_count * sizeof(float) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (TRACE_ON(d3d))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < vector4f_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4], constants[i * 4 + 1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constants[i * 4 + 2], constants[i * 4 + 3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_update_float_pixel_constants(device, start_register, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->updateStateBlock->changed.pixelShaderConstantsF + start_register, 1,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*device->updateStateBlock->changed.pixelShaderConstantsF) * vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_ps_consts_f(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, float *constants, UINT vector4f_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int count = min(vector4f_count, d3d_info->limits.ps_uniform_count - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!constants || count < 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.ps_consts_f[start_register * 4], count * sizeof(float) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_geometry_shader(struct wined3d_device *device, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *prev = device->updateStateBlock->state.geometry_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, shader %p.\n", device, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_shader_incref(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_shader_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.geometry_shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState || shader == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_GEOMETRY_SHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * CDECL wined3d_device_get_geometry_shader(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.geometry_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_gs_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_CONSTANT_BUFFERS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid constant buffer index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.gs_cb[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.gs_cb[idx] = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev != buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_gs_cb(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u.\n", device, idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_CONSTANT_BUFFERS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid constant buffer index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.gs_cb[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_gs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_sampler *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_SAMPLER_OBJECTS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.gs_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.gs_sampler[idx] = sampler;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_sampler_incref(sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_sampler_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_sampler * CDECL wined3d_device_get_gs_sampler(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u.\n", device, idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx >= MAX_SAMPLER_OBJECTS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid sampler index %u.\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.gs_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#define copy_and_next(dest, src, size) memcpy(dest, src, size); dest += (size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT process_vertices_strided(const struct wined3d_device *device, DWORD dwDestIndex, DWORD dwCount,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info *stream_info, struct wined3d_buffer *dest, DWORD flags,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD DestFVF)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_matrix mat, proj_mat, view_mat, world_mat;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_viewport vp;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT vertex_size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE *dest_ptr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL doClip;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD numTextures;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stream_info->use_map & (1 << WINED3D_FFP_NORMAL))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(stream_info->use_map & (1 << WINED3D_FFP_POSITION)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Source has no position mask\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock->state.render_states[WINED3D_RS_CLIPPING])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The clipping code is not quite correct. Some things need
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to be checked against IDirect3DDevice3 (!), d3d8 and d3d9,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * so disable clipping for now.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * (The graphics in Half-Life are broken, and my processvertices
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * test crashes with IDirect3DDevice3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync doClip = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync doClip = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!warned) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Clipping is broken and disabled for now\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync doClip = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vertex_size = get_flexible_vertex_size(DestFVF);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_buffer_map(dest, dwDestIndex * vertex_size, dwCount * vertex_size, &dest_ptr, 0)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to map buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_get_transform(device, WINED3D_TS_VIEW, &view_mat);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_get_transform(device, WINED3D_TS_PROJECTION, &proj_mat);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_get_transform(device, WINED3D_TS_WORLD_MATRIX(0), &world_mat);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("View mat:\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Proj mat:\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("World mat:\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Get the viewport */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_get_viewport(device, &vp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("viewport x %u, y %u, width %u, height %u, min_z %.8e, max_z %.8e.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vp.x, vp.y, vp.width, vp.height, vp.min_z, vp.max_z);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync multiply_matrix(&mat,&view_mat,&world_mat);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync multiply_matrix(&mat,&proj_mat,&mat);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync numTextures = (DestFVF & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < dwCount; i+= 1) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int tex_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ( ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZ ) ||
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW ) ) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The position first */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_POSITION];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const float *p = (const float *)(element->data.addr + i * element->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync float x, y, z, rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("In: ( %06.2f %06.2f %06.2f )\n", p[0], p[1], p[2]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Multiplication with world, view and projection matrix */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("x=%f y=%f z=%f rhw=%f\n", x, y, z, rhw);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WARNING: The following things are taken from d3d7 and were not yet checked
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * against d3d8 or d3d9!
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Clipping conditions: From msdn
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * A vertex is clipped if it does not match the following requirements
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * -rhw < x <= rhw
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * -rhw < y <= rhw
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 0 < z <= rhw
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 0 < rhw ( Not in d3d7, but tested in d3d7)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * If clipping is on is determined by the D3DVOP_CLIP flag in D3D7, and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * by the D3DRS_CLIPPING in D3D9(according to the msdn, not checked)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if( !doClip ||
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( (-rhw -eps < x) && (-rhw -eps < y) && ( -eps < z) &&
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (x <= rhw + eps) && (y <= rhw + eps ) && (z <= rhw + eps) &&
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( rhw > eps ) ) ) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* "Normal" viewport transformation (not clipped)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 1) The values are divided by rhw
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 2) The y axis is negative, so multiply it with -1
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 3) Screen coordinates go from -(Width/2) to +(Width/2) and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * -(Height/2) to +(Height/2). The z range is MinZ to MaxZ
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 4) Multiply x with Width/2 and add Width/2
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 5) The same for the height
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 6) Add the viewpoint X and Y to the 2D coordinates and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The minimum Z value to z
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 7) rhw = 1 / rhw Reciprocal of Homogeneous W....
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Well, basically it's simply a linear transformation into viewport
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * coordinates
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync x /= rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync y /= rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync z /= rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync y *= -1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync x *= vp.width / 2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync y *= vp.height / 2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync z *= vp.max_z - vp.min_z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync x += vp.width / 2 + vp.x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync y += vp.height / 2 + vp.y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync z += vp.min_z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync rhw = 1 / rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync } else {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* That vertex got clipped
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Contrary to OpenGL it is not dropped completely, it just
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * undergoes a different calculation.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Vertex got clipped\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync x += rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync y += rhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync x /= 2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync y /= 2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Msdn mentions that Direct3D9 keeps a list of clipped vertices
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * outside of the main vertex buffer memory. That needs some more
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * investigation...
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Writing (%f %f %f) %f\n", x, y, z, rhw);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( (float *) dest_ptr)[0] = x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( (float *) dest_ptr)[1] = y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( (float *) dest_ptr)[2] = z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( (float *) dest_ptr)[3] = rhw; /* SIC, see ddraw test! */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += 3 * sizeof(float);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += sizeof(float);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (DestFVF & WINED3DFVF_PSIZE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += sizeof(DWORD);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (DestFVF & WINED3DFVF_NORMAL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_NORMAL];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const float *normal = (const float *)(element->data.addr + i * element->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* AFAIK this should go into the lighting information */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Didn't expect the destination to have a normal\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync copy_and_next(dest_ptr, normal, 3 * sizeof(float));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (DestFVF & WINED3DFVF_DIFFUSE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_DIFFUSE];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *color_d = (const DWORD *)(element->data.addr + i * element->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(stream_info->use_map & (1 << WINED3D_FFP_DIFFUSE)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!warned) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("No diffuse color in source, but destination has one\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *( (DWORD *) dest_ptr) = 0xffffffff;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += sizeof(DWORD);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync copy_and_next(dest_ptr, color_d, sizeof(DWORD));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (DestFVF & WINED3DFVF_SPECULAR)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* What's the color value in the feedback buffer? */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_SPECULAR];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *color_s = (const DWORD *)(element->data.addr + i * element->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(stream_info->use_map & (1 << WINED3D_FFP_SPECULAR)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!warned) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("No specular color in source, but destination has one\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(DWORD *)dest_ptr = 0xff000000;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += sizeof(DWORD);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync copy_and_next(dest_ptr, color_s, sizeof(DWORD));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (tex_index = 0; tex_index < numTextures; ++tex_index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_TEXCOORD0 + tex_index];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const float *tex_coord = (const float *)(element->data.addr + i * element->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(stream_info->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + tex_index))))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("No source texture, but destination requests one\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_unmap(dest);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#undef copy_and_next
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_process_vertices(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT src_start_idx, UINT dst_idx, UINT vertex_count, struct wined3d_buffer *dst_buffer,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_vertex_declaration *declaration, DWORD flags, DWORD dst_fvf)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_info stream_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *vs;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, src_start_idx %u, dst_idx %u, vertex_count %u, "
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync "dst_buffer %p, declaration %p, flags %#x, dst_fvf %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, src_start_idx, dst_idx, vertex_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_buffer, declaration, flags, dst_fvf);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (declaration)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Output vertex declaration not implemented yet.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Need any context to write to the vbo. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vs = state->vertex_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->vertex_shader = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_stream_info_from_declaration(device, &stream_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->vertex_shader = vs;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We can't convert FROM a VBO, and vertex buffers used to source into
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * process_vertices() are unlikely to ever be used for drawing. Release
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * VBOs in those buffers and fix up the stream_info structure.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Also apply the start index. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < (sizeof(stream_info.elements) / sizeof(*stream_info.elements)); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stream_info_element *e;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(stream_info.use_map & (1 << i)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e = &stream_info.elements[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (e->data.buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->data.buffer_object = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, gl_info));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glDeleteBuffersARB(1, &vb->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vb->buffer_object = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (e->data.addr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->data.addr += e->stride * src_start_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = process_vertices_strided(device, dst_idx, vertex_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &stream_info, dst_buffer, flags, dst_fvf);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stage, enum wined3d_texture_stage_state state, DWORD value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD old_value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stage %u, state %s, value %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, stage, debug_d3dtexturestate(state), value);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state > WINED3D_HIGHEST_TEXTURE_STATE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid state %#x passed.\n", state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= d3d_info->limits.ffp_blend_stages)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Attempting to set stage %u which is higher than the max stage %u, ignoring.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stage, d3d_info->limits.ffp_blend_stages - 1);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync old_value = device->updateStateBlock->state.texture_states[stage][state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.textureState[stage] |= 1 << state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.texture_states[stage][state] = value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Checked after the assignments to allow proper stateblock recording. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (old_value == value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old value over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage > device->stateBlock->state.lowest_disabled_stage
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->StateTable[STATE_TEXTURESTAGE(0, state)].representative
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync == STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Colorop change above lowest disabled stage? That won't change
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * anything in the GL setup. Changes in other states are important on
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * disabled stages too. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state == WINED3D_TSS_COLOR_OP)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value == WINED3D_TOP_DISABLE && old_value != WINED3D_TOP_DISABLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Previously enabled stage disabled now. Make sure to dirtify
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * all enabled stages above stage, they have to be disabled.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The current stage is dirtified below. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = stage + 1; i < device->stateBlock->state.lowest_disabled_stage; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Additionally dirtifying stage %u.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.lowest_disabled_stage = stage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("New lowest disabled: %u.\n", stage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (value != WINED3D_TOP_DISABLE && old_value == WINED3D_TOP_DISABLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Previously disabled stage enabled. Stages above it may need
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * enabling. Stage must be lowest_disabled_stage here, if it's
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * bigger success is returned above, and stages below the lowest
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * disabled stage can't be enabled (because they are enabled
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * already).
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Again stage stage doesn't need to be dirtified here, it is
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * handled below. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = stage + 1; i < d3d_info->limits.ffp_blend_stages; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->updateStateBlock->state.texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Additionally dirtifying stage %u due to enable.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.lowest_disabled_stage = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("New lowest disabled: %u.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_device_get_texture_stage_state(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stage, enum wined3d_texture_stage_state state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stage %u, state %s.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, stage, debug_d3dtexturestate(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state > WINED3D_HIGHEST_TEXTURE_STATE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid state %#x passed.\n", state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->updateStateBlock->state.texture_states[stage][state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stage, struct wined3d_texture *texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stage %u, texture %p.\n", device, stage, texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Windows accepts overflowing this array... we do not. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= sizeof(device->stateBlock->state.textures) / sizeof(*device->stateBlock->state.textures))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Ignoring invalid stage %u.\n", stage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (texture && texture->resource.pool == WINED3D_POOL_SCRATCH)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Rejecting attempt to set scratch texture.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.textures |= 1 << stage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.textures[stage];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Previous texture %p.\n", prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (texture == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("App is setting the same texture again, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting new texture to %p.\n", texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.textures[stage] = texture;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording... not performing anything\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (texture) wined3d_texture_incref(texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev) wined3d_texture_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LONG bind_count = InterlockedIncrement(&texture->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_texture_incref(texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!prev || texture->target != prev->target)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!prev && stage < d3d_info->limits.ffp_blend_stages)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The source arguments for color and alpha ops have different
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * meanings when a NULL texture is bound, so the COLOR_OP and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * ALPHA_OP have to be dirtified. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_COLOR_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_ALPHA_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (bind_count == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture->sampler = stage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LONG bind_count = InterlockedDecrement(&prev->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture && stage < d3d_info->limits.ffp_blend_stages)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_COLOR_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, WINED3D_TSS_ALPHA_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (bind_count && prev->sampler == stage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Search for other stages the texture is bound to. Shouldn't
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * happen if applications bind textures to a single stage only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Searching for other stages the texture is bound to.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->updateStateBlock->state.textures[i] == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Texture is also bound to stage %u.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev->sampler = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_texture_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(stage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_texture * CDECL wined3d_device_get_texture(const struct wined3d_device *device, UINT stage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stage %u.\n", device, stage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= sizeof(device->stateBlock->state.textures) / sizeof(*device->stateBlock->state.textures))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Ignoring invalid stage %u.\n", stage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL; /* Windows accepts overflowing this array ... we do not. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.textures[stage];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(*backbuffer = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, caps %p.\n", device, caps);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.device_type, caps);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_display_mode(const struct wined3d_device *device, UINT swapchain_idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, mode %p, rotation %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, swapchain_idx, mode, rotation);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_swapchain_get_display_mode(swapchain, mode, rotation);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stateblock *stateblock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &stateblock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_decref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock = stateblock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->isRecordingState = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Recording stateblock %p.\n", stateblock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stateblock **stateblock)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stateblock *object = device->updateStateBlock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stateblock %p.\n", device, stateblock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Not recording.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *stateblock = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stateblock_init_contained_states(object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *stateblock = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->isRecordingState = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock = device->stateBlock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_incref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning stateblock %p.\n", *stateblock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_begin_scene(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* At the moment we have no need for any functionality at the beginning
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * of a scene. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->inScene)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Already in scene, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->inScene = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_end_scene(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->inScene)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Not in scene, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We only have to do this if we need to read the, swapbuffers performs a flush for us */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->gl_info->gl_ops.gl.p_glFlush();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * fails. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->inScene = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_present(const struct wined3d_device *device, const RECT *src_rect,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_window_override, dirty_region, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->swapchain_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_present(device->swapchains[i], src_rect,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_rect, dst_window_override, dirty_region, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_clear(struct wined3d_device *device, DWORD rect_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const RECT *rects, DWORD flags, const struct wined3d_color *color, float depth, DWORD stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT draw_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, rect_count %u, rects %p, flags %#x, color {%.8e, %.8e, %.8e, %.8e}, depth %.8e, stencil %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, rect_count, rects, flags, color->r, color->g, color->b, color->a, depth, stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!rect_count && rects)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Rects is %p, but rect_count is 0, ignoring clear\n", rects);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *ds = device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!ds)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Clearing depth and/or stencil without a depth stencil buffer attached, returning WINED3DERR_INVALIDCALL\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: What about depth stencil buffers without stencil bits? */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (flags & WINED3DCLEAR_TARGET)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ds->resource.width < device->fb.render_targets[0]->resource.width
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ds->resource.height < device->fb.render_targets[0]->resource.height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Silently ignoring depth and target clear with mismatching sizes\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_get_draw_rect(&device->stateBlock->state, &draw_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_clear_render_targets(device, device->adapter->gl_info.limits.buffers,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &device->fb, rect_count, rects, &draw_rect, flags, color, depth, stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_primitive_type(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_primitive_type primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLenum gl_primitive_type, prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, primitive_type %s\n", device, debug_d3dprimitivetype(primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.primitive_type = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_primitive_type = gl_primitive_type_from_d3d(primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.gl_primitive_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.gl_primitive_type = gl_primitive_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->isRecordingState && gl_primitive_type != prev
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (gl_primitive_type == GL_POINTS || prev == GL_POINTS))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_POINT_SIZE_ENABLE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_primitive_type(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_primitive_type *primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, primitive_type %p\n", device, primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *primitive_type = d3d_primitive_type_from_gl(device->stateBlock->state.gl_primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning %s\n", debug_d3dprimitivetype(*primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_draw_primitive(struct wined3d_device *device, UINT start_vertex, UINT vertex_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_vertex %u, vertex_count %u.\n", device, start_vertex, vertex_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->stateBlock->state.vertex_declaration)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Called without a valid vertex declaration set.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock->state.load_base_vertex_index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.load_base_vertex_index = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_BASEVERTEXINDEX);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Account for the loading offset due to index buffers. Instead of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * reloading all sources correct it with the startvertex parameter. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_primitive(device, start_vertex, vertex_count, 0, 0, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *device, UINT start_idx, UINT index_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->stateBlock->state.index_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* D3D9 returns D3DERR_INVALIDCALL when DrawIndexedPrimitive is called
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * without an index buffer set. (The first time at least...)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * D3D8 simply dies, but I doubt it can do much harm to return
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * D3DERR_INVALIDCALL there as well. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Called without a valid index buffer set, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->stateBlock->state.vertex_declaration)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Called without a valid vertex declaration set.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX] &&
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.load_base_vertex_index != device->stateBlock->state.base_vertex_index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.load_base_vertex_index = device->stateBlock->state.base_vertex_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_BASEVERTEXINDEX);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_primitive(device, start_idx, index_count, 0, 0, TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_draw_indexed_primitive_instanced(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_idx, UINT index_count, UINT start_instance, UINT instance_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_primitive(device, start_idx, index_count, start_instance, instance_count, TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* This is a helper function for UpdateTexture, there is no UpdateVolume method in D3D. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT device_update_volume(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_volume *src_volume, struct wined3d_volume *dst_volume)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_map_desc src;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_map_desc dst;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, src_volume %p, dst_volume %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, src_volume, dst_volume);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: Implement direct loading into the gl volume instead of using
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * memcpy and dirtification to improve loading performance. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_volume_map(src_volume, &src, NULL, WINED3D_MAP_READONLY)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_volume_map(dst_volume, &dst, NULL, WINED3D_MAP_DISCARD)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_volume_unmap(src_volume);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(dst.data, src.data, dst_volume->resource.size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_volume_unmap(dst_volume);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_volume_unmap(src_volume);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_volume_unmap(src_volume);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_resource_type type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int level_count, i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, src_texture %p, dst_texture %p.\n", device, src_texture, dst_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Verify that the source and destination textures are non-NULL. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!src_texture || !dst_texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination textures must be non-NULL, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (src_texture == dst_texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination are the same object, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Verify that the source and destination textures are the same type. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync type = src_texture->resource.type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (dst_texture->resource.type != type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination have different types, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Check that both textures have the identical numbers of levels. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync level_count = wined3d_texture_get_level_count(src_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_texture_get_level_count(dst_texture) != level_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination have different level counts, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Make sure that the destination texture is loaded. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_texture->texture_ops->texture_preload(dst_texture, SRGB_RGB);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Update every surface level of the texture. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_TEXTURE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *src_surface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *dst_surface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < level_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to update surface, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_CUBE_TEXTURE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *src_surface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *dst_surface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < level_count * 6; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to update surface, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_VOLUME_TEXTURE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < level_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = device_update_volume(device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync volume_from_resource(wined3d_texture_get_sub_resource(src_texture, i)),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync volume_from_resource(wined3d_texture_get_sub_resource(dst_texture, i)));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to update volume, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unsupported texture type %#x.\n", type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_front_buffer_data(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, struct wined3d_surface *dst_surface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, dst_surface %p.\n", device, swapchain_idx, dst_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *texture;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, num_passes %p.\n", device, num_passes);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] == WINED3D_TEXF_NONE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Sampler state %u has minfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_UNSUPPORTEDTEXTUREFILTER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] == WINED3D_TEXF_NONE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Sampler state %u has magfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_UNSUPPORTEDTEXTUREFILTER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture = state->textures[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture || texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Non-filterable texture and mag filter enabled on samper %u, returning E_FAIL\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_POINT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Non-filterable texture and min filter enabled on samper %u, returning E_FAIL\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_NONE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_POINT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Non-filterable texture and mip filter enabled on samper %u, returning E_FAIL\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->render_states[WINED3D_RS_ZENABLE] || state->render_states[WINED3D_RS_ZWRITEENABLE]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || state->render_states[WINED3D_RS_STENCILENABLE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *ds = device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *target = device->fb.render_targets[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(ds && target
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (ds->resource.width < target->resource.width || ds->resource.height < target->resource.height))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Depth stencil is smaller than the color buffer, returning D3DERR_CONFLICTINGRENDERSTATE\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_CONFLICTINGRENDERSTATE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* return a sensible default */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *num_passes = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("returning D3D_OK\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_software_vertex_processing(struct wined3d_device *device, BOOL software)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, software %#x.\n", device, software);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!warned)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, software %#x stub!\n", device, software);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->softwareVertexProcessing = software;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL CDECL wined3d_device_get_software_vertex_processing(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!warned)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p stub!\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->softwareVertexProcessing;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_raster_status(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, struct wined3d_raster_status *raster_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, raster_status %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, swapchain_idx, raster_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_swapchain_get_raster_status(swapchain, raster_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, segments %.8e.\n", device, segments);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (segments != 0.0f)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!warned)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, segments %.8e stub!\n", device, segments);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncfloat CDECL wined3d_device_get_npatch_mode(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static BOOL warned;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!warned)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p stub!\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync warned = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *src_surface, const RECT *src_rect,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *dst_surface, const POINT *dst_point)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %s.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, src_surface, wine_dbgstr_rect(src_rect),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_surface, wine_dbgstr_point(dst_point));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (src_surface->resource.pool != WINED3D_POOL_SYSTEM_MEM || dst_surface->resource.pool != WINED3D_POOL_DEFAULT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("source %p must be SYSTEMMEM and dest %p must be DEFAULT, returning WINED3DERR_INVALIDCALL\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync src_surface, dst_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return surface_upload_from_surface(dst_surface, dst_point, src_surface, src_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_color_fill(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *surface, const RECT *rect, const struct wined3d_color *color)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT r;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, surface %p, rect %s, color {%.8e, %.8e, %.8e, %.8e}.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, surface, wine_dbgstr_rect(rect),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync color->r, color->g, color->b, color->a);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (surface->resource.pool != WINED3D_POOL_DEFAULT && surface->resource.pool != WINED3D_POOL_SYSTEM_MEM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Color-fill not allowed on %s surfaces.\n", debug_d3dpool(surface->resource.pool));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(&r, 0, 0, surface->resource.width, surface->resource.height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync rect = &r;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return surface_color_fill(surface, rect, color);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = rendertarget_view->resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (resource->type != WINED3D_RTYPE_SURFACE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Only supported on surface resources\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(&rect, 0, 0, resource->width, resource->height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = surface_color_fill(surface_from_resource(resource), &rect, color);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr)) ERR("Color fill failed, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_surface * CDECL wined3d_device_get_render_target(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT render_target_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, render_target_idx %u.\n", device, render_target_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target_idx >= device->adapter->gl_info.limits.buffers)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->fb.render_targets[render_target_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_surface * CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_render_target(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT render_target_idx, struct wined3d_surface *render_target, BOOL set_viewport)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *prev;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, render_target_idx %u, render_target %p, set_viewport %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, render_target_idx, render_target, set_viewport);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target_idx >= device->adapter->gl_info.limits.buffers)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Render target 0 can't be set to NULL. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!render_target && !render_target_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Trying to set render target 0 to NULL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target && !(render_target->resource.usage & WINED3DUSAGE_RENDERTARGET))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Surface %p doesn't have render target usage.\n", render_target);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Set the viewport and scissor rectangles, if requested. Tests show that
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * stateblock recording is ignored, the change goes directly into the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * primary stateblock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!render_target_idx && set_viewport)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.x = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.y = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.width = render_target->resource.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.height = render_target->resource.height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.min_z = 0.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.max_z = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VIEWPORT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.top = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.left = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.right = render_target->resource.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.bottom = render_target->resource.height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SCISSORRECT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
35dfd86e4de7b13cc0bc6dedfd6900b898c52c82vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->fb.render_targets[render_target_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_incref(render_target);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[render_target_idx] = render_target;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release after the assignment, to prevent device_resource_released()
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * from seeing the surface as still in use. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_FRAMEBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_depth_stencil(struct wined3d_device *device, struct wined3d_surface *depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *prev = device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, depth_stencil %p, old depth_stencil %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, depth_stencil, prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev == depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Trying to do a NOP SetRenderTarget operation.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || prev->flags & SFLAG_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_modify_ds_location(prev, SFLAG_DISCARDED,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev->resource.width, prev->resource.height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev == device->onscreen_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(device->onscreen_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->onscreen_depth_stencil = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.depth_stencil = depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_incref(depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!prev != !depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Swapping NULL / non NULL depth stencil affects the depth and tests */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (prev && prev->resource.format->depth_size != depth_stencil->resource.format->depth_size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(prev);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_FRAMEBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_image)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, x_hotspot %u, y_hotspot %u, cursor_image %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, x_hotspot, y_hotspot, cursor_image);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* some basic validation checks */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->cursorTexture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->cursorTexture = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursor_image)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_display_mode mode;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_map_desc map_desc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* MSDN: Cursor must be A8R8G8B8 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursor_image->resource.format->id != WINED3DFMT_B8G8R8A8_UNORM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("surface %p has an invalid format.\n", cursor_image);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d, device->adapter->ordinal, &mode, NULL)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to get display mode, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* MSDN: Cursor must be smaller than the display mode */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursor_image->resource.width > mode.width || cursor_image->resource.height > mode.height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Surface %p dimensions are %ux%u, but screen dimensions are %ux%u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursor_image, cursor_image->resource.width, cursor_image->resource.height,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mode.width, mode.height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: MSDN: Cursor sizes must be a power of 2 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Do not store the surface's pointer because the application may
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * release it after setting the cursor image. Windows doesn't
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * addref the set surface, so we can't do this either without
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * creating circular refcount dependencies. Copy out the gl texture
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * instead. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->cursorWidth = cursor_image->resource.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->cursorHeight = cursor_image->resource.height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (SUCCEEDED(wined3d_surface_map(cursor_image, &map_desc, NULL, WINED3D_MAP_READONLY)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_format *format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync char *mem, *bits = map_desc.data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLint intfmt = format->glInternal;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLint gl_format = format->glFormat;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLint type = format->glType;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync INT height = device->cursorHeight;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync INT width = device->cursorWidth;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync INT bpp = format->byte_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync INT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Reformat the texture memory (pitch and width can be
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * different) */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mem = HeapAlloc(GetProcessHeap(), 0, width * height * bpp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < height; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&mem[width * bpp * i], &bits[map_desc.row_pitch * i], width * bpp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_unmap(cursor_image);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[APPLE_CLIENT_STORAGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync invalidate_active_texture(device, context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Create a new cursor texture */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glGenTextures");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_bind_texture(context, GL_TEXTURE_2D, device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Copy the bitmap memory into the cursor texture */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, intfmt, width, height, 0, gl_format, type, mem);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glTexImage2D");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, mem);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[APPLE_CLIENT_STORAGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("A cursor texture was not returned.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->cursorTexture = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursor_image->resource.width == 32 && cursor_image->resource.height == 32)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT mask_size = cursor_image->resource.width * cursor_image->resource.height / 8;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ICONINFO cursorInfo;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD *maskBits;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HCURSOR cursor;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* 32-bit user32 cursors ignore the alpha channel if it's all
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * zeroes, and use the mask instead. Fill the mask with all ones
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to ensure we still get a fully transparent cursor. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync maskBits = HeapAlloc(GetProcessHeap(), 0, mask_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(maskBits, 0xff, mask_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_map(cursor_image, &map_desc, NULL,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("width: %u height: %u.\n", cursor_image->resource.width, cursor_image->resource.height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.fIcon = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.xHotspot = x_hotspot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.yHotspot = y_hotspot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.hbmMask = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 1, 1, maskBits);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.hbmColor = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 1, 32, map_desc.data);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_unmap(cursor_image);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Create our cursor and clean up. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursor = CreateIconIndirect(&cursorInfo);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursorInfo.hbmMask) DeleteObject(cursorInfo.hbmMask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursorInfo.hbmColor) DeleteObject(cursorInfo.hbmColor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->hardwareCursor) DestroyCursor(device->hardwareCursor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->hardwareCursor = cursor;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->bCursorVisible) SetCursor( cursor );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, maskBits);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->xHotSpot = x_hotspot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->yHotSpot = y_hotspot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_cursor_position(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int x_screen_space, int y_screen_space, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, x %d, y %d, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, x_screen_space, y_screen_space, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->xScreenSpace = x_screen_space;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->yScreenSpace = y_screen_space;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->hardwareCursor)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync POINT pt;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GetCursorPos( &pt );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (x_screen_space == pt.x && y_screen_space == pt.y)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetCursorPos( x_screen_space, y_screen_space );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Switch to the software cursor if position diverges from the hardware one. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GetCursorPos( &pt );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (x_screen_space != pt.x || y_screen_space != pt.y)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->bCursorVisible) SetCursor( NULL );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DestroyCursor( device->hardwareCursor );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->hardwareCursor = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL CDECL wined3d_device_show_cursor(struct wined3d_device *device, BOOL show)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL oldVisible = device->bCursorVisible;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, show %#x.\n", device, show);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * When ShowCursor is first called it should make the cursor appear at the OS's last
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * known cursor position.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (show && !oldVisible)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync POINT pt;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GetCursorPos(&pt);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->xScreenSpace = pt.x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->yScreenSpace = pt.y;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->hardwareCursor)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->bCursorVisible = show;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (show)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetCursor(device->hardwareCursor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetCursor(NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->cursorTexture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->bCursorVisible = show;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return oldVisible;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource, *cursor;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p.\n", device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Checking resource %p for eviction.\n", resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (resource->pool == WINED3D_POOL_MANAGED && !resource->map_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Evicting %p.\n", resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource->resource_ops->resource_unload(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Invalidate stream sources, the buffer(s) may have been evicted. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_STREAMSRC);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void delete_opengl_contexts(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource, *cursor;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Unloading resource %p.\n", resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource->resource_ops->resource_unload(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(shader, &device->shaders, struct wined3d_shader, shader_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_destroy(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->depth_blt_texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->depth_blt_texture = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->cursorTexture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->cursorTexture = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->blitter->free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync destroy_dummy_textures(device, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (device->context_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_destroy_contexts(device->contexts[0]->swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_destroy(device, device->contexts[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, swapchain->context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->context = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT create_primary_opengl_context(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *target;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate shader private data, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->blitter->alloc_private(device)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate blitter private data, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Recreate the primary swapchain's context */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!swapchain->context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->contexts = HeapAlloc(GetProcessHeap(), 0, sizeof(*device->contexts));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->contexts)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate memory for swapchain context array.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->blitter->free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync target = swapchain->back_buffers ? swapchain->back_buffers[0] : swapchain->front_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(context = context_create(swapchain, target, swapchain->ds_format)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create context.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->blitter->free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, swapchain->context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->contexts);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->context[0] = context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->num_contexts = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync create_dummy_textures(device, context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_swapchain_desc *swapchain_desc, const struct wined3d_display_mode *mode,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_reset_cb callback, BOOL reset_state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource, *cursor;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_display_mode m;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL DisplayModeChanged = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL update_desc = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT backbuffer_width = swapchain_desc->backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT backbuffer_height = swapchain_desc->backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr = WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_desc %p, mode %p, callback %p.\n", device, swapchain_desc, mode, callback);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, 0)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to get the first implicit swapchain.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reset_state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stateblock_unbind_resources(device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->fb.render_targets)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain->back_buffers && swapchain->back_buffers[0])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_render_target(device, 0, swapchain->back_buffers[0], FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_render_target(device, 0, swapchain->front_buffer, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 1; i < device->adapter->gl_info.limits.buffers; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_render_target(device, i, NULL, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_depth_stencil(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->onscreen_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(device->onscreen_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->onscreen_depth_stencil = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reset_state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Enumerating resource %p.\n", resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = callback(resource)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Is it necessary to recreate the gl context? Actually every setting can be changed
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * on an existing gl context, so there's no real need for recreation.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * TODO: Figure out how Reset influences resources in D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEMORY and D3DPOOL_MANAGED
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * TODO: Figure out what happens to explicit swapchains, or if we have more than one implicit swapchain
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("New params:\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("backbuffer_width %u\n", swapchain_desc->backbuffer_width);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("backbuffer_height %u\n", swapchain_desc->backbuffer_height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("backbuffer_format %s\n", debug_d3dformat(swapchain_desc->backbuffer_format));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("backbuffer_count %u\n", swapchain_desc->backbuffer_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("multisample_type %#x\n", swapchain_desc->multisample_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("multisample_quality %u\n", swapchain_desc->multisample_quality);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("swap_effect %#x\n", swapchain_desc->swap_effect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device_window %p\n", swapchain_desc->device_window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("windowed %#x\n", swapchain_desc->windowed);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("enable_auto_depth_stencil %#x\n", swapchain_desc->enable_auto_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->enable_auto_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("auto_depth_stencil_format %s\n", debug_d3dformat(swapchain_desc->auto_depth_stencil_format));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("flags %#x\n", swapchain_desc->flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("refresh_rate %u\n", swapchain_desc->refresh_rate);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("swap_interval %u\n", swapchain_desc->swap_interval);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("auto_restore_display_mode %#x\n", swapchain_desc->auto_restore_display_mode);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No special treatment of these parameters. Just store them */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.swap_effect = swapchain_desc->swap_effect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.flags = swapchain_desc->flags;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.swap_interval = swapchain_desc->swap_interval;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.refresh_rate = swapchain_desc->refresh_rate;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* What to do about these? */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->backbuffer_count
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swapchain_desc->backbuffer_count != swapchain->desc.backbuffer_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Cannot change the back buffer count yet.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->device_window
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swapchain_desc->device_window != swapchain->desc.device_window)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Changing the device window from %p to %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.device_window, swapchain_desc->device_window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.device_window = swapchain_desc->device_window;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->device_window = swapchain_desc->device_window;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_set_window(swapchain, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->enable_auto_depth_stencil && !device->auto_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource_desc surface_desc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Creating the depth stencil buffer\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.format = swapchain_desc->auto_depth_stencil_format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.multisample_type = swapchain_desc->multisample_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.multisample_quality = swapchain_desc->multisample_quality;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.pool = WINED3D_POOL_DEFAULT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.width = swapchain_desc->backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.height = swapchain_desc->backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.depth = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.size = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->device_parent, &surface_desc, &device->auto_depth_stencil)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to create the depth stencil buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Reset the depth stencil */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->enable_auto_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_depth_stencil(device, device->auto_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (mode)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DisplayModeChanged = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m = *mode;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (swapchain_desc->windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync m = swapchain->original_mode;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m.width = swapchain_desc->backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m.height = swapchain_desc->backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m.refresh_rate = swapchain_desc->refresh_rate;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m.format_id = swapchain_desc->backbuffer_format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!backbuffer_width || !backbuffer_height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The application is requesting that either the swapchain width or
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * height be set to the corresponding dimension in the window's
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * client rect. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync RECT client_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!swapchain_desc->windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!GetClientRect(swapchain->device_window, &client_rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to get client rect, last error %#x.\n", GetLastError());
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!backbuffer_width)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backbuffer_width = client_rect.right;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!backbuffer_height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backbuffer_height = client_rect.bottom;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (backbuffer_width != swapchain->desc.backbuffer_width
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || backbuffer_height != swapchain->desc.backbuffer_height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!swapchain_desc->windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DisplayModeChanged = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_width = backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_height = backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync update_desc = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->backbuffer_format != WINED3DFMT_UNKNOWN
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swapchain_desc->backbuffer_format != swapchain->desc.backbuffer_format)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_format = swapchain_desc->backbuffer_format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync update_desc = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->multisample_type != swapchain->desc.multisample_type
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || swapchain_desc->multisample_quality != swapchain->desc.multisample_quality)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_type = swapchain_desc->multisample_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_quality = swapchain_desc->multisample_quality;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync update_desc = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (update_desc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->auto_depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!swapchain_desc->windowed != !swapchain->desc.windowed
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || DisplayModeChanged)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to set display mode, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!swapchain_desc->windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain->desc.windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HWND focus_window = device->create_parms.focus_window;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!focus_window)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync focus_window = swapchain_desc->device_window;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to acquire focus window, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* switch from windowed to fs */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc->backbuffer_width,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc->backbuffer_height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fullscreen -> fullscreen mode change */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync MoveWindow(swapchain->device_window, 0, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc->backbuffer_width,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc->backbuffer_height,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (!swapchain->desc.windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fullscreen -> windowed switch */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_restore_fullscreen_window(device, swapchain->device_window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_release_focus_window(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.windowed = swapchain_desc->windowed;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (!swapchain_desc->windowed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD style = device->style;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD exStyle = device->exStyle;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* If we're in fullscreen, and the mode wasn't changed, we have to get the window back into
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the right position. Some applications(Battlefield 2, Guild Wars) move it and then call
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Reset to clear up their mess. Guild Wars also loses the device during that.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->style = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->exStyle = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc->backbuffer_width,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_desc->backbuffer_height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->style = style;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->exStyle = exStyle;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reset_state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Resetting stateblock.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_decref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_decref(device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->d3d_initialized)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync delete_opengl_contexts(device, swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note: No parent needed for initial internal stateblock */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Resetting the stateblock failed with error %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created stateblock %p.\n", device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock = device->stateBlock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_incref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stateblock_init_default_state(device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *rt = device->fb.render_targets[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note the min_z / max_z is not reset. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.x = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.y = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.width = rt->resource.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.height = rt->resource.height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VIEWPORT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.top = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.left = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.right = rt->resource.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->scissor_rect.bottom = rt->resource.height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SCISSORRECT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_update_render_to_fbo(swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_update_draw_bindings(swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reset_state && device->d3d_initialized)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = create_primary_opengl_context(device, swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* All done. There is no need to reload resources or shaders, this will happen automatically on the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * first use
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("not supported!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, enable_dialogs %#x.\n", device, enable_dialogs);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!enable_dialogs) FIXME("Dialogs cannot be disabled yet.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_creation_parameters(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device_creation_parameters *parameters)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, parameters %p.\n", device, parameters);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *parameters = device->create_parms;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_gamma_ramp(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, flags %#x, ramp %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, swapchain_idx, flags, ramp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_set_gamma_ramp(swapchain, flags, ramp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, struct wined3d_gamma_ramp *ramp)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain *swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, ramp %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, swapchain_idx, ramp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_get_gamma_ramp(swapchain, ramp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, resource %p.\n", device, resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&device->resources, &resource->resource_list_entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_resource_remove(struct wined3d_device *device, struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, resource %p.\n", device, resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_remove(&resource->resource_list_entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_resource_type type = resource->type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, resource %p, type %s.\n", device, resource, debug_d3dresourcetype(type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_resource_released(device, resource, type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_SURFACE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *surface = surface_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->d3d_initialized) break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->fb.render_targets[i] == surface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Surface %p is still in use as render target %u.\n", surface, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[i] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->fb.depth_stencil == surface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Surface %p is still in use as depth/stencil buffer.\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.depth_stencil = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_TEXTURE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_CUBE_TEXTURE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_VOLUME_TEXTURE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock && device->stateBlock->state.textures[i] == texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Texture %p is still in use by stateblock %p, stage %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture, device->stateBlock, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.textures[i] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->updateStateBlock != device->stateBlock
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock->state.textures[i] == texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Texture %p is still in use by stateblock %p, stage %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture, device->updateStateBlock, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.textures[i] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_RTYPE_BUFFER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer = buffer_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_STREAMS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock && device->stateBlock->state.streams[i].buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer, device->stateBlock, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.streams[i].buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->updateStateBlock != device->stateBlock
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock->state.streams[i].buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer, device->updateStateBlock, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.streams[i].buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock && device->stateBlock->state.index_buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer, device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.index_buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->updateStateBlock != device->stateBlock
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock->state.index_buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer, device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.index_buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Remove the resource from the resourceStore */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_resource_remove(device, resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Resource released.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_surface * CDECL wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, dc %p.\n", device, dc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!dc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (resource->type == WINED3D_RTYPE_SURFACE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *s = surface_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (s->hDC == dc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Found surface %p for dc %p.\n", s, dc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return s;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE surface_alignment, struct wined3d_device_parent *device_parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct fragment_pipeline *fragment_pipeline;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_vertex_pipe_ops *vertex_pipeline;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->ref = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->wined3d = wined3d;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_incref(device->wined3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter = wined3d->adapter_count ? adapter : NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->device_parent = device_parent;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(&device->resources);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(&device->shaders);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->surface_alignment = surface_alignment;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Save the creation parameters. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.adapter_idx = adapter_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.device_type = device_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.focus_window = focus_window;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.flags = flags;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_PROFILE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBOXWINEPROFILE_DRAWPRIM_INIT(&device->DrawPrimProfile);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend = adapter->shader_backend;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vertex_pipeline = adapter->vertex_pipe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fragment_pipeline = adapter->fragment_pipe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (vertex_pipeline->vp_states && fragment_pipeline->states
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && FAILED(hr = compile_state_table(device->StateTable, device->multistate_funcs,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &adapter->gl_info, &adapter->d3d_info, vertex_pipeline,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fragment_pipeline, misc_state_template)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to compile state table, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_decref(device->wined3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->blitter = adapter->blitter;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create stateblock.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_decref(device->wined3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created stateblock %p.\n", device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock = device->stateBlock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_incref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chaches_init(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_invalidate_state(const struct wined3d_device *device, DWORD state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD rep = device->StateTable[state].representative;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE shift;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->context_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = device->contexts[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(isStateDirty(context, rep)) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->dirtyArray[context->numDirtyEntries++] = rep;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->isStateDirty[idx] |= (1 << shift);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The drawable size of a fbo target is the opengl texture size, which is the power of two size. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *width = context->current_rt->pow2Width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *height = context->current_rt->pow2Height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_swapchain *swapchain = context->swapchain;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The drawable size of a backbuffer / aux buffer offscreen target is the size of the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * current context's drawable, which is the size of the back buffer of the swapchain
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the active context belongs to. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *width = swapchain->desc.backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *height = swapchain->desc.backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncLRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->filter_messages)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Filtering message: window %p, message %#x, wparam %#lx, lparam %#lx.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (unicode)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return DefWindowProcW(window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return DefWindowProcA(window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (message == WM_DESTROY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("unregister window %p.\n", window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_unregister_window(window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (InterlockedCompareExchangePointer((void **)&device->focus_window, NULL, window) != window)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Window %p is not the focus window for device %p.\n", window, device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (message == WM_DISPLAYCHANGE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->device_parent->ops->mode_changed(device->device_parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (unicode)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return CallWindowProcW(proc, window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return CallWindowProcA(proc, window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_flush(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* we use only one context, so just acquiring it here should do the job,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * @todo: perhaps we should introduce the mechanism similar to the one used in flush_to_host
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to avoid context acquisition */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync Assert(context->valid);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->gl_info->gl_ops.gl.p_glFlush();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_flush_to_host(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* no context acquisition is needed */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->context_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = device->contexts[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync pVBoxFlushToHost(context->glCtx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_finish(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* we use only one context, so just acquiring it here should do the job,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * @todo: perhaps we should introduce the mechanism similar to the one used in flush_to_host
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to avoid context acquisition */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync Assert(context->valid);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->gl_info->gl_ops.gl.p_glFinish();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsyncHRESULT CDECL wined3d_device_get_host_id(struct wined3d_device *device, int32_t *pid)
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync{
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync int32_t id = pVBoxGetContextId(device->contexts[0]->glCtx);
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync if (!id)
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync {
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync *pid = 0;
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync ERR("pVBoxGetContextId to get id for context 0x%x", device->contexts[0]->glCtx);
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync return E_FAIL;
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync }
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync *pid = id;
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync return WINED3D_OK;
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync#ifdef VBOX_WITH_WINE_FIX_ZEROVERTATTR
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncstatic GLuint zv_value_el_size(GLenum enmzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync{
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync switch (enmzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync case GL_FLOAT:
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync return 4;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync case GL_UNSIGNED_SHORT:
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync case GL_SHORT:
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync return 2;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync case GL_BYTE:
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync case GL_UNSIGNED_BYTE:
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync return 1;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync default:
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync ERR("unexpected value type %#x\n", enmzvValue);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync return 0;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync}
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncstatic void zv_create(struct wined3d_device *device, GLenum enmzvValue, GLuint czvValue, GLuint czvValueElements, const GLvoid *pzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync{
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GLuint cbValel = zv_value_el_size(enmzvValue);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GLuint cbVal = cbValel * czvValueElements;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GLuint cbBuf = cbVal * czvValue;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GLvoid *pvBuf;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GLubyte *pubBuf;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GLuint i;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync /* quickly sort out if we can use the current value */
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync if (device->zvBuffer
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync && device->enmzvValue == enmzvValue
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync && device->czvValue >= czvValue
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync && device->czvValueElements == czvValueElements
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync && !memcmp(pzvValue, &device->zvValue, cbVal))
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync return;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync if (czvValueElements > 4)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync ERR("invalid czvValueElements %d\n", czvValueElements);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync return;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync pvBuf = HeapAlloc(GetProcessHeap(), 0, cbBuf);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync pubBuf = (GLubyte*)pvBuf;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync for (i = 0; i < czvValue; ++i)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync memcpy(pubBuf, pzvValue, cbVal);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync pubBuf += cbVal;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync /* */
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync if (!device->zvBuffer)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glGenBuffersARB(1, &device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync Assert(device->zvBuffer);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync if (device->cbzvBuffer < cbBuf)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBufferDataARB(GL_ARRAY_BUFFER_ARB, cbBuf, pvBuf, GL_DYNAMIC_DRAW_ARB));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync device->cbzvBuffer = cbBuf;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync else
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, cbBuf, pvBuf));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync device->enmzvValue = enmzvValue;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync device->czvValue = czvValue;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync device->czvValueElements = czvValueElements;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync memcpy(&device->zvValue, pzvValue, cbVal);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync HeapFree(GetProcessHeap(), 0, pvBuf);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync}
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncvoid zv_destroy(struct wined3d_device *device)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync{
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync if (device->zvBuffer)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glDeleteBuffersARB(1, &device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync device->zvBuffer = 0;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync device->cbzvBuffer = 0;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync}
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncvoid zv_bind(struct wined3d_context *context, GLenum enmzvValue, GLuint czvValue, GLuint czvValueElements, GLboolean bzvNormalized, const GLvoid *pzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync{
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync struct wined3d_device *device = context->swapchain->device;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync const struct wined3d_gl_info *gl_info = context->gl_info;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync zv_create(device, enmzvValue, czvValue, czvValueElements, pzvValue);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync Assert(device->zvBuffer);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glVertexAttribPointerARB(0, czvValueElements,
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync enmzvValue,
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync bzvNormalized,
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync 0, /*stride*/
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync NULL /*addr*/));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync if (!(context->numbered_array_mask & (1 << 0)))
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync {
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glEnableVertexAttribArrayARB(0));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync context->numbered_array_mask |= (1 << 0);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync }
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync}
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncvoid zv_bind_by_element(struct wined3d_context *context, const struct wined3d_stream_info_element *element, GLuint czvValue, const GLvoid *pzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync{
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync zv_bind(context, element->format->gl_vtx_type, czvValue, element->format->gl_vtx_format, element->format->gl_normalized, pzvValue);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync}
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync#endif