/* Do not call while under the GL lock. */ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, enum wined3d_surface_type surface_type, struct wined3d_device *device, struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops) { const struct wined3d_adapter *adapter = device->adapter; const struct wined3d_format *format; struct wined3d_display_mode mode; BOOL displaymode_set = FALSE; RECT client_rect; HWND window; HRESULT hr; UINT i; if (desc->backbuffer_count > WINED3DPRESENT_BACK_BUFFER_MAX) { FIXME("The application requested %u back buffers, this is not supported.\n", desc->backbuffer_count); return WINED3DERR_INVALIDCALL; } if (desc->backbuffer_count > 1) { FIXME("The application requested more than one back buffer, this is not properly supported.\n" "Please configure the application to use double buffering (1 back buffer) if possible.\n"); } switch (surface_type) { case WINED3D_SURFACE_TYPE_GDI: swapchain->swapchain_ops = &swapchain_gdi_ops; break; case WINED3D_SURFACE_TYPE_OPENGL: swapchain->swapchain_ops = &swapchain_gl_ops; break; default: ERR("Invalid surface type %#x.\n", surface_type); return WINED3DERR_INVALIDCALL; } window = desc->device_window ? desc->device_window : device->create_parms.focus_window; swapchain->device = device; swapchain->parent = parent; swapchain->parent_ops = parent_ops; swapchain->ref = 1; swapchain->win_handle = window; swapchain->device_window = window; wined3d_get_adapter_display_mode(device->wined3d, adapter->ordinal, &mode, NULL); swapchain->orig_width = mode.width; swapchain->orig_height = mode.height; swapchain->orig_fmt = mode.format_id; format = wined3d_get_format(&adapter->gl_info, mode.format_id); GetClientRect(window, &client_rect); if (desc->windowed && (!desc->backbuffer_width || !desc->backbuffer_height || desc->backbuffer_format == WINED3DFMT_UNKNOWN)) { if (!desc->backbuffer_width) { desc->backbuffer_width = client_rect.right; TRACE("Updating width to %u.\n", desc->backbuffer_width); } if (!desc->backbuffer_height) { desc->backbuffer_height = client_rect.bottom; TRACE("Updating height to %u.\n", desc->backbuffer_height); } if (desc->backbuffer_format == WINED3DFMT_UNKNOWN) { desc->backbuffer_format = swapchain->orig_fmt; TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt)); } } swapchain->desc = *desc; swapchain_update_render_to_fbo(swapchain); TRACE("Creating front buffer.\n"); if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent, parent, swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format, WINED3DUSAGE_RENDERTARGET, swapchain->desc.multisample_type, swapchain->desc.multisample_quality, &swapchain->front_buffer))) { WARN("Failed to create front buffer, hr %#x.\n", hr); goto err; } surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_SWAPCHAIN, swapchain); if (surface_type == WINED3D_SURFACE_TYPE_OPENGL) surface_modify_location(swapchain->front_buffer, SFLAG_INDRAWABLE, TRUE); /* MSDN says we're only allowed a single fullscreen swapchain per device, * so we should really check to see if there is a fullscreen swapchain * already. Does a single head count as full screen? */ if (!desc->windowed) { struct wined3d_display_mode mode; /* Change the display settings */ mode.width = desc->backbuffer_width; mode.height = desc->backbuffer_height; mode.format_id = desc->backbuffer_format; mode.refresh_rate = desc->refresh_rate; mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN; if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &mode))) { WARN("Failed to set display mode, hr %#x.\n", hr); goto err; } displaymode_set = TRUE; } if (surface_type == WINED3D_SURFACE_TYPE_OPENGL) { static const enum wined3d_format_id formats[] = { WINED3DFMT_D24_UNORM_S8_UINT, WINED3DFMT_D32_UNORM, WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_D16_UNORM, WINED3DFMT_S1_UINT_D15_UNORM }; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context)); if (!swapchain->context) { ERR("Failed to create the context array.\n"); hr = E_OUTOFMEMORY; goto err; } swapchain->num_contexts = 1; /* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate. * You are able to add a depth + stencil surface at a later stage when you need it. * In order to support this properly in WineD3D we need the ability to recreate the opengl context and * drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new * context, need torecreate shaders, textures and other resources. * * The context manager already takes care of the state problem and for the other tasks code from Reset * can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now. * Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this * issue needs to be fixed. */ for (i = 0; i < (sizeof(formats) / sizeof(*formats)); i++) { swapchain->ds_format = wined3d_get_format(gl_info, formats[i]); swapchain->context[0] = context_create(swapchain, swapchain->front_buffer, swapchain->ds_format); if (swapchain->context[0]) break; TRACE("Depth stencil format %s is not supported, trying next format\n", debug_d3dformat(formats[i])); } if (!swapchain->context[0]) { WARN("Failed to create context.\n"); hr = WINED3DERR_NOTAVAILABLE; goto err; } if (wined3d_settings.offscreen_rendering_mode != ORM_FBO && (!desc->enable_auto_depth_stencil || swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id)) { FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n"); } context_release(swapchain->context[0]); } if (swapchain->desc.backbuffer_count > 0) { swapchain->back_buffers = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->back_buffers) * swapchain->desc.backbuffer_count); if (!swapchain->back_buffers) { ERR("Failed to allocate backbuffer array memory.\n"); hr = E_OUTOFMEMORY; goto err; } for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { TRACE("Creating back buffer %u.\n", i); if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent, parent, swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format, WINED3DUSAGE_RENDERTARGET, swapchain->desc.multisample_type, swapchain->desc.multisample_quality, &swapchain->back_buffers[i]))) { WARN("Failed to create back buffer %u, hr %#x.\n", i, hr); goto err; } surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_SWAPCHAIN, swapchain); } } /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */ if (desc->enable_auto_depth_stencil && surface_type == WINED3D_SURFACE_TYPE_OPENGL) { TRACE("Creating depth/stencil buffer.\n"); if (!device->auto_depth_stencil) { if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent, device->device_parent, swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height, swapchain->desc.auto_depth_stencil_format, WINED3DUSAGE_DEPTHSTENCIL, swapchain->desc.multisample_type, swapchain->desc.multisample_quality, &device->auto_depth_stencil))) { WARN("Failed to create the auto depth stencil, hr %#x.\n", hr); goto err; } surface_set_container(device->auto_depth_stencil, WINED3D_CONTAINER_NONE, NULL); } } wined3d_swapchain_get_gamma_ramp(swapchain, &swapchain->orig_gamma); return WINED3D_OK; err: if (displaymode_set) { DEVMODEW devmode; ClipCursor(NULL); /* Change the display settings */ memset(&devmode, 0, sizeof(devmode)); devmode.dmSize = sizeof(devmode); devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; devmode.dmBitsPerPel = format->byte_count * CHAR_BIT; devmode.dmPelsWidth = swapchain->orig_width; devmode.dmPelsHeight = swapchain->orig_height; ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL); } if (swapchain->back_buffers) { for (i = 0; i < swapchain->desc.backbuffer_count; ++i) { if (swapchain->back_buffers[i]) { surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_NONE, NULL); wined3d_surface_decref(swapchain->back_buffers[i]); } } HeapFree(GetProcessHeap(), 0, swapchain->back_buffers); } if (swapchain->context) { if (swapchain->context[0]) { context_release(swapchain->context[0]); context_destroy(device, swapchain->context[0]); swapchain->num_contexts = 0; } HeapFree(GetProcessHeap(), 0, swapchain->context); } if (swapchain->front_buffer) { surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_NONE, NULL); wined3d_surface_decref(swapchain->front_buffer); } return hr; }
/* Routine common to the draw primitive and draw indexed primitive routines */ void drawPrimitive(IWineD3DDeviceImpl *device, UINT index_count, UINT StartIdx, UINT idxSize, const void *idxData) { const struct wined3d_state *state = &device->stateBlock->state; struct wined3d_context *context; unsigned int i; if (!index_count) return; if (state->render_states[WINED3DRS_COLORWRITEENABLE]) { /* Invalidate the back buffer memory so LockRect will read it the next time */ for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i) { IWineD3DSurfaceImpl *target = device->render_targets[i]; if (target) { surface_load_location(target, SFLAG_INDRAWABLE, NULL); surface_modify_location(target, SFLAG_INDRAWABLE, TRUE); } } } /* Signals other modules that a drawing is in progress and the stateblock finalized */ device->isInDraw = TRUE; context = context_acquire(device, device->render_targets[0]); if (!context->valid) { context_release(context); WARN("Invalid context, skipping draw.\n"); return; } context_apply_draw_state(context, device); if (device->depth_stencil) { /* Note that this depends on the context_acquire() call above to set * context->render_offscreen properly. We don't currently take the * Z-compare function into account, but we could skip loading the * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note * that we never copy the stencil data.*/ DWORD location = context->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN; if (state->render_states[WINED3DRS_ZWRITEENABLE] || state->render_states[WINED3DRS_ZENABLE]) { IWineD3DSurfaceImpl *ds = device->depth_stencil; RECT current_rect, draw_rect, r; if (location == SFLAG_DS_ONSCREEN && ds != device->onscreen_depth_stencil) device_switch_onscreen_ds(device, context, ds); if (ds->flags & location) SetRect(¤t_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy); else SetRectEmpty(¤t_rect); device_get_draw_rect(device, &draw_rect); IntersectRect(&r, &draw_rect, ¤t_rect); if (!EqualRect(&r, &draw_rect)) surface_load_ds_location(ds, context, location); if (state->render_states[WINED3DRS_ZWRITEENABLE]) { surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy); surface_modify_location(ds, SFLAG_INDRAWABLE, TRUE); } } } if ((!context->gl_info->supported[WINED3D_GL_VERSION_2_0] || (!glPointParameteri && !context->gl_info->supported[NV_POINT_SPRITE])) && context->render_offscreen && state->render_states[WINED3DRS_POINTSPRITEENABLE] && state->gl_primitive_type == GL_POINTS) { FIXME("Point sprite coordinate origin switching not supported.\n"); } /* Ok, we will be updating the screen from here onwards so grab the lock */ ENTER_GL(); { GLenum glPrimType = state->gl_primitive_type; BOOL emulation = FALSE; const struct wined3d_stream_info *stream_info = &device->strided_streams; struct wined3d_stream_info stridedlcl; if (!use_vs(state)) { if (!stream_info->position_transformed && context->num_untracked_materials && state->render_states[WINED3DRS_LIGHTING]) { static BOOL warned; if (!warned) { FIXME("Using software emulation because not all material properties could be tracked\n"); warned = TRUE; } else { TRACE("Using software emulation because not all material properties could be tracked\n"); } emulation = TRUE; } else if (context->fog_coord && state->render_states[WINED3DRS_FOGENABLE]) { /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte * to a float in the vertex buffer */ static BOOL warned; if (!warned) { FIXME("Using software emulation because manual fog coordinates are provided\n"); warned = TRUE; } else { TRACE("Using software emulation because manual fog coordinates are provided\n"); } emulation = TRUE; } if(emulation) { stream_info = &stridedlcl; memcpy(&stridedlcl, &device->strided_streams, sizeof(stridedlcl)); remove_vbos(context->gl_info, state, &stridedlcl); } } if (device->useDrawStridedSlow || emulation) { /* Immediate mode drawing */ if (use_vs(state)) { static BOOL warned; if (!warned) { FIXME("Using immediate mode with vertex shaders for half float emulation\n"); warned = TRUE; } else { TRACE("Using immediate mode with vertex shaders for half float emulation\n"); } drawStridedSlowVs(context->gl_info, state, stream_info, index_count, glPrimType, idxData, idxSize, StartIdx); } else { drawStridedSlow(device, context, stream_info, index_count, glPrimType, idxData, idxSize, StartIdx); } } else if (device->instancedDraw) { /* Instancing emulation with mixing immediate mode and arrays */ drawStridedInstanced(context->gl_info, state, stream_info, index_count, glPrimType, idxData, idxSize, StartIdx); } else { drawStridedFast(glPrimType, index_count, idxSize, idxData, StartIdx); } } /* Finished updating the screen, restore lock */ LEAVE_GL(); for(i = 0; i < device->num_buffer_queries; ++i) { wined3d_event_query_issue(device->buffer_queries[i], device); } if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */ context_release(context); TRACE("Done all gl drawing\n"); /* Control goes back to the device, stateblock values may change again */ device->isInDraw = FALSE; }
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 = swapchain->back_buffers[0]; const struct wined3d_fb_state *fb = &swapchain->device->fb; const struct wined3d_gl_info *gl_info; struct wined3d_context *context; 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; /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */ if (swapchain->device->bCursorVisible && swapchain->device->cursorTexture && !swapchain->device->hardwareCursor) { struct wined3d_surface cursor; 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, }; TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor); /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by * the application because we are only supposed to copy the information out. Using a fake surface * allows us to use the Blitting engine and avoid copying the whole texture -> render target blitting code. */ memset(&cursor, 0, sizeof(cursor)); cursor.resource.ref = 1; cursor.resource.device = swapchain->device; cursor.resource.pool = WINED3D_POOL_SCRATCH; cursor.resource.format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM); cursor.resource.type = WINED3D_RTYPE_SURFACE; cursor.texture_name = swapchain->device->cursorTexture; cursor.texture_target = GL_TEXTURE_2D; cursor.texture_level = 0; cursor.resource.width = swapchain->device->cursorWidth; cursor.resource.height = swapchain->device->cursorHeight; /* The cursor must have pow2 sizes */ cursor.pow2Width = cursor.resource.width; cursor.pow2Height = cursor.resource.height; /* The surface is in the texture */ cursor.flags |= SFLAG_INTEXTURE; /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0, * which is exactly what we want :-) */ if (swapchain->desc.windowed) MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2); wined3d_surface_blt(back_buffer, &destRect, &cursor, NULL, WINEDDBLT_KEYSRC, NULL, WINED3D_TEXF_POINT); } if (swapchain->device->logo_surface) { struct wined3d_surface *src_surface = swapchain->device->logo_surface; 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_KEYSRC, 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, SFLAG_INTEXTURE, NULL); surface_modify_location(back_buffer, SFLAG_INDRAWABLE, FALSE); swapchain->render_to_fbo = TRUE; swapchain_update_draw_bindings(swapchain); } else { surface_load_location(back_buffer, back_buffer->draw_binding, NULL); } if (swapchain->render_to_fbo) { /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer- * window size mismatch is impossible(fullscreen) and src and dst rectangles are * not allowed(they need the COPY swapeffect) * * The DISCARD swap effect is ok as well since any backbuffer content is allowed after * the swap. */ if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP) FIXME("Render-to-fbo with WINED3D_SWAP_EFFECT_FLIP\n"); swapchain_blit(swapchain, context, &src_rect, &dst_rect); } if (swapchain->num_contexts > 1) gl_info->gl_ops.gl.p_glFinish(); SwapBuffers(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; } } /* This is disabled, but the code left in for debug purposes. * * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip, * we can clear it with some ugly color to make bad drawing visible and ease debugging. * The Debug runtime does the same on Windows. However, a few games do not redraw the * screen properly, like Max Payne 2, which leaves a few pixels undefined. * * Tests show that the content of the back buffer after a discard flip is indeed not * reliable, so no game can depend on the exact content. However, it resembles the * old contents in some way, for example by showing fragments at other locations. In * general, the color theme is still intact. So Max payne, which draws rather dark scenes * gets a dark background image. If we clear it with a bright ugly color, the game's * bug shows up much more than it does on Windows, and the players see single pixels * with wrong colors. * (The Max Payne bug has been confirmed on Windows with the debug runtime) */ if (FALSE && swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_DISCARD) { static const struct wined3d_color cyan = {0.0f, 1.0f, 1.0f, 1.0f}; TRACE("Clearing the color buffer with cyan color\n"); wined3d_device_clear(swapchain->device, 0, NULL, WINED3DCLEAR_TARGET, &cyan, 1.0f, 0); } if (!swapchain->render_to_fbo && ((swapchain->front_buffer->flags & SFLAG_INSYSMEM) || (back_buffer->flags & SFLAG_INSYSMEM))) { /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying * Doesn't work with render_to_fbo because we're not flipping */ struct wined3d_surface *front = swapchain->front_buffer; if (front->resource.size == back_buffer->resource.size) { DWORD fbflags; flip_surface(front, back_buffer); /* Tell the front buffer surface that is has been modified. However, * the other locations were preserved during that, so keep the flags. * This serves to update the emulated overlay, if any. */ fbflags = front->flags; surface_modify_location(front, SFLAG_INDRAWABLE, TRUE); front->flags = fbflags; } else { surface_modify_location(front, SFLAG_INDRAWABLE, TRUE); surface_modify_location(back_buffer, SFLAG_INDRAWABLE, TRUE); } } else { surface_modify_location(swapchain->front_buffer, SFLAG_INDRAWABLE, TRUE); /* 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. If it is FLIP however, * the texture / sysmem copy needs to be reloaded from the drawable */ if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP) surface_modify_location(back_buffer, back_buffer->draw_binding, TRUE); } if (fb->depth_stencil) { if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || fb->depth_stencil->flags & SFLAG_DISCARD) { surface_modify_ds_location(fb->depth_stencil, SFLAG_DISCARDED, fb->depth_stencil->resource.width, fb->depth_stencil->resource.height); if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil) { wined3d_surface_decref(swapchain->device->onscreen_depth_stencil); swapchain->device->onscreen_depth_stencil = NULL; } } } context_release(context); }
/* Do not call while under the GL lock. */ static void texture_preload(IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb) { IWineD3DDeviceImpl *device = texture->resource.device; struct wined3d_context *context = NULL; unsigned int i; BOOL srgb_mode; BOOL *dirty; TRACE("texture %p, srgb %#x.\n", texture, srgb); switch (srgb) { case SRGB_RGB: srgb_mode = FALSE; break; case SRGB_BOTH: texture_preload(texture, SRGB_RGB); /* Fallthrough */ case SRGB_SRGB: srgb_mode = TRUE; break; default: srgb_mode = texture->baseTexture.is_srgb; break; } dirty = srgb_mode ? &texture->baseTexture.texture_srgb.dirty : &texture->baseTexture.texture_rgb.dirty; if (!device->isInDraw) { /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture, * thus no danger of recursive calls. */ context = context_acquire(device, NULL); } if (texture->resource.format->id == WINED3DFMT_P8_UINT || texture->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM) { for (i = 0; i < texture->baseTexture.level_count; ++i) { IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[i]; if (palette9_changed(surface)) { TRACE("Reloading surface because the d3d8/9 palette was changed.\n"); /* TODO: This is not necessarily needed with hw palettized texture support. */ surface_load_location(surface, SFLAG_INSYSMEM, NULL); /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ surface_modify_location(surface, SFLAG_INTEXTURE, FALSE); } } } /* If the texture is marked dirty or the srgb sampler setting has changed * since the last load then reload the surfaces. */ if (*dirty) { for (i = 0; i < texture->baseTexture.level_count; ++i) { IWineD3DSurface_LoadTexture((IWineD3DSurface *)texture->baseTexture.sub_resources[i], srgb_mode); } } else { TRACE("Texture %p not dirty, nothing to do.\n", texture); } if (context) context_release(context); /* No longer dirty. */ *dirty = FALSE; }