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

wined3d: Rewrite the draw buffer selection code.

Before it was done in findContext, before selecting the new context which is bad (it doesn't always work). The new code works and this change also fixes some draw buffer regressions that happened during the surface rewrite from the last couple of days.
parent 3febe738
...@@ -674,7 +674,7 @@ static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchai ...@@ -674,7 +674,7 @@ static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchai
* Returns: The needed context * Returns: The needed context
* *
*****************************************************************************/ *****************************************************************************/
static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid) { static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid, GLint *buffer) {
IWineD3DSwapChain *swapchain = NULL; IWineD3DSwapChain *swapchain = NULL;
HRESULT hr; HRESULT hr;
BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen; BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen;
...@@ -693,15 +693,12 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf ...@@ -693,15 +693,12 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
* rendering. No context change is needed in that case * rendering. No context change is needed in that case
*/ */
if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) { if(((IWineD3DSwapChainImpl *) swapchain)->frontBuffer == target) {
if(((IWineD3DSwapChainImpl *) swapchain)->backBuffer) { *buffer = GL_FRONT;
glDrawBuffer(GL_BACK); } else {
checkGLcall("glDrawBuffer(GL_BACK)"); *buffer = GL_BACK;
} else { }
glDrawBuffer(GL_FRONT); if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
checkGLcall("glDrawBuffer(GL_FRONT)");
}
} else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
if(This->pbufferContext && tid == This->pbufferContext->tid) { if(This->pbufferContext && tid == This->pbufferContext->tid) {
This->pbufferContext->tid = 0; This->pbufferContext->tid = 0;
} }
...@@ -719,6 +716,7 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf ...@@ -719,6 +716,7 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
} else { } else {
TRACE("Rendering offscreen\n"); TRACE("Rendering offscreen\n");
This->render_offscreen = TRUE; This->render_offscreen = TRUE;
*buffer = This->offscreenBuffer;
switch(wined3d_settings.offscreen_rendering_mode) { switch(wined3d_settings.offscreen_rendering_mode) {
case ORM_FBO: case ORM_FBO:
...@@ -784,8 +782,6 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf ...@@ -784,8 +782,6 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
*/ */
context = findThreadContextForSwapChain(This->swapchains[0], tid); context = findThreadContextForSwapChain(This->swapchains[0], tid);
} }
glDrawBuffer(This->offscreenBuffer);
checkGLcall("glDrawBuffer(This->offscreenBuffer)");
break; break;
} }
...@@ -849,11 +845,11 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU ...@@ -849,11 +845,11 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
DWORD dirtyState, idx; DWORD dirtyState, idx;
BYTE shift; BYTE shift;
WineD3DContext *context; WineD3DContext *context;
GLint drawBuffer=0;
TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid); TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
if(This->lastActiveRenderTarget != target || tid != This->lastThread) { if(This->lastActiveRenderTarget != target || tid != This->lastThread) {
context = FindContext(This, target, tid); context = FindContext(This, target, tid, &drawBuffer);
This->lastActiveRenderTarget = target; This->lastActiveRenderTarget = target;
This->lastThread = tid; This->lastThread = tid;
} else { } else {
...@@ -874,6 +870,15 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU ...@@ -874,6 +870,15 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
/* We only need ENTER_GL for the gl calls made below and for the helper functions which make GL calls */ /* We only need ENTER_GL for the gl calls made below and for the helper functions which make GL calls */
ENTER_GL(); ENTER_GL();
/* Select the right draw buffer. It is selected in FindContext. */
if(drawBuffer && context->last_draw_buffer != drawBuffer) {
TRACE("Drawing to buffer: %#x\n", drawBuffer);
context->last_draw_buffer = drawBuffer;
glDrawBuffer(drawBuffer);
checkGLcall("glDrawBuffer");
}
switch(usage) { switch(usage) {
case CTXUSAGE_RESOURCELOAD: case CTXUSAGE_RESOURCELOAD:
/* This does not require any special states to be set up */ /* This does not require any special states to be set up */
......
...@@ -493,6 +493,7 @@ struct WineD3DContext { ...@@ -493,6 +493,7 @@ struct WineD3DContext {
DWORD tid; /* Thread ID which owns this context at the moment */ DWORD tid; /* Thread ID which owns this context at the moment */
/* Stores some inforation about the context state for optimization */ /* Stores some inforation about the context state for optimization */
GLint last_draw_buffer;
BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */ BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
BOOL last_was_pshader; BOOL last_was_pshader;
BOOL last_was_vshader; BOOL last_was_vshader;
......
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