static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const void *data) { const struct wined3d_cs_set_depth_stencil_view *op = data; struct wined3d_device *device = cs->device; struct wined3d_rendertarget_view *prev; if ((prev = cs->state.fb->depth_stencil)) { struct wined3d_surface *prev_surface = wined3d_rendertarget_view_get_surface(prev); if (prev_surface && (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || prev_surface->flags & SFLAG_DISCARD)) { surface_modify_ds_location(prev_surface, WINED3D_LOCATION_DISCARDED, prev->width, prev->height); if (prev_surface == device->onscreen_depth_stencil) { wined3d_surface_decref(device->onscreen_depth_stencil); device->onscreen_depth_stencil = NULL; } } } cs->fb.depth_stencil = op->view; if (!prev != !op->view) { /* Swapping NULL / non NULL depth stencil affects the depth and tests */ device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } else if (prev && (prev->format_flags & WINED3DFMT_FLAG_FLOAT) != (op->view->format_flags & WINED3DFMT_FLAG_FLOAT)) { device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } device_invalidate_state(device, STATE_FRAMEBUFFER); }
static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in, const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags) { struct wined3d_surface *back_buffer = surface_from_resource( wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0)); const struct wined3d_fb_state *fb = &swapchain->device->fb; const struct wined3d_gl_info *gl_info; struct wined3d_context *context; struct wined3d_surface *front; RECT src_rect, dst_rect; BOOL render_to_fbo; context = context_acquire(swapchain->device, back_buffer); if (!context->valid) { context_release(context); WARN("Invalid context, skipping present.\n"); return; } gl_info = context->gl_info; if (swapchain->device->logo_texture) { struct wined3d_surface *src_surface = surface_from_resource( wined3d_texture_get_sub_resource(swapchain->device->logo_texture, 0)); RECT rect = {0, 0, src_surface->resource.width, src_surface->resource.height}; /* Blit the logo into the upper left corner of the drawable. */ wined3d_surface_blt(back_buffer, &rect, src_surface, &rect, WINEDDBLT_ALPHATEST, NULL, WINED3D_TEXF_POINT); } if (swapchain->device->bCursorVisible && swapchain->device->cursor_texture && !swapchain->device->hardwareCursor) { struct wined3d_surface *cursor = surface_from_resource( wined3d_texture_get_sub_resource(swapchain->device->cursor_texture, 0)); RECT destRect = { swapchain->device->xScreenSpace - swapchain->device->xHotSpot, swapchain->device->yScreenSpace - swapchain->device->yHotSpot, swapchain->device->xScreenSpace + swapchain->device->cursorWidth - swapchain->device->xHotSpot, swapchain->device->yScreenSpace + swapchain->device->cursorHeight - swapchain->device->yHotSpot, }; RECT src_rect = { 0, 0, swapchain->device->cursor_texture->resource.width, swapchain->device->cursor_texture->resource.height }; const RECT clip_rect = {0, 0, back_buffer->resource.width, back_buffer->resource.height}; TRACE("Rendering the software cursor.\n"); if (swapchain->desc.windowed) MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2); if (wined3d_clip_blit(&clip_rect, &destRect, &src_rect)) wined3d_surface_blt(back_buffer, &destRect, cursor, &src_rect, WINEDDBLT_ALPHATEST, NULL, WINED3D_TEXF_POINT); } TRACE("Presenting HDC %p.\n", context->hdc); render_to_fbo = swapchain->render_to_fbo; if (src_rect_in) { src_rect = *src_rect_in; if (!render_to_fbo && (src_rect.left || src_rect.top || src_rect.right != swapchain->desc.backbuffer_width || src_rect.bottom != swapchain->desc.backbuffer_height)) { render_to_fbo = TRUE; } } else { src_rect.left = 0; src_rect.top = 0; src_rect.right = swapchain->desc.backbuffer_width; src_rect.bottom = swapchain->desc.backbuffer_height; } if (dst_rect_in) dst_rect = *dst_rect_in; else GetClientRect(swapchain->win_handle, &dst_rect); if (!render_to_fbo && (dst_rect.left || dst_rect.top || dst_rect.right != swapchain->desc.backbuffer_width || dst_rect.bottom != swapchain->desc.backbuffer_height)) render_to_fbo = TRUE; /* Rendering to a window of different size, presenting partial rectangles, * or rendering to a different window needs help from FBO_blit or a textured * draw. Render the swapchain to a FBO in the future. * * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve * all these issues - this fails if the window is smaller than the backbuffer. */ if (!swapchain->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO) { surface_load_location(back_buffer, context, WINED3D_LOCATION_TEXTURE_RGB); surface_invalidate_location(back_buffer, WINED3D_LOCATION_DRAWABLE); swapchain->render_to_fbo = TRUE; swapchain_update_draw_bindings(swapchain); } else { surface_load_location(back_buffer, context, back_buffer->container->resource.draw_binding); } if (swapchain->render_to_fbo) { static unsigned int once; if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP && !once++) FIXME("WINED3D_SWAP_EFFECT_FLIP not implemented.\n"); swapchain_blit(swapchain, context, &src_rect, &dst_rect); } if (swapchain->num_contexts > 1) gl_info->gl_ops.gl.p_glFinish(); /* call wglSwapBuffers through the gl table to avoid confusing the Steam overlay */ gl_info->gl_ops.wgl.p_wglSwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */ TRACE("SwapBuffers called, Starting new frame\n"); /* FPS support */ if (TRACE_ON(fps)) { DWORD time = GetTickCount(); ++swapchain->frames; /* every 1.5 seconds */ if (time - swapchain->prev_time > 1500) { TRACE_(fps)("%p @ approx %.2ffps\n", swapchain, 1000.0 * swapchain->frames / (time - swapchain->prev_time)); swapchain->prev_time = time; swapchain->frames = 0; } } front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)); surface_validate_location(front, WINED3D_LOCATION_DRAWABLE); surface_invalidate_location(front, ~WINED3D_LOCATION_DRAWABLE); /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM * and INTEXTURE copies can keep their old content if they have any defined content. * If the swapeffect is COPY, the content remains the same. * * The FLIP swap effect is not implemented yet. We could mark WINED3D_LOCATION_DRAWABLE * up to date and hope WGL flipped front and back buffers and read this data into * the FBO. Don't bother about this for now. */ if (fb->depth_stencil) { struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(fb->depth_stencil); if (ds && (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || ds->flags & SFLAG_DISCARD)) { surface_modify_ds_location(ds, WINED3D_LOCATION_DISCARDED, fb->depth_stencil->width, fb->depth_stencil->height); if (ds == swapchain->device->onscreen_depth_stencil) { wined3d_texture_decref(swapchain->device->onscreen_depth_stencil->container); swapchain->device->onscreen_depth_stencil = NULL; } } } context_release(context); }