Commit e77da5ef authored by Roderick Colenbrander's avatar Roderick Colenbrander Committed by Alexandre Julliard

wined3d: Don't call ActivateContext between ENTER_GL/LEAVE_GL.

parent 1a688cd0
......@@ -100,8 +100,8 @@ void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface) {
TRACE("(%p) : textureName(%d)\n", This, This->baseTexture.textureName);
if (This->baseTexture.textureName != 0) {
ENTER_GL();
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
TRACE("(%p) : Deleting texture %d\n", This, This->baseTexture.textureName);
glDeleteTextures(1, &This->baseTexture.textureName);
LEAVE_GL();
......
......@@ -839,6 +839,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
ENTER_GL();
if(This->lastActiveRenderTarget != target || tid != This->lastThread) {
context = FindContext(This, target, tid);
This->lastActiveRenderTarget = target;
......@@ -906,4 +907,5 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
default:
FIXME("Unexpected context usage requested\n");
}
LEAVE_GL();
}
......@@ -119,9 +119,7 @@ static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
/* No danger of recursive calls, ActivateContext sets isInDraw to true when loading
* offscreen render targets into their texture
*/
ENTER_GL();
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
LEAVE_GL();
} else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0) {
srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
srgb_was_toggled = (This->baseTexture.is_srgb != srgb_mode);
......
......@@ -237,9 +237,9 @@ static void CreateVBO(IWineD3DVertexBufferImpl *object) {
TRACE("Creating an OpenGL vertex buffer object for IWineD3DVertexBuffer %p Usage(%s)\n", object, debug_d3dusage(vboUsage));
ENTER_GL();
/* Make sure that a context is there. Needed in a multithreaded environment. Otherwise this call is a nop */
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
/* Make sure that the gl error is cleared. Do not use checkGLcall
* here because checkGLcall just prints a fixme and continues. However,
......@@ -367,9 +367,9 @@ static void CreateIndexBufferVBO(IWineD3DDeviceImpl *This, IWineD3DIndexBufferIm
*/
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER);
ENTER_GL();
/* Make sure that a context is there. Needed in a multithreaded environment. Otherwise this call is a nop */
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
while(glGetError());
......@@ -1895,12 +1895,10 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface, D3DCB_D
if(!This->d3d_initialized) return WINED3DERR_INVALIDCALL;
ENTER_GL();
/* I don't think that the interface guarants that the device is destroyed from the same thread
* it was created. Thus make sure a context is active for the glDelete* calls
*/
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
LEAVE_GL();
TRACE("Deleting high order patches\n");
for(i = 0; i < PATCHMAP_SIZE; i++) {
......@@ -3968,9 +3966,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ProcessVertices(IWineD3DDevice *iface,
* and this call is quite performance critical, so don't call needlessly
*/
if(This->createParms.BehaviorFlags & WINED3DCREATE_MULTITHREADED) {
ENTER_GL();
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
LEAVE_GL();
}
/* ProcessVertices reads from vertex buffers, which have to be assigned. DrawPrimitive and DrawPrimitiveUP
......@@ -4402,11 +4398,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndScene(IWineD3DDevice *iface) {
return WINED3DERR_INVALIDCALL;
}
ENTER_GL();
if(This->createParms.BehaviorFlags & WINED3DCREATE_MULTITHREADED) {
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
/* We only have to do this if we need to read the, swapbuffers performs a flush for us */
ENTER_GL();
glFlush();
checkGLcall("glFlush");
LEAVE_GL();
......@@ -4454,16 +4450,18 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Coun
return WINED3DERR_INVALIDCALL;
}
ENTER_GL();
/* This is for offscreen rendering as well as for multithreading, thus activate the set render target
* and not the last active one.
*/
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
ENTER_GL();
apply_fbo_state(iface);
LEAVE_GL();
}
ActivateContext(This, This->render_targets[0], CTXUSAGE_CLEAR);
ENTER_GL();
if (Count > 0 && pRects) {
curRect = pRects;
......@@ -5078,10 +5076,10 @@ static HRESULT WINAPI IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
IWineD3DSurface_GetDesc(pDestinationSurface, &winedesc);
}
ENTER_GL();
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
if (GL_SUPPORT(ARB_MULTITEXTURE)) {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
checkGLcall("glActiveTextureARB");
......@@ -5751,13 +5749,13 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
/* Attach src surface to src fbo */
src_swapchain = get_swapchain(src_surface);
ENTER_GL();
if (src_swapchain) {
GLenum buffer;
TRACE("Source surface %p is onscreen\n", src_surface);
ActivateContext(This, src_surface, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
GL_EXTCALL(glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0));
buffer = surface_get_gl_buffer(src_surface, src_swapchain);
glReadBuffer(buffer);
......@@ -5767,11 +5765,13 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
src_rect->y2 = ((IWineD3DSurfaceImpl *)src_surface)->currentDesc.Height - src_rect->y2;
} else {
TRACE("Source surface %p is offscreen\n", src_surface);
ENTER_GL();
bind_fbo(iface, GL_READ_FRAMEBUFFER_EXT, &This->src_fbo);
attach_surface_fbo(This, GL_READ_FRAMEBUFFER_EXT, 0, src_surface);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
checkGLcall("glReadBuffer()");
}
LEAVE_GL();
/* Attach dst surface to dst fbo */
dst_swapchain = get_swapchain(dst_surface);
......@@ -5781,6 +5781,7 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
TRACE("Destination surface %p is onscreen\n", dst_surface);
ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
GL_EXTCALL(glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0));
buffer = surface_get_gl_buffer(dst_surface, dst_swapchain);
glDrawBuffer(buffer);
......@@ -5796,6 +5797,7 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
ENTER_GL();
bind_fbo(iface, GL_DRAW_FRAMEBUFFER_EXT, &This->dst_fbo);
attach_surface_fbo(This, GL_DRAW_FRAMEBUFFER_EXT, 0, dst_surface);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
......@@ -5938,8 +5940,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetCursorProperties(IWineD3DDevice* i
/* some basic validation checks */
if(This->cursorTexture) {
ENTER_GL();
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
glDeleteTextures(1, &This->cursorTexture);
LEAVE_GL();
This->cursorTexture = 0;
......@@ -6179,8 +6181,8 @@ static void updateSurfaceDesc(IWineD3DSurfaceImpl *surface, WINED3DPRESENT_PARAM
while (surface->pow2Height < pPresentationParameters->BackBufferHeight) surface->pow2Height <<= 1;
}
if(surface->glDescription.textureName) {
ENTER_GL();
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
glDeleteTextures(1, &surface->glDescription.textureName);
LEAVE_GL();
surface->glDescription.textureName = 0;
......
......@@ -862,8 +862,8 @@ void blt_to_drawable(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *surface) {
return;
}
ENTER_GL();
ActivateContext(This, This->render_targets[0], CTXUSAGE_BLIT);
ENTER_GL();
if(surface->glDescription.target == GL_TEXTURE_2D) {
glBindTexture(GL_TEXTURE_2D, surface->glDescription.textureName);
......@@ -1035,13 +1035,15 @@ void drawPrimitive(IWineD3DDevice *iface,
}
/* Ok, we will be updating the screen from here onwards so grab the lock */
ENTER_GL();
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
ENTER_GL();
apply_fbo_state(iface);
LEAVE_GL();
}
ActivateContext(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
ENTER_GL();
if (This->depth_copy_state == WINED3D_DCS_COPY) {
depth_copy(iface);
......@@ -1251,12 +1253,12 @@ HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This,
patch->has_normals = TRUE;
patch->has_texcoords = FALSE;
ENTER_GL();
/* 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
*/
ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_BLIT);
ENTER_GL();
glMatrixMode(GL_PROJECTION);
checkGLcall("glMatrixMode(GL_PROJECTION)");
......
......@@ -61,8 +61,8 @@ static ULONG WINAPI IWineD3DIndexBufferImpl_Release(IWineD3DIndexBuffer *iface)
if(This->vbo) {
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
ENTER_GL();
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
/* No need to manually unset the buffer. glDeleteBuffers unsets it for the current context,
* but not for other contexts. However, because the d3d buffer is destroyed the app has to
* unset it before doing the next draw, thus dirtifying the index buffer state and forcing
......@@ -157,12 +157,12 @@ static HRESULT WINAPI IWineD3DIndexBufferImpl_Unlock(IWineD3DIndexBuffer *iface)
/* For now load in unlock */
if(locks == 0 && This->vbo && (This->dirtyend - This->dirtystart) > 0) {
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
ENTER_GL();
if(device->createParms.BehaviorFlags & WINED3DCREATE_MULTITHREADED) {
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
ENTER_GL();
GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, This->vbo));
checkGLcall("glBindBufferARB");
GL_EXTCALL(glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
......
......@@ -359,7 +359,6 @@ ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface) {
* and the lastActiveRenderTarget member shouldn't matter
*/
if(swapchain) {
ENTER_GL(); /* For ActivateContext */
if(swapchain->backBuffer && swapchain->backBuffer[0] != iface) {
TRACE("Activating primary back buffer\n");
ActivateContext(device, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD);
......@@ -374,7 +373,6 @@ ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface) {
*/
device->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe;
}
LEAVE_GL();
} else {
/* May happen during ddraw uninitialization */
TRACE("Render target set, but swapchain does not exist!\n");
......@@ -383,7 +381,6 @@ ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface) {
}
if (This->glDescription.textureName != 0) { /* release the openGL texture.. */
ENTER_GL();
/* Need a context to destroy the texture. Use the currently active render target, but only if
* the primary render target exists. Otherwise lastActiveRenderTarget is garbage, see above.
......@@ -394,6 +391,7 @@ ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface) {
}
TRACE("Deleting texture %d\n", This->glDescription.textureName);
ENTER_GL();
glDeleteTextures(1, &This->glDescription.textureName);
LEAVE_GL();
}
......@@ -468,11 +466,11 @@ void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface) {
} else {
TRACE("(%p) : About to load surface\n", This);
ENTER_GL();
if(!device->isInDraw) {
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
ENTER_GL();
glEnable(This->glDescription.target);/* make sure texture support is enabled in this context */
if (!This->glDescription.level) {
if (!This->glDescription.textureName) {
......@@ -797,8 +795,8 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED
* 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.
*/
ENTER_GL();
ActivateContext(myDevice, iface, CTXUSAGE_BLIT);
ENTER_GL();
/* Select the correct read buffer, and give some debug output.
* There is no need to keep track of the current read buffer or reset it, every part of the code
......@@ -871,12 +869,11 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED
if (0 != This->glDescription.textureName) {
/* Now I have to copy thing bits back */
ENTER_GL();
if(myDevice->createParms.BehaviorFlags & WINED3DCREATE_MULTITHREADED) {
ActivateContext(myDevice, myDevice->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
ENTER_GL();
/* Make sure that a proper texture unit is selected, bind the texture and dirtify the sampler to restore the texture on the next draw */
if (GL_SUPPORT(ARB_MULTITEXTURE)) {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
......@@ -1190,8 +1187,8 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) {
}
/* Activate the correct context for the render target */
ENTER_GL();
ActivateContext(myDevice, iface, CTXUSAGE_BLIT);
ENTER_GL();
if(!swapchain) {
/* Primary offscreen render target */
......@@ -2419,9 +2416,9 @@ static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3D
UINT row;
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
ENTER_GL();
ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
ENTER_GL();
IWineD3DSurface_PreLoad((IWineD3DSurface *) This);
/* Bind the target texture */
......@@ -2506,8 +2503,8 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
TRACE("Using hwstretch blit\n");
/* Activate the Proper context for reading from the source surface, set it up for blitting */
ENTER_GL();
ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
ENTER_GL();
IWineD3DSurface_PreLoad((IWineD3DSurface *) This);
/* Try to use an aux buffer for drawing the rectangle. This way it doesn't need restoring.
......@@ -2969,10 +2966,10 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
/* Now load the surface */
IWineD3DSurface_PreLoad((IWineD3DSurface *) Src);
ENTER_GL();
/* Activate the destination context, set it up for blitting */
ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
ENTER_GL();
if(!dstSwapchain) {
TRACE("Drawing to offscreen buffer\n");
......
......@@ -151,9 +151,9 @@ static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CO
unsigned int sync;
int retval;
ENTER_GL();
ActivateContext(This->wineD3DDevice, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
ENTER_GL();
/* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
if(This->wineD3DDevice->bCursorVisible && This->wineD3DDevice->cursorTexture) {
......
......@@ -109,9 +109,7 @@ static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
/* ActivateContext sets isInDraw to TRUE when loading a pbuffer into a texture, thus no danger of
* recursive calls
*/
ENTER_GL();
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
LEAVE_GL();
} else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0) {
srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
......
......@@ -64,8 +64,8 @@ static ULONG WINAPI IWineD3DVertexBufferImpl_Release(IWineD3DVertexBuffer *iface
if(This->vbo) {
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
ENTER_GL();
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
GL_EXTCALL(glDeleteBuffersARB(1, &This->vbo));
checkGLcall("glDeleteBuffersARB");
LEAVE_GL();
......@@ -294,8 +294,8 @@ static void WINAPI IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *if
if(This->declChanges > VB_MAXDECLCHANGES) {
FIXME("Too much declaration changes, stopping converting\n");
ENTER_GL();
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
GL_EXTCALL(glDeleteBuffersARB(1, &This->vbo));
checkGLcall("glDeleteBuffersARB");
LEAVE_GL();
......@@ -348,10 +348,10 @@ static void WINAPI IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *if
*/
TRACE("No conversion needed, locking directly into the VBO in future\n");
ENTER_GL();
if(!device->isInDraw) {
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
ENTER_GL();
GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, This->vbo));
checkGLcall("glBindBufferARB");
GL_EXTCALL(glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, start, end-start, This->resource.allocatedMemory + start));
......@@ -381,10 +381,10 @@ static void WINAPI IWineD3DVertexBufferImpl_PreLoad(IWineD3DVertexBuffer *if
(int)This->strided.u.s.specular.lpData, /* location */
This->strided.u.s.specular.dwType == WINED3DDECLTYPE_SHORT4 || This->strided.u.s.specular.dwType == WINED3DDECLTYPE_D3DCOLOR);
ENTER_GL();
if(!device->isInDraw) {
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
}
ENTER_GL();
GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, This->vbo));
checkGLcall("glBindBufferARB");
GL_EXTCALL(glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, start, end - start, data));
......
......@@ -102,7 +102,6 @@ static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *ifac
IWineD3DVolumeTexture_BindTexture(iface);
ENTER_GL();
if(!device->isInDraw) {
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
} else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0) {
......@@ -110,6 +109,7 @@ static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *ifac
srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
This->baseTexture.is_srgb = srgb_mode;
}
ENTER_GL();
/* If the texture is marked dirty or the srgb sampler setting has changed since the last load then reload the surfaces */
if (This->baseTexture.dirty) {
for (i = 0; i < This->baseTexture.levels; i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment