From 6cbcec2d4c5f6eb7a3855122eaf0f5c9957c30e0 Mon Sep 17 00:00:00 2001 From: Nick Burns Date: Sat, 20 Dec 2008 20:08:27 -0800 Subject: Apple X11 GLX hacks Workaround some issues with Apple X11 Also force vsync on (using CGL) And cut down the mem-space (so games will play and not run out of VM after a time) --- configure.ac | 7 ++++++ dlls/wined3d/directx.c | 13 ++++++++++++ dlls/winex11.drv/opengl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ libs/wine/mmap.c | 8 +++++++ 4 files changed, 77 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 4bf1ec3..76f556b 100644 --- a/configure.ac +++ b/configure.ac @@ -798,6 +798,13 @@ This probably prevents linking to OpenGL. Try deleting the file and restarting c fi], $X_LIBS -lXext -lX11 -lm $X_EXTRA_LIBS -dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib)], $X_LIBS -lXext -lX11 -lm $X_EXTRA_LIBS) + + dnl If on Mac OSX and using X11 then need -dylib_file + if test -f /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib + then + OPENGL_LIBS="-Xlinker -dylib_file -Xlinker /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib -lGL" + fi + if test "$ac_cv_header_GL_glu_h" = "yes" then WINE_CHECK_SONAME(GLU,gluLookAt,,,[$OPENGL_LIBS $X_LIBS $X_PRE_LIBS -lXext -lX11 -lm $X_EXTRA_LIBS]) diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index d5fd0a5..62ae645 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -795,6 +795,19 @@ static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { GL_EXT_FUNCS_GEN; #undef USE_GL_FUNC +#if defined(__APPLE__) +#include +#define USE_GL_FUNC(type, pfn, ext, replace) { \ + DWORD ver = ver_for_ext(ext); \ + if(gl_info->supported[ext] && !gl_info->pfn) gl_info->pfn = (type) dlsym(RTLD_DEFAULT, #pfn); \ + else if(ver && ver <= gl_info->gl_version && !gl_info->pfn) gl_info->pfn = (type) dlsym(RTLD_DEFAULT, #replace); \ + if(gl_info->supported[ext] && !gl_info->pfn) ERR("%s NULL\n", #pfn); \ + else if(ver && ver <= gl_info->gl_version && !gl_info->pfn) ERR("%s NULL\n", #replace); \ + } + GL_EXT_FUNCS_GEN; +#undef USE_GL_FUNC +#endif + #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn); WGL_EXT_FUNCS_GEN; #undef USE_GL_FUNC diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index df5bae0..35b5bbb 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -75,8 +75,12 @@ typedef struct wine_glextension { } WineGLExtension; struct WineGLInfo { +#if defined(__APPLE__) + const char *pad; +#else const char *glVersion; const char *glExtensions; +#endif int glxVersion[2]; @@ -291,6 +295,10 @@ static BOOL X11DRV_WineGL_InitOpenglInfo(void) wine_tsx11_lock(); +#if defined(__APPLE__) + FIXME("Do not need to check gl version here...\n"); + vis = 0; +#else visual = DefaultVisual(gdi_display, screen); template.visualid = XVisualIDFromVisual(visual); vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num); @@ -318,6 +326,7 @@ static BOOL X11DRV_WineGL_InitOpenglInfo(void) WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION); WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS)); +#endif /* Get the common GLX version supported by GLX client and server ( major/minor) */ pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]); @@ -333,7 +342,10 @@ static BOOL X11DRV_WineGL_InitOpenglInfo(void) WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen); WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx); +#if defined(__APPLE__) +#else TRACE("GL version : %s.\n", WineGLInfo.glVersion); +#endif TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER)); TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]); TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion); @@ -505,7 +517,14 @@ static BOOL has_opengl(void) * code won't be called. */ WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions; } else { +#if defined(__APPLE__) + pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig"); + pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib"); + pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig"); + pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable"); +#else ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion); +#endif } if(glxRequireExtension("GLX_ATI_render_texture")) { @@ -1723,7 +1742,14 @@ PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) /* Check the table of WGL extensions to see if we need to return a WGL extension * or a function pointer to a native OpenGL function. */ if(strncmp(lpszProc, "wgl", 3) != 0) { +#if defined(__APPLE__) +#include + PROC ret = pglXGetProcAddressARB((const GLubyte*)lpszProc); + if(!ret) ret = dlsym(RTLD_DEFAULT, (const char*)lpszProc); + return ret; +#else return pglXGetProcAddressARB((const GLubyte*)lpszProc); +#endif } else { TRACE("('%s'):%*s", lpszProc, padding, " "); for (i = 0; i < WineGLExtensionListSize; ++i) { @@ -1799,6 +1825,23 @@ BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) { } } } +#if defined(__APPLE__) + /* Force vsync on */ +#include + typedef void* CGLContextObj; + typedef int CGLContextParameter; + typedef int CGLError; + #define kCGLCPSwapInterval 222 + if (hglrc != NULL) { + static CGLContextObj (*pCGLGetCurrentContext)(void) = NULL; + static CGLError (*pCGLSetParameter)(CGLContextObj ctx, CGLContextParameter pname, const GLint *params) = NULL; + if(pCGLGetCurrentContext == NULL) pCGLGetCurrentContext = (typeof(pCGLGetCurrentContext)) dlsym(RTLD_DEFAULT, "CGLGetCurrentContext"); + if(pCGLSetParameter == NULL) pCGLSetParameter = (typeof(pCGLSetParameter)) dlsym(RTLD_DEFAULT, "CGLSetParameter"); + + GLint sync = 1; + if(pCGLGetCurrentContext()) pCGLSetParameter(pCGLGetCurrentContext(), kCGLCPSwapInterval, &sync); + } +#endif wine_tsx11_unlock(); TRACE(" returning %s\n", (ret ? "True" : "False")); return ret; @@ -3385,7 +3428,10 @@ static void X11DRV_WineGL_LoadExtensions(void) register_extension_string("WGL_NV_float_buffer"); /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */ +#if defined(__APPLE__) +#else if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL) +#endif register_extension_string("WGL_NV_texture_rectangle"); } @@ -3401,7 +3447,10 @@ static void X11DRV_WineGL_LoadExtensions(void) register_extension_string("WGL_EXT_framebuffer_sRGB"); /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */ +#if defined(__APPLE__) +#else if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL) +#endif register_extension(&WGL_NV_vertex_array_range); /* WINE-specific WGL Extensions */ diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c index ff117cc..6613dfb 100644 --- a/libs/wine/mmap.c +++ b/libs/wine/mmap.c @@ -172,6 +172,14 @@ static int try_mmap_fixed (void *addr, size_t len, int prot, int flags, { vm_address_t result = (vm_address_t)addr; +#if defined(__APPLE__) +#define MAX_MMAP_LEN 0x08000000 +if(len > MAX_MMAP_LEN && (size_t)((char*)addr+len-1) != 0xFFFFFFFF) +{ +printf("len very big (0x%08X) expect errors in (0x%08X -> 0x%08X)\n",len,(size_t)((char*)addr+MAX_MMAP_LEN),(size_t)((char*)addr+len-1)); +len = MAX_MMAP_LEN; +} +#endif if (!vm_allocate(mach_task_self(),&result,len,0)) { if (mmap( (void *)result, len, prot, flags | MAP_FIXED, fildes, off ) != MAP_FAILED) -- 1.6.0.2