From 1d4effcaa56cb9a8bf94f240a57392b3060ad0f3 Mon Sep 17 00:00:00 2001
From: Roderick Colenbrander <thunderbird2k@gmx.net>
Date: Sat, 4 Nov 2006 22:23:15 +0100
Subject: [PATCH] wgl: Fix WoW screen flickering.

---
 dlls/gdi32/driver.c               |  1 +
 dlls/gdi32/gdi_private.h          |  1 +
 dlls/gdi32/opengl.c               | 29 +++++++++++++++++++++++++++++
 dlls/winex11.drv/opengl.c         | 29 +++++++++++++++++++++--------
 dlls/winex11.drv/winex11.drv.spec |  1 +
 5 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/dlls/gdi32/driver.c b/dlls/gdi32/driver.c
index 16bde6524cc..f5ff9afe8a3 100644
--- a/dlls/gdi32/driver.c
+++ b/dlls/gdi32/driver.c
@@ -199,6 +199,7 @@ static struct graphics_driver *create_driver( HMODULE module )
         GET_FUNC(wglCreateContext);
         GET_FUNC(wglDeleteContext);
         GET_FUNC(wglGetProcAddress);
+        GET_FUNC(wglGetPbufferDCARB);
         GET_FUNC(wglMakeContextCurrentARB);
         GET_FUNC(wglMakeCurrent);
         GET_FUNC(wglShareLists);
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index eda98279d43..1dbae75476f 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -187,6 +187,7 @@ typedef struct tagDC_FUNCS
     HGLRC    (*pwglCreateContext)(PHYSDEV);
     BOOL     (*pwglDeleteContext)(HGLRC);
     PROC     (*pwglGetProcAddress)(LPCSTR);
+    HDC      (*pwglGetPbufferDCARB)(PHYSDEV, void*);
     BOOL     (*pwglMakeCurrent)(PHYSDEV, HGLRC);
     BOOL     (*pwglMakeContextCurrentARB)(PHYSDEV, PHYSDEV, HGLRC);
     BOOL     (*pwglShareLists)(HGLRC hglrc1, HGLRC hglrc2);
diff --git a/dlls/gdi32/opengl.c b/dlls/gdi32/opengl.c
index 03ce10d0d08..d171c3db51f 100644
--- a/dlls/gdi32/opengl.c
+++ b/dlls/gdi32/opengl.c
@@ -130,6 +130,33 @@ HDC WINAPI wglGetCurrentDC(void)
     return ctx->hdc;
 }
 
+/***********************************************************************
+ *		wglGetPbufferDCARB
+ */
+static HDC WINAPI wglGetPbufferDCARB(void *pbuffer)
+{
+    HDC ret = 0;
+
+    /* Create a device context to associate with the pbuffer */
+    HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
+    DC *dc = DC_GetDCPtr(hdc);
+
+    TRACE("(%p)\n", pbuffer);
+
+    if (!dc) return FALSE;
+
+    /* The display driver has to do the rest of the work because
+     * we need access to lowlevel datatypes which we can't access here
+     */
+    if (!dc->funcs->pwglGetPbufferDCARB) FIXME(" :stub\n");
+    else ret = dc->funcs->pwglGetPbufferDCARB(dc->physDev, pbuffer);
+
+    TRACE("(%p), hdc=%p\n", pbuffer, ret);
+    
+    GDI_ReleaseObj(hdc);
+    return ret;
+}
+
 /***********************************************************************
  *		wglMakeCurrent (OPENGL32.@)
  */
@@ -281,6 +308,8 @@ PROC WINAPI wglGetProcAddress(LPCSTR func)
      */
     if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
         return wglMakeContextCurrentARB;
+    else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0)
+        return (PROC)wglGetPbufferDCARB;
 
     return ret;
 }
diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c
index feec15013aa..fcb39d4e0ed 100644
--- a/dlls/winex11.drv/opengl.c
+++ b/dlls/winex11.drv/opengl.c
@@ -1871,23 +1871,26 @@ static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
     return GL_TRUE;
 }
 
-/* WGL_ARB_pbuffer: wglGetPbufferDCARB */
-static HDC WINAPI X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
+/* WGL_ARB_pbuffer: wglGetPbufferDCARB
+ * The function wglGetPbufferDCARB returns a device context for a pbuffer.
+ * Gdi32 implements the part of this function which creates a device context.
+ * This part associates the physDev with the X drawable of the pbuffer.
+ */
+HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
 {
     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
-    HDC hDC;
     if (NULL == object) {
         SetLastError(ERROR_INVALID_HANDLE);
         return NULL;
     }
-    hDC = CreateCompatibleDC(object->hdc);
 
     /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
      * We only support one onscreen rendering format (the one from the main visual), so use that. */
-    SetPixelFormat(hDC, 1, NULL);
-    set_drawable(hDC, object->drawable); /* works ?? */
-    TRACE("(%p)->(%p)\n", hPbuffer, hDC);
-    return hDC;
+    physDev->current_pf = 1;
+    physDev->drawable = object->drawable;
+
+    TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
+    return physDev->hdc;
 }
 
 /* WGL_ARB_pbuffer: wglQueryPbufferARB */
@@ -2379,6 +2382,9 @@ static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuf
         SetLastError(ERROR_INVALID_HANDLE);
         return GL_FALSE;
     }
+/* Disable WGL_ARB_render_texture support untill it is implemented properly
+ * using pbuffers or FBOs */
+#if 0
     if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
         int do_init = 0;
         GLint prev_binded_tex;
@@ -2406,6 +2412,7 @@ static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuf
         object->texture = prev_binded_tex;
         return GL_TRUE;
     }
+#endif
     if (NULL != pglXBindTexImageARB) {
         return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
     }
@@ -2834,6 +2841,12 @@ PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
     return NULL;
 }
 
+HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, HPBUFFERARB hPbuffer)
+{
+    ERR_(opengl)("No OpenGL support compiled in.\n");
+    return NULL;
+}
+
 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
     ERR_(opengl)("No OpenGL support compiled in.\n");
     return FALSE;
diff --git a/dlls/winex11.drv/winex11.drv.spec b/dlls/winex11.drv/winex11.drv.spec
index b5b65b44697..7d6214e9799 100644
--- a/dlls/winex11.drv/winex11.drv.spec
+++ b/dlls/winex11.drv/winex11.drv.spec
@@ -134,6 +134,7 @@
 @ cdecl wglCreateContext(ptr) X11DRV_wglCreateContext
 @ cdecl wglDeleteContext(long) X11DRV_wglDeleteContext
 @ cdecl wglGetProcAddress(str) X11DRV_wglGetProcAddress
+@ cdecl wglGetPbufferDCARB(ptr ptr) X11DRV_wglGetPbufferDCARB
 @ cdecl wglMakeContextCurrentARB(ptr ptr long) X11DRV_wglMakeContextCurrentARB
 @ cdecl wglMakeCurrent(ptr long) X11DRV_wglMakeCurrent
 @ cdecl wglShareLists(long long) X11DRV_wglShareLists
-- 
GitLab