Index: trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
===================================================================
--- trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp	(revision 53791)
+++ trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp	(revision 53792)
@@ -77,6 +77,5 @@
 # include <GL/glx.h>
 # include <GL/glext.h>
-//HACK FOR NOW
-typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
+# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0x103
 #endif
 #include "vmsvga_glext/glext.h"
@@ -99,4 +98,15 @@
 *   Defined Constants And Macros                                               *
 *******************************************************************************/
+/** @def VBOX_VMSVGA3D_GL_HACK_LEVEL
+ * Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions
+ * worth of extensions, but missing out on a function pointer of fifteen.  This
+ * causes headache for us when we use the function pointers below.  This hack
+ * changes the code to call the known problematic functions directly.
+ * The value is ((x)<<16 | (y))  where x and y are taken from the GL_VERSION_x_y.
+ */
+#ifndef VBOX_VMSVGA3D_GL_HACK_LEVEL
+# define VBOX_VMSVGA3D_GL_HACK_LEVEL   0
+#endif
+
 #ifndef VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE
 # define VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE 1.0
@@ -569,10 +579,12 @@
         PFNGLFRAMEBUFFERTEXTURELAYERPROC                glFramebufferTextureLayer;
         PFNGLPOINTPARAMETERFPROC                        glPointParameterf;
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
+        PFNGLBLENDCOLORPROC                             glBlendColor;
         PFNGLBLENDEQUATIONPROC                          glBlendEquation;
+#endif
         PFNGLBLENDEQUATIONSEPARATEPROC                  glBlendEquationSeparate;
         PFNGLBLENDFUNCSEPARATEPROC                      glBlendFuncSeparate;
         PFNGLSTENCILOPSEPARATEPROC                      glStencilOpSeparate;
         PFNGLSTENCILFUNCSEPARATEPROC                    glStencilFuncSeparate;
-        PFNGLBLENDCOLORPROC                             glBlendColor;
         PFNGLBINDBUFFERPROC                             glBindBuffer;
         PFNGLDELETEBUFFERSPROC                          glDeleteBuffers;
@@ -588,5 +600,7 @@
         PFNGLDRAWELEMENTSBASEVERTEXPROC                 glDrawElementsBaseVertex;
         PFNGLACTIVETEXTUREPROC                          glActiveTexture;
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
         PFNGLCLIENTACTIVETEXTUREPROC                    glClientActiveTexture;
+#endif
         PFNGLGETPROGRAMIVARBPROC                        glGetProgramivARB;
         PFNGLPROVOKINGVERTEXPROC                        glProvokingVertex;
@@ -718,11 +732,15 @@
 
     /* Temporarily.  Later start if (fMinGLVersion != 0.0 && fActualGLVersion >= fMinGLVersion) return true; */
+#ifdef RT_OS_DARWIN
     AssertMsg(   fMinGLVersion == 0.0
               || fRet == (pState->fGLVersion >= fMinGLVersion)
-#ifdef RT_OS_DARWIN
-              || VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE == 2.1
+              || VBOX_VMSVGA3D_DEFAULT_OGL_PROFILE == 2.1,
+              ("%s actual:%d min:%d fRet=%d\n",
+               pszWantedExtension, (int)(pState->fGLVersion * 10), (int)(fMinGLVersion * 10), fRet));
+#else
+    AssertMsg(fMinGLVersion == 0.0 || fRet == (pState->fGLVersion >= fMinGLVersion),
+              ("%s actual:%d min:%d fRet=%d\n",
+               pszWantedExtension, (int)(pState->fGLVersion * 10), (int)(fMinGLVersion * 10), fRet));
 #endif
-              , ("%s actual:%d min:%d fRet=%d\n",
-                 pszWantedExtension, (int)(pState->fGLVersion * 10), (int)(fMinGLVersion * 10), fRet));
     return fRet;
 }
@@ -1237,6 +1255,10 @@
     pState->ext.glPointParameterf           = (PFNGLPOINTPARAMETERFPROC)OGLGETPROCADDRESS("glPointParameterf");
     AssertMsgReturn(pState->ext.glPointParameterf, ("glPointParameterf missing"), VERR_NOT_IMPLEMENTED);
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
+    pState->ext.glBlendColor                = (PFNGLBLENDCOLORPROC)OGLGETPROCADDRESS("glBlendColor");
+    AssertMsgReturn(pState->ext.glBlendColor, ("glBlendColor missing"), VERR_NOT_IMPLEMENTED);
     pState->ext.glBlendEquation             = (PFNGLBLENDEQUATIONPROC)OGLGETPROCADDRESS("glBlendEquation");
     AssertMsgReturn(pState->ext.glBlendEquation, ("glBlendEquation missing"), VERR_NOT_IMPLEMENTED);
+#endif
     pState->ext.glBlendEquationSeparate     = (PFNGLBLENDEQUATIONSEPARATEPROC)OGLGETPROCADDRESS("glBlendEquationSeparate");
     AssertMsgReturn(pState->ext.glBlendEquationSeparate, ("glBlendEquationSeparate missing"), VERR_NOT_IMPLEMENTED);
@@ -1247,6 +1269,4 @@
     pState->ext.glStencilFuncSeparate       = (PFNGLSTENCILFUNCSEPARATEPROC)OGLGETPROCADDRESS("glStencilFuncSeparate");
     AssertMsgReturn(pState->ext.glStencilFuncSeparate, ("glStencilFuncSeparate missing"), VERR_NOT_IMPLEMENTED);
-    pState->ext.glBlendColor                = (PFNGLBLENDCOLORPROC)OGLGETPROCADDRESS("glBlendColor");
-    AssertMsgReturn(pState->ext.glBlendColor, ("glBlendColor missing"), VERR_NOT_IMPLEMENTED);
     pState->ext.glBindBuffer                = (PFNGLBINDBUFFERPROC)OGLGETPROCADDRESS("glBindBuffer");
     AssertMsgReturn(pState->ext.glBindBuffer, ("glBindBuffer missing"), VERR_NOT_IMPLEMENTED);
@@ -1271,6 +1291,8 @@
     pState->ext.glActiveTexture             = (PFNGLACTIVETEXTUREPROC)OGLGETPROCADDRESS("glActiveTexture");
     AssertMsgReturn(pState->ext.glActiveTexture, ("glActiveTexture missing"), VERR_NOT_IMPLEMENTED);
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
     pState->ext.glClientActiveTexture       = (PFNGLCLIENTACTIVETEXTUREPROC)OGLGETPROCADDRESS("glClientActiveTexture");
     AssertMsgReturn(pState->ext.glClientActiveTexture, ("glClientActiveTexture missing"), VERR_NOT_IMPLEMENTED);
+#endif
     pState->ext.glGetProgramivARB           = (PFNGLGETPROGRAMIVARBPROC)OGLGETPROCADDRESS("glGetProgramivARB");
     AssertMsgReturn(pState->ext.glGetProgramivARB, ("glGetProgramivARB missing"), VERR_NOT_IMPLEMENTED);
@@ -2212,6 +2234,7 @@
 #endif
 
-int vmsvga3dSurfaceDefine(PVGASTATE pThis, uint32_t sid, uint32_t surfaceFlags, SVGA3dSurfaceFormat format, SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES],
-                          uint32_t multisampleCount, SVGA3dTextureFilter autogenFilter, uint32_t cMipLevels, SVGA3dSize *pMipLevelSize)
+int vmsvga3dSurfaceDefine(PVGASTATE pThis, uint32_t sid, uint32_t surfaceFlags, SVGA3dSurfaceFormat format,
+                          SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES], uint32_t multisampleCount,
+                          SVGA3dTextureFilter autogenFilter, uint32_t cMipLevels, SVGA3dSize *pMipLevelSize)
 {
     PVMSVGA3DSURFACE pSurface;
@@ -2329,5 +2352,5 @@
     pSurface->flags             = surfaceFlags;
     pSurface->format            = format;
-    memcpy(pSurface->faces, face, sizeof(face));
+    memcpy(pSurface->faces, face, sizeof(pSurface->faces));
     pSurface->cFaces            = 1;        /* check for cube maps later */
     pSurface->multiSampleCount  = multisampleCount;
@@ -4468,5 +4491,11 @@
                                                     vmsvga3dBlendEquation2GL(pContext->state.aRenderState[SVGA3D_RS_BLENDEQUATIONALPHA].uintValue));
             else
+            {
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x102
+                glBlendEquation(vmsvga3dBlendEquation2GL(pRenderState[i].uintValue));
+#else
                 pState->ext.glBlendEquation(vmsvga3dBlendEquation2GL(pRenderState[i].uintValue));
+#endif
+            }
             VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
             break;
@@ -4478,5 +4507,9 @@
             vmsvgaColor2GLFloatArray(pRenderState[i].uintValue, &red, &green, &blue, &alpha);
 
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x102
+            glBlendColor(red, green, blue, alpha);
+#else
             pState->ext.glBlendColor(red, green, blue, alpha);
+#endif
             VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
             break;
@@ -5795,7 +5828,7 @@
     /* Store for vm state save/restore. */
     pContext->state.aClipPlane[index].fValid = true;
-    memcpy(pContext->state.aClipPlane[index].plane, plane, sizeof(plane));
-
-    /* @todo clip plane affected by model view in OpenGL & view in D3D + vertex shader -> not transformed (see Wine; state.c clipplane) */
+    memcpy(pContext->state.aClipPlane[index].plane, plane, sizeof(pContext->state.aClipPlane[index].plane));
+
+    /** @todo clip plane affected by model view in OpenGL & view in D3D + vertex shader -> not transformed (see Wine; state.c clipplane) */
     oglPlane[0] = (double)plane[0];
     oglPlane[1] = (double)plane[1];
@@ -6109,5 +6142,6 @@
             pState->ext.glEnableVertexAttribArray(index);
             VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
-            pState->ext.glVertexAttribPointer(index, size, type, normalized, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
+            pState->ext.glVertexAttribPointer(index, size, type, normalized, pVertexDecl[iVertex].array.stride,
+                                              (const GLvoid *)(uintptr_t)pVertexDecl[iVertex].array.offset);
             VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
             /* case SVGA3D_DECLUSAGE_COLOR:    @todo color component order not identical!! test GL_BGRA!!  */
@@ -6121,5 +6155,6 @@
                 glEnableClientState(GL_VERTEX_ARRAY);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
-                glVertexPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
+                glVertexPointer(size, type, pVertexDecl[iVertex].array.stride,
+                                (const GLvoid *)(uintptr_t)pVertexDecl[iVertex].array.offset);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
                 break;
@@ -6133,5 +6168,6 @@
                 glEnableClientState(GL_NORMAL_ARRAY);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
-                glNormalPointer(type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
+                glNormalPointer(type, pVertexDecl[iVertex].array.stride,
+                                (const GLvoid *)(uintptr_t)pVertexDecl[iVertex].array.offset);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
                 break;
@@ -6141,8 +6177,13 @@
             case SVGA3D_DECLUSAGE_TEXCOORD:
                 /* Specify the affected texture unit. */
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x103
+                glClientActiveTexture(GL_TEXTURE0 + pVertexDecl[iVertex].identity.usageIndex);
+#else
                 pState->ext.glClientActiveTexture(GL_TEXTURE0 + pVertexDecl[iVertex].identity.usageIndex);
+#endif
                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
-                glTexCoordPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
+                glTexCoordPointer(size, type, pVertexDecl[iVertex].array.stride,
+                                  (const GLvoid *)(uintptr_t)pVertexDecl[iVertex].array.offset);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
                 break;
@@ -6159,8 +6200,9 @@
                 AssertFailed(); /* see position_transformed in Wine */
                 break;
-            case SVGA3D_DECLUSAGE_COLOR:    /* @todo color component order not identical!! test GL_BGRA!! */
+            case SVGA3D_DECLUSAGE_COLOR:    /** @todo color component order not identical!! test GL_BGRA!! */
                 glEnableClientState(GL_COLOR_ARRAY);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
-                glColorPointer(size, type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
+                glColorPointer(size, type, pVertexDecl[iVertex].array.stride,
+                               (const GLvoid *)(uintptr_t)pVertexDecl[iVertex].array.offset);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
                 break;
@@ -6168,5 +6210,6 @@
                 glEnableClientState(GL_FOG_COORD_ARRAY);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
-                pState->ext.glFogCoordPointer(type, pVertexDecl[iVertex].array.stride, (const GLvoid *)pVertexDecl[iVertex].array.offset);
+                pState->ext.glFogCoordPointer(type, pVertexDecl[iVertex].array.stride,
+                                              (const GLvoid *)(uintptr_t)pVertexDecl[iVertex].array.offset);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
                 break;
@@ -6222,5 +6265,9 @@
             case SVGA3D_DECLUSAGE_TEXCOORD:
                 /* Specify the affected texture unit. */
+#if VBOX_VMSVGA3D_GL_HACK_LEVEL >= 0x103
+                glClientActiveTexture(GL_TEXTURE0 + pVertexDecl[iVertex].identity.usageIndex);
+#else
                 pState->ext.glClientActiveTexture(GL_TEXTURE0 + pVertexDecl[iVertex].identity.usageIndex);
+#endif
                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
@@ -6394,16 +6441,14 @@
             Log(("DrawIndexedPrimitive %x cPrimitives=%d cVertices=%d hint.first=%d hint.last=%d index offset=%d primitivecount=%d index width=%d index bias=%d\n", modeDraw, pRange[iPrimitive].primitiveCount, cVertices, pVertexDecl[0].rangeHint.first,  pVertexDecl[0].rangeHint.last,  pRange[iPrimitive].indexArray.offset, pRange[iPrimitive].primitiveCount,  pRange[iPrimitive].indexWidth, pRange[iPrimitive].indexBias));
             if (pRange[iPrimitive].indexBias == 0)
-            {
                 glDrawElements(modeDraw,
                                cVertices,
                                (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
-                               (GLvoid *)(pRange[iPrimitive].indexArray.offset));   /* byte offset in indices buffer */
-            }
+                               (GLvoid *)(uintptr_t)pRange[iPrimitive].indexArray.offset);   /* byte offset in indices buffer */
             else
                 pState->ext.glDrawElementsBaseVertex(modeDraw,
                                                      cVertices,
                                                      (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
-                                                     (GLvoid *)(pRange[iPrimitive].indexArray.offset),   /* byte offset in indices buffer */
-                                                     pRange[iPrimitive].indexBias);        /* basevertex */
+                                                     (GLvoid *)(uintptr_t)pRange[iPrimitive].indexArray.offset, /* byte offset in indices buffer */
+                                                     pRange[iPrimitive].indexBias);  /* basevertex */
 
             /* Unbind the index buffer after usage. */
