Commit 05931f4a authored by H. Verbeet's avatar H. Verbeet Committed by Alexandre Julliard

wined3d: Track FBOs per-context.

Although sharing FBOs across contexts is allowed by EXT_framebuffer_object (issue 76), it causes issues with nVidia drivers. Considering the GL 3 spec explicitly disallows sharing of FBOs accross contexts (Appendix D), this patch is probably the right thing to do.
parent 2f99bcdd
......@@ -485,6 +485,13 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
TRACE("Successfully created new context %p\n", ret);
ret->fbo_color_attachments = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DSurface *) * GL_LIMITS(buffers));
if (!ret->fbo_color_attachments)
{
ERR("Out of memory!\n");
goto out;
}
/* Set up the context defaults */
oldCtx = pwglGetCurrentContext();
oldDrawable = pwglGetCurrentDC();
......@@ -576,8 +583,11 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
}
This->frag_pipe->enable_extension((IWineD3DDevice *) This, TRUE);
out:
return ret;
out:
HeapFree(GetProcessHeap(), 0, ret->fbo_color_attachments);
return NULL;
}
/*****************************************************************************
......@@ -642,6 +652,20 @@ void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context) {
last_device = NULL;
}
/* FIXME: We probably need an active context to do this... */
if (context->fbo) {
GL_EXTCALL(glDeleteFramebuffersEXT(1, &context->fbo));
}
if (context->src_fbo) {
GL_EXTCALL(glDeleteFramebuffersEXT(1, &context->src_fbo));
}
if (context->dst_fbo) {
GL_EXTCALL(glDeleteFramebuffersEXT(1, &context->dst_fbo));
}
HeapFree(GetProcessHeap(), 0, context->fbo_color_attachments);
context->fbo_color_attachments = NULL;
if(context->isPBuffer) {
GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc));
GL_EXTCALL(wglDestroyPbufferARB(context->pbuffer));
......@@ -1195,7 +1219,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
if (This->render_offscreen) {
FIXME("Activating for CTXUSAGE_BLIT for an offscreen target with ORM_FBO. This should be avoided.\n");
bind_fbo((IWineD3DDevice *)This, GL_FRAMEBUFFER_EXT, &This->dst_fbo);
bind_fbo((IWineD3DDevice *)This, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
attach_surface_fbo(This, GL_FRAMEBUFFER_EXT, 0, target);
GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0));
checkGLcall("glFramebufferRenderbufferEXT");
......
......@@ -4027,7 +4027,7 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
device->depth_blt_rb_h = This->currentDesc.Height;
}
bind_fbo((IWineD3DDevice *)device, GL_FRAMEBUFFER_EXT, &device->dst_fbo);
bind_fbo((IWineD3DDevice *)device, GL_FRAMEBUFFER_EXT, &device->activeContext->dst_fbo);
GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, device->depth_blt_rb));
checkGLcall("glFramebufferRenderbufferEXT");
attach_depth_stencil_fbo(device, GL_FRAMEBUFFER_EXT, iface, FALSE);
......@@ -4037,7 +4037,7 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
checkGLcall("depth_blt");
if (device->render_offscreen) {
bind_fbo((IWineD3DDevice *)device, GL_FRAMEBUFFER_EXT, &device->fbo);
bind_fbo((IWineD3DDevice *)device, GL_FRAMEBUFFER_EXT, &device->activeContext->fbo);
} else {
GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
checkGLcall("glBindFramebuffer()");
......@@ -4059,7 +4059,7 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
checkGLcall("depth_blt");
if (device->render_offscreen) {
GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, device->fbo));
GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, device->activeContext->fbo));
checkGLcall("glBindFramebuffer()");
}
......
......@@ -629,6 +629,13 @@ struct WineD3DContext {
HPBUFFERARB pbuffer;
BOOL isPBuffer;
GLint aux_buffers;
/* FBOs */
IWineD3DSurface **fbo_color_attachments;
IWineD3DSurface *fbo_depth_attachment;
GLuint fbo;
GLuint src_fbo;
GLuint dst_fbo;
};
typedef enum ContextUsage {
......@@ -880,9 +887,6 @@ struct IWineD3DDeviceImpl
/* Render Target Support */
IWineD3DSurface **render_targets;
IWineD3DSurface *auto_depth_stencil_buffer;
IWineD3DSurface **fbo_color_attachments;
IWineD3DSurface *fbo_depth_attachment;
IWineD3DSurface *stencilBufferTarget;
/* Caches to avoid unneeded context changes */
......@@ -897,9 +901,6 @@ struct IWineD3DDeviceImpl
/* For rendering to a texture using glCopyTexImage */
BOOL render_offscreen;
GLuint fbo;
GLuint src_fbo;
GLuint dst_fbo;
GLenum *draw_buffers;
GLuint depth_blt_texture;
GLuint depth_blt_rb;
......
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