Index: trunk/src/VBox/Additions/common/crOpenGL/DD_glc.py
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/DD_glc.py	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/DD_glc.py	(revision 18882)
@@ -0,0 +1,142 @@
+print """
+/** @file
+ * VBox OpenGL chromium functions header
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+"""
+# Copyright (c) 2001, Stanford University
+# All rights reserved.
+#
+# See the file LICENSE.txt for information on redistributing this software.
+
+import sys
+
+import apiutil
+
+apiutil.CopyrightC()
+
+print """
+/* DO NOT EDIT - THIS FILE GENERATED BY THE DD_gl.py SCRIPT */
+
+#include "chromium.h"
+#include "cr_string.h"
+#include "cr_version.h"
+#include "stub.h"
+#include "dri_drv.h"
+#include "cr_gl.h"
+"""
+
+commoncall_special = [
+   "ArrayElement",
+   "Begin",
+   "CallList",
+   "CallLists",
+   "Color3f",
+   "Color3fv",
+   "Color4f",
+   "Color4fv",
+   "EdgeFlag",
+   "End",
+   "EvalCoord1f",
+   "EvalCoord1fv",
+   "EvalCoord2f",
+   "EvalCoord2fv",
+   "EvalPoint1",
+   "EvalPoint2",
+   "FogCoordfEXT",
+   "FogCoordfvEXT",
+   "Indexf",
+   "Indexfv",
+   "Materialfv",
+   "MultiTexCoord1fARB",
+   "MultiTexCoord1fvARB",
+   "MultiTexCoord2fARB",
+   "MultiTexCoord2fvARB",
+   "MultiTexCoord3fARB",
+   "MultiTexCoord3fvARB",
+   "MultiTexCoord4fARB",
+   "MultiTexCoord4fvARB",
+   "Normal3f",
+   "Normal3fv",
+   "SecondaryColor3fEXT",
+   "SecondaryColor3fvEXT",
+   "TexCoord1f",
+   "TexCoord1fv",
+   "TexCoord2f",
+   "TexCoord2fv",
+   "TexCoord3f",
+   "TexCoord3fv",
+   "TexCoord4f",
+   "TexCoord4fv",
+   "Vertex2f",
+   "Vertex2fv",
+   "Vertex3f",
+   "Vertex3fv",
+   "Vertex4f",
+   "Vertex4fv",
+   "VertexAttrib1fNV",
+   "VertexAttrib1fvNV",
+   "VertexAttrib2fNV",
+   "VertexAttrib2fvNV",
+   "VertexAttrib3fNV",
+   "VertexAttrib3fvNV",
+   "VertexAttrib4fNV",
+   "VertexAttrib4fvNV",
+   "VertexAttrib1fARB",
+   "VertexAttrib1fvARB",
+   "VertexAttrib2fARB",
+   "VertexAttrib2fvARB",
+   "VertexAttrib3fARB",
+   "VertexAttrib3fvARB",
+   "VertexAttrib4fARB",
+   "VertexAttrib4fvARB",
+   "EvalMesh1",
+   "EvalMesh2",
+   "Rectf",
+   "DrawArrays",
+   "DrawElements",
+   "DrawRangeElements"
+]
+
+keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
+
+for func_name in keys:
+    if "Chromium" == apiutil.Category(func_name):
+        continue
+    if func_name == "BoundsInfoCR":
+        continue
+
+    return_type = apiutil.ReturnType(func_name)
+    params = apiutil.Parameters(func_name)
+
+    if func_name in commoncall_special:
+        print "%s vboxDD_gl%s( %s )" % (return_type, func_name, apiutil.MakeDeclarationString(params) )
+    else:
+        if apiutil.MakeDeclarationString(params)=="void":
+            print "%s vboxDD_gl%s( GLcontext *ctx )" % (return_type, func_name )
+        else:
+            print "%s vboxDD_gl%s( GLcontext *ctx, %s )" % (return_type, func_name, apiutil.MakeDeclarationString(params) )
+    print "{"
+
+    if return_type != "void":
+        print "\treturn ",
+
+    print "\tcr_gl%s( %s );" % (func_name, apiutil.MakeCallString(params))
+    print "}"
+    print ""
+
Index: trunk/src/VBox/Additions/common/crOpenGL/DD_glh.py
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/DD_glh.py	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/DD_glh.py	(revision 18882)
@@ -0,0 +1,139 @@
+print """
+/** @file
+ * VBox OpenGL chromium functions header
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+"""
+# Copyright (c) 2001, Stanford University
+# All rights reserved.
+#
+# See the file LICENSE.txt for information on redistributing this software.
+
+import sys
+
+import apiutil
+
+apiutil.CopyrightC()
+
+print """
+/* DO NOT EDIT - THIS FILE GENERATED BY THE DD_gl.py SCRIPT */
+#ifndef __DD_GL_H__
+#define __DD_GL_H__
+
+#include "chromium.h"
+#include "cr_string.h"
+#include "cr_version.h"
+#include "stub.h"
+
+"""
+
+commoncall_special = [
+   "ArrayElement",
+   "Begin",
+   "CallList",
+   "CallLists",
+   "Color3f",
+   "Color3fv",
+   "Color4f",
+   "Color4fv",
+   "EdgeFlag",
+   "End",
+   "EvalCoord1f",
+   "EvalCoord1fv",
+   "EvalCoord2f",
+   "EvalCoord2fv",
+   "EvalPoint1",
+   "EvalPoint2",
+   "FogCoordfEXT",
+   "FogCoordfvEXT",
+   "Indexf",
+   "Indexfv",
+   "Materialfv",
+   "MultiTexCoord1fARB",
+   "MultiTexCoord1fvARB",
+   "MultiTexCoord2fARB",
+   "MultiTexCoord2fvARB",
+   "MultiTexCoord3fARB",
+   "MultiTexCoord3fvARB",
+   "MultiTexCoord4fARB",
+   "MultiTexCoord4fvARB",
+   "Normal3f",
+   "Normal3fv",
+   "SecondaryColor3fEXT",
+   "SecondaryColor3fvEXT",
+   "TexCoord1f",
+   "TexCoord1fv",
+   "TexCoord2f",
+   "TexCoord2fv",
+   "TexCoord3f",
+   "TexCoord3fv",
+   "TexCoord4f",
+   "TexCoord4fv",
+   "Vertex2f",
+   "Vertex2fv",
+   "Vertex3f",
+   "Vertex3fv",
+   "Vertex4f",
+   "Vertex4fv",
+   "VertexAttrib1fNV",
+   "VertexAttrib1fvNV",
+   "VertexAttrib2fNV",
+   "VertexAttrib2fvNV",
+   "VertexAttrib3fNV",
+   "VertexAttrib3fvNV",
+   "VertexAttrib4fNV",
+   "VertexAttrib4fvNV",
+   "VertexAttrib1fARB",
+   "VertexAttrib1fvARB",
+   "VertexAttrib2fARB",
+   "VertexAttrib2fvARB",
+   "VertexAttrib3fARB",
+   "VertexAttrib3fvARB",
+   "VertexAttrib4fARB",
+   "VertexAttrib4fvARB",
+   "EvalMesh1",
+   "EvalMesh2",
+   "Rectf",
+   "DrawArrays",
+   "DrawElements",
+   "DrawRangeElements"
+]
+
+# Extern-like declarations
+keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
+
+for func_name in keys:
+    if "Chromium" == apiutil.Category(func_name):
+        continue
+    if func_name == "BoundsInfoCR":
+        continue
+
+    return_type = apiutil.ReturnType(func_name)
+    params = apiutil.Parameters(func_name)
+
+    if func_name in commoncall_special:
+        print "extern %s vboxDD_gl%s( %s );" % (return_type, func_name,
+                                                apiutil.MakeDeclarationString( params ))
+    else:
+        if apiutil.MakeDeclarationString(params)=="void":
+            print "extern %s vboxDD_gl%s( GLcontext *ctx );" % (return_type, func_name)
+        else:
+            print "extern %s vboxDD_gl%s( GLcontext *ctx, %s );" % (return_type, func_name,
+                                                                    apiutil.MakeDeclarationString( params ))
+
+print "#endif /* __DD_GL_H__ */"
Index: trunk/src/VBox/Additions/common/crOpenGL/Linux_i386_exports_dri.py
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/Linux_i386_exports_dri.py	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/Linux_i386_exports_dri.py	(revision 18882)
@@ -0,0 +1,93 @@
+# Copyright (c) 2001, Stanford University
+# All rights reserved.
+#
+# See the file LICENSE.txt for information on redistributing this software.
+
+
+import sys
+
+import apiutil
+
+
+def GenerateEntrypoints():
+
+    #apiutil.CopyrightC()
+
+    # Get sorted list of dispatched functions.
+    # The order is very important - it must match cr_opcodes.h
+    # and spu_dispatch_table.h
+    print '%include "iprt/asmdefs.mac"'
+    print ""
+    print "%ifdef RT_ARCH_AMD64"
+    print "extern glim"
+    print "%else ; X86"
+    print "extern glim"
+    print "%endif"
+    print ""
+
+    keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
+
+    for index in range(len(keys)):
+        func_name = keys[index]
+        if apiutil.Category(func_name) == "Chromium":
+            continue
+
+        print "BEGINPROC_EXPORTED cr_gl%s" % func_name
+        print "%ifdef RT_ARCH_AMD64"
+        print "\tmov \trax, qword glim+%d" % (8*index)
+        print "\tjmp \t[rax]"
+        print "%else ; X86"
+        print "\tmov \teax, dword glim+%d" % (4*index)
+        print "\tjmp \t[eax]"
+        print "%endif"
+        print "ENDPROC cr_gl%s" % func_name
+        print ""
+
+
+    print ';'
+    print '; Aliases'
+    print ';'
+
+    # Now loop over all the functions and take care of any aliases
+    allkeys = apiutil.GetAllFunctions(sys.argv[1]+"/APIspec.txt")
+    for func_name in allkeys:
+        if "omit" in apiutil.ChromiumProps(func_name):
+            continue
+
+        if func_name in keys:
+            # we already processed this function earlier
+            continue
+
+        # alias is the function we're aliasing
+        alias = apiutil.Alias(func_name)
+        if alias:
+            # this dict lookup should never fail (raise an exception)!
+            index = keys.index(alias)
+            print "BEGINPROC_EXPORTED cr_gl%s" % func_name
+            print "%ifdef RT_ARCH_AMD64"
+            print "\tmov \trax, qword glim+%d" % (8*index)
+            print "\tjmp \t[rax]"
+            print "%else ; X86"
+            print "\tmov \teax, dword glim+%d" % (4*index)
+            print "\tjmp \t[eax]"
+            print "%endif"
+            print "ENDPROC cr_gl%s" % func_name
+            print ""
+
+
+    print ';'
+    print '; No-op stubs'
+    print ';'
+
+    # Now generate no-op stub functions
+    for func_name in allkeys:
+        if "stub" in apiutil.ChromiumProps(func_name):
+            print "BEGINPROC_EXPORTED cr_gl%s" % func_name
+            print "\tleave"
+            print "\tret"
+            print "ENDPROC cr_gl%s" % func_name
+            print ""
+
+
+GenerateEntrypoints()
+
Index: trunk/src/VBox/Additions/common/crOpenGL/Linux_i386_glxapi_exports.py
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/Linux_i386_glxapi_exports.py	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/Linux_i386_glxapi_exports.py	(revision 18882)
@@ -0,0 +1,107 @@
+#
+# Copyright (C) 2009 Sun Microsystems, Inc.
+#
+# This file is part of VirtualBox Open Source Edition (OSE), as
+# available from http://www.virtualbox.org. This file is free software;
+# you can redistribute it and/or modify it under the terms of the GNU
+# General Public License (GPL) as published by the Free Software
+# Foundation, in version 2 as it comes in the "COPYING" file of the
+# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+# Clara, CA 95054 USA or visit http://www.sun.com if you need
+# additional information or have any questions.
+
+import sys
+
+#Note, this should match the fakedri_glxfuncsList.h order
+glx_functions = [
+"CopyContext",
+"UseXFont",
+#"GetDriverConfig",
+"GetProcAddress",
+"FreeMemoryMESA",
+"QueryExtension",
+"IsDirect",
+"DestroyGLXPbufferSGIX",
+"QueryGLXPbufferSGIX",
+"CreateGLXPixmap",
+"CreateGLXPixmapWithConfigSGIX",
+"QueryContext",
+"CreateContextWithConfigSGIX",
+"SwapBuffers",
+"CreateNewContext",
+"SelectEventSGIX",
+"QueryContextInfoEXT",
+"GetCurrentDrawable",
+"ChooseFBConfig",
+"WaitGL",
+"GetFBConfigs",
+"CreatePixmap",
+"GetSelectedEventSGIX",
+"GetCurrentReadDrawable",
+"ImportContextEXT",
+"GetContextIDEXT",
+"GetCurrentDisplay",
+"QueryServerString",
+"CreateWindow",
+"SelectEvent",
+"GetVisualFromFBConfigSGIX",
+"MakeCurrentReadSGI",
+"GetFBConfigFromVisualSGIX",
+"QueryDrawable",
+"CreateContext",
+"GetConfig",
+"CreateGLXPbufferSGIX",
+"AllocateMemoryMESA",
+"GetMemoryOffsetMESA",
+"CreatePbuffer",
+"ChooseFBConfigSGIX",
+"WaitX",
+"GetVisualFromFBConfig",
+"CreateGLXPixmapMESA",
+#"GetScreenDriver",
+"GetFBConfigAttrib",
+"GetCurrentContext",
+"GetClientString",
+"GetCurrentDisplayEXT",
+"DestroyPixmap",
+"MakeCurrent",
+"DestroyContext",
+"GetProcAddressARB",
+"GetSelectedEvent",
+"FreeContextEXT",
+"DestroyPbuffer",
+"DestroyWindow",
+"DestroyGLXPixmap",
+"QueryVersion",
+"ChooseVisual",
+"MakeContextCurrent",
+"QueryExtensionsString",
+"GetFBConfigAttribSGIX"
+];
+
+print '%include "iprt/asmdefs.mac"'
+print ""
+print "%ifdef RT_ARCH_AMD64"
+print "extern glxim"
+print "%else ; X86"
+print "extern glxim"
+print "%endif"
+print ""
+
+for index in range(len(glx_functions)):
+    func_name = glx_functions[index]
+
+    print "BEGINPROC_EXPORTED vbox_glX%s" % func_name
+    print "%ifdef RT_ARCH_AMD64"
+    print "\tmov \trax, qword glxim+%d" % (8*index)
+    print "\tjmp \t[rax]"
+    print "%else ; X86"
+    print "\tmov \teax, dword glxim+%d" % (4*index)
+    print "\tjmp \t[eax]"
+    print "%endif"
+    print "ENDPROC vbox_glX%s" % func_name
+    print ""
+
Index: trunk/src/VBox/Additions/common/crOpenGL/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/Makefile.kmk	(revision 18881)
+++ trunk/src/VBox/Additions/common/crOpenGL/Makefile.kmk	(revision 18882)
@@ -36,6 +36,5 @@
     VBoxOGLfeedbackspu
 
-ifndef VBOX_OSE
- if1of ($(KBUILD_TARGET),linux solaris)
+if1of ($(KBUILD_TARGET),linux solaris)
 DLLS += \
     VBoxOGL \
@@ -44,5 +43,4 @@
     VBoxOGLpackspu \
     VBoxOGLfeedbackspu
- endif
 endif
 
@@ -52,5 +50,5 @@
   VBoxOGL_FAKEDRI = 1
  endif
- VBOX_PATH_MESA_SOURCE = $(VBOX_PATH_X11_ROOT)/mesa-7.2
+ VBOX_PATH_MESA_SOURCE = $(PATH_ROOT)/src/libs/mesa-7.2
 
  # Only Solaris right now needs C stubs because I can't figure out how to
Index: trunk/src/VBox/Additions/common/crOpenGL/dri_drv.c
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/dri_drv.c	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/dri_drv.c	(revision 18882)
@@ -0,0 +1,1007 @@
+/* $Id$ */
+
+/** @file
+ * VBox OpenGL DRI driver functions
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ * --------------------------------------------------------------------
+ *
+ * This file is based in part on the tdfx driver from X.Org/Mesa, with the
+ * following copyright notice:
+ *
+ * Copyright 2000 VA Linux Systems Inc., Fremont, California.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Original rewrite:
+ *      Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
+ *
+ * Authors:
+ *      Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "cr_error.h"
+#include "cr_gl.h"
+#include "stub.h"
+#include "dri_drv.h"
+#include "DD_gl.h"
+
+/** @todo some of those are or'ed with GL_VERSIONS and ain't needed here*/
+#define need_GL_ARB_occlusion_query
+#define need_GL_ARB_point_parameters
+#define need_GL_NV_point_sprite
+#define need_GL_ARB_texture_compression
+#define need_GL_ARB_transpose_matrix
+#define need_GL_ARB_vertex_buffer_object
+#define need_GL_ARB_vertex_program
+#define need_GL_ARB_window_pos
+#define need_GL_EXT_blend_color
+#define need_GL_EXT_blend_minmax
+#define need_GL_EXT_blend_func_separate
+#define need_GL_EXT_fog_coord
+#define need_GL_EXT_multi_draw_arrays
+#define need_GL_EXT_secondary_color
+#define need_GL_EXT_texture_object
+#define need_GL_EXT_texture3D
+#define need_GL_VERSION_1_3
+#define need_GL_VERSION_1_4
+#define need_GL_VERSION_1_5
+
+#include "drivers/dri/common/extension_helper.h"
+
+/** @todo add more which are supported by chromium like GL_NV_vertex_program etc.*/
+static const struct dri_extension vbox_extensions[] = {
+    { "GL_ARB_depth_texture",              NULL },
+    { "GL_ARB_fragment_program",           NULL },
+    { "GL_ARB_multitexture",               NULL },
+    { "GL_ARB_occlusion_query",            GL_ARB_occlusion_query_functions },
+    { "GL_ARB_point_parameters",           GL_ARB_point_parameters_functions },
+    { "GL_NV_point_sprite",                GL_NV_point_sprite_functions },
+    { "GL_ARB_shadow",                     NULL },
+    { "GL_ARB_shadow_ambient",             NULL },
+    { "GL_ARB_texture_border_clamp",       NULL },
+    { "GL_ARB_texture_compression",        GL_ARB_texture_compression_functions },
+    { "GL_ARB_texture_cube_map",           NULL },
+    { "GL_ARB_texture_env_add",            NULL },
+    { "GL_ARB_texture_env_combine",        NULL },
+    { "GL_EXT_texture_env_combine",        NULL },
+    { "GL_ARB_texture_env_crossbar",       NULL },
+    { "GL_ARB_texture_env_dot3",           NULL },
+    { "GL_EXT_texture_env_dot3",           NULL },
+    { "GL_ARB_texture_mirrored_repeat",    NULL },
+    { "GL_ARB_texture_non_power_of_two",   NULL },
+    { "GL_ARB_transpose_matrix",           GL_ARB_transpose_matrix_functions },
+    { "GL_ARB_vertex_buffer_object",       GL_ARB_vertex_buffer_object_functions },
+    { "GL_ARB_vertex_program",             GL_ARB_vertex_program_functions },
+    { "GL_ARB_window_pos",                 GL_ARB_window_pos_functions },
+    { "GL_EXT_blend_color",                GL_EXT_blend_color_functions },
+    { "GL_EXT_blend_minmax",               GL_EXT_blend_minmax_functions },
+    { "GL_EXT_blend_func_separate",        GL_EXT_blend_func_separate_functions },
+    { "GL_EXT_blend_subtract",             NULL },
+    { "GL_EXT_texture_env_add",            NULL }, /** @todo that's an alias to GL_ARB version, remove it?*/
+    { "GL_EXT_fog_coord",                  GL_EXT_fog_coord_functions },
+    { "GL_EXT_multi_draw_arrays",          GL_EXT_multi_draw_arrays_functions },
+    { "GL_EXT_secondary_color",            GL_EXT_secondary_color_functions },
+    { "GL_EXT_shadow_funcs",               NULL },
+    { "GL_EXT_stencil_wrap",               NULL },
+    { "GL_EXT_texture_cube_map",           NULL }, /** @todo another alias*/
+    { "GL_EXT_texture_edge_clamp",         NULL },
+    { "GL_EXT_texture_filter_anisotropic", NULL },
+    { "GL_EXT_texture_lod_bias",           NULL },
+    { "GL_EXT_texture_object",             GL_EXT_texture_object_functions },
+    { "GL_EXT_texture3D",                  GL_EXT_texture3D_functions },
+    { "GL_NV_texgen_reflection",           NULL },
+    { "GL_ARB_texture_rectangle",          NULL },
+    { "GL_SGIS_generate_mipmap",           NULL },
+    { "GL_SGIS_texture_edge_clamp",        NULL } /** @todo another alias*/
+};
+
+static void
+vboxdriInitExtensions(GLcontext * ctx)
+{
+    /** @todo have to check extensions supported by host here first */
+    driInitExtensions(ctx, vbox_extensions, GL_FALSE);
+}
+
+static GLvertexformat vboxdriTnlVtxFmt;
+
+
+/* This callback tells us that Mesa's internal state has changed.  We probably
+ * don't need to handle this ourselves, so just pass it on to other parts of
+ * Mesa we may be using, as the swrast driver and others do */
+static void
+vboxDDUpdateState(GLcontext * ctx, GLuint new_state)
+{
+    _swrast_InvalidateState(ctx, new_state);
+    _swsetup_InvalidateState(ctx, new_state);
+    _vbo_InvalidateState(ctx, new_state);
+    _tnl_InvalidateState(ctx, new_state);
+}
+
+#if 0  /* See comment in vboxdriInitFuncs */
+static void 
+vboxDDGetBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
+{
+    /*do something, note it's obsolete*/
+}
+
+static void
+vboxDDResizeBuffer( GLcontext *ctx, GLframebuffer *fb,
+                          GLuint width, GLuint height)
+{
+    /*do something, note it's obsolete*/
+}
+
+static void
+vboxDDError(GLcontext *ctx)
+{
+    //__GLcontextRec::ErrorValue contains the error value.
+}
+#endif
+
+static void
+vboxDDDrawPixels(GLcontext *ctx,
+                 GLint x, GLint y, GLsizei width, GLsizei height,
+                 GLenum format, GLenum type,
+                 const struct gl_pixelstore_attrib *unpack,
+                 const GLvoid *pixels)
+{
+}
+
+static void
+vboxDDReadPixels(GLcontext *ctx,
+                 GLint x, GLint y, GLsizei width, GLsizei height,
+                 GLenum format, GLenum type,
+                 const struct gl_pixelstore_attrib *unpack,
+                 GLvoid *dest)
+{
+}
+
+static void
+vboxDDCopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
+           GLsizei width, GLsizei height,
+           GLint dstx, GLint dsty, GLenum type)
+{
+}
+
+static void
+vboxDDBitmap(GLcontext *ctx,
+             GLint x, GLint y, GLsizei width, GLsizei height,
+             const struct gl_pixelstore_attrib *unpack,
+             const GLubyte *bitmap)
+{
+}
+
+static void
+vboxDDTexImage1D(GLcontext *ctx, GLenum target, GLint level,
+                 GLint internalFormat,
+                 GLint width, GLint border,
+                 GLenum format, GLenum type, const GLvoid *pixels,
+                 const struct gl_pixelstore_attrib *packing,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+}
+
+static void
+vboxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level,
+                 GLint internalFormat,
+                 GLint width, GLint height, GLint border,
+                 GLenum format, GLenum type, const GLvoid *pixels,
+                 const struct gl_pixelstore_attrib *packing,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+}
+   
+static void
+vboxDDTexImage3D(GLcontext *ctx, GLenum target, GLint level,
+                 GLint internalFormat,
+                 GLint width, GLint height, GLint depth, GLint border,
+                 GLenum format, GLenum type, const GLvoid *pixels,
+                 const struct gl_pixelstore_attrib *packing,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+}
+
+static void
+vboxDDTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
+                    GLint xoffset, GLsizei width,
+                    GLenum format, GLenum type,
+                    const GLvoid *pixels,
+                    const struct gl_pixelstore_attrib *packing,
+                    struct gl_texture_object *texObj,
+                    struct gl_texture_image *texImage)
+{
+}
+   
+static void
+vboxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
+                    GLint xoffset, GLint yoffset,
+                    GLsizei width, GLsizei height,
+                    GLenum format, GLenum type,
+                    const GLvoid *pixels,
+                    const struct gl_pixelstore_attrib *packing,
+                    struct gl_texture_object *texObj,
+                    struct gl_texture_image *texImage)
+{
+}
+
+   
+static void
+vboxDDTexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
+                    GLint xoffset, GLint yoffset, GLint zoffset,
+                    GLsizei width, GLsizei height, GLint depth,
+                    GLenum format, GLenum type,
+                    const GLvoid *pixels,
+                    const struct gl_pixelstore_attrib *packing,
+                    struct gl_texture_object *texObj,
+                    struct gl_texture_image *texImage)
+{
+}
+
+
+static void
+vboxDDGetTexImage(GLcontext *ctx, GLenum target, GLint level,
+                  GLenum format, GLenum type, GLvoid *pixels,
+                  struct gl_texture_object *texObj,
+                  struct gl_texture_image *texImage)
+{
+}
+
+static void
+vboxDDBindTexture(GLcontext *ctx, GLenum target,
+            struct gl_texture_object *tObj)
+{
+}
+
+static GLboolean
+vboxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *t)
+{
+}
+
+static void
+vboxDDPrioritizeTexture(GLcontext *ctx, struct gl_texture_object *t,
+                        GLclampf priority)
+{
+}
+
+static void
+vboxDDBlendColor(GLcontext *ctx, const GLfloat color[4])
+{
+}
+
+static void
+vboxDDClearColor(GLcontext *ctx, const GLfloat color[4])
+{
+}
+
+static void
+vboxDDClearIndex(GLcontext *ctx, GLuint index)
+{
+}
+
+static void
+vboxDDClipPlane(GLcontext *ctx, GLenum plane, const GLfloat *equation)
+{
+}
+
+/*@todo Enable or disable server-side gl capabilities, not related to glEnable? */
+static void
+vboxDDEnable(GLcontext *ctx, GLenum cap, GLboolean state)
+{
+    if (state) 
+        cr_glEnable(cap);
+    else 
+        cr_glDisable(cap);
+}
+
+static void
+vboxDDRenderMode(GLcontext *ctx, GLenum mode)
+{
+    cr_glRenderMode(mode);
+}
+
+static void
+vboxDDTexParameter(GLcontext *ctx, GLenum target,
+                     struct gl_texture_object *texObj,
+                     GLenum pname, const GLfloat *params)
+{
+}
+
+/*Note, checking glGetError before and after those calls is the only way 
+ *to return if we succeded to get value or not, but it will add 2 sync calls and
+ *will reset glGetError value returned in case application calls it explicitly
+ */
+static GLboolean 
+vboxDDGetBooleanv(GLcontext *ctx, GLenum pname, GLboolean *result)
+{
+    cr_glGetBooleanv(pname, result);
+    return GL_TRUE;
+}
+
+static GLboolean 
+vboxDDGetDoublev(GLcontext *ctx, GLenum pname, GLdouble *result)
+{
+    cr_glGetDoublev(pname, result);
+    return GL_TRUE;
+}
+
+static GLboolean 
+vboxDDGetFloatv(GLcontext *ctx, GLenum pname, GLfloat *result)
+{
+    cr_glGetFloatv(pname, result);
+    return GL_TRUE;
+}
+
+static GLboolean 
+vboxDDGetIntegerv(GLcontext *ctx, GLenum pname, GLint *result)
+{
+    cr_glGetIntegerv(pname, result);
+    return GL_TRUE;
+}
+
+static GLboolean 
+vboxDDGetPointerv(GLcontext *ctx, GLenum pname, GLvoid **result)
+{
+    cr_glGetPointerv(pname, result);
+    return GL_TRUE;
+}
+
+/** @todo 
+ * change stub's createcontext to reuse driver private part of mesa's ctx to store stub ctx info.
+ */
+#define VBOX_GL_FUNC(func) vboxDD_gl##func
+static void
+vboxdriInitFuncs(struct dd_function_table *driver)
+{
+   driver->GetString = VBOX_GL_FUNC(GetString);
+   driver->UpdateState = vboxDDUpdateState;
+#if 0
+   /* I assume that we don't need to change these.  In that case, prefer the
+    * default implementation over a stub. */
+   driver->GetBufferSize = vboxDDGetBufferSize;
+   driver->ResizeBuffers = vboxDDResizeBuffer;
+   driver->Error = vboxDDError;
+#endif
+
+   driver->Finish = VBOX_GL_FUNC(Finish);
+   driver->Flush = VBOX_GL_FUNC(Flush);
+
+   /* framebuffer/image functions */
+   driver->Clear = VBOX_GL_FUNC(Clear);
+   driver->Accum = VBOX_GL_FUNC(Accum);
+   // driver->RasterPos = VBOX_GL_FUNC(RasterPos);  /* No such element in *driver */
+   driver->DrawPixels = vboxDDDrawPixels;
+   driver->ReadPixels = vboxDDReadPixels;
+   driver->CopyPixels = vboxDDCopyPixels;
+   driver->Bitmap = vboxDDBitmap;
+
+   /* Texture functions */
+    /** @todo deal with texnames and gl_texture_object pointers which are passed here*/
+   driver->ChooseTextureFormat = NULL;
+   driver->TexImage1D = vboxDDTexImage1D;
+   driver->TexImage2D = vboxDDTexImage2D;
+   driver->TexImage3D = vboxDDTexImage3D;
+   driver->TexSubImage1D = vboxDDTexSubImage1D;
+   driver->TexSubImage2D = vboxDDTexSubImage2D;
+   driver->TexSubImage3D = vboxDDTexSubImage3D;
+   driver->GetTexImage = vboxDDGetTexImage;
+   driver->CopyTexImage1D = VBOX_GL_FUNC(CopyTexImage1D);
+   driver->CopyTexImage2D = VBOX_GL_FUNC(CopyTexImage2D);
+   driver->CopyTexSubImage1D = VBOX_GL_FUNC(CopyTexSubImage1D);
+   driver->CopyTexSubImage2D = VBOX_GL_FUNC(CopyTexSubImage2D);
+   driver->CopyTexSubImage3D = VBOX_GL_FUNC(CopyTexSubImage3D);
+   // driver->GenerateMipmap = VBOX_GL_FUNC(GenerateMipmap); /** @todo or NULL */
+   // driver->TestProxyTexImage = vboxDDTestProxyTexImage; /** @todo just pass to glTexImage as we take  care or proxy textures there */
+   // driver->CompressedTexImage1D = VBOX_GL_FUNC(CompressedTexImage1D);
+   // driver->CompressedTexImage2D = VBOX_GL_FUNC(CompressedTexImage2D);
+   // driver->CompressedTexImage3D = VBOX_GL_FUNC(CompressedTexImage3D);
+   // driver->CompressedTexSubImage1D = VBOX_GL_FUNC(CompressedTexSubImage1D);
+   // driver->CompressedTexSubImage2D = VBOX_GL_FUNC(CompressedTexSubImage2D);
+   // driver->CompressedTexSubImage3D = VBOX_GL_FUNC(CompressedTexSubImage3D);
+   // driver->GetCompressedTexImage = VBOX_GL_FUNC(GetCompressedTexImage);
+   // driver->CompressedTextureSize = NULL; /** @todo */
+   driver->BindTexture = vboxDDBindTexture;
+   // driver->NewTextureObject = vboxDDNewTextureObject; /** @todo */
+   // driver->DeleteTexture = vboxDDDeleteTexture; /** @todo */
+   // driver->NewTextureImage = vboxDDNewTextureImage; /** @todo */
+   // driver->FreeTexImageData = vboxDDFreeTexImageData; /** @todo */
+   // driver->MapTexture = vboxDDMapTexture; /** @todo */
+   // driver->UnmapTexture = vboxDDUnmapTexture; /** @todo */
+   // driver->TextureMemCpy = vboxDDTextureMemCpy; /** @todo */
+   driver->IsTextureResident = vboxDDIsTextureResident;
+   driver->PrioritizeTexture = vboxDDPrioritizeTexture;
+   driver->ActiveTexture = VBOX_GL_FUNC(ActiveTextureARB);
+   // driver->UpdateTexturePalette = vboxDDUpdateTexturePalette; /** @todo */
+
+   /* imaging */
+   /*driver->CopyColorTable = _swrast_CopyColorTable;
+   driver->CopyColorSubTable = _swrast_CopyColorSubTable;
+   driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
+   driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;*/
+
+   /* Vertex/fragment programs */
+   driver->BindProgram = NULL;
+   // driver->NewProgram = _mesa_new_program;  /** @todo */
+   // driver->DeleteProgram = _mesa_delete_program;  /** @todo */
+   driver->ProgramStringNotify = NULL;
+#if FEATURE_MESA_program_debug
+   // driver->GetProgramRegister = _mesa_get_program_register;  /** @todo */
+#endif /* FEATURE_MESA_program_debug */
+   driver->IsProgramNative = NULL;
+
+   /* simple state commands */
+   driver->AlphaFunc = VBOX_GL_FUNC(AlphaFunc);
+   driver->BlendColor = vboxDDBlendColor;
+   // driver->BlendEquationSeparate = VBOX_GL_FUNC(BlendEquationSeparate);  /** @todo */
+   driver->BlendFuncSeparate = VBOX_GL_FUNC(BlendFuncSeparateEXT);
+   driver->ClearColor = vboxDDClearColor;
+   driver->ClearDepth = VBOX_GL_FUNC(ClearDepth);
+   driver->ClearIndex = vboxDDClearIndex;
+   driver->ClearStencil = VBOX_GL_FUNC(ClearStencil);
+   driver->ClipPlane = vboxDDClipPlane;
+   driver->ColorMask = VBOX_GL_FUNC(ColorMask);
+   driver->ColorMaterial = VBOX_GL_FUNC(ColorMaterial);
+   driver->CullFace = VBOX_GL_FUNC(CullFace);
+   driver->DrawBuffer = VBOX_GL_FUNC(DrawBuffer);  /** @todo */
+   // driver->DrawBuffers = VBOX_GL_FUNC(DrawBuffers);   /** @todo */
+   driver->FrontFace = VBOX_GL_FUNC(FrontFace);
+   driver->DepthFunc = VBOX_GL_FUNC(DepthFunc);
+   driver->DepthMask = VBOX_GL_FUNC(DepthMask);
+   driver->DepthRange = VBOX_GL_FUNC(DepthRange);
+   driver->Enable = vboxDDEnable;
+   driver->Fogfv = VBOX_GL_FUNC(Fogfv);
+   driver->Hint = VBOX_GL_FUNC(Hint);
+   driver->IndexMask = VBOX_GL_FUNC(IndexMask);
+   driver->Lightfv = VBOX_GL_FUNC(Lightfv);
+   driver->LightModelfv = VBOX_GL_FUNC(LightModelfv);
+   driver->LineStipple = VBOX_GL_FUNC(LineStipple);
+   driver->LineWidth = VBOX_GL_FUNC(LineWidth);
+   // driver->LogicOpcode = VBOX_GL_FUNC(LogicOpcode);   /** @todo */
+   driver->PointParameterfv = VBOX_GL_FUNC(PointParameterfvARB);
+   driver->PointSize = VBOX_GL_FUNC(PointSize);
+   driver->PolygonMode = VBOX_GL_FUNC(PolygonMode);
+   driver->PolygonOffset = VBOX_GL_FUNC(PolygonOffset);
+   driver->PolygonStipple = VBOX_GL_FUNC(PolygonStipple);
+   driver->ReadBuffer = VBOX_GL_FUNC(ReadBuffer);
+   driver->RenderMode = vboxDDRenderMode;
+   driver->Scissor = VBOX_GL_FUNC(Scissor);
+   driver->ShadeModel = VBOX_GL_FUNC(ShadeModel);
+   // driver->StencilFuncSeparate = VBOX_GL_FUNC(StencilFuncSeparate);   /** @todo */
+   // driver->StencilOpSeparate = VBOX_GL_FUNC(StencilOpSeparate);   /** @todo */
+   // driver->StencilMaskSeparate = VBOX_GL_FUNC(StencilMaskSeparate);   /** @todo */
+   driver->TexGen = VBOX_GL_FUNC(TexGenfv);
+   driver->TexEnv = VBOX_GL_FUNC(TexEnvfv);
+   driver->TexParameter = vboxDDTexParameter;
+   // driver->TextureMatrix = VBOX_GL_FUNC(TextureMatrix);   /** @todo */
+   driver->Viewport = VBOX_GL_FUNC(Viewport);
+
+   /* vertex arrays */
+   driver->VertexPointer = VBOX_GL_FUNC(VertexPointer);
+   driver->NormalPointer = VBOX_GL_FUNC(NormalPointer);
+   driver->ColorPointer = VBOX_GL_FUNC(ColorPointer);
+   driver->FogCoordPointer = VBOX_GL_FUNC(FogCoordPointerEXT);
+   driver->IndexPointer = VBOX_GL_FUNC(IndexPointer);
+   driver->SecondaryColorPointer = VBOX_GL_FUNC(SecondaryColorPointerEXT);
+   driver->TexCoordPointer = VBOX_GL_FUNC(TexCoordPointer);
+   driver->EdgeFlagPointer = VBOX_GL_FUNC(EdgeFlagPointer);
+   // driver->VertexAttribPointer = VBOX_GL_FUNC(VertexAttribPointer);   /** @todo */
+   // driver->LockArraysEXT = VBOX_GL_FUNC(LockArraysEXT);   /** @todo */
+   // driver->UnlockArraysEXT = VBOX_GL_FUNC(UnlockArraysEXT);   /** @todo */
+
+   /* state queries */
+   driver->GetBooleanv = vboxDDGetBooleanv;
+   driver->GetDoublev = vboxDDGetDoublev;
+   driver->GetFloatv = vboxDDGetFloatv;
+   driver->GetIntegerv = vboxDDGetIntegerv;
+   driver->GetPointerv = vboxDDGetPointerv;
+
+/** @todo */   
+#if FEATURE_ARB_vertex_buffer_object
+   // driver->NewBufferObject = _mesa_new_buffer_object;
+   // driver->DeleteBuffer = _mesa_delete_buffer_object;
+   // driver->BindBuffer = NULL;
+   // driver->BufferData = _mesa_buffer_data;
+   // driver->BufferSubData = _mesa_buffer_subdata;
+   // driver->GetBufferSubData = _mesa_buffer_get_subdata;
+   // driver->MapBuffer = _mesa_buffer_map;
+   // driver->UnmapBuffer = _mesa_buffer_unmap;
+#endif
+
+/** @todo */
+#if FEATURE_EXT_framebuffer_object
+   // driver->NewFramebuffer = _mesa_new_framebuffer;
+   // driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
+   // driver->RenderTexture = _mesa_render_texture;
+   // driver->FinishRenderTexture = _mesa_finish_render_texture;
+   // driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
+#endif
+
+/** @todo */
+#if FEATURE_EXT_framebuffer_blit
+   // driver->BlitFramebuffer = _swrast_BlitFramebuffer;
+#endif
+
+   /* query objects */
+   // driver->NewQueryObject = VBOX_GL_FUNC(NewQueryObject);   /** @todo */
+   // driver->DeleteQuery = VBOX_GL_FUNC(DeleteQuery);   /** @todo */
+   // driver->BeginQuery = VBOX_GL_FUNC(BeginQuery);   /** @todo */
+   // driver->EndQuery = VBOX_GL_FUNC(EndQuery);   /** @todo */
+   // driver->WaitQuery = VBOX_GL_FUNC(WaitQuery);   /** @todo */
+
+   /* APPLE_vertex_array_object */
+/*
+   driver->NewArrayObject = _mesa_new_array_object;
+   driver->DeleteArrayObject = _mesa_delete_array_object;
+   driver->BindArrayObject = NULL;
+*/
+
+   /* T&L stuff */
+   driver->NeedValidate = GL_FALSE;
+   driver->ValidateTnlModule = NULL;
+   driver->CurrentExecPrimitive = 0;
+   driver->CurrentSavePrimitive = 0;
+   driver->NeedFlush = 0;
+   driver->SaveNeedFlush = 0;
+
+   // driver->ProgramStringNotify = _tnl_program_string;   /** @todo */
+   driver->FlushVertices = NULL;
+   driver->SaveFlushVertices = NULL;
+   driver->NotifySaveBegin = NULL;
+   driver->LightingSpaceChange = NULL;
+
+   /* display list */
+   driver->NewList = VBOX_GL_FUNC(NewList);
+   driver->EndList = VBOX_GL_FUNC(EndList);
+   // driver->BeginCallList = VBOX_GL_FUNC(BeginCallList);   /** @todo */
+   // driver->EndCallList = VBOX_GL_FUNC(EndCallList);   /** @todo */
+
+
+   /* shaders */
+   /*
+   driver->AttachShader = _mesa_attach_shader;
+   driver->BindAttribLocation = _mesa_bind_attrib_location;
+   driver->CompileShader = _mesa_compile_shader;
+   driver->CreateProgram = _mesa_create_program;
+   driver->CreateShader = _mesa_create_shader;
+   driver->DeleteProgram2 = _mesa_delete_program2;
+   driver->DeleteShader = _mesa_delete_shader;
+   driver->DetachShader = _mesa_detach_shader;
+   driver->GetActiveAttrib = _mesa_get_active_attrib;
+   driver->GetActiveUniform = _mesa_get_active_uniform;
+   driver->GetAttachedShaders = _mesa_get_attached_shaders;
+   driver->GetAttribLocation = _mesa_get_attrib_location;
+   driver->GetHandle = _mesa_get_handle;
+   driver->GetProgramiv = _mesa_get_programiv;
+   driver->GetProgramInfoLog = _mesa_get_program_info_log;
+   driver->GetShaderiv = _mesa_get_shaderiv;
+   driver->GetShaderInfoLog = _mesa_get_shader_info_log;
+   driver->GetShaderSource = _mesa_get_shader_source;
+   driver->GetUniformfv = _mesa_get_uniformfv;
+   driver->GetUniformiv = _mesa_get_uniformiv;
+   driver->GetUniformLocation = _mesa_get_uniform_location;
+   driver->IsProgram = _mesa_is_program;
+   driver->IsShader = _mesa_is_shader;
+   driver->LinkProgram = _mesa_link_program;
+   driver->ShaderSource = _mesa_shader_source;
+   driver->Uniform = _mesa_uniform;
+   driver->UniformMatrix = _mesa_uniform_matrix;
+   driver->UseProgram = _mesa_use_program;
+   driver->ValidateProgram = _mesa_validate_program;
+   */
+}
+
+static void
+vboxdriInitTnlVtxFmt(GLvertexformat *pVtxFmt)
+{
+   pVtxFmt->ArrayElement = VBOX_GL_FUNC(ArrayElement);
+   pVtxFmt->Begin = VBOX_GL_FUNC(Begin);
+   pVtxFmt->CallList = VBOX_GL_FUNC(CallList);
+   pVtxFmt->CallLists = VBOX_GL_FUNC(CallLists);
+   pVtxFmt->Color3f = VBOX_GL_FUNC(Color3f);
+   pVtxFmt->Color3fv = VBOX_GL_FUNC(Color3fv);
+   pVtxFmt->Color4f = VBOX_GL_FUNC(Color4f);
+   pVtxFmt->Color4fv = VBOX_GL_FUNC(Color4fv);
+   pVtxFmt->EdgeFlag = VBOX_GL_FUNC(EdgeFlag);
+   pVtxFmt->End = VBOX_GL_FUNC(End);
+   pVtxFmt->EvalCoord1f = VBOX_GL_FUNC(EvalCoord1f);
+   pVtxFmt->EvalCoord1fv = VBOX_GL_FUNC(EvalCoord1fv);
+   pVtxFmt->EvalCoord2f = VBOX_GL_FUNC(EvalCoord2f);
+   pVtxFmt->EvalCoord2fv = VBOX_GL_FUNC(EvalCoord2fv);
+   pVtxFmt->EvalPoint1 = VBOX_GL_FUNC(EvalPoint1);
+   pVtxFmt->EvalPoint2 = VBOX_GL_FUNC(EvalPoint2);
+   pVtxFmt->FogCoordfEXT = VBOX_GL_FUNC(FogCoordfEXT);
+   pVtxFmt->FogCoordfvEXT = VBOX_GL_FUNC(FogCoordfvEXT);
+   pVtxFmt->Indexf = VBOX_GL_FUNC(Indexf);
+   pVtxFmt->Indexfv = VBOX_GL_FUNC(Indexfv);
+   pVtxFmt->Materialfv = VBOX_GL_FUNC(Materialfv);
+   pVtxFmt->MultiTexCoord1fARB = VBOX_GL_FUNC(MultiTexCoord1fARB);
+   pVtxFmt->MultiTexCoord1fvARB = VBOX_GL_FUNC(MultiTexCoord1fvARB);
+   pVtxFmt->MultiTexCoord2fARB = VBOX_GL_FUNC(MultiTexCoord2fARB);
+   pVtxFmt->MultiTexCoord2fvARB = VBOX_GL_FUNC(MultiTexCoord2fvARB);
+   pVtxFmt->MultiTexCoord3fARB = VBOX_GL_FUNC(MultiTexCoord3fARB);
+   pVtxFmt->MultiTexCoord3fvARB = VBOX_GL_FUNC(MultiTexCoord3fvARB);
+   pVtxFmt->MultiTexCoord4fARB = VBOX_GL_FUNC(MultiTexCoord4fARB);
+   pVtxFmt->MultiTexCoord4fvARB = VBOX_GL_FUNC(MultiTexCoord4fvARB);
+   pVtxFmt->Normal3f = VBOX_GL_FUNC(Normal3f);
+   pVtxFmt->Normal3fv = VBOX_GL_FUNC(Normal3fv);
+   pVtxFmt->SecondaryColor3fEXT = VBOX_GL_FUNC(SecondaryColor3fEXT);
+   pVtxFmt->SecondaryColor3fvEXT = VBOX_GL_FUNC(SecondaryColor3fvEXT);
+   pVtxFmt->TexCoord1f = VBOX_GL_FUNC(TexCoord1f);
+   pVtxFmt->TexCoord1fv = VBOX_GL_FUNC(TexCoord1fv);
+   pVtxFmt->TexCoord2f = VBOX_GL_FUNC(TexCoord2f);
+   pVtxFmt->TexCoord2fv = VBOX_GL_FUNC(TexCoord2fv);
+   pVtxFmt->TexCoord3f = VBOX_GL_FUNC(TexCoord3f);
+   pVtxFmt->TexCoord3fv = VBOX_GL_FUNC(TexCoord3fv);
+   pVtxFmt->TexCoord4f = VBOX_GL_FUNC(TexCoord4f);
+   pVtxFmt->TexCoord4fv = VBOX_GL_FUNC(TexCoord4fv);
+   pVtxFmt->Vertex2f = VBOX_GL_FUNC(Vertex2f);
+   pVtxFmt->Vertex2fv = VBOX_GL_FUNC(Vertex2fv);
+   pVtxFmt->Vertex3f = VBOX_GL_FUNC(Vertex3f);
+   pVtxFmt->Vertex3fv = VBOX_GL_FUNC(Vertex3fv);
+   pVtxFmt->Vertex4f = VBOX_GL_FUNC(Vertex4f);
+   pVtxFmt->Vertex4fv = VBOX_GL_FUNC(Vertex4fv);
+   pVtxFmt->VertexAttrib1fNV = VBOX_GL_FUNC(VertexAttrib1fARB);
+   pVtxFmt->VertexAttrib1fvNV = VBOX_GL_FUNC(VertexAttrib1fvARB);
+   pVtxFmt->VertexAttrib2fNV = VBOX_GL_FUNC(VertexAttrib2fARB);
+   pVtxFmt->VertexAttrib2fvNV = VBOX_GL_FUNC(VertexAttrib2fvARB);
+   pVtxFmt->VertexAttrib3fNV = VBOX_GL_FUNC(VertexAttrib3fARB);
+   pVtxFmt->VertexAttrib3fvNV = VBOX_GL_FUNC(VertexAttrib3fvARB);
+   pVtxFmt->VertexAttrib4fNV = VBOX_GL_FUNC(VertexAttrib4fARB);
+   pVtxFmt->VertexAttrib4fvNV = VBOX_GL_FUNC(VertexAttrib4fvARB);
+   pVtxFmt->VertexAttrib1fARB = VBOX_GL_FUNC(VertexAttrib1fARB);
+   pVtxFmt->VertexAttrib1fvARB = VBOX_GL_FUNC(VertexAttrib1fvARB);
+   pVtxFmt->VertexAttrib2fARB = VBOX_GL_FUNC(VertexAttrib2fARB);
+   pVtxFmt->VertexAttrib2fvARB = VBOX_GL_FUNC(VertexAttrib2fvARB);
+   pVtxFmt->VertexAttrib3fARB = VBOX_GL_FUNC(VertexAttrib3fARB);
+   pVtxFmt->VertexAttrib3fvARB = VBOX_GL_FUNC(VertexAttrib3fvARB);
+   pVtxFmt->VertexAttrib4fARB = VBOX_GL_FUNC(VertexAttrib4fARB);
+   pVtxFmt->VertexAttrib4fvARB = VBOX_GL_FUNC(VertexAttrib4fvARB);
+
+   pVtxFmt->EvalMesh1 = VBOX_GL_FUNC(EvalMesh1);
+   pVtxFmt->EvalMesh2 = VBOX_GL_FUNC(EvalMesh2);
+   pVtxFmt->Rectf = VBOX_GL_FUNC(Rectf);
+
+   pVtxFmt->DrawArrays = VBOX_GL_FUNC(DrawArrays);
+   pVtxFmt->DrawElements = VBOX_GL_FUNC(DrawElements);
+   pVtxFmt->DrawRangeElements = VBOX_GL_FUNC(DrawRangeElements);
+}
+#undef VBOX_GL_FUNC
+
+static void
+vboxdriExtSetTexOffset(__DRIcontext *pDRICtx, GLint texname,
+                       unsigned long long offset, GLint depth, GLuint pitch)
+{
+}
+
+
+static void
+vboxdriExtSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
+{
+}
+
+/** @todo not sure we need it from start*/
+static const __DRItexOffsetExtension vboxdriTexOffsetExtension = {
+    { __DRI_TEX_OFFSET },
+    vboxdriExtSetTexOffset,
+};
+
+/* This DRI extension is required to support EXT_texture_from_pixmap,
+ * which in turn is required by compiz.
+ */
+static const __DRItexBufferExtension vboxdriTexBufferExtension = {
+    { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
+    vboxdriExtSetTexBuffer,
+};
+
+/* List of DRI extensions supported by VBox DRI driver */
+static const __DRIextension *vboxdriExtensions[] = {
+    &vboxdriTexOffsetExtension.base,
+    &vboxdriTexBufferExtension.base,
+    NULL
+};
+
+static __GLcontextModes *vboxdriFillInModes(unsigned pixel_bits,
+                                            unsigned depth_bits,
+                                            unsigned stencil_bits,
+                                            GLboolean have_back_buffer)
+{
+        unsigned deep = (depth_bits > 17);
+
+        /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
+         * enough to add support.  Basically, if a context is created with an
+         * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
+         * will never be used.
+         */
+
+        static const GLenum db_modes[2] = { GLX_NONE, GLX_SWAP_UNDEFINED_OML };
+        uint8_t depth_bits_array[4];
+        uint8_t stencil_bits_array[4];
+        if(deep) {
+                depth_bits_array[0] = 0;
+                depth_bits_array[1] = 24;
+                stencil_bits_array[0] = 0;
+                stencil_bits_array[1] = 8;
+        } else {
+                depth_bits_array[0] = depth_bits;
+                depth_bits_array[1] = 0;
+                depth_bits_array[2] = depth_bits;
+                depth_bits_array[3] = 0;
+                stencil_bits_array[0] = 0;
+                stencil_bits_array[1] = 0;
+                stencil_bits_array[2] = 8;
+                stencil_bits_array[3] = 8;
+        }
+
+        return driCreateConfigs(
+                deep ? GL_RGBA : GL_RGB,
+                deep ? GL_UNSIGNED_INT_8_8_8_8 : GL_UNSIGNED_SHORT_5_6_5,
+                depth_bits_array,
+                stencil_bits_array,
+                deep ? 2 : 4,
+                db_modes, 2);
+}
+
+/**
+ * This is the driver specific part of the createNewScreen entry point.
+ * Called when using legacy DRI.
+ * 
+ * return the __GLcontextModes supported by this driver
+ */
+static const __DRIconfig **vboxdriInitScreen(__DRIscreenPrivate *psp)
+{
+    static const __DRIversion ddx_expected = { 1, 1, 0 };
+    static const __DRIversion dri_expected = { 4, 0, 0 };
+    static const __DRIversion drm_expected = { 1, 0, 0 };
+    //PVBoxDRI = (PVBoxDRI) psp->pDevPrivate;
+
+    /* Initialise our call table in chromium. */
+    if (!stubInit())
+    {
+        crDebug("vboxdriInitScreen: stubInit failed");
+        return NULL;
+    }
+
+    if ( ! driCheckDriDdxDrmVersions2( "tdfx",
+                                       &psp->dri_version, & dri_expected,
+                                       &psp->ddx_version, & ddx_expected,
+                                       &psp->drm_version, & drm_expected ) )
+        return NULL;
+
+    /* Calling driInitExtensions here, with a NULL context pointer,
+     * does not actually enable the extensions.  It just makes sure
+     * that all the dispatch offsets for all the extensions that
+     * *might* be enables are known.  This is needed because the
+     * dispatch offsets need to be known when _mesa_context_create is
+     * called, but we can't enable the extensions until we have a
+     * context pointer.
+     *
+     * Hello chicken.  Hello egg.  How are you two today?
+     */
+    vboxdriInitExtensions(NULL);
+
+    /** @todo check size of DRIRec (passed from X.Org driver), allocate private
+     * structure if necessary, parse options if necessary, map VRAM if
+     * necessary. */
+    psp->extensions = vboxdriExtensions;
+
+    /* Initialise VtxFmt call table. */
+    vboxdriInitTnlVtxFmt(&vboxdriTnlVtxFmt);
+
+    /*return (const __DRIconfig **)
+           vboxdriFillInModes(psp, dri_priv->cpp * 8,
+                              (dri_priv->cpp == 2) ? 16 : 24,
+                              (dri_priv->cpp == 2) ? 0  : 8, 1);*/
+
+    /** @todo This should depend on what the host can do, not the guest.
+     *  However, we will probably want to discover that in the X.Org driver,
+     *  not here. */
+    return (const __DRIconfig **) vboxdriFillInModes(psp, 24, 24, 8, 1);
+}
+
+static void
+vboxdriDestroyScreen(__DRIscreenPrivate * sPriv)
+{
+    crDebug("vboxdriDestroyScreen");
+#if 0  /* From the tdfx driver */
+   /* free all option information */
+   driDestroyOptionInfo (&sPriv->private->optionCache);
+   FREE(sPriv->private);
+   sPriv->private = NULL;
+#endif
+}
+
+static GLboolean
+vboxdriCreateContext(const __GLcontextModes * mesaVis,
+                     __DRIcontextPrivate * driContextPriv,
+                     void *sharedContextPrivate)
+{
+    //__DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
+    struct dd_function_table functions;
+    GLcontext *ctx, *shareCtx;
+
+#if 0  /* We shouldn't need this sort of thing. */
+    XVisualInfo *vis;
+    vis->visual->visualid;
+    context->dpy = dpy;
+    context->visual = vis;
+
+    GLXContext vboxctx = glXCreateContext(dpy, mesaVis->visualID, GL_TRUE);
+#endif
+    /* We should be allocating a private context structure, where we will
+     * remember the Mesa context (ctx) among other things.  The TDFX driver
+     * also saves importand information in driContextPriv in there - is this
+     * not always available to us? */
+    //driContextPriv->driverPrivate = vboxctx;
+
+    /* Initialise the default driver functions then plug in our vbox ones,
+     * which will actually replace most of the defaults. */
+    /** @todo we should also pass some information from the visual back to the
+     * host. */
+    _mesa_init_driver_functions(&functions);
+    vboxdriInitFuncs(&functions);
+
+    /* Allocate context information for Mesa. */
+    if (sharedContextPrivate)
+      shareCtx = ((tdfxContextPtr) sharedContextPrivate)->glCtx;
+   else 
+      shareCtx = NULL;
+    /** @todo save ctx, or be more confident that we can don't need to. */
+    ctx = _mesa_create_context(mesaVis, shareCtx, &functions,
+                               driContextPriv->driverPrivate);
+    if (!ctx)
+    {
+        crDebug("vboxdriCreateContext: _mesa_create_context failed");
+        return GL_FALSE;
+    }
+
+    /* The TDFX driver parses its configuration files here, via
+     * driParseConfigFiles.  We will probably get any information via guest
+     * properties. */
+
+   /* Set various context configuration.  We take these values from the 
+    * TDFX driver. */
+   /** @r=Leonid, stub.spu->dispatch_table.GetIntegerv(GL_MAX_TEXTURE_UNITS_ARB,&value) etc.
+    * Those would be cached where possible, see include/state/cr_limits.h, VBoxOGLgen/packspu_get.c
+    * Note, that ctx->Const.MaxTextureImageUnits is *not* related to GL_MAX_TEXTURE_UNITS_ARB,
+    * use GL_MAX_TEXTURE_IMAGE_UNITS_ARB instead.
+    * Also, those could fail if we haven't made ctx in our stub yet.
+    */
+   ctx->Const.MaxTextureLevels = 9;
+   ctx->Const.MaxTextureUnits = 1;
+   ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
+   ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
+
+   /* No wide points.
+    */
+   ctx->Const.MinPointSize = 1.0;
+   ctx->Const.MinPointSizeAA = 1.0;
+   ctx->Const.MaxPointSize = 1.0;
+   ctx->Const.MaxPointSizeAA = 1.0;
+
+   /* Disable wide lines as we can't antialias them correctly in
+    * hardware.
+    */
+   /** @note That applies to the TDFX, not to us, but as I don't yet know
+    * what to use instead I am leaving the values for now. */
+   ctx->Const.MinLineWidth = 1.0;
+   ctx->Const.MinLineWidthAA = 1.0;
+   ctx->Const.MaxLineWidth = 1.0;
+   ctx->Const.MaxLineWidthAA = 1.0;
+   ctx->Const.LineWidthGranularity = 1.0;
+
+   /* Initialize the software rasterizer and helper modules - again, TDFX */
+   _swrast_CreateContext( ctx );
+   _vbo_CreateContext( ctx );
+   _tnl_CreateContext( ctx );
+   _swsetup_CreateContext( ctx );
+
+   /* Install the customized pipeline, TDFX */
+   _tnl_destroy_pipeline( ctx );
+   _tnl_install_pipeline( ctx, tdfx_pipeline );
+
+   /* Configure swrast and T&L to match hardware characteristics, TDFX */
+   _swrast_allow_pixel_fog( ctx, GL_TRUE );
+   _swrast_allow_vertex_fog( ctx, GL_FALSE );
+   _tnl_allow_pixel_fog( ctx, GL_TRUE );
+   _tnl_allow_vertex_fog( ctx, GL_FALSE );
+    /*ctx->DriverCtx = ;*/
+
+    /* This was *not* in the TDFX driver. */
+    _mesa_install_exec_vtxfmt(ctx, &vboxdriTnlVtxFmt);
+
+    vboxdriInitExtensions(ctx);
+
+    return GL_TRUE;
+}
+
+
+static void
+vboxdriDestroyContext(__DRIcontextPrivate *driContextPriv)
+{
+    // glXDestroyContext(driContextPriv->driverPrivate);
+    //_mesa_destroy_context ?
+}
+
+/**
+ * This is called when we need to set up GL rendering to a new X window.
+ */
+static GLboolean
+vboxdriCreateBuffer(__DRIscreenPrivate * driScrnPriv,
+                    __DRIdrawablePrivate * driDrawPriv,
+                    const __GLcontextModes * mesaVis, GLboolean isPixmap)
+{
+    return GL_FALSE;
+}
+
+static void
+vboxdriDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
+{
+}
+
+static void
+vboxdriSwapBuffers(__DRIdrawablePrivate * dPriv)
+{
+}
+
+
+GLboolean
+vboxdriMakeCurrent(__DRIcontextPrivate * driContextPriv,
+                   __DRIdrawablePrivate * driDrawPriv,
+                   __DRIdrawablePrivate * driReadPriv)
+{
+    return GL_FALSE;
+}
+
+GLboolean
+vboxdriUnbindContext(__DRIcontextPrivate * driContextPriv)
+{
+    return GL_TRUE;
+}
+
+
+/* This structure is used by dri_util from mesa, don't rename it! */
+DECLEXPORT(const struct __DriverAPIRec) driDriverAPI = {
+    .InitScreen       = vboxdriInitScreen,
+    .DestroyScreen    = vboxdriDestroyScreen,
+    .CreateContext    = vboxdriCreateContext,
+    .DestroyContext   = vboxdriDestroyContext,
+    .CreateBuffer     = vboxdriCreateBuffer,
+    .DestroyBuffer    = vboxdriDestroyBuffer,
+    .SwapBuffers      = vboxdriSwapBuffers,
+    .MakeCurrent      = vboxdriMakeCurrent,
+    .UnbindContext    = vboxdriUnbindContext,
+    .GetSwapInfo      = NULL,
+    .WaitForMSC       = NULL,
+    .WaitForSBC       = NULL,
+    .SwapBuffersMSC   = NULL,
+    .CopySubBuffer    = NULL,
+    .GetDrawableMSC   = NULL,
+    .InitScreen2      = NULL
+};
Index: trunk/src/VBox/Additions/common/crOpenGL/dri_drv.h
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/dri_drv.h	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/dri_drv.h	(revision 18882)
@@ -0,0 +1,24 @@
+/* $Id$ */
+
+/** @file
+ *
+ * VirtualBox guest OpenGL DRI header
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ */
+
+#ifndef ___CROPENGL_DRIDRV_H
+#define ___CROPENGL_DRIDRV_H
+
+#include "src/mesa/main/mtypes.h"
+#include "src/mesa/drivers/dri/common/dri_util.h"
+#include "src/mesa/glapi/dispatch.h"
+#include "src/mesa/main/dd.h"
+
+#endif /* ___CROPENGL_DRIDRV_H */
+
Index: trunk/src/VBox/Additions/common/crOpenGL/dri_glx.h
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/dri_glx.h	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/dri_glx.h	(revision 18882)
@@ -0,0 +1,157 @@
+/* $Id$ */
+
+/** @file
+ *
+ * VirtualBox guest OpenGL DRI GLX header
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ */
+
+#ifndef ___CROPENGL_DRI_GLX_H
+#define ___CROPENGL_DRI_GLX_H
+
+#include "chromium.h"
+#include "stub.h"
+
+#if defined(VBOXOGL_FAKEDRI) || defined(VBOXOGL_DRI)
+ #define VBOXGLXTAG(Func) vboxstub_##Func
+ #define VBOXGLXENTRYTAG(Func) vbox_##Func
+ #define VBOXGLTAG(Func) cr_##Func
+#else
+ #define VBOXGLXTAG(Func) Func
+ #define VBOXGLXENTRYTAG(Func) Func
+ #define VBOXGLTAG(Func) Func
+#endif
+
+#ifdef VBOXOGL_FAKEDRI
+extern DECLEXPORT(const char *) VBOXGLXTAG(glXGetDriverConfig)(const char *driverName);
+extern DECLEXPORT(void) VBOXGLXTAG(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer);
+extern DECLEXPORT(GLXContext) VBOXGLXTAG(glXImportContextEXT)(Display *dpy, GLXContextID contextID);
+extern DECLEXPORT(GLXContextID) VBOXGLXTAG(glXGetContextIDEXT)(const GLXContext ctx);
+extern DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrentReadSGI)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
+extern DECLEXPORT(const char *) VBOXGLXTAG(glXGetScreenDriver)(Display *dpy, int scrNum);
+extern DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplayEXT)(void);
+extern DECLEXPORT(void) VBOXGLXTAG(glXFreeContextEXT)(Display *dpy, GLXContext ctx);
+/*Mesa insternal*/
+extern DECLEXPORT(int) VBOXGLXTAG(glXQueryContextInfoEXT)(Display *dpy, GLXContext ctx);
+extern DECLEXPORT(void *) VBOXGLXTAG(glXAllocateMemoryMESA)(Display *dpy, int scrn,
+                                                       size_t size, float readFreq,
+                                                       float writeFreq, float priority);
+extern DECLEXPORT(GLuint) VBOXGLXTAG(glXGetMemoryOffsetMESA)(Display *dpy, int scrn, const void *pointer );
+extern DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap);
+#endif
+
+/*Common glX functions*/
+extern DECLEXPORT(void) VBOXGLXTAG(glXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, 
+#if defined(SunOS)
+unsigned long mask);
+#else
+unsigned long mask);
+#endif
+extern DECLEXPORT(void) VBOXGLXTAG(glXUseXFont)(Font font, int first, int count, int listBase);
+extern DECLEXPORT(CR_GLXFuncPtr) VBOXGLXTAG(glXGetProcAddress)(const GLubyte *name);
+extern DECLEXPORT(Bool) VBOXGLXTAG(glXQueryExtension)(Display *dpy, int *errorBase, int *eventBase);
+extern DECLEXPORT(Bool) VBOXGLXTAG(glXIsDirect)(Display *dpy, GLXContext ctx);
+extern DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmap)(Display *dpy, XVisualInfo *vis, Pixmap pixmap);
+extern DECLEXPORT(void) VBOXGLXTAG(glXSwapBuffers)(Display *dpy, GLXDrawable drawable);
+extern DECLEXPORT(GLXDrawable) VBOXGLXTAG(glXGetCurrentDrawable)(void);
+extern DECLEXPORT(void) VBOXGLXTAG(glXWaitGL)(void);
+extern DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplay)(void);
+extern DECLEXPORT(const char *) VBOXGLXTAG(glXQueryServerString)(Display *dpy, int screen, int name);
+extern DECLEXPORT(GLXContext) VBOXGLXTAG(glXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext share, Bool direct);
+extern DECLEXPORT(int) VBOXGLXTAG(glXGetConfig)(Display *dpy, XVisualInfo *vis, int attrib, int *value);
+extern DECLEXPORT(void) VBOXGLXTAG(glXWaitX)(void);
+extern DECLEXPORT(GLXContext) VBOXGLXTAG(glXGetCurrentContext)(void);
+extern DECLEXPORT(const char *) VBOXGLXTAG(glXGetClientString)(Display *dpy, int name);
+extern DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrent)(Display *dpy, GLXDrawable drawable, GLXContext ctx);
+extern DECLEXPORT(void) VBOXGLXTAG(glXDestroyContext)(Display *dpy, GLXContext ctx);
+extern DECLEXPORT(CR_GLXFuncPtr) VBOXGLXTAG(glXGetProcAddressARB)(const GLubyte *name);
+extern DECLEXPORT(void) VBOXGLXTAG(glXDestroyGLXPixmap)(Display *dpy, GLXPixmap pix);
+extern DECLEXPORT(Bool) VBOXGLXTAG(glXQueryVersion)(Display *dpy, int *major, int *minor);
+extern DECLEXPORT(XVisualInfo *) VBOXGLXTAG(glXChooseVisual)(Display *dpy, int screen, int *attribList);
+extern DECLEXPORT(const char *) VBOXGLXTAG(glXQueryExtensionsString)(Display *dpy, int screen);
+
+/**
+ * Set this to 1 if you want to build stub functions for the
+ * GL_SGIX_pbuffer and GLX_SGIX_fbconfig extensions.
+ * This used to be disabled, due to "messy compilation issues",
+ * according to the earlier comment; but they're needed just
+ * to resolve symbols for OpenInventor applications, and I
+ * haven't found any reference to exactly what the "messy compilation
+ * issues" are, so I'm re-enabling the code by default.
+ */
+#define GLX_EXTRAS 1
+
+#define GLX_SGIX_video_resize 1
+
+/**
+ * Prototypes, in case they're not in glx.h or glxext.h
+ * Unfortunately, there's some inconsistency between the extension
+ * specs, and the SGI, NVIDIA, XFree86 and common glxext.h header
+ * files.
+ */
+#if defined(GLX_GLXEXT_VERSION)
+/* match glxext.h, XFree86, Mesa */
+#define ATTRIB_TYPE const int
+#else
+#define ATTRIB_TYPE int
+#endif
+
+#if GLX_EXTRAS
+extern DECLEXPORT(GLXPbufferSGIX) VBOXGLXTAG(glXCreateGLXPbufferSGIX)
+(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list);
+
+extern DECLEXPORT(int) VBOXGLXTAG(glXQueryGLXPbufferSGIX)
+(Display *dpy, GLXPbuffer pbuf, int attribute, unsigned int *value);
+
+extern DECLEXPORT(GLXFBConfigSGIX *) VBOXGLXTAG(glXChooseFBConfigSGIX)
+(Display *dpy, int screen, int *attrib_list, int *nelements);
+
+extern DECLEXPORT(void) VBOXGLXTAG(glXDestroyGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf);
+extern DECLEXPORT(void) VBOXGLXTAG(glXSelectEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long mask);
+extern DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long *mask);
+
+extern DECLEXPORT(GLXFBConfigSGIX) VBOXGLXTAG(glXGetFBConfigFromVisualSGIX)(Display *dpy, XVisualInfo *vis);
+extern DECLEXPORT(XVisualInfo *) VBOXGLXTAG(glXGetVisualFromFBConfigSGIX)(Display *dpy, GLXFBConfig config);
+extern DECLEXPORT(GLXContext) VBOXGLXTAG(glXCreateContextWithConfigSGIX)
+(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
+
+extern DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmapWithConfigSGIX)(Display *dpy, GLXFBConfig config, Pixmap pixmap);
+extern DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttribSGIX)(Display *dpy, GLXFBConfig config, int attribute, int *value);
+
+/*
+ * GLX 1.3 functions
+ */
+extern DECLEXPORT(GLXFBConfig *) VBOXGLXTAG(glXChooseFBConfig)(Display *dpy, int screen, ATTRIB_TYPE *attrib_list, int *nelements);
+extern DECLEXPORT(GLXPbuffer) VBOXGLXTAG(glXCreatePbuffer)(Display *dpy, GLXFBConfig config, ATTRIB_TYPE *attrib_list);
+extern DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const ATTRIB_TYPE *attrib_list);
+extern DECLEXPORT(GLXWindow) VBOXGLXTAG(glXCreateWindow)(Display *dpy, GLXFBConfig config, Window win, ATTRIB_TYPE *attrib_list);
+extern DECLEXPORT(GLXContext) VBOXGLXTAG(glXCreateNewContext)
+(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
+
+extern DECLEXPORT(void) VBOXGLXTAG(glXDestroyPbuffer)(Display *dpy, GLXPbuffer pbuf);
+extern DECLEXPORT(void) VBOXGLXTAG(glXDestroyPixmap)(Display *dpy, GLXPixmap pixmap);
+extern DECLEXPORT(void) VBOXGLXTAG(glXDestroyWindow)(Display *dpy, GLXWindow win);
+extern DECLEXPORT(GLXDrawable) VBOXGLXTAG(glXGetCurrentReadDrawable)(void);
+extern DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value);
+extern DECLEXPORT(GLXFBConfig *) VBOXGLXTAG(glXGetFBConfigs)(Display *dpy, int screen, int *nelements);
+extern DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEvent)(Display *dpy, GLXDrawable draw, unsigned long *event_mask);
+extern DECLEXPORT(XVisualInfo *) VBOXGLXTAG(glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config);
+extern DECLEXPORT(Bool) VBOXGLXTAG(glXMakeContextCurrent)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
+extern DECLEXPORT(int) VBOXGLXTAG(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value);
+extern DECLEXPORT(void) VBOXGLXTAG(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value);
+extern DECLEXPORT(void) VBOXGLXTAG(glXSelectEvent)(Display *dpy, GLXDrawable draw, unsigned long event_mask);
+
+#ifdef CR_EXT_texture_from_pixmap
+extern DECLEXPORT(void) VBOXGLXTAG(glXBindTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer, const int *attrib_list);
+extern DECLEXPORT(void) VBOXGLXTAG(glXReleaseTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer);
+#endif
+
+#endif /* GLX_EXTRAS */
+
+#endif //___CROPENGL_DRI_GLX_H
Index: trunk/src/VBox/Additions/common/crOpenGL/fakedri_drv.c
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/fakedri_drv.c	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/fakedri_drv.c	(revision 18882)
@@ -0,0 +1,509 @@
+/* $Id$ */
+
+/** @file
+ * VBox OpenGL DRI driver functions
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ */
+
+#define _GNU_SOURCE 1
+
+#include "cr_error.h"
+#include "cr_gl.h"
+#include "cr_mem.h"
+#include "stub.h"
+#include "fakedri_drv.h"
+#include "dri_glx.h"
+#include "iprt/mem.h"
+#include "iprt/err.h"
+#include <dlfcn.h>
+#include <elf.h>
+#include <unistd.h>
+#include "xf86.h"
+
+#define VBOX_NO_MESA_PATCH_REPORTS
+
+//#define DEBUG_DRI_CALLS
+
+//@todo this could be different...
+#define DRI_DEFAULT_DRIVER_DIR "/usr/lib/dri"
+#define DRI_XORG_DRV_DIR "/usr/lib/xorg/modules/drivers/"
+
+#ifdef DEBUG_DRI_CALLS
+ #define SWDRI_SHOWNAME(pext, func) \
+   crDebug("SWDRI: sc %s->%s", #pext, #func)
+#else
+ #define SWDRI_SHOWNAME(pext, func)
+#endif
+
+#define SWDRI_SAFECALL(pext, func, ...)        \
+    SWDRI_SHOWNAME(pext, func);                \
+    if (pext && pext->func){                   \
+        (*pext->func)(__VA_ARGS__);            \
+    } else {                                   \
+        crDebug("swcore_call NULL for "#func); \
+    }
+
+#define SWDRI_SAFERET(pext, func, ...)         \
+    SWDRI_SHOWNAME(pext, func);                \
+    if (pext && pext->func){                   \
+        return (*pext->func)(__VA_ARGS__);     \
+    } else {                                   \
+        crDebug("swcore_call NULL for "#func); \
+        return 0;                              \
+    }
+
+#define SWDRI_SAFERET_CORE(func, ...) SWDRI_SAFERET(gpSwDriCoreExternsion, func, __VA_ARGS__)
+#define SWDRI_SAFECALL_CORE(func, ...) SWDRI_SAFECALL(gpSwDriCoreExternsion, func, __VA_ARGS__)
+#define SWDRI_SAFERET_SWRAST(func, ...) SWDRI_SAFERET(gpSwDriSwrastExtension, func, __VA_ARGS__)
+#define SWDRI_SAFECALL_SWRAST(func, ...) SWDRI_SAFECALL(gpSwDriSwrastExtension, func, __VA_ARGS__)
+
+#ifndef PAGESIZE
+#define PAGESIZE 4096
+#endif
+
+static struct _glapi_table vbox_glapi_table;
+fakedri_glxapi_table glxim;
+
+static const __DRIextension **gppSwDriExternsion = NULL;
+static const __DRIcoreExtension *gpSwDriCoreExternsion = NULL;
+static const __DRIswrastExtension *gpSwDriSwrastExtension = NULL;
+
+extern const __DRIextension * __driDriverExtensions[];
+
+#define GLAPI_ENTRY(Func) pGLTable->Func = cr_gl##Func;
+static void
+vboxFillMesaGLAPITable(struct _glapi_table *pGLTable)
+{
+    #include "fakedri_glfuncsList.h"
+
+    pGLTable->SampleMaskSGIS = cr_glSampleMaskEXT;
+    pGLTable->SamplePatternSGIS = cr_glSamplePatternEXT;
+    pGLTable->WindowPos2dMESA = cr_glWindowPos2d;
+    pGLTable->WindowPos2dvMESA = cr_glWindowPos2dv;
+    pGLTable->WindowPos2fMESA = cr_glWindowPos2f;
+    pGLTable->WindowPos2fvMESA = cr_glWindowPos2fv;
+    pGLTable->WindowPos2iMESA = cr_glWindowPos2i;
+    pGLTable->WindowPos2ivMESA = cr_glWindowPos2iv;
+    pGLTable->WindowPos2sMESA = cr_glWindowPos2s;
+    pGLTable->WindowPos2svMESA = cr_glWindowPos2sv;
+    pGLTable->WindowPos3dMESA = cr_glWindowPos3d;
+    pGLTable->WindowPos3dvMESA = cr_glWindowPos3dv;
+    pGLTable->WindowPos3fMESA = cr_glWindowPos3f;
+    pGLTable->WindowPos3fvMESA = cr_glWindowPos3fv;
+    pGLTable->WindowPos3iMESA = cr_glWindowPos3i;
+    pGLTable->WindowPos3ivMESA = cr_glWindowPos3iv;
+    pGLTable->WindowPos3sMESA = cr_glWindowPos3s;
+    pGLTable->WindowPos3svMESA = cr_glWindowPos3sv;
+};
+#undef GLAPI_ENTRY
+
+#define GLXAPI_ENTRY(Func) pGLXTable->Func = VBOXGLXTAG(glX##Func);
+static void
+vboxFillGLXAPITable(fakedri_glxapi_table *pGLXTable)
+{
+    #include "fakedri_glxfuncsList.h"
+}
+#undef GLXAPI_ENTRY
+
+static void
+vboxPatchMesaExport(const char* psFuncName, const void *pStart, const void *pEnd)
+{
+    Dl_info dlip;
+    Elf32_Sym* sym=0;
+    int rv;
+    void *alPatch;
+    void *pMesaEntry;
+
+#ifndef VBOX_NO_MESA_PATCH_REPORTS
+    crDebug("vboxPatchMesaExport: %s", psFuncName);
+#endif
+
+    pMesaEntry = dlsym(RTLD_DEFAULT, psFuncName);
+
+    if (!pMesaEntry)
+    {
+        crDebug("%s not defined in current scope, are we being loaded by mesa's libGL.so?", psFuncName);
+        return;
+    }
+
+    rv = dladdr1(pMesaEntry, &dlip, (void**)&sym, RTLD_DL_SYMENT);
+    if (!rv || !sym)
+    {
+        crError("Failed to get size for %p(%s)", pMesaEntry, psFuncName);
+        return;
+    }
+
+#if VBOX_OGL_GLX_USE_CSTUBS
+    {
+        Dl_info dlip1;
+        Elf32_Sym* sym1=0;
+        int rv;
+
+        rv = dladdr1(pStart, &dlip1, (void**)&sym1, RTLD_DL_SYMENT);
+        if (!rv || !sym)
+        {
+            crError("Failed to get size for %p", pStart);
+            return;
+        }
+
+        pEnd = pStart + sym1->st_size;
+        crDebug("VBox Entry: %p, start: %p(%s:%s), size: %i", pStart, dlip1.dli_saddr, dlip1.dli_fname, dlip1.dli_sname, sym1->st_size);
+    }
+#endif
+
+#ifndef VBOX_NO_MESA_PATCH_REPORTS
+    crDebug("Mesa Entry: %p, start: %p(%s:%s), size: %i", pMesaEntry, dlip.dli_saddr, dlip.dli_fname, dlip.dli_sname, sym->st_size);
+    crDebug("Vbox code: start: %p, end %p, size: %i", pStart, pEnd, pEnd-pStart);
+#endif
+
+    if (sym->st_size<(pEnd-pStart))
+    {
+        crDebug("Can't patch size too small.(%s)", psFuncName);
+        return;
+    }
+
+    /* Get aligned start adress we're going to patch*/
+    alPatch = (void*) ((uintptr_t)dlip.dli_saddr & ~(uintptr_t)(PAGESIZE-1));
+
+#ifndef VBOX_NO_MESA_PATCH_REPORTS
+    crDebug("MProtecting: %p, %i", alPatch, dlip.dli_saddr-alPatch+pEnd-pStart);
+#endif
+
+    /* Get write access to mesa functions */
+    rv = RTMemProtect(alPatch, dlip.dli_saddr-alPatch+pEnd-pStart, 
+                      RTMEM_PROT_READ|RTMEM_PROT_WRITE|RTMEM_PROT_EXEC);
+    if (RT_FAILURE(rv))
+    {
+        crError("mprotect failed with %x (%s)", rv, psFuncName);
+    }
+
+#ifndef VBOX_NO_MESA_PATCH_REPORTS
+    crDebug("Writing %i bytes to %p from %p", pEnd-pStart, dlip.dli_saddr, pStart);
+#endif
+
+    crMemcpy(dlip.dli_saddr, pStart, pEnd-pStart);
+
+    /*@todo Restore the protection, probably have to check what was it before us...*/
+    rv = RTMemProtect(alPatch, dlip.dli_saddr-alPatch+pEnd-pStart, 
+                      RTMEM_PROT_READ|RTMEM_PROT_EXEC);
+    if (RT_FAILURE(rv))
+    {
+        crError("mprotect2 failed with %x (%s)", rv, psFuncName);
+    }
+}
+
+#ifdef VBOX_OGL_GLX_USE_CSTUBS
+static void
+# define GLXAPI_ENTRY(Func) vboxPatchMesaExport("glX"#Func, &vbox_glX##Func, NULL);
+vboxPatchMesaExports()
+#else
+static void
+# define GLXAPI_ENTRY(Func) vboxPatchMesaExport("glX"#Func, &vbox_glX##Func, &vbox_glX##Func##_EndProc);
+vboxPatchMesaExports()
+#endif
+{
+    crDebug("Patching mesa glx entries");
+    #include "fakedri_glxfuncsList.h"
+}
+#undef GLXAPI_ENTRY
+
+bool vbox_load_sw_dri()
+{
+    const char *libPaths, *p, *next;;
+    char realDriverName[200];
+    void *handle;
+    int len, i;
+
+    /*code from Mesa-7.2/src/glx/x11/dri_common.c:driOpenDriver*/
+
+    libPaths = NULL;
+    if (geteuid() == getuid()) {
+        /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
+        libPaths = getenv("LIBGL_DRIVERS_PATH");
+        if (!libPaths)
+            libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
+    }
+    if (libPaths == NULL)
+        libPaths = DRI_DEFAULT_DRIVER_DIR;
+
+    handle = NULL;
+    for (p = libPaths; *p; p = next) 
+    {
+        next = strchr(p, ':');
+        if (next == NULL) 
+        {
+            len = strlen(p);
+            next = p + len;
+        } 
+        else 
+        {
+            len = next - p;
+            next++;
+        }
+
+        snprintf(realDriverName, sizeof realDriverName, "%.*s/%s_dri.so", len, p, "swrast");
+        crDebug("trying %s", realDriverName);
+        handle = dlopen(realDriverName, RTLD_NOW | RTLD_LOCAL);
+        if (handle) break;
+    }
+
+    /*end code*/
+
+    if (handle) gppSwDriExternsion = dlsym(handle, "__driDriverExtensions");
+
+    if (!gppSwDriExternsion)
+    {
+        crDebug("%s doesn't export __driDriverExtensions", realDriverName);
+        return false;
+    }
+    crDebug("loaded %s", realDriverName);
+
+    for (i = 0; gppSwDriExternsion[i]; i++) 
+    {
+        if (strcmp(gppSwDriExternsion[i]->name, __DRI_CORE) == 0)
+            gpSwDriCoreExternsion = (__DRIcoreExtension *) gppSwDriExternsion[i];
+        if (strcmp(gppSwDriExternsion[i]->name, __DRI_SWRAST) == 0)
+            gpSwDriSwrastExtension = (__DRIswrastExtension *) gppSwDriExternsion[i];
+    }
+
+    return gpSwDriCoreExternsion && gpSwDriSwrastExtension;
+}
+
+void __attribute__ ((constructor)) vbox_install_into_mesa(void)
+{
+    if (!stubInit())
+    {
+        crDebug("vboxdriInitScreen: stubInit failed");
+        return;
+    }
+
+    {
+        void (*pxf86Msg)(MessageType type, const char *format, ...) _printf_attribute(2,3);
+
+        pxf86Msg = dlsym(RTLD_DEFAULT, "xf86Msg");
+        if (pxf86Msg)
+        {
+            pxf86Msg(X_INFO, "Next line is added to allow vboxvideo_drv.so to appear as whitelisted driver\n");
+            pxf86Msg(X_INFO, "The file referenced, is *NOT* loaded\n");
+            pxf86Msg(X_INFO, "Loading %s/ati_drv.so\n", DRI_XORG_DRV_DIR);
+
+            /* we're failing to proxy software dri driver calls for certain xservers, so just make sure we're unloaded for now */
+            __driDriverExtensions[0] = NULL;
+            return;
+        }
+    }
+
+    /* Load swrast_dri.so to proxy dri related calls there. */
+    if (!vbox_load_sw_dri())
+    {
+        crDebug("vboxdriInitScreen: vbox_load_sw_dri failed...going to fail badly");
+        return;
+    }
+
+    /* Handle gl api.
+     * In the end application call would look like this:
+     * app call glFoo->(mesa asm dispatch stub)->cr_glFoo(vbox asm dispatch stub)->SPU Foo function(packspuFoo or alike)
+     * Note, we don't need to install extension functions via _glapi_add_dispatch, because we'd override glXGetProcAddress.
+     */    
+    /* We don't support all mesa's functions. Initialize our table to mesa dispatch first*/
+    crMemcpy(&vbox_glapi_table, _glapi_get_dispatch(), sizeof(struct _glapi_table));
+    /* Now install our assembly dispatch entries into table */
+    vboxFillMesaGLAPITable(&vbox_glapi_table);
+    /* Install our dispatch table into mesa */
+    _glapi_set_dispatch(&vbox_glapi_table);
+
+    /* Handle glx api.
+     * In the end application call would look like this:
+     * app call glxFoo->(mesa asm dispatch stub patched with vbox_glXFoo:jmp glxim[Foo's index])->VBOXGLXTAG(glxFoo)
+     */
+    /* Fill structure used by our assembly stubs */
+    vboxFillGLXAPITable(&glxim);
+    /* Now patch functions exported by libGL.so */
+    vboxPatchMesaExports();
+}
+
+/*
+ * @todo we're missing first glx related call from the client application.
+ * Luckily, this doesn't add much problems, except for some cases.
+ */
+
+/* __DRIcoreExtension */
+
+static __DRIscreen *
+vboxdriCreateNewScreen(int screen, int fd, unsigned int sarea_handle,
+                       const __DRIextension **extensions, const __DRIconfig ***driverConfigs,
+                       void *loaderPrivate)
+{
+    (void) fd;
+    (void) sarea_handle;
+    SWDRI_SAFERET_SWRAST(createNewScreen, screen, extensions, driverConfigs, loaderPrivate);
+}
+
+static void 
+vboxdriDestroyScreen(__DRIscreen *screen)
+{
+    SWDRI_SAFECALL_CORE(destroyScreen, screen);
+}
+
+static const __DRIextension **
+vboxdriGetExtensions(__DRIscreen *screen)
+{
+    SWDRI_SAFERET_CORE(getExtensions, screen);
+}
+
+static int
+vboxdriGetConfigAttrib(const __DRIconfig *config,
+                       unsigned int attrib,
+                       unsigned int *value)
+{
+    SWDRI_SAFERET_CORE(getConfigAttrib, config, attrib, value);
+}
+
+static int
+vboxdriIndexConfigAttrib(const __DRIconfig *config, int index,
+                         unsigned int *attrib, unsigned int *value)
+{
+    SWDRI_SAFERET_CORE(indexConfigAttrib, config, index, attrib, value);
+}
+
+static __DRIdrawable *
+vboxdriCreateNewDrawable(__DRIscreen *screen,
+                         const __DRIconfig *config,
+                         unsigned int drawable_id,
+                         unsigned int head,
+                         void *loaderPrivate)
+{
+    (void) drawable_id;
+    (void) head;
+    SWDRI_SAFERET_SWRAST(createNewDrawable, screen, config, loaderPrivate);
+}
+
+static void 
+vboxdriDestroyDrawable(__DRIdrawable *drawable)
+{
+    SWDRI_SAFECALL_CORE(destroyDrawable, drawable);
+}
+
+static void
+vboxdriSwapBuffers(__DRIdrawable *drawable)
+{
+    SWDRI_SAFECALL_CORE(swapBuffers, drawable);
+}
+
+static __DRIcontext *
+vboxdriCreateNewContext(__DRIscreen *screen,
+                        const __DRIconfig *config,
+                        __DRIcontext *shared,
+                        void *loaderPrivate)
+{
+    SWDRI_SAFERET_CORE(createNewContext, screen, config, shared, loaderPrivate);
+}
+
+static int 
+vboxdriCopyContext(__DRIcontext *dest,
+                   __DRIcontext *src,
+                   unsigned long mask)
+{
+    SWDRI_SAFERET_CORE(copyContext, dest, src, mask);
+}
+
+static void 
+vboxdriDestroyContext(__DRIcontext *context)
+{
+    SWDRI_SAFECALL_CORE(destroyContext, context);
+}
+
+static int 
+vboxdriBindContext(__DRIcontext *ctx,
+                   __DRIdrawable *pdraw,
+                   __DRIdrawable *pread)
+{
+    SWDRI_SAFERET_CORE(bindContext, ctx, pdraw, pread);
+}
+
+static int 
+vboxdriUnbindContext(__DRIcontext *ctx)
+{
+    SWDRI_SAFERET_CORE(unbindContext, ctx)
+}
+
+/* __DRIlegacyExtension */
+
+static __DRIscreen *
+vboxdriCreateNewScreen_Legacy(int scrn,
+                              const __DRIversion *ddx_version,
+                              const __DRIversion *dri_version,
+                              const __DRIversion *drm_version,
+                              const __DRIframebuffer *frame_buffer,
+                              drmAddress pSAREA, int fd, 
+                              const __DRIextension **extensions,
+                              const __DRIconfig ***driver_modes,
+                              void *loaderPrivate)
+{
+    (void) ddx_version;
+    (void) dri_version;
+    (void) frame_buffer;
+    (void) pSAREA;
+    (void) fd;
+    SWDRI_SAFERET_SWRAST(createNewScreen, scrn, extensions, driver_modes, loaderPrivate);
+}
+
+static __DRIdrawable *
+vboxdriCreateNewDrawable_Legacy(__DRIscreen *psp, const __DRIconfig *config,
+                                drm_drawable_t hwDrawable, int renderType,
+                                const int *attrs, void *data)
+{
+    (void) hwDrawable;
+    (void) renderType;
+    (void) attrs;
+    (void) data;
+    SWDRI_SAFERET_SWRAST(createNewDrawable, psp, config, data);
+}
+
+static __DRIcontext *
+vboxdriCreateNewContext_Legacy(__DRIscreen *psp, const __DRIconfig *config,
+                               int render_type, __DRIcontext *shared, 
+                               drm_context_t hwContext, void *data)
+{
+    (void) render_type;
+    (void) hwContext;
+    return vboxdriCreateNewContext(psp, config, shared, data);
+}
+
+
+static const __DRIlegacyExtension vboxdriLegacyExtension = {
+    { __DRI_LEGACY, __DRI_LEGACY_VERSION },
+    vboxdriCreateNewScreen_Legacy,
+    vboxdriCreateNewDrawable_Legacy,
+    vboxdriCreateNewContext_Legacy
+};
+
+static const __DRIcoreExtension vboxdriCoreExtension = {
+    { __DRI_CORE, __DRI_CORE_VERSION },
+    vboxdriCreateNewScreen, /* driCreateNewScreen */
+    vboxdriDestroyScreen,
+    vboxdriGetExtensions,
+    vboxdriGetConfigAttrib,
+    vboxdriIndexConfigAttrib,
+    vboxdriCreateNewDrawable, /* driCreateNewDrawable */
+    vboxdriDestroyDrawable,
+    vboxdriSwapBuffers,
+    vboxdriCreateNewContext,
+    vboxdriCopyContext,
+    vboxdriDestroyContext,
+    vboxdriBindContext,
+    vboxdriUnbindContext
+};
+
+/* This structure is used by dri_util from mesa, don't rename it! */
+DECLEXPORT(const __DRIextension *) __driDriverExtensions[] = {
+    &vboxdriLegacyExtension.base,
+    &vboxdriCoreExtension.base,
+    NULL
+};
Index: trunk/src/VBox/Additions/common/crOpenGL/fakedri_drv.h
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/fakedri_drv.h	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/fakedri_drv.h	(revision 18882)
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/** @file
+ *
+ * VirtualBox guest OpenGL DRI header
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ */
+
+#ifndef ___CROPENGL_FAKEDRIDRV_H
+#define ___CROPENGL_FAKEDRIDRV_H
+
+#include "src/mesa/main/mtypes.h"
+#include "src/mesa/main/dd.h"
+#include "src/mesa/glapi/dispatch.h"
+#include "src/mesa/glapi/glapi.h"
+#include "src/mesa/glapi/glapitable.h"
+#include "src/mesa/glapi/glapioffsets.h"
+#include "src/mesa/drivers/dri/common/dri_util.h"
+#include "GL/internal/dri_interface.h"
+
+#include "glx_proto.h"
+
+#ifdef VBOX_OGL_GLX_USE_CSTUBS
+# include "dri_glx.h"
+#endif
+
+typedef struct _vbox_glxapi_table
+{
+    #define GLXAPI_ENTRY(Func) PGLXFUNC_##Func Func;
+    #include "fakedri_glxfuncsList.h"
+    #undef GLXAPI_ENTRY
+} fakedri_glxapi_table;
+
+extern fakedri_glxapi_table glxim;
+
+#ifdef VBOX_OGL_GLX_USE_CSTUBS
+/* Extern declarations for our C stubs */
+extern void VBOXGLXENTRYTAG(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer) ;
+extern GLXContext VBOXGLXENTRYTAG(glXImportContextEXT)(Display *dpy, GLXContextID contextID) ;
+extern GLXContextID VBOXGLXENTRYTAG(glXGetContextIDEXT)(const GLXContext ctx) ;
+extern Bool VBOXGLXENTRYTAG(glXMakeCurrentReadSGI)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx) ;
+extern Display * VBOXGLXENTRYTAG(glXGetCurrentDisplayEXT)(void) ;
+extern void VBOXGLXENTRYTAG(glXFreeContextEXT)(Display *dpy, GLXContext ctx) ;
+extern int VBOXGLXENTRYTAG(glXQueryContextInfoEXT)(Display *dpy, GLXContext ctx) ;
+extern void * VBOXGLXENTRYTAG(glXAllocateMemoryMESA)(Display *dpy, int scrn,
+                                                     size_t size, float readFreq,
+                                                     float writeFreq, float priority);
+extern GLuint VBOXGLXENTRYTAG(glXGetMemoryOffsetMESA)(Display *dpy, int scrn, const void *pointer ) ;
+extern GLXPixmap VBOXGLXENTRYTAG(glXCreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap) ;
+extern void VBOXGLXENTRYTAG(glXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask);
+extern void VBOXGLXENTRYTAG(glXUseXFont)(Font font, int first, int count, int listBase) ;
+extern CR_GLXFuncPtr VBOXGLXENTRYTAG(glXGetProcAddress)(const GLubyte *name) ;
+extern Bool VBOXGLXENTRYTAG(glXQueryExtension)(Display *dpy, int *errorBase, int *eventBase) ;
+extern Bool VBOXGLXENTRYTAG(glXIsDirect)(Display *dpy, GLXContext ctx) ;
+extern GLXPixmap VBOXGLXENTRYTAG(glXCreateGLXPixmap)(Display *dpy, XVisualInfo *vis, Pixmap pixmap) ;
+extern void VBOXGLXENTRYTAG(glXSwapBuffers)(Display *dpy, GLXDrawable drawable) ;
+extern GLXDrawable VBOXGLXENTRYTAG(glXGetCurrentDrawable)(void) ;
+extern void VBOXGLXENTRYTAG(glXWaitGL)(void) ;
+extern Display * VBOXGLXENTRYTAG(glXGetCurrentDisplay)(void) ;
+extern const char * VBOXGLXENTRYTAG(glXQueryServerString)(Display *dpy, int screen, int name) ;
+extern GLXContext VBOXGLXENTRYTAG(glXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext share, Bool direct) ;
+extern int VBOXGLXENTRYTAG(glXGetConfig)(Display *dpy, XVisualInfo *vis, int attrib, int *value) ;
+extern void VBOXGLXENTRYTAG(glXWaitX)(void) ;
+extern GLXContext VBOXGLXENTRYTAG(glXGetCurrentContext)(void) ;
+extern const char * VBOXGLXENTRYTAG(glXGetClientString)(Display *dpy, int name) ;
+extern Bool VBOXGLXENTRYTAG(glXMakeCurrent)(Display *dpy, GLXDrawable drawable, GLXContext ctx) ;
+extern void VBOXGLXENTRYTAG(glXDestroyContext)(Display *dpy, GLXContext ctx) ;
+extern CR_GLXFuncPtr VBOXGLXENTRYTAG(glXGetProcAddressARB)(const GLubyte *name) ;
+extern void VBOXGLXENTRYTAG(glXDestroyGLXPixmap)(Display *dpy, GLXPixmap pix) ;
+extern Bool VBOXGLXENTRYTAG(glXQueryVersion)(Display *dpy, int *major, int *minor) ;
+extern XVisualInfo * VBOXGLXENTRYTAG(glXChooseVisual)(Display *dpy, int screen, int *attribList) ;
+extern const char * VBOXGLXENTRYTAG(glXQueryExtensionsString)(Display *dpy, int screen) ;
+extern GLXPbufferSGIX VBOXGLXENTRYTAG(glXCreateGLXPbufferSGIX)(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list);
+extern int VBOXGLXENTRYTAG(glXQueryGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf, int attribute, unsigned int *value);
+extern GLXFBConfigSGIX * VBOXGLXENTRYTAG(glXChooseFBConfigSGIX)(Display *dpy, int screen, int *attrib_list, int *nelements);
+extern void VBOXGLXENTRYTAG(glXDestroyGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf) ;
+extern void VBOXGLXENTRYTAG(glXSelectEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long mask) ;
+extern void VBOXGLXENTRYTAG(glXGetSelectedEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long *mask) ;
+extern GLXFBConfigSGIX VBOXGLXENTRYTAG(glXGetFBConfigFromVisualSGIX)(Display *dpy, XVisualInfo *vis) ;
+extern XVisualInfo * VBOXGLXENTRYTAG(glXGetVisualFromFBConfigSGIX)(Display *dpy, GLXFBConfig config) ;
+extern GLXContext VBOXGLXENTRYTAG(glXCreateContextWithConfigSGIX)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
+extern GLXPixmap VBOXGLXENTRYTAG(glXCreateGLXPixmapWithConfigSGIX)(Display *dpy, GLXFBConfig config, Pixmap pixmap) ;
+extern int VBOXGLXENTRYTAG(glXGetFBConfigAttribSGIX)(Display *dpy, GLXFBConfig config, int attribute, int *value) ;
+extern GLXFBConfig * VBOXGLXENTRYTAG(glXChooseFBConfig)(Display *dpy, int screen, ATTRIB_TYPE *attrib_list, int *nelements) ;
+extern GLXPbuffer VBOXGLXENTRYTAG(glXCreatePbuffer)(Display *dpy, GLXFBConfig config, ATTRIB_TYPE *attrib_list) ;
+extern GLXPixmap VBOXGLXENTRYTAG(glXCreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const ATTRIB_TYPE *attrib_list) ;
+extern GLXWindow VBOXGLXENTRYTAG(glXCreateWindow)(Display *dpy, GLXFBConfig config, Window win, ATTRIB_TYPE *attrib_list) ;
+extern GLXContext VBOXGLXENTRYTAG(glXCreateNewContext)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
+extern void VBOXGLXENTRYTAG(glXDestroyPbuffer)(Display *dpy, GLXPbuffer pbuf) ;
+extern void VBOXGLXENTRYTAG(glXDestroyPixmap)(Display *dpy, GLXPixmap pixmap) ;
+extern void VBOXGLXENTRYTAG(glXDestroyWindow)(Display *dpy, GLXWindow win) ;
+extern GLXDrawable VBOXGLXENTRYTAG(glXGetCurrentReadDrawable)(void) ;
+extern int VBOXGLXENTRYTAG(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value) ;
+extern GLXFBConfig * VBOXGLXENTRYTAG(glXGetFBConfigs)(Display *dpy, int screen, int *nelements) ;
+extern void VBOXGLXENTRYTAG(glXGetSelectedEvent)(Display *dpy, GLXDrawable draw, unsigned long *event_mask) ;
+extern XVisualInfo * VBOXGLXENTRYTAG(glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config) ;
+extern Bool VBOXGLXENTRYTAG(glXMakeContextCurrent)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx) ;
+extern int VBOXGLXENTRYTAG(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value) ;
+extern void VBOXGLXENTRYTAG(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value) ;
+extern void VBOXGLXENTRYTAG(glXSelectEvent)(Display *dpy, GLXDrawable draw, unsigned long event_mask) ;
+#else
+/* Extern declarations for our asm stubs */
+# define GLXAPI_ENTRY(Func) \
+    extern void vbox_glX##Func;\
+    extern void vbox_glX##Func##_EndProc;
+# include "fakedri_glxfuncsList.h"
+# undef GLXAPI_ENTRY
+#endif
+
+#endif /* ___CROPENGL_FAKEDRIDRV_H */
+
Index: trunk/src/VBox/Additions/common/crOpenGL/fakedri_glfuncsList.h
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/fakedri_glfuncsList.h	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/fakedri_glfuncsList.h	(revision 18882)
@@ -0,0 +1,706 @@
+/* $Id$ */
+
+/** @file
+ * VBox OpenGL list of opengl functions common in Mesa and vbox opengl stub
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ */
+
+#ifndef GLAPI_ENTRY
+#error GLAPI_ENTRY should be defined.
+#endif
+
+GLAPI_ENTRY(NewList)
+GLAPI_ENTRY(EndList)
+GLAPI_ENTRY(CallList)
+GLAPI_ENTRY(CallLists)
+GLAPI_ENTRY(DeleteLists)
+GLAPI_ENTRY(GenLists)
+GLAPI_ENTRY(ListBase)
+GLAPI_ENTRY(Begin)
+GLAPI_ENTRY(Bitmap)
+GLAPI_ENTRY(Color3b)
+GLAPI_ENTRY(Color3bv)
+GLAPI_ENTRY(Color3d)
+GLAPI_ENTRY(Color3dv)
+GLAPI_ENTRY(Color3f)
+GLAPI_ENTRY(Color3fv)
+GLAPI_ENTRY(Color3i)
+GLAPI_ENTRY(Color3iv)
+GLAPI_ENTRY(Color3s)
+GLAPI_ENTRY(Color3sv)
+GLAPI_ENTRY(Color3ub)
+GLAPI_ENTRY(Color3ubv)
+GLAPI_ENTRY(Color3ui)
+GLAPI_ENTRY(Color3uiv)
+GLAPI_ENTRY(Color3us)
+GLAPI_ENTRY(Color3usv)
+GLAPI_ENTRY(Color4b)
+GLAPI_ENTRY(Color4bv)
+GLAPI_ENTRY(Color4d)
+GLAPI_ENTRY(Color4dv)
+GLAPI_ENTRY(Color4f)
+GLAPI_ENTRY(Color4fv)
+GLAPI_ENTRY(Color4i)
+GLAPI_ENTRY(Color4iv)
+GLAPI_ENTRY(Color4s)
+GLAPI_ENTRY(Color4sv)
+GLAPI_ENTRY(Color4ub)
+GLAPI_ENTRY(Color4ubv)
+GLAPI_ENTRY(Color4ui)
+GLAPI_ENTRY(Color4uiv)
+GLAPI_ENTRY(Color4us)
+GLAPI_ENTRY(Color4usv)
+GLAPI_ENTRY(EdgeFlag)
+GLAPI_ENTRY(EdgeFlagv)
+GLAPI_ENTRY(End)
+GLAPI_ENTRY(Indexd)
+GLAPI_ENTRY(Indexdv)
+GLAPI_ENTRY(Indexf)
+GLAPI_ENTRY(Indexfv)
+GLAPI_ENTRY(Indexi)
+GLAPI_ENTRY(Indexiv)
+GLAPI_ENTRY(Indexs)
+GLAPI_ENTRY(Indexsv)
+GLAPI_ENTRY(Normal3b)
+GLAPI_ENTRY(Normal3bv)
+GLAPI_ENTRY(Normal3d)
+GLAPI_ENTRY(Normal3dv)
+GLAPI_ENTRY(Normal3f)
+GLAPI_ENTRY(Normal3fv)
+GLAPI_ENTRY(Normal3i)
+GLAPI_ENTRY(Normal3iv)
+GLAPI_ENTRY(Normal3s)
+GLAPI_ENTRY(Normal3sv)
+GLAPI_ENTRY(RasterPos2d)
+GLAPI_ENTRY(RasterPos2dv)
+GLAPI_ENTRY(RasterPos2f)
+GLAPI_ENTRY(RasterPos2fv)
+GLAPI_ENTRY(RasterPos2i)
+GLAPI_ENTRY(RasterPos2iv)
+GLAPI_ENTRY(RasterPos2s)
+GLAPI_ENTRY(RasterPos2sv)
+GLAPI_ENTRY(RasterPos3d)
+GLAPI_ENTRY(RasterPos3dv)
+GLAPI_ENTRY(RasterPos3f)
+GLAPI_ENTRY(RasterPos3fv)
+GLAPI_ENTRY(RasterPos3i)
+GLAPI_ENTRY(RasterPos3iv)
+GLAPI_ENTRY(RasterPos3s)
+GLAPI_ENTRY(RasterPos3sv)
+GLAPI_ENTRY(RasterPos4d)
+GLAPI_ENTRY(RasterPos4dv)
+GLAPI_ENTRY(RasterPos4f)
+GLAPI_ENTRY(RasterPos4fv)
+GLAPI_ENTRY(RasterPos4i)
+GLAPI_ENTRY(RasterPos4iv)
+GLAPI_ENTRY(RasterPos4s)
+GLAPI_ENTRY(RasterPos4sv)
+GLAPI_ENTRY(Rectd)
+GLAPI_ENTRY(Rectdv)
+GLAPI_ENTRY(Rectf)
+GLAPI_ENTRY(Rectfv)
+GLAPI_ENTRY(Recti)
+GLAPI_ENTRY(Rectiv)
+GLAPI_ENTRY(Rects)
+GLAPI_ENTRY(Rectsv)
+GLAPI_ENTRY(TexCoord1d)
+GLAPI_ENTRY(TexCoord1dv)
+GLAPI_ENTRY(TexCoord1f)
+GLAPI_ENTRY(TexCoord1fv)
+GLAPI_ENTRY(TexCoord1i)
+GLAPI_ENTRY(TexCoord1iv)
+GLAPI_ENTRY(TexCoord1s)
+GLAPI_ENTRY(TexCoord1sv)
+GLAPI_ENTRY(TexCoord2d)
+GLAPI_ENTRY(TexCoord2dv)
+GLAPI_ENTRY(TexCoord2f)
+GLAPI_ENTRY(TexCoord2fv)
+GLAPI_ENTRY(TexCoord2i)
+GLAPI_ENTRY(TexCoord2iv)
+GLAPI_ENTRY(TexCoord2s)
+GLAPI_ENTRY(TexCoord2sv)
+GLAPI_ENTRY(TexCoord3d)
+GLAPI_ENTRY(TexCoord3dv)
+GLAPI_ENTRY(TexCoord3f)
+GLAPI_ENTRY(TexCoord3fv)
+GLAPI_ENTRY(TexCoord3i)
+GLAPI_ENTRY(TexCoord3iv)
+GLAPI_ENTRY(TexCoord3s)
+GLAPI_ENTRY(TexCoord3sv)
+GLAPI_ENTRY(TexCoord4d)
+GLAPI_ENTRY(TexCoord4dv)
+GLAPI_ENTRY(TexCoord4f)
+GLAPI_ENTRY(TexCoord4fv)
+GLAPI_ENTRY(TexCoord4i)
+GLAPI_ENTRY(TexCoord4iv)
+GLAPI_ENTRY(TexCoord4s)
+GLAPI_ENTRY(TexCoord4sv)
+GLAPI_ENTRY(Vertex2d)
+GLAPI_ENTRY(Vertex2dv)
+GLAPI_ENTRY(Vertex2f)
+GLAPI_ENTRY(Vertex2fv)
+GLAPI_ENTRY(Vertex2i)
+GLAPI_ENTRY(Vertex2iv)
+GLAPI_ENTRY(Vertex2s)
+GLAPI_ENTRY(Vertex2sv)
+GLAPI_ENTRY(Vertex3d)
+GLAPI_ENTRY(Vertex3dv)
+GLAPI_ENTRY(Vertex3f)
+GLAPI_ENTRY(Vertex3fv)
+GLAPI_ENTRY(Vertex3i)
+GLAPI_ENTRY(Vertex3iv)
+GLAPI_ENTRY(Vertex3s)
+GLAPI_ENTRY(Vertex3sv)
+GLAPI_ENTRY(Vertex4d)
+GLAPI_ENTRY(Vertex4dv)
+GLAPI_ENTRY(Vertex4f)
+GLAPI_ENTRY(Vertex4fv)
+GLAPI_ENTRY(Vertex4i)
+GLAPI_ENTRY(Vertex4iv)
+GLAPI_ENTRY(Vertex4s)
+GLAPI_ENTRY(Vertex4sv)
+GLAPI_ENTRY(ClipPlane)
+GLAPI_ENTRY(ColorMaterial)
+GLAPI_ENTRY(CullFace)
+GLAPI_ENTRY(Fogf)
+GLAPI_ENTRY(Fogfv)
+GLAPI_ENTRY(Fogi)
+GLAPI_ENTRY(Fogiv)
+GLAPI_ENTRY(FrontFace)
+GLAPI_ENTRY(Hint)
+GLAPI_ENTRY(Lightf)
+GLAPI_ENTRY(Lightfv)
+GLAPI_ENTRY(Lighti)
+GLAPI_ENTRY(Lightiv)
+GLAPI_ENTRY(LightModelf)
+GLAPI_ENTRY(LightModelfv)
+GLAPI_ENTRY(LightModeli)
+GLAPI_ENTRY(LightModeliv)
+GLAPI_ENTRY(LineStipple)
+GLAPI_ENTRY(LineWidth)
+GLAPI_ENTRY(Materialf)
+GLAPI_ENTRY(Materialfv)
+GLAPI_ENTRY(Materiali)
+GLAPI_ENTRY(Materialiv)
+GLAPI_ENTRY(PointSize)
+GLAPI_ENTRY(PolygonMode)
+GLAPI_ENTRY(PolygonStipple)
+GLAPI_ENTRY(Scissor)
+GLAPI_ENTRY(ShadeModel)
+GLAPI_ENTRY(TexParameterf)
+GLAPI_ENTRY(TexParameterfv)
+GLAPI_ENTRY(TexParameteri)
+GLAPI_ENTRY(TexParameteriv)
+GLAPI_ENTRY(TexImage1D)
+GLAPI_ENTRY(TexImage2D)
+GLAPI_ENTRY(TexEnvf)
+GLAPI_ENTRY(TexEnvfv)
+GLAPI_ENTRY(TexEnvi)
+GLAPI_ENTRY(TexEnviv)
+GLAPI_ENTRY(TexGend)
+GLAPI_ENTRY(TexGendv)
+GLAPI_ENTRY(TexGenf)
+GLAPI_ENTRY(TexGenfv)
+GLAPI_ENTRY(TexGeni)
+GLAPI_ENTRY(TexGeniv)
+GLAPI_ENTRY(FeedbackBuffer)
+GLAPI_ENTRY(SelectBuffer)
+GLAPI_ENTRY(RenderMode)
+GLAPI_ENTRY(InitNames)
+GLAPI_ENTRY(LoadName)
+GLAPI_ENTRY(PassThrough)
+GLAPI_ENTRY(PopName)
+GLAPI_ENTRY(PushName)
+GLAPI_ENTRY(DrawBuffer)
+GLAPI_ENTRY(Clear)
+GLAPI_ENTRY(ClearAccum)
+GLAPI_ENTRY(ClearIndex)
+GLAPI_ENTRY(ClearColor)
+GLAPI_ENTRY(ClearStencil)
+GLAPI_ENTRY(ClearDepth)
+GLAPI_ENTRY(StencilMask)
+GLAPI_ENTRY(ColorMask)
+GLAPI_ENTRY(DepthMask)
+GLAPI_ENTRY(IndexMask)
+GLAPI_ENTRY(Accum)
+GLAPI_ENTRY(Disable)
+GLAPI_ENTRY(Enable)
+GLAPI_ENTRY(Finish)
+GLAPI_ENTRY(Flush)
+GLAPI_ENTRY(PopAttrib)
+GLAPI_ENTRY(PushAttrib)
+GLAPI_ENTRY(Map1d)
+GLAPI_ENTRY(Map1f)
+GLAPI_ENTRY(Map2d)
+GLAPI_ENTRY(Map2f)
+GLAPI_ENTRY(MapGrid1d)
+GLAPI_ENTRY(MapGrid1f)
+GLAPI_ENTRY(MapGrid2d)
+GLAPI_ENTRY(MapGrid2f)
+GLAPI_ENTRY(EvalCoord1d)
+GLAPI_ENTRY(EvalCoord1dv)
+GLAPI_ENTRY(EvalCoord1f)
+GLAPI_ENTRY(EvalCoord1fv)
+GLAPI_ENTRY(EvalCoord2d)
+GLAPI_ENTRY(EvalCoord2dv)
+GLAPI_ENTRY(EvalCoord2f)
+GLAPI_ENTRY(EvalCoord2fv)
+GLAPI_ENTRY(EvalMesh1)
+GLAPI_ENTRY(EvalPoint1)
+GLAPI_ENTRY(EvalMesh2)
+GLAPI_ENTRY(EvalPoint2)
+GLAPI_ENTRY(AlphaFunc)
+GLAPI_ENTRY(BlendFunc)
+GLAPI_ENTRY(LogicOp)
+GLAPI_ENTRY(StencilFunc)
+GLAPI_ENTRY(StencilOp)
+GLAPI_ENTRY(DepthFunc)
+GLAPI_ENTRY(PixelZoom)
+GLAPI_ENTRY(PixelTransferf)
+GLAPI_ENTRY(PixelTransferi)
+GLAPI_ENTRY(PixelStoref)
+GLAPI_ENTRY(PixelStorei)
+GLAPI_ENTRY(PixelMapfv)
+GLAPI_ENTRY(PixelMapuiv)
+GLAPI_ENTRY(PixelMapusv)
+GLAPI_ENTRY(ReadBuffer)
+GLAPI_ENTRY(CopyPixels)
+GLAPI_ENTRY(ReadPixels)
+GLAPI_ENTRY(DrawPixels)
+GLAPI_ENTRY(GetBooleanv)
+GLAPI_ENTRY(GetClipPlane)
+GLAPI_ENTRY(GetDoublev)
+GLAPI_ENTRY(GetError)
+GLAPI_ENTRY(GetFloatv)
+GLAPI_ENTRY(GetIntegerv)
+GLAPI_ENTRY(GetLightfv)
+GLAPI_ENTRY(GetLightiv)
+GLAPI_ENTRY(GetMapdv)
+GLAPI_ENTRY(GetMapfv)
+GLAPI_ENTRY(GetMapiv)
+GLAPI_ENTRY(GetMaterialfv)
+GLAPI_ENTRY(GetMaterialiv)
+GLAPI_ENTRY(GetPixelMapfv)
+GLAPI_ENTRY(GetPixelMapuiv)
+GLAPI_ENTRY(GetPixelMapusv)
+GLAPI_ENTRY(GetPolygonStipple)
+GLAPI_ENTRY(GetString)
+GLAPI_ENTRY(GetTexEnvfv)
+GLAPI_ENTRY(GetTexEnviv)
+GLAPI_ENTRY(GetTexGendv)
+GLAPI_ENTRY(GetTexGenfv)
+GLAPI_ENTRY(GetTexGeniv)
+GLAPI_ENTRY(GetTexImage)
+GLAPI_ENTRY(GetTexParameterfv)
+GLAPI_ENTRY(GetTexParameteriv)
+GLAPI_ENTRY(GetTexLevelParameterfv)
+GLAPI_ENTRY(GetTexLevelParameteriv)
+GLAPI_ENTRY(IsEnabled)
+GLAPI_ENTRY(IsList)
+GLAPI_ENTRY(DepthRange)
+GLAPI_ENTRY(Frustum)
+GLAPI_ENTRY(LoadIdentity)
+GLAPI_ENTRY(LoadMatrixf)
+GLAPI_ENTRY(LoadMatrixd)
+GLAPI_ENTRY(MatrixMode)
+GLAPI_ENTRY(MultMatrixf)
+GLAPI_ENTRY(MultMatrixd)
+GLAPI_ENTRY(Ortho)
+GLAPI_ENTRY(PopMatrix)
+GLAPI_ENTRY(PushMatrix)
+GLAPI_ENTRY(Rotated)
+GLAPI_ENTRY(Rotatef)
+GLAPI_ENTRY(Scaled)
+GLAPI_ENTRY(Scalef)
+GLAPI_ENTRY(Translated)
+GLAPI_ENTRY(Translatef)
+GLAPI_ENTRY(Viewport)
+GLAPI_ENTRY(ArrayElement)
+GLAPI_ENTRY(BindTexture)
+GLAPI_ENTRY(ColorPointer)
+GLAPI_ENTRY(DisableClientState)
+GLAPI_ENTRY(DrawArrays)
+GLAPI_ENTRY(DrawElements)
+GLAPI_ENTRY(EdgeFlagPointer)
+GLAPI_ENTRY(EnableClientState)
+GLAPI_ENTRY(IndexPointer)
+GLAPI_ENTRY(Indexub)
+GLAPI_ENTRY(Indexubv)
+GLAPI_ENTRY(InterleavedArrays)
+GLAPI_ENTRY(NormalPointer)
+GLAPI_ENTRY(PolygonOffset)
+GLAPI_ENTRY(TexCoordPointer)
+GLAPI_ENTRY(VertexPointer)
+GLAPI_ENTRY(AreTexturesResident)
+GLAPI_ENTRY(CopyTexImage1D)
+GLAPI_ENTRY(CopyTexImage2D)
+GLAPI_ENTRY(CopyTexSubImage1D)
+GLAPI_ENTRY(CopyTexSubImage2D)
+GLAPI_ENTRY(DeleteTextures)
+GLAPI_ENTRY(GenTextures)
+GLAPI_ENTRY(GetPointerv)
+GLAPI_ENTRY(IsTexture)
+GLAPI_ENTRY(PrioritizeTextures)
+GLAPI_ENTRY(TexSubImage1D)
+GLAPI_ENTRY(TexSubImage2D)
+GLAPI_ENTRY(PopClientAttrib)
+GLAPI_ENTRY(PushClientAttrib)
+GLAPI_ENTRY(BlendColor)
+GLAPI_ENTRY(BlendEquation)
+GLAPI_ENTRY(DrawRangeElements)
+GLAPI_ENTRY(ColorTable)
+GLAPI_ENTRY(ColorTableParameterfv)
+GLAPI_ENTRY(ColorTableParameteriv)
+GLAPI_ENTRY(CopyColorTable)
+GLAPI_ENTRY(GetColorTable)
+GLAPI_ENTRY(GetColorTableParameterfv)
+GLAPI_ENTRY(GetColorTableParameteriv)
+GLAPI_ENTRY(ColorSubTable)
+GLAPI_ENTRY(CopyColorSubTable)
+GLAPI_ENTRY(ConvolutionFilter1D)
+GLAPI_ENTRY(ConvolutionFilter2D)
+GLAPI_ENTRY(ConvolutionParameterf)
+GLAPI_ENTRY(ConvolutionParameterfv)
+GLAPI_ENTRY(ConvolutionParameteri)
+GLAPI_ENTRY(ConvolutionParameteriv)
+GLAPI_ENTRY(CopyConvolutionFilter1D)
+GLAPI_ENTRY(CopyConvolutionFilter2D)
+GLAPI_ENTRY(GetConvolutionFilter)
+GLAPI_ENTRY(GetConvolutionParameterfv)
+GLAPI_ENTRY(GetConvolutionParameteriv)
+GLAPI_ENTRY(GetSeparableFilter)
+GLAPI_ENTRY(SeparableFilter2D)
+GLAPI_ENTRY(GetHistogram)
+GLAPI_ENTRY(GetHistogramParameterfv)
+GLAPI_ENTRY(GetHistogramParameteriv)
+GLAPI_ENTRY(GetMinmax)
+GLAPI_ENTRY(GetMinmaxParameterfv)
+GLAPI_ENTRY(GetMinmaxParameteriv)
+GLAPI_ENTRY(Histogram)
+GLAPI_ENTRY(Minmax)
+GLAPI_ENTRY(ResetHistogram)
+GLAPI_ENTRY(ResetMinmax)
+GLAPI_ENTRY(TexImage3D)
+GLAPI_ENTRY(TexSubImage3D)
+GLAPI_ENTRY(CopyTexSubImage3D)
+GLAPI_ENTRY(MultiTexCoord1dARB)
+GLAPI_ENTRY(MultiTexCoord1dvARB)
+GLAPI_ENTRY(MultiTexCoord1fARB)
+GLAPI_ENTRY(MultiTexCoord1fvARB)
+GLAPI_ENTRY(MultiTexCoord1iARB)
+GLAPI_ENTRY(MultiTexCoord1ivARB)
+GLAPI_ENTRY(MultiTexCoord1sARB)
+GLAPI_ENTRY(MultiTexCoord1svARB)
+GLAPI_ENTRY(MultiTexCoord2dARB)
+GLAPI_ENTRY(MultiTexCoord2dvARB)
+GLAPI_ENTRY(MultiTexCoord2fARB)
+GLAPI_ENTRY(MultiTexCoord2fvARB)
+GLAPI_ENTRY(MultiTexCoord2iARB)
+GLAPI_ENTRY(MultiTexCoord2ivARB)
+GLAPI_ENTRY(MultiTexCoord2sARB)
+GLAPI_ENTRY(MultiTexCoord2svARB)
+GLAPI_ENTRY(MultiTexCoord3dARB)
+GLAPI_ENTRY(MultiTexCoord3dvARB)
+GLAPI_ENTRY(MultiTexCoord3fARB)
+GLAPI_ENTRY(MultiTexCoord3fvARB)
+GLAPI_ENTRY(MultiTexCoord3iARB)
+GLAPI_ENTRY(MultiTexCoord3ivARB)
+GLAPI_ENTRY(MultiTexCoord3sARB)
+GLAPI_ENTRY(MultiTexCoord3svARB)
+GLAPI_ENTRY(MultiTexCoord4dARB)
+GLAPI_ENTRY(MultiTexCoord4dvARB)
+GLAPI_ENTRY(MultiTexCoord4fARB)
+GLAPI_ENTRY(MultiTexCoord4fvARB)
+GLAPI_ENTRY(MultiTexCoord4iARB)
+GLAPI_ENTRY(MultiTexCoord4ivARB)
+GLAPI_ENTRY(MultiTexCoord4sARB)
+GLAPI_ENTRY(MultiTexCoord4svARB)
+//GLAPI_ENTRY(AttachShader)
+//GLAPI_ENTRY(CreateProgram)
+//GLAPI_ENTRY(CreateShader)
+//GLAPI_ENTRY(DeleteProgram)
+//GLAPI_ENTRY(DeleteShader)
+//GLAPI_ENTRY(DetachShader)
+//GLAPI_ENTRY(GetAttachedShaders)
+//GLAPI_ENTRY(GetProgramInfoLog)
+//GLAPI_ENTRY(GetProgramiv)
+//GLAPI_ENTRY(GetShaderInfoLog)
+//GLAPI_ENTRY(GetShaderiv)
+//GLAPI_ENTRY(IsProgram)
+//GLAPI_ENTRY(IsShader)
+//GLAPI_ENTRY(StencilFuncSeparate)
+//GLAPI_ENTRY(StencilMaskSeparate)
+//GLAPI_ENTRY(StencilOpSeparate)
+//GLAPI_ENTRY(UniformMatrix2x3fv)
+//GLAPI_ENTRY(UniformMatrix2x4fv)
+//GLAPI_ENTRY(UniformMatrix3x2fv)
+//GLAPI_ENTRY(UniformMatrix3x4fv)
+//GLAPI_ENTRY(UniformMatrix4x2fv)
+//GLAPI_ENTRY(UniformMatrix4x3fv)
+GLAPI_ENTRY(LoadTransposeMatrixdARB)
+GLAPI_ENTRY(LoadTransposeMatrixfARB)
+GLAPI_ENTRY(MultTransposeMatrixdARB)
+GLAPI_ENTRY(MultTransposeMatrixfARB)
+GLAPI_ENTRY(SampleCoverageARB)
+GLAPI_ENTRY(CompressedTexImage1DARB)
+GLAPI_ENTRY(CompressedTexImage2DARB)
+GLAPI_ENTRY(CompressedTexImage3DARB)
+GLAPI_ENTRY(CompressedTexSubImage1DARB)
+GLAPI_ENTRY(CompressedTexSubImage2DARB)
+GLAPI_ENTRY(CompressedTexSubImage3DARB)
+GLAPI_ENTRY(GetCompressedTexImageARB)
+GLAPI_ENTRY(DisableVertexAttribArrayARB)
+GLAPI_ENTRY(EnableVertexAttribArrayARB)
+GLAPI_ENTRY(GetProgramEnvParameterdvARB)
+GLAPI_ENTRY(GetProgramEnvParameterfvARB)
+GLAPI_ENTRY(GetProgramLocalParameterdvARB)
+GLAPI_ENTRY(GetProgramLocalParameterfvARB)
+GLAPI_ENTRY(GetProgramStringARB)
+GLAPI_ENTRY(GetProgramivARB)
+GLAPI_ENTRY(GetVertexAttribdvARB)
+GLAPI_ENTRY(GetVertexAttribfvARB)
+GLAPI_ENTRY(GetVertexAttribivARB)
+GLAPI_ENTRY(ProgramEnvParameter4dARB)
+GLAPI_ENTRY(ProgramEnvParameter4dvARB)
+GLAPI_ENTRY(ProgramEnvParameter4fARB)
+GLAPI_ENTRY(ProgramEnvParameter4fvARB)
+GLAPI_ENTRY(ProgramLocalParameter4dARB)
+GLAPI_ENTRY(ProgramLocalParameter4dvARB)
+GLAPI_ENTRY(ProgramLocalParameter4fARB)
+GLAPI_ENTRY(ProgramLocalParameter4fvARB)
+GLAPI_ENTRY(ProgramStringARB)
+GLAPI_ENTRY(VertexAttrib1dARB)
+GLAPI_ENTRY(VertexAttrib1dvARB)
+GLAPI_ENTRY(VertexAttrib1fARB)
+GLAPI_ENTRY(VertexAttrib1fvARB)
+GLAPI_ENTRY(VertexAttrib1sARB)
+GLAPI_ENTRY(VertexAttrib1svARB)
+GLAPI_ENTRY(VertexAttrib2dARB)
+GLAPI_ENTRY(VertexAttrib2dvARB)
+GLAPI_ENTRY(VertexAttrib2fARB)
+GLAPI_ENTRY(VertexAttrib2fvARB)
+GLAPI_ENTRY(VertexAttrib2sARB)
+GLAPI_ENTRY(VertexAttrib2svARB)
+GLAPI_ENTRY(VertexAttrib3dARB)
+GLAPI_ENTRY(VertexAttrib3dvARB)
+GLAPI_ENTRY(VertexAttrib3fARB)
+GLAPI_ENTRY(VertexAttrib3fvARB)
+GLAPI_ENTRY(VertexAttrib3sARB)
+GLAPI_ENTRY(VertexAttrib3svARB)
+GLAPI_ENTRY(VertexAttrib4NbvARB)
+GLAPI_ENTRY(VertexAttrib4NivARB)
+GLAPI_ENTRY(VertexAttrib4NsvARB)
+GLAPI_ENTRY(VertexAttrib4NubARB)
+GLAPI_ENTRY(VertexAttrib4NubvARB)
+GLAPI_ENTRY(VertexAttrib4NuivARB)
+GLAPI_ENTRY(VertexAttrib4NusvARB)
+GLAPI_ENTRY(VertexAttrib4bvARB)
+GLAPI_ENTRY(VertexAttrib4dARB)
+GLAPI_ENTRY(VertexAttrib4dvARB)
+GLAPI_ENTRY(VertexAttrib4fARB)
+GLAPI_ENTRY(VertexAttrib4fvARB)
+GLAPI_ENTRY(VertexAttrib4ivARB)
+GLAPI_ENTRY(VertexAttrib4sARB)
+GLAPI_ENTRY(VertexAttrib4svARB)
+GLAPI_ENTRY(VertexAttrib4ubvARB)
+GLAPI_ENTRY(VertexAttrib4uivARB)
+GLAPI_ENTRY(VertexAttrib4usvARB)
+GLAPI_ENTRY(VertexAttribPointerARB)
+GLAPI_ENTRY(BindBufferARB)
+GLAPI_ENTRY(BufferDataARB)
+GLAPI_ENTRY(BufferSubDataARB)
+GLAPI_ENTRY(DeleteBuffersARB)
+GLAPI_ENTRY(GenBuffersARB)
+GLAPI_ENTRY(GetBufferParameterivARB)
+GLAPI_ENTRY(GetBufferPointervARB)
+GLAPI_ENTRY(GetBufferSubDataARB)
+GLAPI_ENTRY(IsBufferARB)
+GLAPI_ENTRY(MapBufferARB)
+GLAPI_ENTRY(UnmapBufferARB)
+GLAPI_ENTRY(BeginQueryARB)
+GLAPI_ENTRY(DeleteQueriesARB)
+GLAPI_ENTRY(EndQueryARB)
+GLAPI_ENTRY(GenQueriesARB)
+GLAPI_ENTRY(GetQueryObjectivARB)
+GLAPI_ENTRY(GetQueryObjectuivARB)
+GLAPI_ENTRY(GetQueryivARB)
+GLAPI_ENTRY(IsQueryARB)
+//GLAPI_ENTRY(AttachObjectARB)
+//GLAPI_ENTRY(CompileShaderARB)
+//GLAPI_ENTRY(CreateProgramObjectARB)
+//GLAPI_ENTRY(CreateShaderObjectARB)
+//GLAPI_ENTRY(DeleteObjectARB)
+//GLAPI_ENTRY(DetachObjectARB)
+//GLAPI_ENTRY(GetActiveUniformARB)
+//GLAPI_ENTRY(GetAttachedObjectsARB)
+//GLAPI_ENTRY(GetHandleARB)
+//GLAPI_ENTRY(GetInfoLogARB)
+//GLAPI_ENTRY(GetObjectParameterfvARB)
+//GLAPI_ENTRY(GetObjectParameterivARB)
+//GLAPI_ENTRY(GetShaderSourceARB)
+//GLAPI_ENTRY(GetUniformLocationARB)
+//GLAPI_ENTRY(GetUniformfvARB)
+//GLAPI_ENTRY(GetUniformivARB)
+//GLAPI_ENTRY(LinkProgramARB)
+//GLAPI_ENTRY(ShaderSourceARB)
+//GLAPI_ENTRY(Uniform1fARB)
+//GLAPI_ENTRY(Uniform1fvARB)
+//GLAPI_ENTRY(Uniform1iARB)
+//GLAPI_ENTRY(Uniform1ivARB)
+//GLAPI_ENTRY(Uniform2fARB)
+//GLAPI_ENTRY(Uniform2fvARB)
+//GLAPI_ENTRY(Uniform2iARB)
+//GLAPI_ENTRY(Uniform2ivARB)
+//GLAPI_ENTRY(Uniform3fARB)
+//GLAPI_ENTRY(Uniform3fvARB)
+//GLAPI_ENTRY(Uniform3iARB)
+//GLAPI_ENTRY(Uniform3ivARB)
+//GLAPI_ENTRY(Uniform4fARB)
+//GLAPI_ENTRY(Uniform4fvARB)
+//GLAPI_ENTRY(Uniform4iARB)
+//GLAPI_ENTRY(Uniform4ivARB)
+//GLAPI_ENTRY(UniformMatrix2fvARB)
+//GLAPI_ENTRY(UniformMatrix3fvARB)
+//GLAPI_ENTRY(UniformMatrix4fvARB)
+//GLAPI_ENTRY(UseProgramObjectARB)
+//GLAPI_ENTRY(ValidateProgramARB)
+//GLAPI_ENTRY(BindAttribLocationARB)
+//GLAPI_ENTRY(GetActiveAttribARB)
+//GLAPI_ENTRY(GetAttribLocationARB)
+//GLAPI_ENTRY(DrawBuffersARB)
+//GLAPI_ENTRY(PolygonOffsetEXT)
+//GLAPI_ENTRY(GetPixelTexGenParameterfvSGIS)
+//GLAPI_ENTRY(GetPixelTexGenParameterivSGIS)
+//GLAPI_ENTRY(PixelTexGenParameterfSGIS)
+//GLAPI_ENTRY(PixelTexGenParameterfvSGIS)
+//GLAPI_ENTRY(PixelTexGenParameteriSGIS)
+//GLAPI_ENTRY(PixelTexGenParameterivSGIS)
+GLAPI_ENTRY(PointParameterfEXT)
+GLAPI_ENTRY(PointParameterfvEXT)
+//GLAPI_ENTRY(LockArraysEXT)
+//GLAPI_ENTRY(UnlockArraysEXT)
+//GLAPI_ENTRY(CullParameterdvEXT)
+//GLAPI_ENTRY(CullParameterfvEXT)
+GLAPI_ENTRY(SecondaryColor3bEXT)
+GLAPI_ENTRY(SecondaryColor3bvEXT)
+GLAPI_ENTRY(SecondaryColor3dEXT)
+GLAPI_ENTRY(SecondaryColor3dvEXT)
+GLAPI_ENTRY(SecondaryColor3fEXT)
+GLAPI_ENTRY(SecondaryColor3fvEXT)
+GLAPI_ENTRY(SecondaryColor3iEXT)
+GLAPI_ENTRY(SecondaryColor3ivEXT)
+GLAPI_ENTRY(SecondaryColor3sEXT)
+GLAPI_ENTRY(SecondaryColor3svEXT)
+GLAPI_ENTRY(SecondaryColor3ubEXT)
+GLAPI_ENTRY(SecondaryColor3ubvEXT)
+GLAPI_ENTRY(SecondaryColor3uiEXT)
+GLAPI_ENTRY(SecondaryColor3uivEXT)
+GLAPI_ENTRY(SecondaryColor3usEXT)
+GLAPI_ENTRY(SecondaryColor3usvEXT)
+GLAPI_ENTRY(SecondaryColorPointerEXT)
+GLAPI_ENTRY(MultiDrawArraysEXT)
+GLAPI_ENTRY(MultiDrawElementsEXT)
+GLAPI_ENTRY(FogCoordPointerEXT)
+GLAPI_ENTRY(FogCoorddEXT)
+GLAPI_ENTRY(FogCoorddvEXT)
+GLAPI_ENTRY(FogCoordfEXT)
+GLAPI_ENTRY(FogCoordfvEXT)
+//GLAPI_ENTRY(PixelTexGenSGIX)
+GLAPI_ENTRY(BlendFuncSeparateEXT)
+GLAPI_ENTRY(FlushVertexArrayRangeNV)
+GLAPI_ENTRY(VertexArrayRangeNV)
+GLAPI_ENTRY(CombinerInputNV)
+GLAPI_ENTRY(CombinerOutputNV)
+GLAPI_ENTRY(CombinerParameterfNV)
+GLAPI_ENTRY(CombinerParameterfvNV)
+GLAPI_ENTRY(CombinerParameteriNV)
+GLAPI_ENTRY(CombinerParameterivNV)
+GLAPI_ENTRY(FinalCombinerInputNV)
+GLAPI_ENTRY(GetCombinerInputParameterfvNV)
+GLAPI_ENTRY(GetCombinerInputParameterivNV)
+GLAPI_ENTRY(GetCombinerOutputParameterfvNV)
+GLAPI_ENTRY(GetCombinerOutputParameterivNV)
+GLAPI_ENTRY(GetFinalCombinerInputParameterfvNV)
+GLAPI_ENTRY(GetFinalCombinerInputParameterivNV)
+GLAPI_ENTRY(DeleteFencesNV)
+GLAPI_ENTRY(FinishFenceNV)
+GLAPI_ENTRY(GenFencesNV)
+GLAPI_ENTRY(GetFenceivNV)
+GLAPI_ENTRY(IsFenceNV)
+GLAPI_ENTRY(SetFenceNV)
+GLAPI_ENTRY(TestFenceNV)
+GLAPI_ENTRY(AreProgramsResidentNV)
+GLAPI_ENTRY(BindProgramNV)
+GLAPI_ENTRY(DeleteProgramsNV)
+GLAPI_ENTRY(ExecuteProgramNV)
+GLAPI_ENTRY(GenProgramsNV)
+GLAPI_ENTRY(GetProgramParameterdvNV)
+GLAPI_ENTRY(GetProgramParameterfvNV)
+GLAPI_ENTRY(GetProgramStringNV)
+GLAPI_ENTRY(GetProgramivNV)
+GLAPI_ENTRY(GetTrackMatrixivNV)
+GLAPI_ENTRY(GetVertexAttribPointervNV)
+GLAPI_ENTRY(GetVertexAttribdvNV)
+GLAPI_ENTRY(GetVertexAttribfvNV)
+GLAPI_ENTRY(GetVertexAttribivNV)
+GLAPI_ENTRY(IsProgramNV)
+GLAPI_ENTRY(LoadProgramNV)
+GLAPI_ENTRY(ProgramParameters4dvNV)
+GLAPI_ENTRY(ProgramParameters4fvNV)
+GLAPI_ENTRY(RequestResidentProgramsNV)
+GLAPI_ENTRY(TrackMatrixNV)
+GLAPI_ENTRY(VertexAttrib1dNV)
+GLAPI_ENTRY(VertexAttrib1dvNV)
+GLAPI_ENTRY(VertexAttrib1fNV)
+GLAPI_ENTRY(VertexAttrib1fvNV)
+GLAPI_ENTRY(VertexAttrib1sNV)
+GLAPI_ENTRY(VertexAttrib1svNV)
+GLAPI_ENTRY(VertexAttrib2dNV)
+GLAPI_ENTRY(VertexAttrib2dvNV)
+GLAPI_ENTRY(VertexAttrib2fNV)
+GLAPI_ENTRY(VertexAttrib2fvNV)
+GLAPI_ENTRY(VertexAttrib2sNV)
+GLAPI_ENTRY(VertexAttrib2svNV)
+GLAPI_ENTRY(VertexAttrib3dNV)
+GLAPI_ENTRY(VertexAttrib3dvNV)
+GLAPI_ENTRY(VertexAttrib3fNV)
+GLAPI_ENTRY(VertexAttrib3fvNV)
+GLAPI_ENTRY(VertexAttrib3sNV)
+GLAPI_ENTRY(VertexAttrib3svNV)
+GLAPI_ENTRY(VertexAttrib4dNV)
+GLAPI_ENTRY(VertexAttrib4dvNV)
+GLAPI_ENTRY(VertexAttrib4fNV)
+GLAPI_ENTRY(VertexAttrib4fvNV)
+GLAPI_ENTRY(VertexAttrib4sNV)
+GLAPI_ENTRY(VertexAttrib4svNV)
+GLAPI_ENTRY(VertexAttrib4ubNV)
+GLAPI_ENTRY(VertexAttrib4ubvNV)
+GLAPI_ENTRY(VertexAttribPointerNV)
+GLAPI_ENTRY(VertexAttribs1dvNV)
+GLAPI_ENTRY(VertexAttribs1fvNV)
+GLAPI_ENTRY(VertexAttribs1svNV)
+GLAPI_ENTRY(VertexAttribs2dvNV)
+GLAPI_ENTRY(VertexAttribs2fvNV)
+GLAPI_ENTRY(VertexAttribs2svNV)
+GLAPI_ENTRY(VertexAttribs3dvNV)
+GLAPI_ENTRY(VertexAttribs3fvNV)
+GLAPI_ENTRY(VertexAttribs3svNV)
+GLAPI_ENTRY(VertexAttribs4dvNV)
+GLAPI_ENTRY(VertexAttribs4fvNV)
+GLAPI_ENTRY(VertexAttribs4svNV)
+GLAPI_ENTRY(VertexAttribs4ubvNV)
+GLAPI_ENTRY(PointParameteriNV)
+GLAPI_ENTRY(PointParameterivNV)
+GLAPI_ENTRY(GetProgramNamedParameterdvNV)
+GLAPI_ENTRY(GetProgramNamedParameterfvNV)
+GLAPI_ENTRY(ProgramNamedParameter4dNV)
+GLAPI_ENTRY(ProgramNamedParameter4dvNV)
+GLAPI_ENTRY(ProgramNamedParameter4fNV)
+GLAPI_ENTRY(ProgramNamedParameter4fvNV)
+
Index: trunk/src/VBox/Additions/common/crOpenGL/fakedri_glxfuncsList.h
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/fakedri_glxfuncsList.h	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/fakedri_glxfuncsList.h	(revision 18882)
@@ -0,0 +1,88 @@
+/* $Id$ */
+
+/** @file
+ * VBox OpenGL list of opengl functions common in Mesa and vbox opengl stub
+ */
+
+/*
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+ *
+ * Sun Microsystems, Inc. confidential
+ * All rights reserved
+ */
+
+#ifndef GLXAPI_ENTRY
+#error GLXAPI_ENTRY should be defined.
+#endif
+
+/*This should match glX* entries which are exported by Mesa's libGL.so,
+ * use something like the following to get the list:
+ * objdump -T libGL.so|grep glX|grep -v __|awk '{print $7;};'|sed 's/glX//'|awk '{OFS=""; print "GLXAPI_ENTRY(",$1,")"}'
+ */
+
+/* #######Note: if you change the list, don't forget to change Linux_i386_glxapi_exports.py####### */
+
+GLXAPI_ENTRY(CopyContext)
+GLXAPI_ENTRY(UseXFont)
+/*GLXAPI_ENTRY(GetDriverConfig)*/
+GLXAPI_ENTRY(GetProcAddress)
+GLXAPI_ENTRY(FreeMemoryMESA)
+GLXAPI_ENTRY(QueryExtension)
+GLXAPI_ENTRY(IsDirect)
+GLXAPI_ENTRY(DestroyGLXPbufferSGIX)
+GLXAPI_ENTRY(QueryGLXPbufferSGIX)
+GLXAPI_ENTRY(CreateGLXPixmap)
+GLXAPI_ENTRY(CreateGLXPixmapWithConfigSGIX)
+GLXAPI_ENTRY(QueryContext)
+GLXAPI_ENTRY(CreateContextWithConfigSGIX)
+GLXAPI_ENTRY(SwapBuffers)
+GLXAPI_ENTRY(CreateNewContext)
+GLXAPI_ENTRY(SelectEventSGIX)
+GLXAPI_ENTRY(QueryContextInfoEXT)
+GLXAPI_ENTRY(GetCurrentDrawable)
+GLXAPI_ENTRY(ChooseFBConfig)
+GLXAPI_ENTRY(WaitGL)
+GLXAPI_ENTRY(GetFBConfigs)
+GLXAPI_ENTRY(CreatePixmap)
+GLXAPI_ENTRY(GetSelectedEventSGIX)
+GLXAPI_ENTRY(GetCurrentReadDrawable)
+GLXAPI_ENTRY(ImportContextEXT)
+GLXAPI_ENTRY(GetContextIDEXT)
+GLXAPI_ENTRY(GetCurrentDisplay)
+GLXAPI_ENTRY(QueryServerString)
+GLXAPI_ENTRY(CreateWindow)
+GLXAPI_ENTRY(SelectEvent)
+GLXAPI_ENTRY(GetVisualFromFBConfigSGIX)
+GLXAPI_ENTRY(MakeCurrentReadSGI)
+GLXAPI_ENTRY(GetFBConfigFromVisualSGIX)
+GLXAPI_ENTRY(QueryDrawable)
+GLXAPI_ENTRY(CreateContext)
+GLXAPI_ENTRY(GetConfig)
+GLXAPI_ENTRY(CreateGLXPbufferSGIX)
+GLXAPI_ENTRY(AllocateMemoryMESA)
+GLXAPI_ENTRY(GetMemoryOffsetMESA)
+GLXAPI_ENTRY(CreatePbuffer)
+GLXAPI_ENTRY(ChooseFBConfigSGIX)
+GLXAPI_ENTRY(WaitX)
+GLXAPI_ENTRY(GetVisualFromFBConfig)
+GLXAPI_ENTRY(CreateGLXPixmapMESA)
+/*GLXAPI_ENTRY(GetScreenDriver)*/
+GLXAPI_ENTRY(GetFBConfigAttrib)
+GLXAPI_ENTRY(GetCurrentContext)
+GLXAPI_ENTRY(GetClientString)
+GLXAPI_ENTRY(GetCurrentDisplayEXT)
+GLXAPI_ENTRY(DestroyPixmap)
+GLXAPI_ENTRY(MakeCurrent)
+GLXAPI_ENTRY(DestroyContext)
+GLXAPI_ENTRY(GetProcAddressARB)
+GLXAPI_ENTRY(GetSelectedEvent)
+GLXAPI_ENTRY(FreeContextEXT)
+GLXAPI_ENTRY(DestroyPbuffer)
+GLXAPI_ENTRY(DestroyWindow)
+GLXAPI_ENTRY(DestroyGLXPixmap)
+GLXAPI_ENTRY(QueryVersion)
+GLXAPI_ENTRY(ChooseVisual)
+GLXAPI_ENTRY(MakeContextCurrent)
+GLXAPI_ENTRY(QueryExtensionsString)
+GLXAPI_ENTRY(GetFBConfigAttribSGIX)
+
Index: trunk/src/VBox/Additions/common/crOpenGL/glx.c
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/glx.c	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/glx.c	(revision 18882)
@@ -0,0 +1,2379 @@
+/* Copyright (c) 2001, Stanford University
+ * All rights reserved
+ *
+ * See the file LICENSE.txt for information on redistributing this software.
+ */
+
+/* opengl_stub/glx.c */
+#include "chromium.h"
+#include "cr_error.h"
+#include "cr_spu.h"
+#include "cr_mem.h"
+#include "cr_string.h"
+#include "stub.h"
+#include "dri_glx.h"
+
+#include <X11/Xregion.h>
+
+//#define VBOX_NO_NATIVEGL
+
+/* Force full pixmap update if there're more damaged regions than this number*/
+#define CR_MAX_DAMAGE_REGIONS_TRACKED 50
+
+/* Force "bigger" update (full or clip) if it's reducing number of regions updated 
+ * but doesn't increase updated area more than given number
+ */
+#define CR_MIN_DAMAGE_PROFIT_SIZE 64*64
+
+/*@todo combine it in some other place*/
+/* Size of pack spu buffer - some delta for commands packing, see pack/packspu_config.c*/
+
+/** Ramshankar: Solaris compiz fix */
+#ifdef RT_OS_SOLARIS
+# define CR_MAX_TRANSFER_SIZE 20*1024*1024
+#else
+# define CR_MAX_TRANSFER_SIZE 4*1024*1024
+#endif
+
+/** For optimizing glXMakeCurrent */
+static Display *currentDisplay = NULL;
+static GLXDrawable currentDrawable = 0;
+static GLXDrawable currentReadDrawable = 0;
+
+/**
+ * Keep a list of structures which associates X visual IDs with
+ * Chromium visual bitmasks.
+ */
+struct VisualInfo {
+    Display *dpy;
+    int screen;
+    VisualID visualid;
+    int visBits;
+    struct VisualInfo *next;
+};
+
+static struct VisualInfo *VisualInfoList = NULL;
+
+static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect);
+
+static void
+AddVisualInfo(Display *dpy, int screen, VisualID visualid, int visBits)
+{
+    struct VisualInfo *v;
+    for (v = VisualInfoList; v; v = v->next) {
+        if (v->dpy == dpy && v->screen == screen && v->visualid == visualid) {
+            v->visBits |= visBits;
+            return;
+        }
+    }
+    v = (struct VisualInfo *) crAlloc(sizeof(struct VisualInfo));
+    v->dpy = dpy;
+    v->screen = screen;
+    v->visualid = visualid;
+    v->visBits = visBits;
+    v->next = VisualInfoList;
+    VisualInfoList = v;
+}
+
+static struct VisualInfo *
+FindVisualInfo(Display *dpy, int screen, VisualID visualid)
+{
+    struct VisualInfo *v;
+    for (v = VisualInfoList; v; v = v->next) {
+        if (v->dpy == dpy && v->screen == screen && v->visualid == visualid)
+            return v;
+    }
+    return NULL;
+}
+
+/**
+ * Return string for a GLX error code
+ */
+static const char *glx_error_string(int err)
+{
+    static const char *glxErrors[] = {
+        "none",
+        "GLX_BAD_SCREEN",
+        "GLX_BAD_ATTRIBUTE",
+        "GLX_NO_EXTENSION",
+        "GLX_BAD_VISUAL",
+        "GLX_BAD_CONTEXT",
+        "GLX_BAD_VALUE",
+        "GLX_BAD_ENUM"
+    };
+    if (err > 0 && err < 8) {
+        return glxErrors[err];
+    }
+    else {
+        static char tmp[100];
+        sprintf(tmp, "0x%x", err);
+        return tmp;
+    }
+}
+
+/* Given an XVisualInfo structure, try to figure out what its 
+ * OpenGL capabilities are, if we have a native OpenGL.
+ * Returns 0 if no information is available.
+ */
+static struct {
+    int gl_attrib;
+    char *attrib_name;
+    enum {TEST_TRUE, TEST_GREATER_0} test;
+    int match_vis_bits;
+} attrib_map[] = {
+    {GLX_RGBA, "GLX_RGBA", TEST_TRUE, CR_RGB_BIT},
+    {GLX_DOUBLEBUFFER, "GLX_DOUBLEBUFFER", TEST_TRUE, CR_DOUBLE_BIT},
+    {GLX_STEREO, "GLX_STEREO", TEST_TRUE, CR_STEREO_BIT},
+    {GLX_LEVEL, "GLX_LEVEL", TEST_GREATER_0, CR_OVERLAY_BIT},
+    {GLX_ALPHA_SIZE, "GLX_ALPHA_SIZE", TEST_GREATER_0, CR_ALPHA_BIT},
+    {GLX_DEPTH_SIZE, "GLX_DEPTH_SIZE", TEST_GREATER_0, CR_DEPTH_BIT},
+    {GLX_STENCIL_SIZE, "GLX_STENCIL_SIZE", TEST_GREATER_0, CR_STENCIL_BIT},
+    {GLX_ACCUM_RED_SIZE, "GLX_ACCUM_RED_SIZE", TEST_GREATER_0, CR_ACCUM_BIT},
+    {GLX_SAMPLE_BUFFERS_SGIS, "GLX_SAMPLE_BUFFERS_SGIS", TEST_GREATER_0, CR_MULTISAMPLE_BIT},
+};
+#ifndef VBOX_NO_NATIVEGL  /* Currently not used */
+static int QueryVisBits(Display *dpy, XVisualInfo *vis)
+{
+    int visBits = 0;
+    int foo, bar, return_val, value;
+    unsigned int i;
+
+    /* We can only query the OpenGL capabilities if we actually
+     * have a native OpenGL underneath us.  Without it, we can't
+     * get at all the actual OpenGL characteristics.
+     */
+    if (!stub.haveNativeOpenGL) return 0;
+
+    if (!stub.wsInterface.glXQueryExtension(dpy, &foo, &bar)) return 0;
+
+    /* If we don't have the GLX_USE_GL attribute, we've failed. */
+    return_val = stub.wsInterface.glXGetConfig(dpy, vis, GLX_USE_GL, &value);
+    if (return_val) {
+        crDebug("native glXGetConfig returned %d (%s) at %s line %d",
+            return_val, glx_error_string(return_val), __FILE__, __LINE__);
+        return 0;
+    }
+    if (value == 0) {
+        crDebug("visual ID 0x%x doesn't support OpenGL at %s line %d",
+            (int) vis->visual->visualid, __FILE__, __LINE__);
+        return 0;
+    }
+
+    for (i = 0; i < sizeof(attrib_map)/sizeof(attrib_map[0]); i++) {
+        return_val = stub.wsInterface.glXGetConfig(dpy, vis, attrib_map[i].gl_attrib, &value);
+        if (return_val) {
+            crDebug("native glXGetConfig(%s) returned %d (%s) at %s line %d",
+                attrib_map[i].attrib_name, return_val, glx_error_string(return_val), __FILE__, __LINE__);
+            return 0;
+        }
+
+        switch(attrib_map[i].test) {
+            case TEST_TRUE:
+                if (value)
+                    visBits |= attrib_map[i].match_vis_bits;
+                break;
+
+            case TEST_GREATER_0:
+                if (value > 0)
+                    visBits |= attrib_map[i].match_vis_bits;
+                break;
+
+            default:
+                crWarning("illegal attribute map test for %s at %s line %d", 
+                    attrib_map[i].attrib_name, __FILE__, __LINE__);
+                return 0;
+        }
+    }
+
+    return visBits;
+}
+#endif /* not 0 */
+
+
+
+#ifndef VBOX_NO_NATIVEGL /* Old code */
+DECLEXPORT(XVisualInfo *)
+VBOXGLXTAG(glXChooseVisual)( Display *dpy, int screen, int *attribList )
+{
+    XVisualInfo *vis;
+    int *attrib;
+    int visBits = 0;
+
+    stubInit();
+
+    for (attrib = attribList; *attrib != None; attrib++)
+    {
+        switch (*attrib)
+        {
+            case GLX_USE_GL:
+                /* ignored, this is mandatory */
+                break;
+
+            case GLX_BUFFER_SIZE:
+                /* this is for color-index visuals, which we don't support */
+                attrib++;
+                break;
+
+            case GLX_LEVEL:
+                if (attrib[1] > 0)
+                    visBits |= CR_OVERLAY_BIT;
+                attrib++;
+                break;
+
+            case GLX_RGBA:
+                visBits |= CR_RGB_BIT;
+                break;
+
+            case GLX_DOUBLEBUFFER:
+                visBits |= CR_DOUBLE_BIT;
+                break;
+
+            case GLX_STEREO:
+                visBits |= CR_STEREO_BIT;
+                /*
+                crWarning( "glXChooseVisual: stereo unsupported" );
+                return NULL;
+                */
+                break;
+
+            case GLX_AUX_BUFFERS:
+                {
+                    int aux_buffers = attrib[1];
+                    if (aux_buffers != 0)
+                    {
+                        crWarning("glXChooseVisual: aux_buffers=%d unsupported",
+                                            aux_buffers);
+                        return NULL;
+                    }
+                }
+                attrib++;
+                break;
+
+            case GLX_RED_SIZE:
+            case GLX_GREEN_SIZE:
+            case GLX_BLUE_SIZE:
+                if (attrib[1] > 0)
+                    visBits |= CR_RGB_BIT;
+                attrib++;
+                break;
+
+            case GLX_ALPHA_SIZE:
+                if (attrib[1] > 0)
+                    visBits |= CR_ALPHA_BIT;
+                attrib++;
+                break;
+
+            case GLX_DEPTH_SIZE:
+                if (attrib[1] > 0)
+                    visBits |= CR_DEPTH_BIT;
+                attrib++;
+                break;
+
+            case GLX_STENCIL_SIZE:
+                if (attrib[1] > 0)
+                    visBits |= CR_STENCIL_BIT;
+                attrib++;
+                break;
+
+            case GLX_ACCUM_RED_SIZE:
+            case GLX_ACCUM_GREEN_SIZE:
+            case GLX_ACCUM_BLUE_SIZE:
+            case GLX_ACCUM_ALPHA_SIZE:
+                if (attrib[1] > 0)
+                    visBits |= CR_ACCUM_BIT;
+                attrib++;
+                break;
+
+            case GLX_SAMPLE_BUFFERS_SGIS: /* aka GLX_SAMPLES_ARB */
+                if (attrib[1] > 0)
+                    visBits |= CR_MULTISAMPLE_BIT;
+                attrib++;
+                break;
+            case GLX_SAMPLES_SGIS: /* aka GLX_SAMPLES_ARB */
+                /* just ignore value for now, we'll try to get 4 samples/pixel */
+                if (attrib[1] > 4)
+                    return NULL;
+                visBits |= CR_MULTISAMPLE_BIT;
+                attrib++;
+                break;
+
+#ifdef GLX_VERSION_1_3
+            case GLX_X_VISUAL_TYPE:
+            case GLX_TRANSPARENT_TYPE_EXT:
+            case GLX_TRANSPARENT_INDEX_VALUE_EXT:
+            case GLX_TRANSPARENT_RED_VALUE_EXT:
+            case GLX_TRANSPARENT_GREEN_VALUE_EXT:
+            case GLX_TRANSPARENT_BLUE_VALUE_EXT:
+            case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
+                /* ignore */
+                crWarning("glXChooseVisual: ignoring attribute 0x%x", *attrib);
+                attrib++;
+                break;
+#endif
+
+            default:
+                crWarning( "glXChooseVisual: bad attrib=0x%x", *attrib );
+                return NULL;
+        }
+    }
+
+    if ((visBits & CR_RGB_BIT) == 0 && (visBits & CR_OVERLAY_BIT) == 0)
+    {
+        /* normal layer, color index mode not supported */
+        crWarning( "glXChooseVisual: didn't request RGB visual?" );
+        return NULL;
+    }
+
+    vis = crChooseVisual(&stub.wsInterface, dpy, screen, GL_FALSE, visBits);
+    if (!vis && (visBits & CR_STEREO_BIT)) {
+        /* try non-stereo */
+        visBits &= ~CR_STEREO_BIT;
+        vis = crChooseVisual(&stub.wsInterface, dpy, screen, GL_FALSE, visBits);
+    }
+
+    if (vis) {
+        AddVisualInfo(dpy, screen, vis->visual->visualid, visBits);
+    }
+    return vis;
+}
+#else  /* not 0 */
+DECLEXPORT(XVisualInfo *)
+VBOXGLXTAG(glXChooseVisual)( Display *dpy, int screen, int *attribList )
+{
+    bool useRGBA = false;
+    int *attrib;
+    XVisualInfo searchvis, *pret;
+    int nvisuals;
+    stubInit();
+
+    for (attrib = attribList; *attrib != None; attrib++)
+    {
+        switch (*attrib)
+        {
+            case GLX_USE_GL:
+                /* ignored, this is mandatory */
+                break;
+
+            case GLX_BUFFER_SIZE:
+                /* this is for color-index visuals, which we don't support */
+                attrib++;
+                break;
+
+            case GLX_LEVEL:
+                if (attrib[1] != 0)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_RGBA:
+                useRGBA = true;
+                break;
+
+            case GLX_STEREO:
+                goto err_exit;
+                /*
+                crWarning( "glXChooseVisual: stereo unsupported" );
+                return NULL;
+                */
+                break;
+
+            case GLX_AUX_BUFFERS:
+                if (attrib[1] != 0)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_RED_SIZE:
+            case GLX_GREEN_SIZE:
+            case GLX_BLUE_SIZE:
+                if (attrib[1] > 8)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_ALPHA_SIZE:
+                if (attrib[1] > 8)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_DEPTH_SIZE:
+                if (attrib[1] > 16)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_STENCIL_SIZE:
+                if (attrib[1] > 8)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_ACCUM_RED_SIZE:
+            case GLX_ACCUM_GREEN_SIZE:
+            case GLX_ACCUM_BLUE_SIZE:
+            case GLX_ACCUM_ALPHA_SIZE:
+                if (attrib[1] > 16)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_SAMPLE_BUFFERS_SGIS: /* aka GLX_SAMPLES_ARB */
+                if (attrib[1] > 0)
+                    goto err_exit;
+                attrib++;
+                break;
+            case GLX_SAMPLES_SGIS: /* aka GLX_SAMPLES_ARB */
+                if (attrib[1] > 0)
+                    goto err_exit;
+                attrib++;
+                break;
+
+            case GLX_DOUBLEBUFFER: /* @todo, check if we support it */
+                break;
+
+#ifdef GLX_VERSION_1_3
+            case GLX_X_VISUAL_TYPE:
+            case GLX_TRANSPARENT_TYPE_EXT:
+            case GLX_TRANSPARENT_INDEX_VALUE_EXT:
+            case GLX_TRANSPARENT_RED_VALUE_EXT:
+            case GLX_TRANSPARENT_GREEN_VALUE_EXT:
+            case GLX_TRANSPARENT_BLUE_VALUE_EXT:
+            case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
+                /* ignore */
+                crWarning("glXChooseVisual: ignoring attribute 0x%x", *attrib);
+                attrib++;
+                break;
+#endif
+
+            default:
+                crWarning( "glXChooseVisual: bad attrib=0x%x, ignoring", *attrib );
+                attrib++;
+                //return NULL;
+        }
+    }
+
+    if (!useRGBA)
+        return NULL;
+
+    searchvis.visualid = XVisualIDFromVisual(DefaultVisual(dpy, screen));
+    pret = XGetVisualInfo(dpy, VisualIDMask, &searchvis, &nvisuals);
+      
+    if (nvisuals!=1) crWarning("glXChooseVisual: XGetVisualInfo returned %i visuals for %x", nvisuals, (unsigned int) searchvis.visualid);
+    if (pret)
+      crDebug("glXChooseVisual returned %x depth=%i", (unsigned int)pret->visualid, pret->depth);
+    return pret;
+
+err_exit:
+    crDebug("glXChooseVisual returning NULL, due to attrib=0x%x, next=0x%x", attrib[0], attrib[1]);
+    return NULL;
+}
+#endif
+
+/**
+ **  There is a problem with glXCopyContext.
+ ** IRIX and Mesa both define glXCopyContext
+ ** to have the mask argument being a 
+ ** GLuint.  XFree 4 and oss.sgi.com
+ ** define it to be an unsigned long.
+ ** Solution: We don't support
+ ** glXCopyContext anyway so we'll just
+ ** #ifdef out the code.
+ */
+DECLEXPORT(void)
+VBOXGLXTAG(glXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, 
+#if defined(AIX) || defined(PLAYSTATION2)
+GLuint mask )
+#elif defined(SunOS)
+unsigned long mask )
+#else
+unsigned long mask )
+#endif
+{
+    (void) dpy;
+    (void) src;
+    (void) dst;
+    (void) mask;
+    crWarning( "Unsupported GLX Call: glXCopyContext()" );
+}
+
+
+/**
+ * Get the display string for the given display pointer.
+ * Never return just ":0.0".  In that case, prefix with our host name.
+ */
+static void
+stubGetDisplayString( Display *dpy, char *nameResult, int maxResult )
+{
+    const char *dpyName = DisplayString(dpy);
+    char host[1000];
+#ifndef VBOX_NO_NATIVEGL
+    if (dpyName[0] == ':')
+    {
+        crGetHostname(host, 1000);
+    }
+    else
+#endif
+    {
+      host[0] = 0;
+    }
+    if (crStrlen(host) + crStrlen(dpyName) >= maxResult - 1)
+    {
+        /* return null string */
+        crWarning("Very long host / display name string in stubDisplayString!");
+        nameResult[0] = 0;
+    }
+    else
+    {
+        /* return host concatenated with dpyName */
+        crStrcpy(nameResult, host);
+        crStrcat(nameResult, dpyName);
+    }
+}
+
+
+
+DECLEXPORT(GLXContext)
+VBOXGLXTAG(glXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext share, Bool direct)
+{
+    char dpyName[MAX_DPY_NAME];
+    ContextInfo *context;
+    int visBits = CR_RGB_BIT | CR_DOUBLE_BIT | CR_DEPTH_BIT; /* default vis */
+    int i, numExt;
+
+    stubInit();
+
+    CRASSERT(stub.contextTable);
+
+    /*
+    {
+        char **list;
+
+        list = XListExtensions(dpy, &numExt);
+        crDebug("X extensions [%i]:", numExt);
+        for (i=0; i<numExt; ++i)
+        {
+            crDebug("%s", list[i]);
+        }
+        XFreeExtensionList(list);
+    }
+    */
+
+    stubGetDisplayString(dpy, dpyName, MAX_DPY_NAME);
+#ifndef VBOX_NO_NATIVEGL  /* We only care about the host capabilities, not the guest. */
+    if (stub.haveNativeOpenGL) {
+        int foo, bar;
+        if (stub.wsInterface.glXQueryExtension(dpy, &foo, &bar)) {
+            /* If we have real GLX, compute the Chromium visual bitmask now.
+             * otherwise, we'll use the default desiredVisual bitmask.
+             */
+            struct VisualInfo *v = FindVisualInfo(dpy, DefaultScreen(dpy),
+                                                  vis->visual->visualid);
+            if (v) {
+                visBits = v->visBits;
+                /*crDebug("%s visBits=0x%x", __FUNCTION__, visBits);*/
+            }
+            else {
+                /* For some reason, we haven't tested this visual
+                 * before.  This could be because the visual was found 
+                 * through a different display connection to the same
+                 * display (as happens in GeoProbe), or through a
+                 * connection to an external daemon that queries
+                 * visuals.  If we can query it directly, we can still
+                 * find the proper visBits.
+                 */
+                int newVisBits = QueryVisBits(dpy, vis);
+                if (newVisBits > 0) {
+                    AddVisualInfo(dpy, DefaultScreen(dpy), vis->visual->visualid, newVisBits);
+                    crDebug("Application used unexpected but queryable visual id 0x%x", (int) vis->visual->visualid);
+                    visBits = newVisBits;
+                }
+                else {
+                    crWarning("Application used unexpected and unqueryable visual id 0x%x; using default visbits", (int) vis->visual->visualid);
+                }
+            }
+
+            /*crDebug("ComputeVisBits(0x%x) = 0x%x", (int)vis->visual->visualid, visBits);*/
+            if (stub.force_pbuffers) {
+                crDebug("App faker: Forcing use of Pbuffers");
+                visBits |= CR_PBUFFER_BIT;
+            }
+
+            if (!v) {
+                 AddVisualInfo(dpy, DefaultScreen(dpy),
+                               vis->visual->visualid, visBits);
+            }
+
+        }
+    }
+    else {
+        crDebug("No native OpenGL; cannot compute visbits");
+    }
+#endif
+
+    context = stubNewContext(dpyName, visBits, UNDECIDED, (unsigned long) share);
+    if (!context)
+        return 0;
+
+    context->dpy = dpy;
+    context->visual = vis;
+    context->direct = direct;
+
+    return (GLXContext) context->id;
+}
+
+
+DECLEXPORT(void) VBOXGLXTAG(glXDestroyContext)( Display *dpy, GLXContext ctx )
+{
+    (void) dpy;
+    stubDestroyContext( (unsigned long) ctx );
+}
+
+
+DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx )
+{
+    ContextInfo *context;
+    WindowInfo *window;
+    Bool retVal;
+
+    /*crDebug("glXMakeCurrent(%p, 0x%x, 0x%x)", (void *) dpy, (int) drawable, (int) ctx);*/
+
+    if (ctx && drawable) {
+        context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) ctx);
+        window = stubGetWindowInfo(dpy, drawable);
+
+        if (context && context->type == UNDECIDED) {
+            XSync(dpy, 0); /* sync to force window creation on the server */
+        }
+    }
+    else {
+        dpy = NULL;
+        window = NULL;
+        context = NULL;
+    }
+
+    currentDisplay = dpy;
+    currentDrawable = drawable;
+
+    retVal = stubMakeCurrent(window, context);
+    return retVal;
+}
+
+
+DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmap)( Display *dpy, XVisualInfo *vis, Pixmap pixmap )
+{
+    (void) dpy;
+    (void) vis;
+    (void) pixmap;
+
+    stubInit();
+    crWarning( "Unsupported GLX Call: glXCreateGLXPixmap()" );
+    return (GLXPixmap) 0;
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXDestroyGLXPixmap)( Display *dpy, GLXPixmap pix )
+{
+    VBOXGLXTAG(glXDestroyPixmap)(dpy, pix);
+}
+
+#ifndef VBOX_NO_NATIVEGL  /* old code */
+DECLEXPORT(int) VBOXGLXTAG(glXGetConfig)( Display *dpy, XVisualInfo *vis, int attrib, int *value )
+{
+    struct VisualInfo *v;
+    int visBits;
+
+    if (!vis) {
+        /* SGI OpenGL Performer hits this */
+        crWarning("glXGetConfig called with NULL XVisualInfo");
+        return GLX_BAD_VISUAL;
+    }
+
+    v = FindVisualInfo(dpy, DefaultScreen(dpy), vis->visual->visualid);
+    if (v) {
+        visBits = v->visBits;
+    }
+    else {
+        visBits = 0;
+    }
+
+    stubInit();
+
+    /* try to satisfy this request with the native glXGetConfig() */
+    if (stub.haveNativeOpenGL)
+    {
+        int foo, bar;
+        int return_val;
+
+        if (stub.wsInterface.glXQueryExtension(dpy, &foo, &bar))
+        {
+            return_val = stub.wsInterface.glXGetConfig( dpy, vis, attrib, value );
+            if (return_val)
+            {
+                crDebug("faker native glXGetConfig returned %s",
+                                glx_error_string(return_val));
+            }
+            return return_val;
+        }
+    }
+
+    /*
+     * If the GLX application chooses its visual via a bunch of calls to
+     * glXGetConfig, instead of by calling glXChooseVisual, we need to keep
+     * track of which attributes are queried to help satisfy context creation
+     * later.
+     */
+    switch ( attrib ) {
+
+        case GLX_USE_GL:
+            *value = 1;
+            break;
+
+        case GLX_BUFFER_SIZE:
+            *value = 32;
+            break;
+
+        case GLX_LEVEL:
+            visBits |= CR_OVERLAY_BIT;
+            *value = (visBits & CR_OVERLAY_BIT) ? 1 : 0;
+            break;
+
+        case GLX_RGBA:
+            visBits |= CR_RGB_BIT;
+            *value = 1;
+            break;
+
+        case GLX_DOUBLEBUFFER:
+            *value = 1;
+            break;
+
+        case GLX_STEREO:
+            *value = 1;
+            break;
+
+        case GLX_AUX_BUFFERS:
+            *value = 0;
+            break;
+
+        case GLX_RED_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_GREEN_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_BLUE_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_ALPHA_SIZE:
+            visBits |= CR_ALPHA_BIT;
+            *value = (visBits & CR_ALPHA_BIT) ? 8 : 0;
+            break;
+
+        case GLX_DEPTH_SIZE:
+            visBits |= CR_DEPTH_BIT;
+            *value = 16;
+            break;
+
+        case GLX_STENCIL_SIZE:
+            visBits |= CR_STENCIL_BIT;
+            *value = 8;
+            break;
+
+        case GLX_ACCUM_RED_SIZE:
+            visBits |= CR_ACCUM_BIT;
+            *value = 16;
+            break;
+
+        case GLX_ACCUM_GREEN_SIZE:
+            visBits |= CR_ACCUM_BIT;
+            *value = 16;
+            break;
+
+        case GLX_ACCUM_BLUE_SIZE:
+            visBits |= CR_ACCUM_BIT;
+            *value = 16;
+            break;
+
+        case GLX_ACCUM_ALPHA_SIZE:
+            visBits |= CR_ACCUM_BIT;
+            *value = 16;
+            break;
+
+        case GLX_SAMPLE_BUFFERS_SGIS:
+            visBits |= CR_MULTISAMPLE_BIT;
+            *value = 0;  /* fix someday */
+            break;
+
+        case GLX_SAMPLES_SGIS:
+            visBits |= CR_MULTISAMPLE_BIT;
+            *value = 0;  /* fix someday */
+            break;
+
+        case GLX_VISUAL_CAVEAT_EXT:
+            *value = GLX_NONE_EXT;
+            break;
+#if  defined(SunOS)
+        /*
+          I don't think this is even a valid attribute for glxGetConfig. 
+          No idea why this gets called under SunOS but we simply ignore it
+          -- jw
+        */
+        case GLX_X_VISUAL_TYPE:
+          crWarning ("Ignoring Unsuported GLX Call: glxGetConfig with attrib 0x%x", attrib);
+          break;
+#endif 
+
+        case GLX_TRANSPARENT_TYPE:
+            *value = GLX_NONE_EXT;
+            break;
+        case GLX_TRANSPARENT_INDEX_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_RED_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_GREEN_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_BLUE_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_ALPHA_VALUE:
+            *value = 0;
+            break;
+        default:
+            crWarning( "Unsupported GLX Call: glXGetConfig with attrib 0x%x", attrib );
+            return GLX_BAD_ATTRIBUTE;
+    }
+
+    AddVisualInfo(dpy, DefaultScreen(dpy), vis->visual->visualid, visBits);
+
+    return 0;
+}
+#else  /* not 0 */
+DECLEXPORT(int) VBOXGLXTAG(glXGetConfig)( Display *dpy, XVisualInfo *vis, int attrib, int *value )
+{
+    if (!vis) {
+        /* SGI OpenGL Performer hits this */
+        crWarning("glXGetConfig called with NULL XVisualInfo");
+        return GLX_BAD_VISUAL;
+    }
+
+    stubInit();
+
+    *value = 0;  /* For sanity */
+
+    switch ( attrib ) {
+
+        case GLX_USE_GL:
+            *value = 1;
+            break;
+
+        case GLX_BUFFER_SIZE:
+            *value = 32;
+            break;
+
+        case GLX_LEVEL:
+            *value = 0;  /* for now */
+            break;
+
+        case GLX_RGBA:
+            *value = 1;
+            break;
+
+        case GLX_DOUBLEBUFFER:
+            *value = 1;
+            break;
+
+        case GLX_STEREO:
+            *value = 1;
+            break;
+
+        case GLX_AUX_BUFFERS:
+            *value = 0;
+            break;
+
+        case GLX_RED_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_GREEN_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_BLUE_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_ALPHA_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_DEPTH_SIZE:
+            *value = 16;
+            break;
+
+        case GLX_STENCIL_SIZE:
+            *value = 8;
+            break;
+
+        case GLX_ACCUM_RED_SIZE:
+            *value = 16;
+            break;
+
+        case GLX_ACCUM_GREEN_SIZE:
+            *value = 16;
+            break;
+
+        case GLX_ACCUM_BLUE_SIZE:
+            *value = 16;
+            break;
+
+        case GLX_ACCUM_ALPHA_SIZE:
+            *value = 16;
+            break;
+
+        case GLX_SAMPLE_BUFFERS_SGIS:
+            *value = 0;  /* fix someday */
+            break;
+
+        case GLX_SAMPLES_SGIS:
+            *value = 0;  /* fix someday */
+            break;
+
+        case GLX_VISUAL_CAVEAT_EXT:
+            *value = GLX_NONE_EXT;
+            break;
+#if defined(SunOS) || 1
+        /*
+          I don't think this is even a valid attribute for glxGetConfig. 
+          No idea why this gets called under SunOS but we simply ignore it
+          -- jw
+        */
+        case GLX_X_VISUAL_TYPE:
+          crWarning ("Ignoring Unsuported GLX Call: glxGetConfig with attrib 0x%x", attrib);
+          break;
+#endif 
+
+        case GLX_TRANSPARENT_TYPE:
+            *value = GLX_NONE_EXT;
+            break;
+        case GLX_TRANSPARENT_INDEX_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_RED_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_GREEN_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_BLUE_VALUE:
+            *value = 0;
+            break;
+        case GLX_TRANSPARENT_ALPHA_VALUE:
+            *value = 0;
+            break;
+        default:
+            crWarning( "Unsupported GLX Call: glXGetConfig with attrib 0x%x, ignoring...", attrib );
+            //return GLX_BAD_ATTRIBUTE;
+            *value = 0;
+    }
+
+    return 0;
+}
+#endif
+
+DECLEXPORT(GLXContext) VBOXGLXTAG(glXGetCurrentContext)( void )
+{
+    if (stub.currentContext)
+        return (GLXContext) stub.currentContext->id;
+    else
+        return (GLXContext) NULL;
+}
+
+DECLEXPORT(GLXDrawable) VBOXGLXTAG(glXGetCurrentDrawable)(void)
+{
+    return currentDrawable;
+}
+
+DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplay)(void)
+{
+    return currentDisplay;
+}
+
+DECLEXPORT(Bool) VBOXGLXTAG(glXIsDirect)(Display *dpy, GLXContext ctx)
+{
+    (void) dpy;
+    (void) ctx;
+    crDebug("->glXIsDirect");
+    return True;
+}
+
+DECLEXPORT(Bool) VBOXGLXTAG(glXQueryExtension)(Display *dpy, int *errorBase, int *eventBase)
+{
+    (void) dpy;
+    (void) errorBase;
+    (void) eventBase;
+    return 1; /* You BET we do... */
+}
+
+DECLEXPORT(Bool) VBOXGLXTAG(glXQueryVersion)( Display *dpy, int *major, int *minor )
+{
+    (void) dpy;
+    *major = 1;
+    *minor = 3;
+    return 1;
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXSwapBuffers)( Display *dpy, GLXDrawable drawable )
+{
+    const WindowInfo *window = stubGetWindowInfo(dpy, drawable);
+    stubSwapBuffers( window, 0 );
+}
+
+#ifndef VBOX_NO_NATIVEGL
+DECLEXPORT(void) VBOXGLXTAG(glXUseXFont)( Font font, int first, int count, int listBase )
+{
+    if (stub.currentContext->type == CHROMIUM)
+    {
+        Display *dpy = stub.wsInterface.glXGetCurrentDisplay();
+        if (dpy) {
+            stubUseXFont( dpy, font, first, count, listBase );
+        }
+        else {
+            dpy = XOpenDisplay(NULL);
+            if (!dpy)
+                return;
+            stubUseXFont( dpy, font, first, count, listBase );
+            XCloseDisplay(dpy);
+        }
+    } else
+        stub.wsInterface.glXUseXFont( font, first, count, listBase );
+}
+#else /* not 0 */
+DECLEXPORT(void) VBOXGLXTAG(glXUseXFont)( Font font, int first, int count, int listBase )
+{
+    Display *dpy = stub.currentContext->dpy;
+    if (dpy) {
+        stubUseXFont( dpy, font, first, count, listBase );
+    }
+    else {
+        dpy = XOpenDisplay(NULL);
+        if (!dpy)
+            return;
+        stubUseXFont( dpy, font, first, count, listBase );
+        XCloseDisplay(dpy);
+    }
+}
+#endif
+
+DECLEXPORT(void) VBOXGLXTAG(glXWaitGL)( void )
+{
+    static int first_call = 1;
+
+    if ( first_call )
+    {
+        crDebug( "Ignoring unsupported GLX call: glXWaitGL()" );
+        first_call = 0;
+    }
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXWaitX)( void )
+{
+    static int first_call = 1;
+
+    if ( first_call )
+    {
+        crDebug( "Ignoring unsupported GLX call: glXWaitX()" );
+        first_call = 0;
+    }
+}
+
+DECLEXPORT(const char *) VBOXGLXTAG(glXQueryExtensionsString)( Display *dpy, int screen )
+{
+    /* XXX maybe also advertise GLX_SGIS_multisample? */
+
+    static const char *retval = "GLX_ARB_multisample GLX_EXT_texture_from_pixmap GLX_SGIX_fbconfig";
+
+    (void) dpy;
+    (void) screen;
+
+    crDebug("->glXQueryExtensionsString");
+    return retval;
+}
+
+DECLEXPORT(const char *) VBOXGLXTAG(glXGetClientString)( Display *dpy, int name )
+{
+    const char *retval;
+    (void) dpy;
+    (void) name;
+
+    switch ( name ) {
+
+        case GLX_VENDOR:
+            retval  = "Chromium";
+            break;
+
+        case GLX_VERSION:
+            retval  = "1.2 Chromium";
+            break;
+
+        case GLX_EXTENSIONS:
+            /*@todo should be a screen not a name...but it's not used anyway*/
+            retval  = glXQueryExtensionsString(dpy, name);
+            break;
+
+        default:
+            retval  = NULL;
+    }
+
+    return retval;
+}
+
+DECLEXPORT(const char *) VBOXGLXTAG(glXQueryServerString)( Display *dpy, int screen, int name )
+{
+    const char *retval;
+    (void) dpy;
+    (void) screen;
+
+    switch ( name ) {
+
+        case GLX_VENDOR:
+            retval  = "Chromium";
+            break;
+
+        case GLX_VERSION:
+            retval  = "1.2 Chromium";
+            break;
+
+        case GLX_EXTENSIONS:
+            retval  = glXQueryExtensionsString(dpy, screen);
+            break;
+
+        default:
+            retval  = NULL;
+    }
+
+    return retval;
+}
+
+DECLEXPORT(CR_GLXFuncPtr) VBOXGLXTAG(glXGetProcAddressARB)( const GLubyte *name )
+{
+    return (CR_GLXFuncPtr) crGetProcAddress( (const char *) name );
+}
+
+DECLEXPORT(CR_GLXFuncPtr) VBOXGLXTAG(glXGetProcAddress)( const GLubyte *name )
+{
+    return (CR_GLXFuncPtr) crGetProcAddress( (const char *) name );
+}
+
+
+#if GLX_EXTRAS
+
+DECLEXPORT(GLXPbufferSGIX) 
+VBOXGLXTAG(glXCreateGLXPbufferSGIX)(Display *dpy, GLXFBConfigSGIX config,
+                                    unsigned int width, unsigned int height,
+                                    int *attrib_list)
+{
+    (void) dpy;
+    (void) config;
+    (void) width;
+    (void) height;
+    (void) attrib_list;
+    crWarning("glXCreateGLXPbufferSGIX not implemented by Chromium");
+    return 0;
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXDestroyGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf)
+{
+    (void) dpy;
+    (void) pbuf;
+    crWarning("glXDestroyGLXPbufferSGIX not implemented by Chromium");
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXSelectEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long mask)
+{
+    (void) dpy;
+    (void) drawable;
+    (void) mask;
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long *mask)
+{
+    (void) dpy;
+    (void) drawable;
+    (void) mask;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXQueryGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf,
+                                                   int attribute, unsigned int *value)
+{
+    (void) dpy;
+    (void) pbuf;
+    (void) attribute;
+    (void) value;
+    crWarning("glXQueryGLXPbufferSGIX not implemented by Chromium");
+    return 0;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttribSGIX)(Display *dpy, GLXFBConfig config,
+                                                     int attribute, int *value)
+{
+    return VBOXGLXTAG(glXGetFBConfigAttrib)(dpy, config, attribute, value);
+}
+
+DECLEXPORT(GLXFBConfigSGIX *) 
+VBOXGLXTAG(glXChooseFBConfigSGIX)(Display *dpy, int screen,
+                                  int *attrib_list, int *nelements)
+{
+    (void) dpy;
+    (void) screen;
+    (void) attrib_list;
+    (void) nelements;
+    crWarning("glXChooseFBConfigSGIX not implemented by Chromium");
+    return NULL;
+}
+
+DECLEXPORT(GLXPixmap) 
+VBOXGLXTAG(glXCreateGLXPixmapWithConfigSGIX)(Display *dpy,
+                                             GLXFBConfig config,
+                                             Pixmap pixmap)
+{
+    (void) dpy;
+    (void) config;
+    (void) pixmap;
+    crWarning("glXCreateGLXPixmapWithConfigSGIX not implemented by Chromium");
+    return 0;    }
+
+DECLEXPORT(GLXContext) 
+VBOXGLXTAG(glXCreateContextWithConfigSGIX)(Display *dpy, GLXFBConfig config,
+                                           int render_type,
+                                           GLXContext share_list,
+                                           Bool direct)
+{
+    (void) dpy;
+    (void) config;
+    (void) render_type;
+    (void) share_list;
+    (void) direct;
+    crWarning("glXCreateContextWithConfigSGIX not implemented by Chromium");
+    return NULL;
+}
+
+DECLEXPORT(XVisualInfo *) 
+VBOXGLXTAG(glXGetVisualFromFBConfigSGIX)(Display *dpy,
+                                         GLXFBConfig config)
+{
+    (void) dpy;
+    (void) config;
+    crWarning("glXGetVisualFromFBConfigSGIX not implemented by Chromium");
+    return NULL;
+}
+
+DECLEXPORT(GLXFBConfigSGIX)
+VBOXGLXTAG(glXGetFBConfigFromVisualSGIX)(Display *dpy, XVisualInfo *vis)
+{
+    (void) dpy;
+    (void) vis;
+    crWarning("glXGetFBConfigFromVisualSGIX not implemented by Chromium");
+    return NULL;
+}
+
+/*
+ * GLX 1.3 functions
+ */
+DECLEXPORT(GLXFBConfig *) 
+VBOXGLXTAG(glXChooseFBConfig)(Display *dpy, int screen, ATTRIB_TYPE *attrib_list, int *nelements)
+{
+    (void) dpy;
+    (void) screen;
+    (void) attrib_list;
+    (void) nelements;
+    crWarning("glXChooseFBConfig not implemented by Chromium");
+    return NULL;
+}
+
+DECLEXPORT(GLXContext) 
+VBOXGLXTAG(glXCreateNewContext)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct)
+{
+    XVisualInfo *vis;
+
+    (void) dpy;
+    (void) config;
+    (void) render_type;
+    (void) share_list;
+    (void) direct;
+
+    if (render_type != GLX_RGBA_TYPE)
+    {
+        crWarning("glXCreateNewContext, unsupported render_type %x", render_type);
+        return NULL;
+    }
+
+    vis = VBOXGLXTAG(glXGetVisualFromFBConfig)(dpy, config);
+    return VBOXGLXTAG(glXCreateContext)(dpy, vis, share_list, direct);
+}
+
+DECLEXPORT(GLXPbuffer) 
+VBOXGLXTAG(glXCreatePbuffer)(Display *dpy, GLXFBConfig config, ATTRIB_TYPE *attrib_list)
+{
+    (void) dpy;
+    (void) config;
+    (void) attrib_list;
+    crWarning("glXCreatePbuffer not implemented by Chromium");
+    return 0;
+}
+
+/* Note: there're examples where glxpixmaps are created without current context, so can't do much of the work here.
+ * Instead we'd do necessary initialization on first use of those pixmaps.
+ */
+DECLEXPORT(GLXPixmap) 
+VBOXGLXTAG(glXCreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const ATTRIB_TYPE *attrib_list)
+{
+    (void) dpy;
+    (void) config;
+    (void) attrib_list;
+
+    return (GLXPixmap) pixmap;
+}
+
+DECLEXPORT(GLXWindow) 
+VBOXGLXTAG(glXCreateWindow)(Display *dpy, GLXFBConfig config, Window win, ATTRIB_TYPE *attrib_list)
+{
+    GLXFBConfig *realcfg;
+    int nconfigs;
+    //XVisualInfo *vis;
+    (void) dpy;
+    (void) config;
+    (void) win;
+    (void) attrib_list;
+    //crWarning("glXCreateWindow not implemented by Chromium");
+    //vis = VBOXGLXTAG(glXGetVisualFromFBConfig)(config);
+    if (stub.wsInterface.glXGetFBConfigs)
+    {
+        realcfg = stub.wsInterface.glXGetFBConfigs(dpy, 0, &nconfigs);
+        if (!realcfg || nconfigs<1)
+        {
+            crWarning("glXCreateWindow !realcfg || nconfigs<1");
+            return 0;
+        }
+        else
+        {
+            return stub.wsInterface.glXCreateWindow(dpy, realcfg[0], win, attrib_list);
+        }
+    }
+    else
+    {
+        crWarning("glXCreateWindow stub.wsInterface.glXChooseFBConfig==NULL");
+        return 0;
+    }
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXDestroyPbuffer)(Display *dpy, GLXPbuffer pbuf)
+{
+    (void) dpy;
+    (void) pbuf;
+    crWarning("glXDestroyPbuffer not implemented by Chromium");
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXDestroyPixmap)(Display *dpy, GLXPixmap pixmap)
+{
+    GLX_Pixmap_t *pGlxPixmap;
+
+    if (!stub.currentContext)
+    {
+        crWarning("glXDestroyPixmap failed, no current context");
+        return;
+    }
+
+    pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.currentContext->pGLXPixmapsHash, (unsigned int) pixmap);
+
+    if (pGlxPixmap)
+    {
+        if (pGlxPixmap->gc)
+        {
+            XFreeGC(dpy, pGlxPixmap->gc);
+        }
+
+        if (pGlxPixmap->hShmPixmap>0)
+        {
+            XFreePixmap(dpy, pGlxPixmap->hShmPixmap);
+        }
+
+        if (pGlxPixmap->hDamage>0)
+        {
+            //crDebug("Destroy: Damage for drawable 0x%x, handle 0x%x", (unsigned int) pixmap, (unsigned int) pGlxPixmap->damage);
+            XDamageDestroy(stub.currentContext->damageDpy, pGlxPixmap->hDamage);
+        }
+
+        if (pGlxPixmap->pDamageRegion)
+        {
+            XDestroyRegion(pGlxPixmap->pDamageRegion);
+        }
+
+        crHashtableDelete(stub.currentContext->pGLXPixmapsHash, (unsigned int) pixmap, crFree);
+    }
+    /*else
+    {
+        crWarning("glXDestroyPixmap called for unknown glxpixmap 0x%x", (unsigned int) pixmap);
+    }*/
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXDestroyWindow)(Display *dpy, GLXWindow win)
+{
+    (void) dpy;
+    (void) win;
+    crWarning("glXDestroyWindow not implemented by Chromium");
+}
+
+DECLEXPORT(GLXDrawable) VBOXGLXTAG(glXGetCurrentReadDrawable)(void)
+{
+    //crWarning("glXGetCurrentReadDrawable not implemented by Chromium");
+    return currentReadDrawable;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value)
+{
+    XVisualInfo * pVisual;
+
+    pVisual =  glXGetVisualFromFBConfig(dpy, config);
+    if (!pVisual)
+    {
+        crWarning("glXGetFBConfigAttrib for 0x%x, failed to get XVisualInfo", (int)config);
+        return GLX_BAD_ATTRIBUTE;
+    }
+    //crDebug("glXGetFBConfigAttrib 0x%x for 0x%x, visualid=0x%x, depth=%i", attribute, (int)config, (int)pVisual->visualid, pVisual->depth);
+    
+
+    switch (attribute)
+    {
+        case GLX_DRAWABLE_TYPE:
+            *value = GLX_PIXMAP_BIT;
+            break;
+        case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
+            *value = GLX_TEXTURE_2D_BIT_EXT;
+            break;
+        case GLX_BIND_TO_TEXTURE_RGBA_EXT:
+            //crDebug("attribute=GLX_BIND_TO_TEXTURE_RGBA_EXT");
+            *value = True;
+            break;
+        case GLX_BIND_TO_TEXTURE_RGB_EXT:
+            *value = True;
+            break;
+        case GLX_DOUBLEBUFFER:
+            //crDebug("attribute=GLX_DOUBLEBUFFER");
+            *value = True;
+            break;
+        case GLX_Y_INVERTED_EXT:
+            *value = True;
+            break;
+        case GLX_ALPHA_SIZE:
+            //crDebug("attribute=GLX_ALPHA_SIZE");
+            *value = pVisual->depth==32 ? 8:0;
+            break;
+        case GLX_BUFFER_SIZE:
+            //crDebug("attribute=GLX_BUFFER_SIZE");
+            *value = pVisual->depth;
+            break;
+        case GLX_STENCIL_SIZE:
+            //crDebug("attribute=GLX_STENCIL_SIZE");
+            *value = 8;
+            break;
+        case GLX_DEPTH_SIZE:
+            *value = 16;
+            //crDebug("attribute=GLX_DEPTH_SIZE");
+            break;
+        case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
+            *value = 0;
+            break;
+        case GLX_RENDER_TYPE:
+            //crDebug("attribute=GLX_RENDER_TYPE");
+            *value = GLX_RGBA_BIT;
+            break;
+        case GLX_CONFIG_CAVEAT:
+            //crDebug("attribute=GLX_CONFIG_CAVEAT");
+            *value = GLX_NONE;
+            break;
+        case GLX_VISUAL_ID:
+            //crDebug("attribute=GLX_VISUAL_ID");
+            *value = pVisual->visualid;
+            break;
+        case GLX_FBCONFIG_ID:
+            *value = pVisual->visualid; /*or config, though those are the same at the moment but this could change one day?*/
+            break;
+        case GLX_RED_SIZE:
+        case GLX_GREEN_SIZE:
+        case GLX_BLUE_SIZE:
+            *value = 8;
+            break;
+        case GLX_LEVEL:
+            *value = 0;
+            break;
+        case GLX_STEREO:
+            *value = false;
+            break;
+        case GLX_AUX_BUFFERS:
+            *value = 0;
+            break;
+        case GLX_ACCUM_RED_SIZE:
+        case GLX_ACCUM_GREEN_SIZE:
+        case GLX_ACCUM_BLUE_SIZE:
+        case GLX_ACCUM_ALPHA_SIZE:
+            *value = 0;
+            break;
+        case GLX_X_VISUAL_TYPE:
+            *value = GLX_TRUE_COLOR;
+            break;
+        case GLX_TRANSPARENT_TYPE:
+            *value = GLX_NONE;
+            break;
+        case GLX_SAMPLE_BUFFERS:
+        case GLX_SAMPLES:
+            *value = 1;
+            break;
+        default:
+            crDebug("glXGetFBConfigAttrib: unknown attribute=0x%x", attribute); 
+            XFree(pVisual);
+            return GLX_BAD_ATTRIBUTE;
+    }
+
+    XFree(pVisual);
+    return Success;
+}
+
+#if !defined(VBOX_NO_NATIVEGL) || 1 /* need fbconfigs atleast for depths 24 and 32 */
+DECLEXPORT(GLXFBConfig *) VBOXGLXTAG(glXGetFBConfigs)(Display *dpy, int screen, int *nelements)
+{
+    GLXFBConfig *pGLXFBConfigs = NULL;
+    struct VisualInfo *v;
+    int i=0, cVisuals;
+    XVisualInfo searchvis, *pVisuals;
+
+    *nelements = 0;
+
+    /*
+    for (v = VisualInfoList; v; v = v->next) {
+        if (v->dpy == dpy && v->screen == screen)
+            ++*nelements;
+    }
+
+    if (*nelements)
+        pGLXFBConfigs = crAlloc(*nelements * sizeof(GLXFBConfig));
+
+    for (v = VisualInfoList; v && i<*nelements; v = v->next) {
+        if (v->dpy == dpy && v->screen == screen)
+            pGLXFBConfigs[i++] = (GLXFBConfig) v->visualid;
+    }
+    */
+
+    /*@todo doesn't really list all the common visuals, have to use some static list*/
+    searchvis.screen = screen;
+    pVisuals = XGetVisualInfo(dpy, VisualScreenMask, &searchvis, nelements);
+
+    if (*nelements)
+        pGLXFBConfigs = crAlloc(*nelements * sizeof(GLXFBConfig));
+
+    for (i=0; i<*nelements; ++i)
+    {
+        pGLXFBConfigs[i] = (GLXFBConfig) pVisuals[i].visualid;
+    }
+
+    XFree(pVisuals);
+
+    crDebug("glXGetFBConfigs returned %i configs", *nelements);
+    for (i=0; i<*nelements; ++i)
+    {
+        crDebug("glXGetFBConfigs[%i]=0x%x", i, (unsigned int) pGLXFBConfigs[i]);
+    }
+    return pGLXFBConfigs;
+}
+#else /* not 0 */
+DECLEXPORT(GLXFBConfig *) VBOXGLXTAG(glXGetFBConfigs)(Display *dpy, int screen, int *nelements)
+{
+    int i;
+
+    GLXFBConfig *pGLXFBConfigs = crAlloc(sizeof(GLXFBConfig));
+
+    *nelements = 1;
+    *pGLXFBConfigs = (GLXFBConfig) XVisualIDFromVisual(DefaultVisual(dpy, screen));
+
+    crDebug("glXGetFBConfigs returned %i configs", *nelements);
+    for (i=0; i<*nelements; ++i)
+    {
+        crDebug("glXGetFBConfigs[%i]=0x%x", i, (unsigned int) pGLXFBConfigs[i]);
+    }
+    return pGLXFBConfigs;
+}
+#endif
+
+DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEvent)(Display *dpy, GLXDrawable draw, unsigned long *event_mask)
+{
+    (void) dpy;
+    (void) draw;
+    (void) event_mask;
+    crWarning("glXGetSelectedEvent not implemented by Chromium");
+}
+
+DECLEXPORT(XVisualInfo *) VBOXGLXTAG(glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config)
+{
+    (void) dpy;
+    (void) config;
+    
+    struct VisualInfo *v;
+
+    /*
+    for (v = VisualInfoList; v; v = v->next) {
+        if (v->dpy == dpy && v->visualid == (VisualID)config)
+        {
+            XVisualInfo temp, *pret;
+            int nret;
+
+            temp.visualid = v->visualid;
+            pret = XGetVisualInfo(dpy, VisualIDMask, &temp, &nret);
+            
+            if (nret!=1) crWarning("XGetVisualInfo returned %i visuals", nret);
+            crDebug("glXGetVisualFromFBConfig(cfg/visid==0x%x): depth=%i", (int) config, pret->depth);
+            return pret;
+        }
+    }
+    */
+
+    {
+        XVisualInfo temp, *pret;
+        int nret;
+
+        temp.visualid = (VisualID)config;
+        pret = XGetVisualInfo(dpy, VisualIDMask, &temp, &nret);
+        
+        if (nret!=1) crWarning("XGetVisualInfo returned %i visuals for %x", nret, (unsigned int) config);
+        //crDebug("glXGetVisualFromFBConfig(cfg/visid==0x%x): depth=%i", (int) config, pret->depth);
+        return pret;
+    }
+
+    crDebug("glXGetVisualFromFBConfig unknown fbconfig 0x%x", (int) config);
+    return NULL;
+}
+
+DECLEXPORT(Bool) VBOXGLXTAG(glXMakeContextCurrent)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
+{
+    (void) display;
+    (void) draw;
+    (void) read;
+    (void) ctx;
+    //crWarning("glXMakeContextCurrent not implemented by Chromium");
+    currentReadDrawable = read;
+    return VBOXGLXTAG(glXMakeCurrent)(display, draw, ctx);
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value)
+{
+    (void) dpy;
+    (void) ctx;
+    (void) attribute;
+    (void) value;
+    crWarning("glXQueryContext not implemented by Chromium");
+    return 0;
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
+{
+    (void) dpy;
+    (void) draw;
+    (void) attribute;
+    (void) value;
+    crWarning("glXQueryDrawable not implemented by Chromium");
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXSelectEvent)(Display *dpy, GLXDrawable draw, unsigned long event_mask)
+{
+    (void) dpy;
+    (void) draw;
+    (void) event_mask;
+    crWarning("glXSelectEvent not implemented by Chromium");
+}
+
+#ifdef CR_EXT_texture_from_pixmap
+/*typedef struct
+{
+    int x, y;
+    unsigned int w, h, border, depth;
+    Window root;
+    void *data;
+} pminfo;*/
+
+static void stubInitXSharedMemory(Display *dpy)
+{
+    int vma, vmi;
+    Bool pixmaps;
+
+    if (stub.bShmInitFailed || stub.xshmSI.shmid>=0)
+        return;
+
+    stub.bShmInitFailed = GL_TRUE;
+
+    /* Check for extension and pixmaps format */
+
+    if (!XShmQueryExtension(dpy))
+    {
+        crWarning("No XSHM extension");
+        return;
+    }
+
+    if (!XShmQueryVersion(dpy, &vma, &vmi, &pixmaps) || !pixmaps)
+    {
+        crWarning("XSHM extension doesn't support pixmaps");
+        return;
+    }
+
+    if (XShmPixmapFormat(dpy)!=ZPixmap)
+    {
+        crWarning("XSHM extension doesn't support ZPixmap format");
+        return;
+    }
+
+    /* Alloc shared memory, so far using hardcoded value...could fail for bigger displays one day */
+    stub.xshmSI.readOnly = false;
+    stub.xshmSI.shmid = shmget(IPC_PRIVATE, 4*4096*2048, IPC_CREAT | 0600);
+    if (stub.xshmSI.shmid<0)
+    {
+        crWarning("XSHM Failed to create shared segment");
+        return;
+    }
+
+    stub.xshmSI.shmaddr = (char*) shmat(stub.xshmSI.shmid, NULL, 0);
+    if (stub.xshmSI.shmaddr==(void*)-1)
+    {
+        crWarning("XSHM Failed to attach shared segment");
+        shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
+        return;
+    }
+
+
+    if (!XShmAttach(dpy, &stub.xshmSI))
+    {
+        crWarning("XSHM Failed to attach shared segment to XServer");
+        shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
+        shmdt(stub.xshmSI.shmaddr);
+        return;
+    }
+
+    stub.bShmInitFailed = GL_FALSE;
+    crInfo("Using XSHM for GLX_EXT_texture_from_pixmap");
+
+    /*Anyway mark to be deleted when our process detaches it, in case of segfault etc*/   
+
+/* Ramshankar: Solaris compiz fix */
+#ifndef RT_OS_SOLARIS
+    shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
+#endif
+}
+
+static void stubInitXDamageExtension(ContextInfo *pContext)
+{
+    int erb, vma, vmi;
+
+    CRASSERT(pContext);
+    
+    if (pContext->damageInitFailed || pContext->damageDpy)
+        return;
+
+    pContext->damageInitFailed = True;
+
+    /* Open second xserver connection to make sure we'd recieve all the xdamage messages 
+     * and those wouldn't be eaten by application even queue */
+    pContext->damageDpy = XOpenDisplay(DisplayString(pContext->dpy));
+
+    if (!pContext->damageDpy)
+    {
+        crWarning("XDamage: Can't connect to display %s", DisplayString(pContext->dpy));
+        return;
+    }
+
+    if (!XDamageQueryExtension(pContext->damageDpy, &pContext->damageEventsBase, &erb)
+        || !XDamageQueryVersion(pContext->damageDpy, &vma, &vmi))
+    {
+        crWarning("XDamage not found or old version (%i.%i), going to run *very* slow", vma, vmi);
+        XCloseDisplay(pContext->damageDpy);
+        pContext->damageDpy = NULL;
+        return;
+    }
+
+    crDebug("XDamage %i.%i", vma, vmi);
+    pContext->damageInitFailed = False;
+}
+
+static void stubCheckXDamageCB(unsigned long key, void *data1, void *data2)
+{
+    GLX_Pixmap_t *pGlxPixmap = (GLX_Pixmap_t *) data1;
+    XDamageNotifyEvent *e = (XDamageNotifyEvent *) data2;
+
+    if (pGlxPixmap->hDamage==e->damage)
+    {
+        /*crDebug("Event: Damage for pixmap 0x%lx(drawable 0x%x), handle 0x%x (level=%i) [%i,%i,%i,%i]",
+                key, (unsigned int) e->drawable, (unsigned int) e->damage, (int) e->level,
+                e->area.x, e->area.y, e->area.width, e->area.height);*/
+
+        if (pGlxPixmap->pDamageRegion)
+        {
+            /* If it's dirty and regions are empty, it marked for full update, so do nothing.*/
+            if (!pGlxPixmap->bPixmapImageDirty || !XEmptyRegion(pGlxPixmap->pDamageRegion))
+            {
+                if (CR_MAX_DAMAGE_REGIONS_TRACKED <= pGlxPixmap->pDamageRegion->numRects)
+                {
+                    /* Mark for full update */
+                    EMPTY_REGION(pGlxPixmap->pDamageRegion);
+                }
+                else
+                {
+                    /* Add to damage regions */
+                    XUnionRectWithRegion(&e->area, pGlxPixmap->pDamageRegion, pGlxPixmap->pDamageRegion);
+                }
+            }
+        }
+
+        pGlxPixmap->bPixmapImageDirty = True;
+    }
+}
+
+static GLX_Pixmap_t* stubInitGlxPixmap(Display *dpy, GLXDrawable draw, ContextInfo *pContext)
+{
+    int x, y;
+    unsigned int w, h;
+    unsigned int border;
+    unsigned int depth;
+    Window root;
+    GLX_Pixmap_t *pGlxPixmap;
+
+    CRASSERT(pContext);
+
+    if (!XGetGeometry(dpy, (Pixmap)draw, &root, &x, &y, &w, &h, &border, &depth))
+    {
+        crWarning("stubInitGlxPixmap failed in call to XGetGeometry for 0x%x", (int) draw);
+        return NULL;
+    }
+
+    pGlxPixmap = crAlloc(sizeof(GLX_Pixmap_t));
+    if (!pGlxPixmap)
+    {
+        crWarning("stubInitGlxPixmap failed to allocate memory");
+        return NULL;
+    }
+
+    pGlxPixmap->x = x;
+    pGlxPixmap->y = y;
+    pGlxPixmap->w = w;
+    pGlxPixmap->h = h;
+    pGlxPixmap->border = border;
+    pGlxPixmap->depth = depth;
+    pGlxPixmap->root = root;
+
+    /* Try to allocate shared memory
+     * As we're allocating huge chunk of memory, do it in this function, only if this extension is really used
+     */
+    if (!stub.bShmInitFailed && stub.xshmSI.shmid<0)
+    {
+        stubInitXSharedMemory(dpy);
+    }
+
+    if (stub.xshmSI.shmid>=0)
+    {
+        XGCValues xgcv;
+        xgcv.graphics_exposures = False;
+        xgcv.subwindow_mode = IncludeInferiors;
+        pGlxPixmap->gc = XCreateGC(dpy, (Pixmap)draw, GCGraphicsExposures|GCSubwindowMode, &xgcv);
+
+        pGlxPixmap->hShmPixmap = XShmCreatePixmap(dpy, pGlxPixmap->root, stub.xshmSI.shmaddr, &stub.xshmSI, 
+                                                  pGlxPixmap->w, pGlxPixmap->h, pGlxPixmap->depth);
+    }
+    else
+    {
+        pGlxPixmap->gc = NULL;
+        pGlxPixmap->hShmPixmap = 0;
+    }
+
+    stubInitXDamageExtension(pContext);
+
+    /* If there's damage extension, then get handle for damage events related to this pixmap */
+    if (pContext->damageDpy)
+    {
+        pGlxPixmap->hDamage = XDamageCreate(pContext->damageDpy, (Pixmap)draw, XDamageReportRawRectangles);
+        /*crDebug("Create: Damage for drawable 0x%x, handle 0x%x (level=%i)",
+                 (unsigned int) draw, (unsigned int) pGlxPixmap->damage, (int) XDamageReportRawRectangles);*/
+        pGlxPixmap->pDamageRegion = XCreateRegion();
+        if (!pGlxPixmap->pDamageRegion)
+        {
+            crWarning("stubInitGlxPixmap failed to create empy damage region for drawable 0x%x", (unsigned int) draw);
+        }
+
+        /*We have never seen this pixmap before, so mark it as dirty for first use*/
+        pGlxPixmap->bPixmapImageDirty = True;
+    }
+    else
+    {
+        pGlxPixmap->hDamage = 0;
+        pGlxPixmap->pDamageRegion = NULL;
+    }
+
+    /* glTexSubImage2D generates GL_INVALID_OP if texture array hasn't been defined by a call to glTexImage2D first. 
+     * It's fine for small textures which would be updated in stubXshmUpdateWholeImage, but we'd never call glTexImage2D for big ones.
+     * Note that we're making empty texture by passing NULL as pixels pointer, so there's no overhead transferring data to host.*/
+    if (CR_MAX_TRANSFER_SIZE < 4*pGlxPixmap->w*pGlxPixmap->h)
+    {
+        stub.spu->dispatch_table.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pGlxPixmap->w, pGlxPixmap->h, 0, 
+                                            GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+    }
+
+    crHashtableAdd(pContext->pGLXPixmapsHash, (unsigned int) draw, pGlxPixmap);
+
+    return pGlxPixmap;
+}
+
+static void stubXshmUpdateWholeImage(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap)
+{
+    /* To limit the size of transferring buffer, split bigger texture into regions
+     * which fit into connection buffer. Could be done in hgcm or packspu but implementation in this place allows to avoid
+     * unnecessary memcpy. 
+     * This also workarounds guest driver failures when sending 6+mb texture buffers on linux.
+     */
+    if (CR_MAX_TRANSFER_SIZE < 4*pGlxPixmap->w*pGlxPixmap->h)
+    {
+        XRectangle rect;
+
+        rect.x = pGlxPixmap->x;
+        rect.y = pGlxPixmap->y;
+        rect.width = pGlxPixmap->w;
+        rect.height = CR_MAX_TRANSFER_SIZE/(4*pGlxPixmap->w);
+
+        /*crDebug("Texture size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
+                pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, rect.height);*/
+
+        for (; (rect.y+rect.height)<=(pGlxPixmap->y+pGlxPixmap->h); rect.y+=rect.height)
+        {
+            stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
+        }
+
+        if (rect.y!=(pGlxPixmap->y+pGlxPixmap->h))
+        {
+            rect.height=pGlxPixmap->h-rect.y;
+            stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
+        }
+    }
+    else
+    {
+        XCopyArea(dpy, (Pixmap)draw, pGlxPixmap->hShmPixmap, pGlxPixmap->gc, 
+                  pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, 0, 0);
+        /* Have to make sure XCopyArea is processed */
+        XSync(dpy, False);
+        stub.spu->dispatch_table.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pGlxPixmap->w, pGlxPixmap->h, 0, 
+                                            GL_BGRA, GL_UNSIGNED_BYTE, stub.xshmSI.shmaddr);
+        /*crDebug("Sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]", 
+                  (unsigned int) draw, (unsigned int)pGlxPixmap->hDamage, 
+                  pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);*/
+    }
+}
+
+static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect)
+{
+    /* See comment in stubXshmUpdateWholeImage */
+    if (CR_MAX_TRANSFER_SIZE < 4*pRect->width*pRect->height)
+    {
+        XRectangle rect;
+
+        rect.x = pRect->x;
+        rect.y = pRect->y;
+        rect.width = pRect->width;
+        rect.height = CR_MAX_TRANSFER_SIZE/(4*pRect->width);
+
+        /*crDebug("Region size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
+                pRect->x, pRect->y, pRect->width, pRect->height, rect.height);*/
+
+        for (; (rect.y+rect.height)<=(pRect->y+pRect->height); rect.y+=rect.height)
+        {
+            stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
+        }
+
+        if (rect.y!=(pRect->y+pRect->height))
+        {
+            rect.height=pRect->y+pRect->height-rect.y;
+            stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
+        }
+    }
+    else
+    {
+        GLint origUnpackRowLength;
+
+        XCopyArea(dpy, (Pixmap)draw, pGlxPixmap->hShmPixmap, pGlxPixmap->gc, 
+                  pRect->x, pRect->y, pRect->width, pRect->height, 0, 0);
+        /* Have to make sure XCopyArea is processed */
+        XSync(dpy, False);
+
+        /* Save original value, doesn't cause sync as it's reported by state tracker*/
+        if (pRect->width!=pGlxPixmap->w)
+        {
+            stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_ROW_LENGTH, &origUnpackRowLength);
+            stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ROW_LENGTH, pGlxPixmap->w);
+        }
+        stub.spu->dispatch_table.TexSubImage2D(GL_TEXTURE_2D, 0, pRect->x, pRect->y, pRect->width, pRect->height, 
+                                               GL_BGRA, GL_UNSIGNED_BYTE, stub.xshmSI.shmaddr);
+        if (pRect->width!=pGlxPixmap->w)
+        {
+            /* Restore original value*/
+            stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ROW_LENGTH, origUnpackRowLength);
+        }
+
+        /*crDebug("Region sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]", 
+                (unsigned int) draw, (unsigned int)pGlxPixmap->hDamage, 
+                pRect->x, pRect->y, pRect->width, pRect->height);*/
+    }
+}
+
+#if 0
+Bool checkevents(Display *display, XEvent *event, XPointer arg)
+{
+    //crDebug("got type: 0x%x", event->type);
+    if (event->type==damage_evb+XDamageNotify)
+    {
+        XDamageNotifyEvent *e = (XDamageNotifyEvent *) event;
+        /* we're interested in pixmaps only...and those have e->drawable set to 0 or other strange value for some odd reason 
+         * so have to walk glxpixmaps hashtable to find if we have damage event handle assigned to some pixmap
+         */
+        /*crDebug("Event: Damage for drawable 0x%x, handle 0x%x (level=%i) [%i,%i,%i,%i]",
+                (unsigned int) e->drawable, (unsigned int) e->damage, (int) e->level,
+                e->area.x, e->area.y, e->area.width, e->area.height);*/
+        CRASSERT(stub.currentContext);
+        crHashtableWalk(stub.currentContext->pGLXPixmapsHash, checkdamageCB, e);
+    }
+    return False;
+}
+#endif
+
+/*@todo check what error codes could we throw for failures here*/
+DECLEXPORT(void) VBOXGLXTAG(glXBindTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer, const int *attrib_list)
+{
+    static int cnt=0;
+    XImage dummyimg;
+
+    GLX_Pixmap_t *pGlxPixmap;
+
+    crDebug("->glXBindTexImageEXT");
+
+    if (!stub.currentContext)
+    {
+        crWarning("glXBindTexImageEXT called without current context");
+        return;
+    }
+
+    pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.currentContext->pGLXPixmapsHash, (unsigned int) draw);
+    if (!pGlxPixmap)
+    {
+        /*Not a fault, just setup the desired information, see comment for glXCreatePixmap function*/
+        pGlxPixmap = stubInitGlxPixmap(dpy, draw, stub.currentContext);
+
+        if (!pGlxPixmap) return;
+    }
+
+    /* If there's damage extension, then process incoming events as we need the information right now */
+    if (stub.currentContext->damageDpy)
+    {
+        /* Sync connections, note that order of syncs is important here.
+         * First make sure client commands are finished, then make sure we get all the damage events back*/
+        XSync(dpy, False);
+        XSync(stub.currentContext->damageDpy, False);
+
+        while (XPending(stub.currentContext->damageDpy))
+        {
+            XEvent event;
+            XNextEvent(stub.currentContext->damageDpy, &event);
+            if (event.type==stub.currentContext->damageEventsBase+XDamageNotify)
+            {
+                crHashtableWalk(stub.currentContext->pGLXPixmapsHash, stubCheckXDamageCB, &event);
+            }
+        }
+    }
+
+    /* No shared memory? Rollback to use slow x protocol then */
+    if (stub.xshmSI.shmid<0)
+    {
+        /*@todo add damage support here too*/
+        XImage *pxim;
+
+        pxim = XGetImage(dpy, (Pixmap)draw, pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, AllPlanes, ZPixmap);
+        /*if (pxim)
+        {
+            if (!ptextable)
+            {
+                ptextable = crAllocHashtable();
+            }
+            pm = crHashtableSearch(ptextable, (unsigned int) draw);
+            if (!pm)
+            {
+                pm = crCalloc(sizeof(pminfo));
+                crHashtableAdd(ptextable, (unsigned int) draw, pm);
+            }
+            pm->w = w;
+            pm->h = h;
+            if (pm->data) crFree(pm->data);
+            pm->data = crAlloc(4*w*h);
+            crMemcpy(pm->data, (void*)(&(pxim->data[0])), 4*w*h);
+        }*/
+
+        if (NULL==pxim)
+        {
+            crWarning("Failed, to get pixmap data for 0x%x", (unsigned int) draw);
+            return;
+        }
+
+        stub.spu->dispatch_table.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pxim->width, pxim->height, 0, 
+                                            GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(pxim->data[0])));
+        XDestroyImage(pxim);
+    }
+    else /* Use shm to get pixmap data */
+    {
+        /* Check if we have damage extension */
+        if (stub.currentContext->damageDpy)
+        {
+            if (pGlxPixmap->bPixmapImageDirty)
+            {
+                /* Either we failed to allocate damage region or this pixmap is marked for full update */
+                if (!pGlxPixmap->pDamageRegion || XEmptyRegion(pGlxPixmap->pDamageRegion))
+                {
+                    /*crDebug("**FULL** update for 0x%x", (unsigned int)draw);*/
+                    stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
+                }
+                else
+                {
+                    long fullArea, damageArea=0, clipdamageArea, i;
+                    XRectangle damageClipBox;
+
+                    fullArea = pGlxPixmap->w * pGlxPixmap->h;
+                    XClipBox(pGlxPixmap->pDamageRegion, &damageClipBox);
+                    clipdamageArea = damageClipBox.width * damageClipBox.height;
+
+                    //crDebug("FullSize [%i,%i,%i,%i]", pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);
+                    //crDebug("Clip [%i,%i,%i,%i]", damageClipBox.x, damageClipBox.y, damageClipBox.width, damageClipBox.height);
+
+                    for (i=0; i<pGlxPixmap->pDamageRegion->numRects; ++i)
+                    {
+                        BoxPtr pBox = &pGlxPixmap->pDamageRegion->rects[i];
+                        damageArea += (pBox->x2-pBox->x1)*(pBox->y2-pBox->y1);
+                        //crDebug("Damage rect [%i,%i,%i,%i]", pBox->x1, pBox->y1, pBox->x2, pBox->y2);
+                    }
+
+                    if (damageArea>clipdamageArea || clipdamageArea>fullArea)
+                    {
+                        crWarning("glXBindTexImageEXT, damage regions seems to be broken, forcing full update");
+                        /*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li", 
+                                (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
+                        stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
+                    }
+                    else /*We have corect damage info*/
+                    {
+                        if (CR_MIN_DAMAGE_PROFIT_SIZE > (fullArea-damageArea))
+                        {
+                            /*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li", 
+                                    (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
+                            stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
+                        }
+                        else if (CR_MIN_DAMAGE_PROFIT_SIZE > (clipdamageArea-damageArea))
+                        {
+                            /*crDebug("**PARTIAL** update for 0x%x, numRect=%li, FS=%li, *CS*=%li, DS=%li", 
+                                    (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
+                            stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &damageClipBox);
+                        }
+                        else
+                        {
+                            /*crDebug("**PARTIAL** update for 0x%x, numRect=*%li*, FS=%li, CS=%li, *DS*=%li", 
+                                    (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
+                            for (i=0; i<pGlxPixmap->pDamageRegion->numRects; ++i)
+                            {
+                                XRectangle rect;
+                                BoxPtr pBox = &pGlxPixmap->pDamageRegion->rects[i];
+                                
+                                rect.x = pBox->x1;
+                                rect.y = pBox->y1;
+                                rect.width = pBox->x2-pBox->x1;
+                                rect.height = pBox->y2-pBox->y1;
+
+                                stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
+                            }
+                        }
+                    }
+                }
+
+                /* Clean dirty flag and damage region */
+                pGlxPixmap->bPixmapImageDirty = False;
+                if (pGlxPixmap->pDamageRegion)
+                    EMPTY_REGION(pGlxPixmap->pDamageRegion);
+            }
+        }
+        else
+        {
+            stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
+        }
+    }
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXReleaseTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer)
+{
+    (void) dpy;
+    (void) draw;
+    (void) buffer;
+    //crDebug("glXReleaseTexImageEXT 0x%x", (unsigned int)draw);
+}
+#endif
+
+#endif /* GLX_EXTRAS */
+
+
+#ifdef GLX_SGIX_video_resize
+/* more dummy funcs.  These help when linking with older GLUTs */
+
+DECLEXPORT(int) VBOXGLXTAG(glXBindChannelToWindowSGIX)(Display *dpy, int scrn, int chan, Window w)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) chan;
+    (void) w;
+    crDebug("glXBindChannelToWindowSGIX");
+    return 0;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSGIX)(Display *dpy, int scrn, int chan, int x , int y, int w, int h)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) chan;
+    (void) x;
+    (void) y;
+    (void) w;
+    (void) h;
+    crDebug("glXChannelRectSGIX");
+    return 0;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelRectSGIX)(Display *dpy, int scrn, int chan, int *x, int *y, int *w, int *h)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) chan;
+    (void) x;
+    (void) y;
+    (void) w;
+    (void) h;
+    crDebug("glXQueryChannelRectSGIX");
+    return 0;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelDeltasSGIX)(Display *dpy, int scrn, int chan, int *dx, int *dy, int *dw, int *dh)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) chan;
+    (void) dx;
+    (void) dy;
+    (void) dw;
+    (void) dh;
+    crDebug("glXQueryChannelDeltasSGIX");
+    return 0;
+}
+
+DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSyncSGIX)(Display *dpy, int scrn, int chan, GLenum synctype)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) chan;
+    (void) synctype;
+    crDebug("glXChannelRectSyncSGIX");
+    return 0;
+}
+
+#endif /* GLX_SGIX_video_resize */
+
+#ifdef VBOXOGL_FAKEDRI
+DECLEXPORT(const char *) VBOXGLXTAG(glXGetDriverConfig)(const char *driverName)
+{
+    return NULL;
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) pointer;
+}
+
+DECLEXPORT(GLXContext) VBOXGLXTAG(glXImportContextEXT)(Display *dpy, GLXContextID contextID)
+{
+    (void) dpy;
+    (void) contextID;
+    return NULL;
+}
+
+DECLEXPORT(GLXContextID) VBOXGLXTAG(glXGetContextIDEXT)(const GLXContext ctx)
+{
+    (void) ctx;
+    return 0;
+}
+
+DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrentReadSGI)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
+{
+    return VBOXGLXTAG(glXMakeContextCurrent)(display, draw, read, ctx);
+}
+
+DECLEXPORT(const char *) VBOXGLXTAG(glXGetScreenDriver)(Display *dpy, int scrNum)
+{
+    static char *screendriver = "vboxvideo";
+    return screendriver;
+}
+
+DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplayEXT)(void)
+{
+    return VBOXGLXTAG(glXGetCurrentDisplay());
+}
+
+DECLEXPORT(void) VBOXGLXTAG(glXFreeContextEXT)(Display *dpy, GLXContext ctx)
+{
+    VBOXGLXTAG(glXDestroyContext(dpy, ctx));
+}
+
+/*Mesa internal*/
+DECLEXPORT(int) VBOXGLXTAG(glXQueryContextInfoEXT)(Display *dpy, GLXContext ctx)
+{
+    (void) dpy;
+    (void) ctx;
+    return 0;
+}
+
+DECLEXPORT(void *) VBOXGLXTAG(glXAllocateMemoryMESA)(Display *dpy, int scrn,
+                                                     size_t size, float readFreq,
+                                                     float writeFreq, float priority)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) size;
+    (void) readFreq;
+    (void) writeFreq;
+    (void) priority;
+    return NULL;
+}
+
+DECLEXPORT(GLuint) VBOXGLXTAG(glXGetMemoryOffsetMESA)(Display *dpy, int scrn, const void *pointer)
+{
+    (void) dpy;
+    (void) scrn;
+    (void) pointer;
+    return 0;
+}
+
+DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap)
+{
+    (void) dpy;
+    (void) visual;
+    (void) pixmap;
+    (void) cmap;
+    return 0;
+}
+
+#endif /*VBOXOGL_FAKEDRI*/
Index: trunk/src/VBox/Additions/common/crOpenGL/xfont.c
===================================================================
--- trunk/src/VBox/Additions/common/crOpenGL/xfont.c	(revision 18882)
+++ trunk/src/VBox/Additions/common/crOpenGL/xfont.c	(revision 18882)
@@ -0,0 +1,244 @@
+/* Copyright (c) 2001, Stanford University
+ * All rights reserved
+ *
+ * See the file LICENSE.txt for information on redistributing this software.
+ */
+
+#include "chromium.h"
+#include "cr_error.h"
+#include "cr_mem.h"
+#include "stub.h"
+
+/** code borrowed from Mesa */
+
+
+/** Fill a BITMAP with a character C from thew current font
+   in the graphics context GC.  WIDTH is the width in bytes
+   and HEIGHT is the height in bits.
+
+   Note that the generated bitmaps must be used with
+
+        glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
+        glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
+        glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+        glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
+        glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
+        glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+
+   Possible optimizations:
+
+     * use only one reusable pixmap with the maximum dimensions.
+     * draw the entire font into a single pixmap (careful with
+       proportional fonts!).
+*/
+
+
+/**
+ * Generate OpenGL-compatible bitmap.
+ */
+static void
+fill_bitmap(Display *dpy, Window win, GC gc,
+			unsigned int width, unsigned int height,
+			int x0, int y0, unsigned int c, GLubyte *bitmap)
+{
+	XImage *image;
+	unsigned int x, y;
+	Pixmap pixmap;
+	XChar2b char2b;
+
+	pixmap = XCreatePixmap(dpy, win, 8*width, height, 1);
+	XSetForeground(dpy, gc, 0);
+	XFillRectangle(dpy, pixmap, gc, 0, 0, 8*width, height);
+	XSetForeground(dpy, gc, 1);
+
+	char2b.byte1 = (c >> 8) & 0xff;
+	char2b.byte2 = (c & 0xff);
+
+	XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1);
+
+	image = XGetImage(dpy, pixmap, 0, 0, 8*width, height, 1, XYPixmap);
+	if (image) {
+		/* Fill the bitmap (X11 and OpenGL are upside down wrt each other).  */
+		for (y = 0; y < height; y++)
+			for (x = 0; x < 8*width; x++)
+				if (XGetPixel(image, x, y))
+					bitmap[width*(height - y - 1) + x/8] |= (1 << (7 - (x % 8)));
+		XDestroyImage(image);
+	}
+
+	XFreePixmap(dpy, pixmap);
+}
+
+/*
+ * determine if a given glyph is valid and return the
+ * corresponding XCharStruct.
+ */
+static XCharStruct *isvalid(XFontStruct *fs, unsigned int which)
+{
+	unsigned int rows, pages;
+	unsigned int byte1 = 0, byte2 = 0;
+	int i, valid = 1;
+
+	rows = fs->max_byte1 - fs->min_byte1 + 1;
+	pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
+
+	if (rows == 1) {
+		/* "linear" fonts */
+		if ((fs->min_char_or_byte2 > which) ||
+			(fs->max_char_or_byte2 < which)) valid = 0;
+	}
+	else {
+		/* "matrix" fonts */
+		byte2 = which & 0xff;
+		byte1 = which >> 8;
+		if ((fs->min_char_or_byte2 > byte2) ||
+			(fs->max_char_or_byte2 < byte2) ||
+			(fs->min_byte1 > byte1) ||
+			(fs->max_byte1 < byte1)) valid = 0;
+	}
+
+	if (valid) {
+		if (fs->per_char) {
+			if (rows == 1) {
+				/* "linear" fonts */
+				return fs->per_char + (which-fs->min_char_or_byte2);
+			}
+			else {
+				/* "matrix" fonts */
+				i = ((byte1 - fs->min_byte1) * pages) +
+					(byte2 - fs->min_char_or_byte2);
+				return fs->per_char + i;
+			}
+		}
+		else {
+			return &fs->min_bounds;
+		}
+	}
+	return NULL;
+}
+
+
+void stubUseXFont( Display *dpy, Font font, int first, int count, int listbase )
+{
+	Window win;
+	Pixmap pixmap;
+	GC gc;
+	XGCValues values;
+	unsigned long valuemask;
+	XFontStruct *fs;
+	GLint swapbytes, lsbfirst, rowlength;
+	GLint skiprows, skippixels, alignment;
+	unsigned int max_width, max_height, max_bm_width, max_bm_height;
+	GLubyte *bm;
+	int i;
+
+	win = RootWindow(dpy, DefaultScreen(dpy));
+
+	fs = XQueryFont(dpy, font);
+	if (!fs) {
+		crWarning("Couldn't get font structure information");
+		return;
+	}
+
+	/* Allocate a bitmap that can fit all characters.  */
+	max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing;
+	max_height = fs->max_bounds.ascent + fs->max_bounds.descent;
+	max_bm_width = (max_width + 7) / 8;
+	max_bm_height = max_height;
+
+	bm = (GLubyte *) crAlloc((max_bm_width * max_bm_height) * sizeof(GLubyte));
+	if (!bm) {
+		XFreeFontInfo( NULL, fs, 1 );
+		crWarning("Couldn't allocate bitmap in glXUseXFont()");
+		return;
+	}
+
+	/* Save the current packing mode for bitmaps.  */
+	glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
+	glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
+	glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
+	glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
+	glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
+	glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
+
+	/* Enforce a standard packing mode which is compatible with
+	   fill_bitmap() from above.  This is actually the default mode,
+	   except for the (non)alignment.  */
+	glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
+	glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
+	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+	glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+	glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+	pixmap = XCreatePixmap(dpy, win, 10, 10, 1);
+	values.foreground = BlackPixel(dpy, DefaultScreen (dpy));
+	values.background = WhitePixel(dpy, DefaultScreen (dpy));
+	values.font = fs->fid;
+	valuemask = GCForeground | GCBackground | GCFont;
+	gc = XCreateGC(dpy, pixmap, valuemask, &values);
+	XFreePixmap(dpy, pixmap);
+
+	for (i = 0; i < count; i++) {
+		unsigned int width, height, bm_width, bm_height;
+		GLfloat x0, y0, dx, dy;
+		XCharStruct *ch;
+		int x, y;
+		unsigned int c = first + i;
+		int list = listbase + i;
+		int valid;
+
+		/* check on index validity and get the bounds */
+		ch = isvalid(fs, c);
+		if (!ch) {
+			ch = &fs->max_bounds;
+			valid = 0;
+		}
+		else {
+			valid = 1;
+		}
+
+		/* glBitmap()' parameters:
+		   straight from the glXUseXFont(3) manpage.  */
+		width = ch->rbearing - ch->lbearing;
+		height = ch->ascent + ch->descent;
+		x0 = -ch->lbearing;
+		y0 = ch->descent - 0;  /* XXX used to subtract 1 here */
+		                       /* but that caused a conformace failure */
+		dx = ch->width;
+		dy = 0;
+
+		/* X11's starting point.  */
+		x = -ch->lbearing;
+		y = ch->ascent;
+
+		/* Round the width to a multiple of eight.  We will use this also
+		for the pixmap for capturing the X11 font.  This is slightly
+		inefficient, but it makes the OpenGL part real easy.  */
+		bm_width = (width + 7) / 8;
+		bm_height = height;
+
+		glNewList(list, GL_COMPILE);
+		if (valid && (bm_width > 0) && (bm_height > 0)) {
+			crMemset(bm, '\0', bm_width * bm_height);
+			fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
+			glBitmap(width, height, x0, y0, dx, dy, bm);
+		}
+		else {
+			glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
+		}
+		glEndList();
+	}
+
+	crFree(bm);
+	XFreeFontInfo(NULL, fs, 1);
+	XFreeGC(dpy, gc);
+
+	/* Restore saved packing modes.  */
+	glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
+	glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
+	glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
+	glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
+	glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
+	glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
+}
