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 * 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 * 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 * 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
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.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Define the default light parameters as specified by MSDN. */
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 FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL fixed_get_input(BYTE usage, BYTE usage_idx, unsigned int *regnum)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((usage == WINED3D_DECL_USAGE_POSITION || usage == WINED3D_DECL_USAGE_POSITIONT) && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_BLEND_WEIGHT && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_BLEND_INDICES && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_NORMAL && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_PSIZE && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_COLOR && !usage_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_COLOR && usage_idx == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (usage == WINED3D_DECL_USAGE_TEXCOORD && usage_idx < WINED3DDP_MAXTEXCOORD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unsupported input stream [usage=%s, usage_idx=%u]\n", debug_d3ddeclusage(usage), usage_idx);
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 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 unsigned int i;
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 /* Translate the declaration into strided data. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_vertex_declaration_element *element = &declaration->elements[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_state *stream = &state->streams[element->input_slot];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p Element %p (%u of %u)\n", declaration->elements,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Stream %u, buffer %p.\n", element->input_slot, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_get_memory(buffer, &device->adapter->gl_info, &data);
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 WARN_(d3d_perf)("load_base_vertex_index is < 0 (%d), not using VBOs.\n", state->load_base_vertex_index);
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 TRACE("offset %u input_slot %u usage_idx %d\n", element->offset, element->input_slot, element->usage_idx);
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 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 = fixed_get_input(element->usage, element->usage_idx, &idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync "input_slot %u, offset %u, stride %u, format %s, buffer_object %u]\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync debug_d3ddeclusage(element->usage), element->usage_idx, element->input_slot,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element->offset, stride, debug_d3dformat(element->format->id), data.buffer_object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].format = element->format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].offset = element->offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream_info->elements[idx].stream_idx = element->input_slot;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->adapter->gl_info.supported[ARB_VERTEX_ARRAY_BGRA]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Preload the vertex buffers. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0, map = stream_info->use_map; map; map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer = state->streams[element->stream_idx].buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* If the preload dropped the buffer object, update the stream info. */
a1161adeea4a93de6a9370a0a7ab1e58652b365evboxsync buffer->buffer_object != element->data.buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync element->data.addr = buffer_get_sysmem(buffer, &device->adapter->gl_info) + (ptrdiff_t)element->data.addr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->buffer_queries[device->num_buffer_queries++] = buffer->query;
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 struct wined3d_stream_info *stream_info = &device->stream_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("============================= Vertex Declaration =============================\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_stream_info_from_declaration(device, stream_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->vertex_shader && !stream_info->position_transformed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->vertex_declaration->half_float_conv_needed && !stream_info->all_vbo)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using drawStridedSlow with vertex shaders for FLOAT16 conversion.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync slow_mask |= -!gl_info->supported[ARB_VERTEX_ARRAY_BGRA]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync & ((1 << WINED3D_FFP_DIFFUSE) | (1 << WINED3D_FFP_SPECULAR));
1675f41731e9e75ac43352afd2b690c08795b032vboxsync if (((stream_info->position_transformed && !device->adapter->d3d_info.xyzrhw)
1675f41731e9e75ac43352afd2b690c08795b032vboxsync || (stream_info->use_map & slow_mask)) && !stream_info->all_vbo)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_preload_texture(const struct wined3d_state *state, unsigned int idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync srgb = state->sampler_states[idx][WINED3D_SAMP_SRGB_TEXTURE] ? SRGB_SRGB : SRGB_RGB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture->texture_ops->texture_preload(texture, srgb);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_preload_textures(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->vertex_shader->reg_maps.sampler_type[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_preload_texture(state, MAX_FRAGMENT_SAMPLERS + i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!device->contexts) new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_context_remove(struct wined3d_device *device, struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Context %p doesn't exist in context array.\n", context);
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/* 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 surface_load_ds_location(device->onscreen_depth_stencil, context, SFLAG_INTEXTURE);
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 wined3d_surface_incref(device->onscreen_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL is_full_clear(const struct wined3d_surface *target, const RECT *draw_rect, const RECT *clear_rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* partial draw rect */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* partial clear rect */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (clear_rect && (clear_rect->left > 0 || clear_rect->top > 0
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 /* 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 /* current_rect ⊇ draw_rect, modify only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* draw_rect ⊇ current_rect, test if we're doing a full clear. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Full clear, modify only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* clear_rect ⊇ draw_rect, modify only. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Full load. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(out_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
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 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 unsigned int i;
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 * 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 for (i = 0; i < rt_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *rt = fb->render_targets[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync target->get_drawable_size(context, &drawable_width, &drawable_height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
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 if (!context_apply_clear_state(context, device, rt_count, fb))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to apply clear state, skipping clear.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Only set the values up once, as they are not changing. */
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 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD location = render_offscreen ? fb->depth_stencil->draw_binding : SFLAG_INDRAWABLE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_modify_ds_location(fb->depth_stencil, location, ds_rect.right, ds_rect.bottom);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < rt_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *rt = fb->render_targets[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_modify_location(rt, rt->draw_binding, TRUE);
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 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 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 /* Now process each rect in turn. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < rect_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note that GL uses lower left, width/height. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IntersectRect(¤t_rect, draw_rect, &clear_rect[i]);
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 TRACE("Rectangle with negative dimensions, ignoring.\n");
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 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 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. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_device_incref(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&device->ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", device, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_device_decref(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&device->ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", device, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_stateblock_decref(device->updateStateBlock)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the update stateblock.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the stateblock.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Device released with resources still bound, acceptable but unexpected.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Leftover resource %p with type %s (%#x).\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource, debug_d3dresourcetype(resource->type), resource->type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncUINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_swapchain * CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u.\n", device, swapchain_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_load_logo(struct wined3d_device *device, const char *filename)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hbm = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Create a 32x32 white surface to indicate that wined3d is used, but the specified image
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * couldn't be loaded
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 ERR("Wine logo requested, but failed to create surface, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_surface_getdc(device->logo_surface, &dcs)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BitBlt(dcs, 0, 0, bm.bmWidth, bm.bmHeight, dcb, 0, 0, SRCCOPY);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_releasedc(device->logo_surface, dcs);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_set_color_key(device->logo_surface, WINEDDCKEY_SRCBLT, &color_key);
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/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void create_dummy_textures(struct wined3d_device *device, struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
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 /* 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 count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Make appropriate texture active */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_2d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy 2D texture %u given name %u.\n", i, device->dummy_texture_2d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy rectangle texture %u given name %u.\n", i, device->dummy_texture_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_3d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy 3D texture %u given name %u.\n", i, device->dummy_texture_3d[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]);
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 gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_cube[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dummy cube texture %u given name %u.\n", i, device->dummy_texture_cube[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++j)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glTexImage2D(j, 0, GL_RGBA8, 1, 1, 0,
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/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void destroy_dummy_textures(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_cube);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_cube)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_3d)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_rect)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_2d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteTextures(count, device->dummy_texture_2d)");
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 /* Make sure the window is managed, otherwise we won't get keyboard input. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Filter out window decorations. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_setup_fullscreen_window(struct wined3d_device *device, HWND window, UINT w, UINT h)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting up window %p for fullscreen mode.\n", window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowPos(window, HWND_TOPMOST, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window)
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 TRACE("Restoring window style of window %p to %08x, %08x.\n",
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 SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Delete the old values. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedExchangePointer((void **)&device->focus_window, window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->focus_window) wined3d_unregister_window(device->focus_window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedExchangePointer((void **)&device->focus_window, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
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 TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*device->fb.render_targets) * gl_info->limits.buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Initialize the texture unit mapping to a 1:1 mapping */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (state = 0; state < MAX_COMBINED_SAMPLERS; ++state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->texUnitMap[state] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->rev_tex_unit_map[state] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Shader private data couldn't be allocated\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->blitter->alloc_private(device)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Blitter private data couldn't be allocated\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Setup the implicit swapchain. This also initializes a context. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = device->device_parent->ops->create_swapchain(device->device_parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain->back_buffers && swapchain->back_buffers[0])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting rendertarget to %p.\n", swapchain->back_buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[0] = swapchain->back_buffers[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting rendertarget to %p.\n", swapchain->front_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.render_targets[0] = swapchain->front_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_incref(device->fb.render_targets[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Depth Stencil support */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fb.depth_stencil = device->auto_depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Set up some starting GL setup */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Setup all the devices defaults */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, swapchain->front_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using auxiliary buffer for offscreen rendering\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using back buffer for offscreen rendering\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("All defaults now set up, leaving 3D init.\n");
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 HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_desc %p.\n", device, swapchain_desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Setup the implicit swapchain */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = device->device_parent->ops->create_swapchain(device->device_parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->swapchains = HeapAlloc(GetProcessHeap(), 0, device->swapchain_count * sizeof(*device->swapchains));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBOXWINEPROFILE_DRAWPRIM_TERM(&device->DrawPrimProfile);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Force making the context current again, to verify it is still valid
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * (workaround for broken drivers) */
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 /* Unload resources */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Delete the mouse cursor texture */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->cursorTexture);
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 gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Destroy the shader backend. Note that this has to happen after all shaders are destroyed. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release the buffers (with sanity checks)*/
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Releasing depth/stencil buffer %p.\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Something's still holding the auto depth stencil buffer (%p).\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_render_target(device, i, NULL, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Releasing the render target at %p\n", surface);
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 HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_uninit_gdi(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
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/* 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 * There is no way to deactivate thread safety once it is enabled.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_multithreaded(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* For now just store the flag (needed in case of ddraw). */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->create_parms.flags |= WINED3DCREATE_MULTITHREADED;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncUINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (device->adapter->TextureRam - device->adapter->UsedTextureRam) / (1024 * 1024));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->adapter->TextureRam - device->adapter->UsedTextureRam;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_stream_output(struct wined3d_device *device, UINT idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p, offset %u.\n", device, idx, buffer, offset);
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 InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev_buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_stream_output(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, offset %p.\n", device, idx, offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *offset = device->stateBlock->state.stream_output[idx].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.stream_output[idx].buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_stream_source(struct wined3d_device *device, UINT stream_idx,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer, UINT offset, UINT stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Stream index %u out of range.\n", stream_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Offset %u is not 4 byte aligned.\n", offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->updateStateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.streamSource |= 1 << stream_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old values over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev_buffer->resource.bind_count);
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 TRACE("device %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Stream index %u out of range.\n", stream_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->stateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT divider)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, divider %#x.\n", device, stream_idx, divider);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Verify input. At least in d3d9 this is invalid. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && (divider & WINED3DSTREAMSOURCE_INDEXEDDATA))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("INSTANCEDATA and INDEXEDDATA were set, returning D3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && !stream_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("INSTANCEDATA used on stream 0, returning D3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Divider is 0, returning D3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->updateStateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream->flags = divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.streamFreq |= 1 << stream_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stream->frequency != old_freq || stream->flags != old_flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_stream_source_freq(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stream_idx %u, divider %p.\n", device, stream_idx, divider);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stream = &device->updateStateBlock->state.streams[stream_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_transform(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_transform_state d3dts, const struct wined3d_matrix *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 /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.transform[d3dts >> 5] |= 1 << (d3dts & 0x1f);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.transforms[d3dts] = *matrix;
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 * 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 TRACE("The application is setting the same matrix over again.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.transforms[d3dts] = *matrix;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (d3dts < WINED3D_TS_WORLD_MATRIX(device->adapter->gl_info.limits.blends))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TRANSFORM(d3dts));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_transform(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_transform_state state, struct wined3d_matrix *matrix)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *matrix = device->stateBlock->state.transforms[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_multiply_transform(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_transform_state state, const struct wined3d_matrix *matrix)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s, matrix %p.\n", device, debug_d3dtstype(state), matrix);
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 mat = &device->updateStateBlock->state.transforms[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Apply change via set transform - will reapply to eg. lights this way. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_transform(device, state, &temp);
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 TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Check the parameter range. Need for speed most wanted sets junk lights
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * which confuse the GL driver. */
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 WARN("Attenuation is negative, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Ignores attenuation */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Light type out of range, returning WINED3DERR_INVALIDCALL\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&device->updateStateBlock->state.light_map[hash_idx], &object->entry);
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->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 /* Update the live definitions if the light is currently assigned a glIndex. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (object->glIndex != -1 && !device->isRecordingState)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_ACTIVELIGHT(object->glIndex));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Save away the information. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Position */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* FIXME: Range */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Direction */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Position */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Direction */
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 /* 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 rho = light->theta + (light->phi - light->theta) / (2 * light->falloff);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* FIXME: Range */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unrecognized light type %#x.\n", light->type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_light(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->stateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light information requested but light not defined\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UINT light_idx, BOOL enable)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, enable %#x.\n", device, light_idx, enable);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->updateStateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Special case - enabling an undefined light creates one with a strict set of parameters. */
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 /* 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 light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Adding default lights has failed dismally\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_ACTIVELIGHT(light_info->glIndex));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.lights[light_info->glIndex] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Find a free GL light. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.lights[i] = light_info;
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 * TODO: Test how this affects rendering. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* i == light_info->glIndex */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_ACTIVELIGHT(i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, light_idx %u, enable %p.\n", device, light_idx, enable);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH(e, &device->stateBlock->state.light_map[hash_idx])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync light_info = LIST_ENTRY(e, struct wined3d_light_info, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Light enabled state requested but light not defined.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* true is 128 according to SetLightEnable */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Validate plane_idx. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application has requested clipplane this device doesn't support.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.clipplane |= 1 << plane_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!memcmp(&device->updateStateBlock->state.clip_planes[plane_idx], plane, sizeof(*plane)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting old values over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.clip_planes[plane_idx] = *plane;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_CLIPPLANE(plane_idx));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_clip_plane(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Validate plane_idx. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (plane_idx >= device->adapter->gl_info.limits.clipplanes)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application has requested clipplane this device doesn't support.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *plane = device->stateBlock->state.clip_planes[plane_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_clip_status(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, clip_status %p stub!\n", device, clip_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_clip_status(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, clip_status %p stub!\n", device, clip_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_material(struct wined3d_device *device, const struct wined3d_material *material)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, material %p.\n", device, material);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.material = *material;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_material(const struct wined3d_device *device, struct wined3d_material *material)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, material %p.\n", device, material);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *material = device->updateStateBlock->state.material;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_index_buffer(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer, enum wined3d_format_id format_id)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev_buffer = device->updateStateBlock->state.index_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.index_buffer = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.index_format = format_id;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedDecrement(&prev_buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_index_buffer(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device, INT base_index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, base_index %d.\n", device, base_index);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.base_vertex_index = base_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncINT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.base_vertex_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_viewport(struct wined3d_device *device, const struct wined3d_viewport *viewport)
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 device->updateStateBlock->state.viewport = *viewport;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_viewport(const struct wined3d_device *device, struct wined3d_viewport *viewport)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, viewport %p.\n", device, viewport);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void resolve_depth_buffer(struct wined3d_state *state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *texture = state->textures[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture || texture->resource.type != WINED3D_RTYPE_TEXTURE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || !(texture->resource.format->flags & WINED3DFMT_FLAG_DEPTH))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface = surface_from_resource(texture->sub_resources[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_blt(surface, NULL, depth_stencil, NULL, 0, NULL, WINED3D_TEXF_POINT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_render_state(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD old_value = device->stateBlock->state.render_states[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s (%#x), value %#x.\n", device, debug_d3drenderstate(state), state, value);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.renderState[state >> 5] |= 1 << (state & 0x1f);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.render_states[state] = value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Compared here and not before the assignment to allow proper stateblock recording. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old value over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state == WINED3D_RS_POINTSIZE && value == WINED3D_RESZ_CODE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("RESZ multisampled depth buffer resolve triggered.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_device_get_render_state(const struct wined3d_device *device, enum wined3d_render_state state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, state %s (%#x).\n", device, debug_d3drenderstate(state), state);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.render_states[state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_sampler_state(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT sampler_idx, enum wined3d_sampler_state state, DWORD value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, sampler_idx %u, state %s, value %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, sampler_idx, debug_d3dsamplerstate(state), value);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= sizeof(device->stateBlock->state.sampler_states)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync / sizeof(*device->stateBlock->state.sampler_states))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return; /* Windows accepts overflowing this array ... we do not. */
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 /* Handle recording of state blocks. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old value over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(sampler_idx));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_device_get_sampler_state(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT sampler_idx, enum wined3d_sampler_state state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, sampler_idx, debug_d3dsamplerstate(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (sampler_idx >= sizeof(device->stateBlock->state.sampler_states)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync / sizeof(*device->stateBlock->state.sampler_states))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0; /* Windows accepts overflowing this array ... we do not. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.sampler_states[sampler_idx][state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_scissor_rect(struct wined3d_device *device, const RECT *rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, rect %s.\n", device, wine_dbgstr_rect(rect));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.scissorRect = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (EqualRect(&device->updateStateBlock->state.scissor_rect, rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("App is setting the old scissor rectangle over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync CopyRect(&device->updateStateBlock->state.scissor_rect, rect);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SCISSORRECT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *rect = device->updateStateBlock->state.scissor_rect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning rect %s.\n", wine_dbgstr_rect(rect));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vertex_declaration(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_vertex_declaration *prev = device->updateStateBlock->state.vertex_declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, declaration %p.\n", device, declaration);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vertex_declaration = declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexDecl = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Checked after the assignment to allow proper stateblock recording. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old declaration over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_vertex_declaration * CDECL wined3d_device_get_vertex_declaration(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->stateBlock->state.vertex_declaration;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vertex_shader(struct wined3d_device *device, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *prev = device->updateStateBlock->state.vertex_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vertex_shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexShader = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old shader over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * CDECL wined3d_device_get_vertex_shader(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vs_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vs_cb[idx] = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_vs_cb(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_vs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.vs_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.vs_sampler[idx] = sampler;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_sampler * CDECL wined3d_device_get_vs_sampler(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_vs_consts_b(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
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 for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexShaderConstantsB |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_vs_consts_b(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.vs_consts_b[start_register], count * sizeof(BOOL));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_vs_consts_i(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
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 for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.vertexShaderConstantsI |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_vs_consts_i(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.vs_consts_i[start_register * 4], count * sizeof(int) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const float *constants, UINT vector4f_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Specifically test start_register > limit to catch MAX_UINT overflows
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * when adding start_register + vector4f_count. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register + vector4f_count > d3d_info->limits.vs_uniform_count
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register > d3d_info->limits.vs_uniform_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.vs_consts_f[start_register * 4],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < vector4f_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_update_float_vertex_constants(device, start_register, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_VERTEXSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->updateStateBlock->changed.vertexShaderConstantsF + start_register, 1,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*device->updateStateBlock->changed.vertexShaderConstantsF) * vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_vs_consts_f(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, float *constants, UINT vector4f_count)
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 TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.vs_consts_f[start_register * 4], count * sizeof(float) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_invalidate_texture_stage(const struct wined3d_device *device, DWORD stage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, i));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_stage(struct wined3d_device *device, DWORD stage, DWORD unit)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_update_fixed_function_usage_map(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_TEXTURES; ++i)
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 /* Not used, and disable higher stages. */
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_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_op == WINED3D_TOP_MULTIPLY_ADD || alpha_op == WINED3D_TOP_LERP)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((color_op == WINED3D_TOP_BUMPENVMAP || color_op == WINED3D_TOP_BUMPENVMAP_LUMINANCE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fixed_function_usage_map |= (1 << (i + 1));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_fixed_function_samplers(struct wined3d_device *device, const struct wined3d_d3d_info *d3d_info)
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 /* Now work out the mapping */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_psamplers(struct wined3d_device *device, const struct wined3d_d3d_info *d3d_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_sampler_texture_type *sampler_type =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.pixel_shader->reg_maps.sampler_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
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 DWORD current_mapping = device->rev_tex_unit_map[unit];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Not currently used */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (current_mapping == WINED3D_UNMAPPED_STAGE) return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Used by a fragment sampler */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No pixel shader, check fixed function */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return current_mapping >= MAX_TEXTURES || !(device->fixed_function_usage_map & (1 << current_mapping));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Pixel shader, check the shader's sampler map */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Used by a vertex sampler */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return !vshader_sampler_tokens[current_mapping - MAX_FRAGMENT_SAMPLERS];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_map_vsamplers(struct wined3d_device *device, BOOL ps, const struct wined3d_gl_info *gl_info)
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 /* 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 for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->texUnitMap[vsampler_idx] != WINED3D_UNMAPPED_STAGE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Already mapped somewhere */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (start >= 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device_unit_free_for_vs(device, pshader_sampler_type, vshader_sampler_type, start))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(vsampler_idx));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_update_tex_unit_map(struct wined3d_device *device)
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 * 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 device_map_fixed_function_samplers(device, d3d_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_pixel_shader(struct wined3d_device *device, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *prev = device->updateStateBlock->state.pixel_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.pixel_shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.pixelShader = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old shader over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * CDECL wined3d_device_get_pixel_shader(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_ps_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.ps_cb[idx] = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_ps_cb(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_ps_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.ps_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.ps_sampler[idx] = sampler;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_sampler * CDECL wined3d_device_get_ps_sampler(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_ps_consts_b(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
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 for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.pixelShaderConstantsB |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_ps_consts_b(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, BOOL *constants, UINT bool_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(bool_count, MAX_CONST_B - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, bool_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.ps_consts_b[start_register], count * sizeof(BOOL));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_ps_consts_i(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
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 for (i = start_register; i < count + start_register; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.pixelShaderConstantsI |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_ps_consts_i(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, int *constants, UINT vector4i_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT count = min(vector4i_count, MAX_CONST_I - start_register);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4i_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4i_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.ps_consts_i[start_register * 4], count * sizeof(int) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, const float *constants, UINT vector4f_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Specifically test start_register > limit to catch MAX_UINT overflows
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * when adding start_register + vector4f_count. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register + vector4f_count > d3d_info->limits.ps_uniform_count
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || start_register > d3d_info->limits.ps_uniform_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(&device->updateStateBlock->state.ps_consts_f[start_register * 4],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < vector4f_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Set FLOAT constant %u to {%.8e, %.8e, %.8e, %.8e}.\n", start_register + i,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_update_float_pixel_constants(device, start_register, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADERCONSTANT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(device->updateStateBlock->changed.pixelShaderConstantsF + start_register, 1,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*device->updateStateBlock->changed.pixelShaderConstantsF) * vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_ps_consts_f(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_register, float *constants, UINT vector4f_count)
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 TRACE("device %p, start_register %u, constants %p, vector4f_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, start_register, constants, vector4f_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(constants, &device->stateBlock->state.ps_consts_f[start_register * 4], count * sizeof(float) * 4);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_geometry_shader(struct wined3d_device *device, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *prev = device->updateStateBlock->state.geometry_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.geometry_shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_GEOMETRY_SHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * CDECL wined3d_device_get_geometry_shader(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_gs_cb(struct wined3d_device *device, UINT idx, struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, buffer %p.\n", device, idx, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.gs_cb[idx] = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync InterlockedIncrement(&buffer->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_buffer * CDECL wined3d_device_get_gs_cb(const struct wined3d_device *device, UINT idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_gs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, idx %u, sampler %p.\n", device, idx, sampler);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.gs_sampler[idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.gs_sampler[idx] = sampler;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_sampler * CDECL wined3d_device_get_gs_sampler(const struct wined3d_device *device, UINT idx)
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 struct wined3d_matrix mat, proj_mat, view_mat, world_mat;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stream_info->use_map & (1 << WINED3D_FFP_NORMAL))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(stream_info->use_map & (1 << WINED3D_FFP_POSITION)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock->state.render_states[WINED3D_RS_CLIPPING])
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 FIXME("Clipping is broken and disabled for now\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_buffer_map(dest, dwDestIndex * vertex_size, dwCount * vertex_size, &dest_ptr, 0)))
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 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 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 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 /* Get the viewport */
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 numTextures = (DestFVF & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
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 TRACE("In: ( %06.2f %06.2f %06.2f )\n", p[0], p[1], p[2]);
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 /* WARNING: The following things are taken from d3d7 and were not yet checked
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * against d3d8 or d3d9!
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Clipping conditions: From msdn
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 * 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 ( (-rhw -eps < x) && (-rhw -eps < y) && ( -eps < z) &&
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (x <= rhw + eps) && (y <= rhw + eps ) && (z <= rhw + eps) &&
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 * Well, basically it's simply a linear transformation into viewport
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * coordinates
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* That vertex got clipped
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Contrary to OpenGL it is not dropped completely, it just
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * undergoes a different calculation.
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 ( (float *) dest_ptr)[0] = x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ( (float *) dest_ptr)[3] = rhw; /* SIC, see ddraw test! */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((DestFVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += sizeof(float);
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 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 ERR("No diffuse color in source, but destination has one\n");
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 ERR("No specular color in source, but destination has one\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (tex_index = 0; tex_index < numTextures; ++tex_index)
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 ERR("No source texture, but destination requests one\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dest_ptr += GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float));
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 struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
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 FIXME("Output vertex declaration not implemented yet.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Need any context to write to the vbo. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_stream_info_from_declaration(device, &stream_info);
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 * Also apply the start index. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < (sizeof(stream_info.elements) / sizeof(*stream_info.elements)); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
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 hr = process_vertices_strided(device, dst_idx, vertex_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stage, enum wined3d_texture_stage_state state, DWORD value)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stage %u, state %s, value %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, stage, debug_d3dtexturestate(state), value);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Attempting to set stage %u which is higher than the max stage %u, ignoring.\n",
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 /* Checked after the assignments to allow proper stateblock recording. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Application is setting the old value over, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage > device->stateBlock->state.lowest_disabled_stage
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->StateTable[STATE_TEXTURESTAGE(0, state)].representative
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 unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value == WINED3D_TOP_DISABLE && old_value != WINED3D_TOP_DISABLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Previously enabled stage disabled now. Make sure to dirtify
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * all enabled stages above stage, they have to be disabled.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The current stage is dirtified below. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = stage + 1; i < device->stateBlock->state.lowest_disabled_stage; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.lowest_disabled_stage = stage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (value != WINED3D_TOP_DISABLE && old_value == WINED3D_TOP_DISABLE)
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 * 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 if (device->updateStateBlock->state.texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Additionally dirtifying stage %u due to enable.\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.lowest_disabled_stage = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_TEXTURESTAGE(stage, state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_device_get_texture_stage_state(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stage, enum wined3d_texture_stage_state state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->updateStateBlock->state.texture_states[stage][state];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stage %u, texture %p.\n", device, stage, texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Windows accepts overflowing this array... we do not. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= sizeof(device->stateBlock->state.textures) / sizeof(*device->stateBlock->state.textures))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (texture && texture->resource.pool == WINED3D_POOL_SCRATCH)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Rejecting attempt to set scratch texture.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->changed.textures |= 1 << stage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync prev = device->updateStateBlock->state.textures[stage];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("App is setting the same texture again, nothing to do.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.textures[stage] = texture;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LONG bind_count = InterlockedIncrement(&texture->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_PIXELSHADER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!prev && stage < d3d_info->limits.ffp_blend_stages)
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 LONG bind_count = InterlockedDecrement(&prev->resource.bind_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture && stage < d3d_info->limits.ffp_blend_stages)
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 unsigned int i;
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 if (device->updateStateBlock->state.textures[i] == prev)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SAMPLER(stage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_texture * CDECL wined3d_device_get_texture(const struct wined3d_device *device, UINT stage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (stage >= sizeof(device->stateBlock->state.textures) / sizeof(*device->stateBlock->state.textures))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL; /* Windows accepts overflowing this array ... we do not. */
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 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 if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(*backbuffer = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal,
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 TRACE("device %p, swapchain_idx %u, mode %p, rotation %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_swapchain_get_display_mode(swapchain, mode, rotation);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_stateblock_create(device, WINED3D_SBT_RECORDED, &stateblock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_decref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_end_stateblock(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_stateblock *object = device->updateStateBlock;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, stateblock %p.\n", device, stateblock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_incref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_begin_scene(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* At the moment we have no need for any functionality at the beginning
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * of a scene. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Already in scene, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_end_scene(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Not in scene, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We only have to do this if we need to read the, swapbuffers performs a flush for us */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * fails. */
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 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 wined3d_swapchain_present(device->swapchains[i], src_rect,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_rect, dst_window_override, dirty_region, flags);
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 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 WARN("Rects is %p, but rect_count is 0, ignoring clear\n", rects);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *ds = device->fb.depth_stencil;
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 if (ds->resource.width < device->fb.render_targets[0]->resource.width
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ds->resource.height < device->fb.render_targets[0]->resource.height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Silently ignoring depth and target clear with mismatching sizes\n");
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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_primitive_type(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, primitive_type %s\n", device, debug_d3dprimitivetype(primitive_type));
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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_primitive_type(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, primitive_type %p\n", device, primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *primitive_type = d3d_primitive_type_from_gl(device->stateBlock->state.gl_primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning %s\n", debug_d3dprimitivetype(*primitive_type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_draw_primitive(struct wined3d_device *device, UINT start_vertex, UINT vertex_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_vertex %u, vertex_count %u.\n", device, start_vertex, vertex_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Called without a valid vertex declaration set.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock->state.load_base_vertex_index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.load_base_vertex_index = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_BASEVERTEXINDEX);
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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_draw_indexed_primitive(struct wined3d_device *device, UINT start_idx, UINT index_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
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 WARN("Called without a valid vertex declaration set.\n");
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 device->stateBlock->state.load_base_vertex_index = device->stateBlock->state.base_vertex_index;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_BASEVERTEXINDEX);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_primitive(device, start_idx, index_count, 0, 0, TRUE);
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 TRACE("device %p, start_idx %u, index_count %u.\n", device, start_idx, index_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync draw_primitive(device, start_idx, index_count, start_instance, instance_count, TRUE);
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 TRACE("device %p, src_volume %p, dst_volume %p.\n",
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 if (FAILED(hr = wined3d_volume_map(dst_volume, &dst, NULL, WINED3D_MAP_DISCARD)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(dst.data, src.data, dst_volume->resource.size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, src_texture %p, dst_texture %p.\n", device, src_texture, dst_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Verify that the source and destination textures are non-NULL. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination textures must be non-NULL, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination are the same object, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Verify that the source and destination textures are the same type. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Source and destination have different types, returning WINED3DERR_INVALIDCALL.\n");
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 WARN("Source and destination have different level counts, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Make sure that the destination texture is loaded. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_texture->texture_ops->texture_preload(dst_texture, SRGB_RGB);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Update every surface level of the texture. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < level_count; ++i)
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 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 for (i = 0; i < level_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync volume_from_resource(wined3d_texture_get_sub_resource(src_texture, i)),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync volume_from_resource(wined3d_texture_get_sub_resource(dst_texture, i)));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_front_buffer_data(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, struct wined3d_surface *dst_surface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, dst_surface %p.\n", device, swapchain_idx, dst_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, num_passes %p.\n", device, num_passes);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] == WINED3D_TEXF_NONE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Sampler state %u has minfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] == WINED3D_TEXF_NONE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Sampler state %u has magfilter D3DTEXF_NONE, returning D3DERR_UNSUPPORTEDTEXTUREFILTER\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture || texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Non-filterable texture and mag filter enabled on samper %u, returning E_FAIL\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_POINT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Non-filterable texture and min filter enabled on samper %u, returning E_FAIL\n", i);
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 WARN("Non-filterable texture and mip filter enabled on samper %u, returning E_FAIL\n", i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->render_states[WINED3D_RS_ZENABLE] || state->render_states[WINED3D_RS_ZWRITEENABLE]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *ds = device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *target = device->fb.render_targets[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (ds->resource.width < target->resource.width || ds->resource.height < target->resource.height))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Depth stencil is smaller than the color buffer, returning D3DERR_CONFLICTINGRENDERSTATE\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* return a sensible default */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_software_vertex_processing(struct wined3d_device *device, BOOL software)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, software %#x.\n", device, software);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, software %#x stub!\n", device, software);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL CDECL wined3d_device_get_software_vertex_processing(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_get_raster_status(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, struct wined3d_raster_status *raster_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_idx %u, raster_status %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_swapchain_get_raster_status(swapchain, raster_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, segments %.8e.\n", device, segments);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("device %p, segments %.8e stub!\n", device, segments);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncfloat CDECL wined3d_device_get_npatch_mode(const struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0.0f;
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 TRACE("device %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %s.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (src_surface->resource.pool != WINED3D_POOL_SYSTEM_MEM || dst_surface->resource.pool != WINED3D_POOL_DEFAULT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("source %p must be SYSTEMMEM and dest %p must be DEFAULT, returning WINED3DERR_INVALIDCALL\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return surface_upload_from_surface(dst_surface, dst_point, src_surface, src_rect);
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 TRACE("device %p, surface %p, rect %s, color {%.8e, %.8e, %.8e, %.8e}.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (surface->resource.pool != WINED3D_POOL_DEFAULT && surface->resource.pool != WINED3D_POOL_SYSTEM_MEM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Color-fill not allowed on %s surfaces.\n", debug_d3dpool(surface->resource.pool));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync SetRect(&r, 0, 0, surface->resource.width, surface->resource.height);
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 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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_surface * CDECL wined3d_device_get_render_target(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, render_target_idx %u.\n", device, render_target_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target_idx >= device->adapter->gl_info.limits.buffers)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return device->fb.render_targets[render_target_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_surface * CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device)
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 TRACE("device %p, render_target_idx %u, render_target %p, set_viewport %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, render_target_idx, render_target, set_viewport);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target_idx >= device->adapter->gl_info.limits.buffers)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Render target 0 can't be set to NULL. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (render_target && !(render_target->resource.usage & WINED3DUSAGE_RENDERTARGET))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Surface %p doesn't have render target usage.\n", render_target);
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 struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.width = render_target->resource.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync state->viewport.height = render_target->resource.height;
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 prev = device->fb.render_targets[render_target_idx];
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 device_invalidate_state(device, STATE_FRAMEBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_depth_stencil(struct wined3d_device *device, struct wined3d_surface *depth_stencil)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *prev = device->fb.depth_stencil;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, depth_stencil %p, old depth_stencil %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Trying to do a NOP SetRenderTarget operation.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(device->onscreen_depth_stencil);
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 else if (prev && prev->resource.format->depth_size != depth_stencil->resource.format->depth_size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_FRAMEBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_image)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, x_hotspot %u, y_hotspot %u, cursor_image %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* some basic validation checks */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* MSDN: Cursor must be A8R8G8B8 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursor_image->resource.format->id != WINED3DFMT_B8G8R8A8_UNORM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("surface %p has an invalid format.\n", cursor_image);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d, device->adapter->ordinal, &mode, NULL)))
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 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 /* TODO: MSDN: Cursor sizes must be a power of 2 */
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 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 /* 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 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 /* Create a new cursor texture */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glGenTextures(1, &device->cursorTexture);
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 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 if (cursor_image->resource.width == 32 && cursor_image->resource.height == 32)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT mask_size = cursor_image->resource.width * cursor_image->resource.height / 8;
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 WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("width: %u height: %u.\n", cursor_image->resource.width, cursor_image->resource.height);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.hbmMask = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cursorInfo.hbmColor = CreateBitmap(cursor_image->resource.width, cursor_image->resource.height,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Create our cursor and clean up. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursorInfo.hbmMask) DeleteObject(cursorInfo.hbmMask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cursorInfo.hbmColor) DeleteObject(cursorInfo.hbmColor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->hardwareCursor) DestroyCursor(device->hardwareCursor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_set_cursor_position(struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int x_screen_space, int y_screen_space, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (x_screen_space == pt.x && y_screen_space == pt.y)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Switch to the software cursor if position diverges from the hardware one. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (x_screen_space != pt.x || y_screen_space != pt.y)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL CDECL wined3d_device_show_cursor(struct wined3d_device *device, BOOL show)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * When ShowCursor is first called it should make the cursor appear at the OS's last
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * known cursor position.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Checking resource %p for eviction.\n", resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (resource->pool == WINED3D_POOL_MANAGED && !resource->map_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Invalidate stream sources, the buffer(s) may have been evicted. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void delete_opengl_contexts(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(shader, &device->shaders, struct wined3d_shader, shader_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->cursorTexture);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain_destroy_contexts(device->contexts[0]->swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT create_primary_opengl_context(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->shader_backend->shader_alloc_private(device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter->vertex_pipe, device->adapter->fragment_pipe)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate shader private data, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = device->blitter->alloc_private(device)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate blitter private data, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Recreate the primary swapchain's context */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->contexts = HeapAlloc(GetProcessHeap(), 0, sizeof(*device->contexts));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate memory for swapchain context array.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync target = swapchain->back_buffers ? swapchain->back_buffers[0] : swapchain->front_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(context = context_create(swapchain, target, swapchain->ds_format)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_free_private(device);
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 UINT backbuffer_width = swapchain_desc->backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT backbuffer_height = swapchain_desc->backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, swapchain_desc %p, mode %p, callback %p.\n", device, swapchain_desc, mode, callback);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(swapchain = wined3d_device_get_swapchain(device, 0)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to get the first implicit swapchain.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain->back_buffers && swapchain->back_buffers[0])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_render_target(device, 0, swapchain->back_buffers[0], FALSE);
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 wined3d_device_set_render_target(device, i, NULL, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_surface_decref(device->onscreen_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
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 * TODO: Figure out how Reset influences resources in D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEMORY and D3DPOOL_MANAGED
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * TODO: Figure out what happens to explicit swapchains, or if we have more than one implicit swapchain
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("enable_auto_depth_stencil %#x\n", swapchain_desc->enable_auto_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("auto_depth_stencil_format %s\n", debug_d3dformat(swapchain_desc->auto_depth_stencil_format));
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 /* No special treatment of these parameters. Just store them */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.swap_effect = swapchain_desc->swap_effect;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.swap_interval = swapchain_desc->swap_interval;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.refresh_rate = swapchain_desc->refresh_rate;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* What to do about these? */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swapchain_desc->backbuffer_count != swapchain->desc.backbuffer_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Cannot change the back buffer count yet.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swapchain_desc->device_window != swapchain->desc.device_window)
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 if (swapchain_desc->enable_auto_depth_stencil && !device->auto_depth_stencil)
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.width = swapchain_desc->backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_desc.height = swapchain_desc->backbuffer_height;
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 ERR("Failed to create the depth stencil buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Reset the depth stencil */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_set_depth_stencil(device, device->auto_depth_stencil);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync m.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
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 if (!GetClientRect(swapchain->device_window, &client_rect))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to get client rect, last error %#x.\n", GetLastError());
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (backbuffer_width != swapchain->desc.backbuffer_width
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || backbuffer_height != swapchain->desc.backbuffer_height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_width = backbuffer_width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_height = backbuffer_height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->backbuffer_format != WINED3DFMT_UNKNOWN
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swapchain_desc->backbuffer_format != swapchain->desc.backbuffer_format)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.backbuffer_format = swapchain_desc->backbuffer_format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain_desc->multisample_type != swapchain->desc.multisample_type
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || swapchain_desc->multisample_quality != swapchain->desc.multisample_quality)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_type = swapchain_desc->multisample_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.multisample_quality = swapchain_desc->multisample_quality;
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 for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
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 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 if (!swapchain_desc->windowed != !swapchain->desc.windowed
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HWND focus_window = device->create_parms.focus_window;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to acquire focus window, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* switch from windowed to fs */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fullscreen -> fullscreen mode change */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fullscreen -> windowed switch */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_device_restore_fullscreen_window(device, swapchain->device_window);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->desc.windowed = swapchain_desc->windowed;
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 wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_decref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note: No parent needed for initial internal stateblock */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Resetting the stateblock failed with error %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created stateblock %p.\n", device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_incref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *rt = device->fb.render_targets[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_state *state = &device->stateBlock->state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Note the min_z / max_z is not reset. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_SCISSORRECT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = create_primary_opengl_context(device, swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* All done. There is no need to reload resources or shaders, this will happen automatically on the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * first use
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, enable_dialogs %#x.\n", device, enable_dialogs);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!enable_dialogs) FIXME("Dialogs cannot be disabled yet.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_creation_parameters(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device_creation_parameters *parameters)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, parameters %p.\n", device, parameters);
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 TRACE("device %p, swapchain_idx %u, flags %#x, ramp %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_set_gamma_ramp(swapchain, flags, ramp);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT swapchain_idx, struct wined3d_gamma_ramp *ramp)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, resource %p.\n", device, resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&device->resources, &resource->resource_list_entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void device_resource_remove(struct wined3d_device *device, struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, resource %p.\n", device, resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, resource %p, type %s.\n", device, resource, debug_d3dresourcetype(type));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *surface = surface_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Surface %p is still in use as render target %u.\n", surface, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Surface %p is still in use as depth/stencil buffer.\n", surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock && device->stateBlock->state.textures[i] == texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Texture %p is still in use by stateblock %p, stage %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock->state.textures[i] == texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Texture %p is still in use by stateblock %p, stage %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.textures[i] = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer = buffer_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_STREAMS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock && device->stateBlock->state.streams[i].buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->stateBlock->state.streams[i].buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock->state.streams[i].buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.streams[i].buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stateBlock && device->stateBlock->state.index_buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && device->updateStateBlock->state.index_buffer == buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->updateStateBlock->state.index_buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Remove the resource from the resourceStore */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_surface * CDECL wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *s = surface_from_resource(resource);
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 struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_vertex_pipe_ops *vertex_pipeline;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->adapter = wined3d->adapter_count ? adapter : NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Save the creation parameters. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBOXWINEPROFILE_DRAWPRIM_INIT(&device->DrawPrimProfile);
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 ERR("Failed to compile state table, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_stateblock_create(device, WINED3D_SBT_INIT, &device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < sizeof(device->multistate_funcs) / sizeof(device->multistate_funcs[0]); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created stateblock %p.\n", device->stateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_stateblock_incref(device->updateStateBlock);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid device_invalidate_state(const struct wined3d_device *device, DWORD state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD rep = device->StateTable[state].representative;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context->dirtyArray[context->numDirtyEntries++] = rep;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The drawable size of a fbo target is the opengl texture size, which is the power of two size. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height)
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. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncLRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Filtering message: window %p, message %#x, wparam %#lx, lparam %#lx.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return DefWindowProcW(window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return DefWindowProcA(window, message, wparam, lparam);
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 device->device_parent->ops->mode_changed(device->device_parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return CallWindowProcW(proc, window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return CallWindowProcA(proc, window, message, wparam, lparam);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_flush(struct wined3d_device *device)
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);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_flush_to_host(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* no context acquisition is needed */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_device_finish(struct wined3d_device *device)
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);
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsyncHRESULT CDECL wined3d_device_get_host_id(struct wined3d_device *device, int32_t *pid)
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync int32_t id = pVBoxGetContextId(device->contexts[0]->glCtx);
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync ERR("pVBoxGetContextId to get id for context 0x%x", device->contexts[0]->glCtx);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncstatic void zv_create(struct wined3d_device *device, GLenum enmzvValue, GLuint czvValue, GLuint czvValueElements, const GLvoid *pzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync /* quickly sort out if we can use the current value */
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync ERR("invalid czvValueElements %d\n", czvValueElements);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync for (i = 0; i < czvValue; ++i)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBufferDataARB(GL_ARRAY_BUFFER_ARB, cbBuf, pvBuf, GL_DYNAMIC_DRAW_ARB));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, cbBuf, pvBuf));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glDeleteBuffersARB(1, &device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncvoid zv_bind(struct wined3d_context *context, GLenum enmzvValue, GLuint czvValue, GLuint czvValueElements, GLboolean bzvNormalized, const GLvoid *pzvValue)
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync struct wined3d_device *device = context->swapchain->device;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync const struct wined3d_gl_info *gl_info = context->gl_info;
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync zv_create(device, enmzvValue, czvValue, czvValueElements, pzvValue);
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, device->zvBuffer));
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync GL_EXTCALL(glVertexAttribPointerARB(0, czvValueElements,
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsync 0, /*stride*/
0ac83e2abcde6d1badbbeaf979676be588dd64bbvboxsyncvoid zv_bind_by_element(struct wined3d_context *context, const struct wined3d_stream_info_element *element, GLuint czvValue, const GLvoid *pzvValue)