mesa: Fix remap_table setup.
[mesa.git] / src / mesa / main / es_generator.py
index 8f28da16df81d1617b2647241140d9e8c0deea1a..87d8bd316828dbc5df4089d74d298b83681569d7 100644 (file)
@@ -191,8 +191,14 @@ print """
 #include "%s"
 #include "%s"
 #include "main/mfeatures.h"
+#include "main/compiler.h"
+#include "main/api_exec.h"
 
 #if FEATURE_%s
+
+#ifndef GLAPIENTRYP
+#define GLAPIENTRYP GL_APIENTRYP
+#endif
 """ % (versionHeader, versionExtHeader, shortname.upper())
 
 # Everyone needs these types.
@@ -206,48 +212,7 @@ typedef double GLclampd;
 /* Mesa error handling requires these */
 extern void *_mesa_get_current_context(void);
 extern void _mesa_error(void *ctx, GLenum error, const char *fmtString, ... );
-
-#include "main/compiler.h"
-#include "main/api_exec.h"
-#include "main/remap.h"
-
-/* cannot include main/dispatch.h here */
-#ifdef IN_DRI_DRIVER
-#define _GLAPI_USE_REMAP_TABLE
-#endif
-/* glapi uses GLAPIENTRY while GLES headers define GL_APIENTRY */
-#ifndef GLAPIENTRY
-#define GLAPIENTRY GL_APIENTRY
-#endif
-#include "%sapi/main/glapidispatch.h"
-
-#if FEATURE_remap_table
-
-#if !FEATURE_GL
-int driDispatchRemapTable[driDispatchRemapTable_size];
-#endif
-
-#define need_MESA_remap_table
-
-#include "%sapi/main/remap_helper.h"
-
-void
-_mesa_init_remap_table_%s(void)
-{
-   _mesa_do_init_remap_table(_mesa_function_pool,
-                             driDispatchRemapTable_size,
-                             MESA_remap_table_functions);
-}
-
-void
-_mesa_map_static_functions_%s(void)
-{
-}
-
-#endif
-
-typedef void (*_glapi_proc)(void); /* generic function pointer */
-""" % (shortname, shortname, shortname, shortname);
+"""
 
 # Finally we get to the all-important functions
 print """/*************************************************************
@@ -711,15 +676,69 @@ for funcName in keys:
 # end for each function
 
 print """
+#include "glapi/glapi.h"
+
+#if FEATURE_remap_table
+
+/* cannot include main/dispatch.h here */
+#define _GLAPI_USE_REMAP_TABLE
+#include "%sapi/main/glapidispatch.h"
+
+#define need_MESA_remap_table
+#include "%sapi/main/remap_helper.h"
+
+static void
+init_remap_table(void)
+{
+   _glthread_DECLARE_STATIC_MUTEX(mutex);
+   static GLboolean initialized = GL_FALSE;
+   const struct gl_function_pool_remap *remap = MESA_remap_table_functions;
+   int i;
+
+   _glthread_LOCK_MUTEX(mutex);
+   if (initialized) {
+      _glthread_UNLOCK_MUTEX(mutex);
+      return;
+   }
+
+   for (i = 0; i < driDispatchRemapTable_size; i++) {
+      GLint offset;
+      const char *spec;
+
+      /* sanity check */
+      ASSERT(i == remap[i].remap_index);
+      spec = _mesa_function_pool + remap[i].pool_index;
+
+      offset = _mesa_map_function_spec(spec);
+      remap_table[i] = offset;
+   }
+   initialized = GL_TRUE;
+   _glthread_UNLOCK_MUTEX(mutex);
+}
+
+#else /* FEATURE_remap_table */
+
+/* cannot include main/dispatch.h here */
+#include "%sapi/main/glapidispatch.h"
+
+static INLINE void
+init_remap_table(void)
+{
+}
+
+#endif /* FEATURE_remap_table */
+
 struct _glapi_table *
 _mesa_create_exec_table_%s(void)
 {
    struct _glapi_table *exec;
+
    exec = _mesa_alloc_dispatch_table(_gloffset_COUNT);
    if (exec == NULL)
       return NULL;
 
-""" % shortname
+   init_remap_table();
+""" % (shortname, shortname, shortname, shortname)
 
 for func in keys:
     prefix = "_es_" if func not in allSpecials else "_check_"