From 49e076eabdfca5d27e3ce8448dc0532e314f0e75 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 3 May 2010 22:03:28 +0200 Subject: [PATCH] wined3d: Separate context acquisition and state application. --- dlls/wined3d/arb_program_shader.c | 7 +++-- dlls/wined3d/basetexture.c | 4 +-- dlls/wined3d/buffer.c | 8 ++--- dlls/wined3d/context.c | 33 ++++---------------- dlls/wined3d/cubetexture.c | 2 +- dlls/wined3d/device.c | 50 ++++++++++++++++--------------- dlls/wined3d/drawprim.c | 7 +++-- dlls/wined3d/glsl_shader.c | 4 +-- dlls/wined3d/query.c | 20 ++++++------- dlls/wined3d/surface.c | 40 ++++++++++++++----------- dlls/wined3d/swapchain.c | 13 ++++---- dlls/wined3d/texture.c | 2 +- dlls/wined3d/volumetexture.c | 2 +- dlls/wined3d/wined3d_private.h | 19 +++++------- 14 files changed, 98 insertions(+), 113 deletions(-) diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index fd719c2749..e79538a5c7 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -4556,7 +4556,7 @@ static void shader_arb_destroy(IWineD3DBaseShader *iface) { if (shader_data->num_gl_shaders) { - struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + struct wined3d_context *context = context_acquire(device, NULL); ENTER_GL(); for (i = 0; i < shader_data->num_gl_shaders; ++i) @@ -4582,7 +4582,7 @@ static void shader_arb_destroy(IWineD3DBaseShader *iface) { if (shader_data->num_gl_shaders) { - struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + struct wined3d_context *context = context_acquire(device, NULL); ENTER_GL(); for (i = 0; i < shader_data->num_gl_shaders; ++i) @@ -6993,7 +6993,8 @@ HRESULT arbfp_blit_surface(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_ surface_internal_preload(src_surface, SRGB_RGB); /* Activate the destination context, set it up for blitting */ - context = context_acquire(device, dst_surface, CTXUSAGE_BLIT); + context = context_acquire(device, dst_surface); + context_apply_blit_state(context, device); /* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates', * while OpenGL coordinates are window relative. diff --git a/dlls/wined3d/basetexture.c b/dlls/wined3d/basetexture.c index 35a78a45fb..0c4f684dcc 100644 --- a/dlls/wined3d/basetexture.c +++ b/dlls/wined3d/basetexture.c @@ -115,7 +115,7 @@ void basetexture_unload(IWineD3DBaseTexture *iface) if (This->baseTexture.texture_rgb.name || This->baseTexture.texture_srgb.name) { - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); } if(This->baseTexture.texture_rgb.name) { @@ -193,7 +193,7 @@ HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DT * Or should we delay the applying until the texture is used for drawing? For now, apply * immediately. */ - struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + struct wined3d_context *context = context_acquire(device, NULL); ENTER_GL(); glBindTexture(textureDimensions, This->baseTexture.texture_rgb.name); diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index a8fc0d18e6..b56895b6b1 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -700,7 +700,7 @@ static void STDMETHODCALLTYPE buffer_UnLoad(IWineD3DBuffer *iface) IWineD3DDeviceImpl *device = This->resource.device; struct wined3d_context *context; - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); /* Download the buffer, but don't permanently enable double buffering */ if(!(This->flags & WINED3D_BUFFER_DOUBLEBUFFER)) @@ -935,7 +935,7 @@ static void STDMETHODCALLTYPE buffer_PreLoad(IWineD3DBuffer *iface) TRACE("iface %p\n", iface); This->flags &= ~(WINED3D_BUFFER_NOSYNC | WINED3D_BUFFER_DISCARD); - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); if (!This->buffer_object) { @@ -1261,7 +1261,7 @@ static HRESULT STDMETHODCALLTYPE buffer_Map(IWineD3DBuffer *iface, UINT offset, IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER); } - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; ENTER_GL(); GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object)); @@ -1367,7 +1367,7 @@ static HRESULT STDMETHODCALLTYPE buffer_Unmap(IWineD3DBuffer *iface) IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER); } - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; ENTER_GL(); GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object)); diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 71030bab72..d1aa3e9af3 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -1977,7 +1977,7 @@ static void context_validate_onscreen_formats(IWineD3DDeviceImpl *device, struct } /* Context activation is done by the caller. */ -static void context_apply_blit_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) +void context_apply_blit_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) { if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { @@ -2015,7 +2015,7 @@ static void context_apply_blit_state(struct wined3d_context *context, IWineD3DDe } /* Context activation is done by the caller. */ -static void context_apply_clear_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) +void context_apply_clear_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) { const struct StateEntry *state_table = device->StateTable; @@ -2054,7 +2054,7 @@ static void context_apply_clear_state(struct wined3d_context *context, IWineD3DD } /* Context activation is done by the caller. */ -static void context_apply_draw_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) +void context_apply_draw_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) { const struct StateEntry *state_table = device->StateTable; unsigned int i; @@ -2186,13 +2186,12 @@ static void context_setup_target(IWineD3DDeviceImpl *device, * usage: Prepares the context for blitting, drawing or other actions * *****************************************************************************/ -struct wined3d_context *context_acquire(IWineD3DDeviceImpl *device, - IWineD3DSurfaceImpl *target, enum ContextUsage usage) +struct wined3d_context *context_acquire(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *target) { struct wined3d_context *current_context = context_get_current(); struct wined3d_context *context; - TRACE("device %p, target %p, usage %#x.\n", device, target, usage); + TRACE("device %p, target %p.\n", device, target); context = FindContext(device, target); context_setup_target(device, context, target); @@ -2227,27 +2226,5 @@ struct wined3d_context *context_acquire(IWineD3DDeviceImpl *device, } } - switch (usage) - { - case CTXUSAGE_BLIT: - context_apply_blit_state(context, device); - break; - - case CTXUSAGE_CLEAR: - context_apply_clear_state(context, device); - break; - - case CTXUSAGE_DRAWPRIM: - context_apply_draw_state(context, device); - break; - - case CTXUSAGE_RESOURCELOAD: - break; - - default: - FIXME("Unexpected context usage requested.\n"); - break; - } - return context; } diff --git a/dlls/wined3d/cubetexture.c b/dlls/wined3d/cubetexture.c index 23b45543e7..12acee2657 100644 --- a/dlls/wined3d/cubetexture.c +++ b/dlls/wined3d/cubetexture.c @@ -67,7 +67,7 @@ static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3 { /* No danger of recursive calls, context_acquire() sets isInDraw to true * when loading offscreen render targets into their texture. */ - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); } if (This->resource.format_desc->format == WINED3DFMT_P8_UINT diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 0c7b4a1191..a59cf02895 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1675,7 +1675,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface, /* Setup all the devices defaults */ IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)This->stateBlock); - context = context_acquire(This, swapchain->front_buffer, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, swapchain->front_buffer); create_dummy_textures(This); @@ -1806,7 +1806,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface, /* I don't think that the interface guarantees that the device is destroyed from the same thread * it was created. Thus make sure a context is active for the glDelete* calls */ - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); gl_info = context->gl_info; if(This->logo_surface) IWineD3DSurface_Release(This->logo_surface); @@ -3911,7 +3911,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ProcessVertices(IWineD3DDevice *iface, } /* Need any context to write to the vbo. */ - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); /* ProcessVertices reads from vertex buffers, which have to be assigned. DrawPrimitive and DrawPrimitiveUP * control the streamIsUP flag, thus restore it afterwards. @@ -4324,7 +4324,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndScene(IWineD3DDevice *iface) return WINED3DERR_INVALIDCALL; } - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); /* We only have to do this if we need to read the, swapbuffers performs a flush for us */ wglFlush(); /* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever @@ -4457,7 +4457,15 @@ HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfac IWineD3DSurface_LoadLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, NULL); } - context = context_acquire(This, target, CTXUSAGE_CLEAR); + context = context_acquire(This, target); + if (!context->valid) + { + context_release(context); + WARN("Invalid context, skipping clear.\n"); + return WINED3D_OK; + } + + context_apply_clear_state(context, This); if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { if (!surface_is_offscreen(target)) @@ -4481,13 +4489,6 @@ HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfac } } - if (!context->valid) - { - context_release(context); - WARN("Invalid context, skipping clear.\n"); - return WINED3D_OK; - } - target->get_drawable_size(context, &drawable_width, &drawable_height); ENTER_GL(); @@ -5299,7 +5300,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface, if (convert != NO_CONVERSION) return IWineD3DSurface_BltFast(dst_surface, dst_x, dst_y, src_surface, src_rect, 0); - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); ENTER_GL(); GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); @@ -5522,7 +5523,7 @@ static void color_fill_fbo(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface, { TRACE("Surface %p is onscreen\n", surface); - context = context_acquire(This, surface, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, surface); ENTER_GL(); context_bind_fbo(context, GL_FRAMEBUFFER, NULL); context_set_draw_buffer(context, surface_get_gl_buffer(surface)); @@ -5531,7 +5532,7 @@ static void color_fill_fbo(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface, { TRACE("Surface %p is offscreen\n", surface); - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); ENTER_GL(); context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo); context_attach_surface_fbo(context, GL_FRAMEBUFFER, 0, surface); @@ -5817,9 +5818,9 @@ void stretch_rect_fbo(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_surfa IWineD3DSurface_LoadLocation((IWineD3DSurface *)src_surface, SFLAG_INDRAWABLE, NULL); IWineD3DSurface_LoadLocation((IWineD3DSurface *)dst_surface, SFLAG_INDRAWABLE, NULL); - if (!surface_is_offscreen(src_surface)) context = context_acquire(device, src_surface, CTXUSAGE_RESOURCELOAD); - else if (!surface_is_offscreen(dst_surface)) context = context_acquire(device, dst_surface, CTXUSAGE_RESOURCELOAD); - else context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + if (!surface_is_offscreen(src_surface)) context = context_acquire(device, src_surface); + else if (!surface_is_offscreen(dst_surface)) context = context_acquire(device, dst_surface); + else context = context_acquire(device, NULL); if (!context->valid) { @@ -6032,8 +6033,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetCursorProperties(IWineD3DDevice* i TRACE("(%p) : Spot Pos(%u,%u)\n", This, XHotSpot, YHotSpot); /* some basic validation checks */ - if(This->cursorTexture) { - struct wined3d_context *context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + if (This->cursorTexture) + { + struct wined3d_context *context = context_acquire(This, NULL); ENTER_GL(); glDeleteTextures(1, &This->cursorTexture); LEAVE_GL(); @@ -6096,7 +6098,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetCursorProperties(IWineD3DDevice* i memcpy(&mem[width * bpp * i], &bits[rect.Pitch * i], width * bpp); IWineD3DSurface_UnlockRect(pCursorBitmap); - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); ENTER_GL(); @@ -6273,7 +6275,7 @@ static HRESULT updateSurfaceDesc(IWineD3DSurfaceImpl *surface, const WINED3DPRES if (surface->texture_name) { - struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + struct wined3d_context *context = context_acquire(device, NULL); ENTER_GL(); glDeleteTextures(1, &surface->texture_name); LEAVE_GL(); @@ -6342,7 +6344,7 @@ static void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChainImpl struct wined3d_context *context; IWineD3DBaseShaderImpl *shader; - context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This, NULL); gl_info = context->gl_info; IWineD3DDevice_EnumResources(iface, reset_unload_resources, NULL); @@ -6434,7 +6436,7 @@ static HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwap return WINED3D_OK; err: - context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD); + context_acquire(This, NULL); destroy_dummy_textures(This, context->gl_info); context_release(context); context_destroy(This, context); diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 5f88f4ebbe..1f904eaa9d 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -594,7 +594,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT /* Signals other modules that a drawing is in progress and the stateblock finalized */ This->isInDraw = TRUE; - context = context_acquire(This, This->render_targets[0], CTXUSAGE_DRAWPRIM); + context = context_acquire(This, This->render_targets[0]); if (!context->valid) { context_release(context); @@ -602,6 +602,8 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT return; } + context_apply_draw_state(context, This); + if (This->depth_stencil) { /* Note that this depends on the context_acquire() call above to set @@ -812,7 +814,8 @@ HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, /* Simply activate the context for blitting. This disables all the things we don't want and * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the * patch (as opposed to normal draws) will most likely need different changes anyway. */ - context = context_acquire(This, NULL, CTXUSAGE_BLIT); + context = context_acquire(This, NULL); + context_apply_blit_state(context, This); /* First, locate the position data. This is provided in a vertex buffer in the stateblock. * Beware of vbos diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index aca9d0e27a..2e869308f9 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -4688,7 +4688,7 @@ static void shader_glsl_destroy(IWineD3DBaseShader *iface) { return; } - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; if (priv->glsl_program && (IWineD3DBaseShader *)priv->glsl_program->pshader == iface) @@ -4707,7 +4707,7 @@ static void shader_glsl_destroy(IWineD3DBaseShader *iface) { return; } - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; if (priv->glsl_program && (IWineD3DBaseShader *)priv->glsl_program->vshader == iface) diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c index 90cdbd4788..5552bb1f91 100644 --- a/dlls/wined3d/query.c +++ b/dlls/wined3d/query.c @@ -59,7 +59,7 @@ enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_qu return WINED3D_EVENT_QUERY_WRONG_THREAD; } - context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, query->context->current_rt); gl_info = context->gl_info; ENTER_GL(); @@ -136,7 +136,7 @@ enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_ return WINED3D_EVENT_QUERY_WRONG_THREAD; } - context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, query->context->current_rt); ENTER_GL(); if (gl_info->supported[ARB_SYNC]) @@ -190,17 +190,17 @@ void wined3d_event_query_issue(struct wined3d_event_query *query, IWineD3DDevice if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId()) { context_free_event_query(query); - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); context_alloc_event_query(context, query); } else { - context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, query->context->current_rt); } } else { - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); context_alloc_event_query(context, query); } @@ -348,7 +348,7 @@ static HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, return S_OK; } - context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This->device, query->context->current_rt); ENTER_GL(); @@ -485,12 +485,12 @@ static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, D FIXME("Wrong thread, can't restart query.\n"); context_free_occlusion_query(query); - context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This->device, NULL); context_alloc_occlusion_query(context, query); } else { - context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This->device, query->context->current_rt); ENTER_GL(); GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); @@ -501,7 +501,7 @@ static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, D else { if (query->context) context_free_occlusion_query(query); - context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This->device, NULL); context_alloc_occlusion_query(context, query); } @@ -525,7 +525,7 @@ static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, D } else { - context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD); + context = context_acquire(This->device, query->context->current_rt); ENTER_GL(); GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 6ec3ed9f54..bb18b952de 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -51,7 +51,7 @@ static void surface_cleanup(IWineD3DSurfaceImpl *This) * target, Uninit3D() will activate a context before doing anything. */ if (device->render_targets && device->render_targets[0]) { - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); } ENTER_GL(); @@ -1085,7 +1085,7 @@ void surface_internal_preload(IWineD3DSurfaceImpl *surface, enum WINED3DSRGB srg TRACE("(%p) : About to load surface\n", surface); - if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + if (!device->isInDraw) context = context_acquire(device, NULL); if (surface->resource.format_desc->format == WINED3DFMT_P8_UINT || surface->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM) @@ -1197,7 +1197,7 @@ static void WINAPI IWineD3DSurfaceImpl_UnLoad(IWineD3DSurface *iface) { IWineD3DSurface_ModifyLocation(iface, SFLAG_INSRGBTEX, FALSE); This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED); - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; /* Destroy PBOs, but load them into real sysmem before */ @@ -1272,7 +1272,8 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, const RECT *rect, v * should help here. Furthermore unlockrect will need the context set up for blitting. The context manager will find * context->last_was_blit set on the unlock. */ - context = context_acquire(device, This, CTXUSAGE_BLIT); + context = context_acquire(device, This); + context_apply_blit_state(context, device); gl_info = context->gl_info; ENTER_GL(); @@ -1500,7 +1501,7 @@ static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This, BOOL srgb) * locking during offscreen rendering). RESOURCELOAD is ok because glCopyTexSubImage2D isn't affected by any * states in the stateblock, and no driver was found yet that had bugs in that regard. */ - context = context_acquire(device, This, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, This); gl_info = context->gl_info; surface_bind_and_dirtify(This, srgb); @@ -1634,7 +1635,7 @@ static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This) GLenum error; struct wined3d_context *context; - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); ENTER_GL(); GL_EXTCALL(glGenBuffersARB(1, &This->pbo)); @@ -1737,7 +1738,7 @@ lock_end: const struct wined3d_gl_info *gl_info; struct wined3d_context *context; - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; ENTER_GL(); @@ -1793,7 +1794,8 @@ static void flush_to_framebuffer_drawpixels(IWineD3DSurfaceImpl *This, GLenum fm struct wined3d_context *context; /* Activate the correct context for the render target */ - context = context_acquire(device, This, CTXUSAGE_BLIT); + context = context_acquire(device, This); + context_apply_blit_state(context, device); gl_info = context->gl_info; ENTER_GL(); @@ -1896,7 +1898,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) { TRACE("Freeing PBO memory\n"); - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); gl_info = context->gl_info; ENTER_GL(); @@ -1997,7 +1999,7 @@ static void surface_release_client_storage(IWineD3DSurfaceImpl *surface) { struct wined3d_context *context; - context = context_acquire(surface->resource.device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(surface->resource.device, NULL); ENTER_GL(); glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); @@ -3005,7 +3007,8 @@ static void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *dst_surface, IWineD3D upsidedown = TRUE; } - context = context_acquire(device, src_surface, CTXUSAGE_BLIT); + context = context_acquire(device, src_surface); + context_apply_blit_state(context, device); surface_internal_preload(dst_surface, SRGB_RGB); ENTER_GL(); @@ -3113,7 +3116,8 @@ static void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *dst_surface, IWine TRACE("Using hwstretch blit\n"); /* Activate the Proper context for reading from the source surface, set it up for blitting */ - context = context_acquire(device, src_surface, CTXUSAGE_BLIT); + context = context_acquire(device, src_surface); + context_apply_blit_state(context, device); surface_internal_preload(dst_surface, SRGB_RGB); src_offscreen = surface_is_offscreen(src_surface); @@ -3672,7 +3676,8 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *dst_surface, surface_internal_preload(src_surface, SRGB_RGB); /* Activate the destination context, set it up for blitting */ - context = context_acquire(device, dst_surface, CTXUSAGE_BLIT); + context = context_acquire(device, dst_surface); + context_apply_blit_state(context, device); /* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates', * while OpenGL coordinates are window relative. @@ -4329,7 +4334,8 @@ static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT surface_get_rect(This, rect_in, &src_rect); - context = context_acquire(device, This, CTXUSAGE_BLIT); + context = context_acquire(device, This); + context_apply_blit_state(context, device); if (context->render_offscreen) { dst_rect.left = src_rect.left; @@ -4430,7 +4436,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, D { struct wined3d_context *context = NULL; - if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + if (!device->isInDraw) context = context_acquire(device, NULL); surface_bind_and_dirtify(This, !(This->Flags & SFLAG_INTEXTURE)); surface_download_data(This, gl_info); @@ -4471,7 +4477,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, D TRACE("Removing the pbo attached to surface %p\n", This); - if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + if (!device->isInDraw) context = context_acquire(device, NULL); surface_remove_pbo(This, gl_info); if (context) context_release(context); } @@ -4537,7 +4543,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, D IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INSYSMEM, rect); } - if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + if (!device->isInDraw) context = context_acquire(device, NULL); surface_prepare_texture(This, gl_info, srgb); surface_bind_and_dirtify(This, srgb); diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index a7b6a70ab4..25c04b1fb6 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -142,7 +142,8 @@ static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context * float tex_right = src_rect->right; float tex_bottom = src_rect->bottom; - context2 = context_acquire(This->device, This->back_buffers[0], CTXUSAGE_BLIT); + context2 = context_acquire(This->device, This->back_buffers[0]); + context_apply_blit_state(context2, device); if(backbuffer->Flags & SFLAG_NORMCOORD) { @@ -168,13 +169,13 @@ static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context * context_set_draw_buffer(context, GL_BACK); /* Set the viewport to the destination rectandle, disable any projection - * transformation set up by CTXUSAGE_BLIT, and draw a (-1,-1)-(1,1) quad. + * transformation set up by context_apply_blit_state(), and draw a + * (-1,-1)-(1,1) quad. * * Back up viewport and matrix to avoid breaking last_was_blit * - * Note that CTXUSAGE_BLIT set up viewport and ortho to match the surface - * size - we want the GL drawable(=window) size. - */ + * Note that context_apply_blit_state() set up viewport and ortho to + * match the surface size - we want the GL drawable(=window) size. */ glPushAttrib(GL_VIEWPORT_BIT); glViewport(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom); glMatrixMode(GL_PROJECTION); @@ -220,7 +221,7 @@ static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CO IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride); - context = context_acquire(This->device, This->back_buffers[0], CTXUSAGE_RESOURCELOAD); + context = context_acquire(This->device, This->back_buffers[0]); if (!context->valid) { context_release(context); diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 258dea2b97..98e7909370 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -63,7 +63,7 @@ static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRG { /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture, * thus no danger of recursive calls. */ - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + context = context_acquire(device, NULL); } if (This->resource.format_desc->format == WINED3DFMT_P8_UINT diff --git a/dlls/wined3d/volumetexture.c b/dlls/wined3d/volumetexture.c index ee453d0fb3..9fccb2b893 100644 --- a/dlls/wined3d/volumetexture.c +++ b/dlls/wined3d/volumetexture.c @@ -39,7 +39,7 @@ static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINE TRACE("(%p) : About to load texture.\n", This); - if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); + if (!device->isInDraw) context = context_acquire(device, NULL); else if (gl_info->supported[EXT_TEXTURE_SRGB] && This->baseTexture.bindCount > 0) { srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE]; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 8fb4dfbed4..fabf22a0b9 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1186,26 +1186,19 @@ HRESULT arbfp_blit_surface(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_ IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect_in, enum blit_operation blit_op, DWORD Filter) DECLSPEC_HIDDEN; -typedef enum ContextUsage { - CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */ - CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfaces */ - CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */ - CTXUSAGE_CLEAR = 4, /* Drawable and states are set up for clearing */ -} ContextUsage; - -struct wined3d_context *context_acquire(IWineD3DDeviceImpl *This, - IWineD3DSurfaceImpl *target, enum ContextUsage usage) DECLSPEC_HIDDEN; +struct wined3d_context *context_acquire(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target) DECLSPEC_HIDDEN; void context_alloc_event_query(struct wined3d_context *context, struct wined3d_event_query *query) DECLSPEC_HIDDEN; void context_alloc_occlusion_query(struct wined3d_context *context, struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN; -void context_resource_released(IWineD3DDevice *iface, - IWineD3DResource *resource, WINED3DRESOURCETYPE type) DECLSPEC_HIDDEN; -void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) DECLSPEC_HIDDEN; +void context_apply_blit_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN; +void context_apply_clear_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN; +void context_apply_draw_state(struct wined3d_context *context, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN; void context_attach_depth_stencil_fbo(struct wined3d_context *context, GLenum fbo_target, IWineD3DSurfaceImpl *depth_stencil, BOOL use_render_buffer) DECLSPEC_HIDDEN; void context_attach_surface_fbo(const struct wined3d_context *context, GLenum fbo_target, DWORD idx, IWineD3DSurfaceImpl *surface) DECLSPEC_HIDDEN; +void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) DECLSPEC_HIDDEN; struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain, IWineD3DSurfaceImpl *target, const struct wined3d_format_desc *ds_format_desc) DECLSPEC_HIDDEN; void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context) DECLSPEC_HIDDEN; @@ -1214,6 +1207,8 @@ void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPE struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN; DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN; void context_release(struct wined3d_context *context) DECLSPEC_HIDDEN; +void context_resource_released(IWineD3DDevice *iface, + IWineD3DResource *resource, WINED3DRESOURCETYPE type) DECLSPEC_HIDDEN; BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN; void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN; void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;