yagl: Remove cur_ts global variable (1/3) 18/243118/1
authorLukasz Kostyra <l.kostyra@samsung.com>
Tue, 11 Aug 2020 11:33:04 +0000 (13:33 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Thu, 3 Sep 2020 07:49:50 +0000 (09:49 +0200)
cur_ts was a global variable used for easy global access to currently
running thread's state. Access to the variable was not synchronized at
all. The variable was overwritten each time a thread started working
and NULLed each time a thread stopped working. This was a cause
of multitude of multithreading issues in yagl code. Some examples are:
- Thread A could NULLify cur_ts after finishing work while thread B
tries to dereference it during logging routine setup. This in turn can
result in a randomly occuring segmentation fault (ex. when calling
YAGL_LOG_FUNC_ENTER which accessed cur_ts for PID/TID info).
- Information in cur_ts could be misleading for thread A because
thread B set its own instance of cur_ts right after thread A.
- Memory leaks and other issues due to cur_ts being re-allocated on the
same global pointer.

Issues have to be resolved by removing cur_ts. Now every thread based
function has a first parameter cur_ts, which provides the same information
in a per-thread and reentrant-safe manner.

In situations where cur_ts could not be reached (ex. initialization or
main thread code) YAGL_LOG_NO_TS macro was introduced, which for now sets
pid/tid information to 0. Macro's proper implementation will be done in
upcoming changes.

Some yagl modules also used local _ts structures (ex. egl_api_ts or
egl_onscreen_ts) and used them in the same way cur_ts was managed.
These also provide thread/reentry dangers and will be removed in
consecutive commits.

Change-Id: I9c55371a522d8f06cb3ce8120f88946e9d246695

52 files changed:
hw/yagl/yagl_api.h
hw/yagl/yagl_apis/egl/yagl_egl_api_ps.c
hw/yagl/yagl_apis/egl/yagl_egl_api_ps.h
hw/yagl/yagl_apis/egl/yagl_egl_api_ts.c
hw/yagl/yagl_apis/egl/yagl_egl_api_ts.h
hw/yagl/yagl_apis/egl/yagl_egl_calls.c
hw/yagl/yagl_apis/egl/yagl_egl_context.c
hw/yagl/yagl_apis/egl/yagl_egl_context.h
hw/yagl/yagl_apis/egl/yagl_egl_display.c
hw/yagl/yagl_apis/egl/yagl_egl_display.h
hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c
hw/yagl/yagl_apis/egl/yagl_host_egl_calls.h
hw/yagl/yagl_apis/gles/yagl_gles_api_ts.c
hw/yagl/yagl_apis/gles/yagl_gles_api_ts.h
hw/yagl/yagl_apis/gles/yagl_gles_calls.c
hw/yagl/yagl_apis/gles/yagl_host_gles_calls.c
hw/yagl/yagl_apis/gles/yagl_host_gles_calls.h
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_surface.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_surface.h
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.h
hw/yagl/yagl_compiled_transfer.c
hw/yagl/yagl_compiled_transfer.h
hw/yagl/yagl_device.c
hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c
hw/yagl/yagl_drivers/gles_ogl/yagl_gles_ogl.c
hw/yagl/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c
hw/yagl/yagl_egl_backend.h
hw/yagl/yagl_eglb_context.h
hw/yagl/yagl_eglb_display.h
hw/yagl/yagl_eglb_surface.h
hw/yagl/yagl_gles_driver.c
hw/yagl/yagl_gles_driver.h
hw/yagl/yagl_log.h
hw/yagl/yagl_mem.c
hw/yagl/yagl_mem.h
hw/yagl/yagl_object_map.h
hw/yagl/yagl_process.c
hw/yagl/yagl_server.c
hw/yagl/yagl_thread.c
hw/yagl/yagl_thread.h
hw/yagl/yagl_transport.c
hw/yagl/yagl_transport.h
hw/yagl/yagl_types.h

index bf11c0a..64547b1 100644 (file)
@@ -41,18 +41,18 @@ struct yagl_api_ps
 {
     struct yagl_api *api;
 
-    void (*thread_init)(struct yagl_api_ps */*api_ps*/);
+    void (*thread_init)(struct yagl_thread_state */*ts*/, struct yagl_api_ps */*api_ps*/);
 
-    void (*batch_start)(struct yagl_api_ps */*api_ps*/);
+    void (*batch_start)(struct yagl_thread_state */*ts*/, struct yagl_api_ps */*api_ps*/);
 
     yagl_api_func (*get_func)(struct yagl_api_ps */*api_ps*/,
                               uint32_t /*func_id*/);
 
-    void (*batch_end)(struct yagl_api_ps */*api_ps*/);
+    void (*batch_end)(struct yagl_thread_state */*ts*/, struct yagl_api_ps */*api_ps*/);
 
-    void (*thread_fini)(struct yagl_api_ps */*api_ps*/);
+    void (*thread_fini)(struct yagl_thread_state */*ts*/, struct yagl_api_ps */*api_ps*/);
 
-    void (*destroy)(struct yagl_api_ps */*api_ps*/);
+    void (*destroy)(struct yagl_thread_state */*ts*/, struct yagl_api_ps */*api_ps*/);
 };
 
 void yagl_api_ps_init(struct yagl_api_ps *api_ps,
@@ -70,7 +70,7 @@ void yagl_api_ps_cleanup(struct yagl_api_ps *api_ps);
 
 struct yagl_api
 {
-    struct yagl_api_ps *(*process_init)(struct yagl_api */*api*/);
+    struct yagl_api_ps *(*process_init)(struct yagl_process_state *ps, struct yagl_api */*api*/);
 
     void (*destroy)(struct yagl_api */*api*/);
 };
index ab10cae..1733dfc 100644 (file)
@@ -40,8 +40,6 @@ void yagl_egl_api_ps_init(struct yagl_egl_api_ps *egl_api_ps,
     egl_api_ps->backend = backend;
     egl_api_ps->egl_iface = egl_iface;
 
-    yagl_process_register_egl_interface(cur_ts->ps, egl_api_ps->egl_iface);
-
     QLIST_INIT(&egl_api_ps->displays);
 }
 
@@ -55,8 +53,6 @@ void yagl_egl_api_ps_cleanup(struct yagl_egl_api_ps *egl_api_ps)
     }
 
     assert(QLIST_EMPTY(&egl_api_ps->displays));
-
-    yagl_process_unregister_egl_interface(cur_ts->ps);
 }
 
 struct yagl_egl_display *yagl_egl_api_ps_display_get(struct yagl_egl_api_ps *egl_api_ps,
@@ -73,7 +69,8 @@ struct yagl_egl_display *yagl_egl_api_ps_display_get(struct yagl_egl_api_ps *egl
     return NULL;
 }
 
-struct yagl_egl_display *yagl_egl_api_ps_display_add(struct yagl_egl_api_ps *egl_api_ps,
+struct yagl_egl_display *yagl_egl_api_ps_display_add(struct yagl_thread_state *cur_ts,
+                                                     struct yagl_egl_api_ps *egl_api_ps,
                                                      uint32_t display_id)
 {
     struct yagl_egl_display *dpy;
@@ -84,7 +81,7 @@ struct yagl_egl_display *yagl_egl_api_ps_display_add(struct yagl_egl_api_ps *egl
         }
     }
 
-    dpy = yagl_egl_display_create(egl_api_ps->backend, display_id);
+    dpy = yagl_egl_display_create(cur_ts, egl_api_ps->backend, display_id);
 
     if (!dpy) {
         return NULL;
index f963540..8a3563a 100644 (file)
@@ -57,7 +57,8 @@ void yagl_egl_api_ps_cleanup(struct yagl_egl_api_ps *egl_api_ps);
 struct yagl_egl_display *yagl_egl_api_ps_display_get(struct yagl_egl_api_ps *egl_api_ps,
                                                      yagl_host_handle handle);
 
-struct yagl_egl_display *yagl_egl_api_ps_display_add(struct yagl_egl_api_ps *egl_api_ps,
+struct yagl_egl_display *yagl_egl_api_ps_display_add(struct yagl_thread_state *cur_ts,
+                                                     struct yagl_egl_api_ps *egl_api_ps,
                                                      uint32_t display_id);
 
 #endif
index 0b938d0..7af8eef 100644 (file)
@@ -33,7 +33,8 @@
 #include "yagl_eglb_context.h"
 #include "yagl_egl_backend.h"
 
-void yagl_egl_api_ts_init(struct yagl_egl_api_ts *egl_api_ts,
+void yagl_egl_api_ts_init(struct yagl_thread_state *cur_ts,
+                          struct yagl_egl_api_ts *egl_api_ts,
                           struct yagl_egl_api_ps *api_ps)
 {
     egl_api_ts->api_ps = api_ps;
@@ -43,13 +44,14 @@ void yagl_egl_api_ts_init(struct yagl_egl_api_ts *egl_api_ts,
     yagl_egl_api_ts_reset(egl_api_ts);
 }
 
-void yagl_egl_api_ts_cleanup(struct yagl_egl_api_ts *egl_api_ts)
+void yagl_egl_api_ts_cleanup(struct yagl_thread_state *cur_ts,
+                             struct yagl_egl_api_ts *egl_api_ts)
 {
     if (egl_api_ts->context) {
         /*
          * Force release current.
          */
-        egl_api_ts->backend->release_current(egl_api_ts->backend, true);
+        egl_api_ts->backend->release_current(cur_ts, egl_api_ts->backend, true);
 
         yagl_egl_context_update_surfaces(egl_api_ts->context, NULL, NULL);
     }
index 86b6bc0..ba3d04a 100644 (file)
@@ -54,10 +54,12 @@ struct yagl_egl_api_ts
     struct yagl_egl_context *context;
 };
 
-void yagl_egl_api_ts_init(struct yagl_egl_api_ts *egl_api_ts,
+void yagl_egl_api_ts_init(struct yagl_thread_state *cur_ts,
+                          struct yagl_egl_api_ts *egl_api_ts,
                           struct yagl_egl_api_ps *api_ps);
 
-void yagl_egl_api_ts_cleanup(struct yagl_egl_api_ts *egl_api_ts);
+void yagl_egl_api_ts_cleanup(struct yagl_thread_state *cur_ts,
+                             struct yagl_egl_api_ts *egl_api_ts);
 
 void yagl_egl_api_ts_update_context(struct yagl_egl_api_ts *egl_api_ts,
                                     struct yagl_egl_context *ctx);
index 8f114da..52aa00d 100644 (file)
@@ -42,6 +42,7 @@
  */
 static void yagl_func_eglGetDisplay(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     uint32_t display_id;
     EGLint *error;
     yagl_host_handle *retval;
@@ -49,7 +50,7 @@ static void yagl_func_eglGetDisplay(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(eglGetDisplay, uint32_t, void*, display_id, error);
-    *retval = yagl_host_eglGetDisplay(display_id, error);
+    *retval = yagl_host_eglGetDisplay(cur_ts, display_id, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -58,6 +59,7 @@ static void yagl_func_eglGetDisplay(struct yagl_transport *t)
  */
 static void yagl_func_eglInitialize(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     EGLint *major;
     EGLint *minor;
@@ -69,7 +71,7 @@ static void yagl_func_eglInitialize(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT4(eglInitialize, yagl_host_handle, void*, void*, void*, dpy, major, minor, error);
-    *retval = yagl_host_eglInitialize(dpy, major, minor, error);
+    *retval = yagl_host_eglInitialize(cur_ts, dpy, major, minor, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -78,6 +80,7 @@ static void yagl_func_eglInitialize(struct yagl_transport *t)
  */
 static void yagl_func_eglTerminate(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     EGLint *error;
     EGLBoolean *retval;
@@ -85,7 +88,7 @@ static void yagl_func_eglTerminate(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(eglTerminate, yagl_host_handle, void*, dpy, error);
-    *retval = yagl_host_eglTerminate(dpy, error);
+    *retval = yagl_host_eglTerminate(cur_ts, dpy, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -94,6 +97,7 @@ static void yagl_func_eglTerminate(struct yagl_transport *t)
  */
 static void yagl_func_eglGetConfigs(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle *configs;
     int32_t configs_maxcount;
@@ -106,7 +110,7 @@ static void yagl_func_eglGetConfigs(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT3(eglGetConfigs, yagl_host_handle, void*, void*, dpy, configs, error);
     *configs_count = 0;
-    *retval = yagl_host_eglGetConfigs(dpy, configs, configs_maxcount, configs_count, error);
+    *retval = yagl_host_eglGetConfigs(cur_ts, dpy, configs, configs_maxcount, configs_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -115,6 +119,7 @@ static void yagl_func_eglGetConfigs(struct yagl_transport *t)
  */
 static void yagl_func_eglChooseConfig(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     const EGLint *attrib_list;
     int32_t attrib_list_count;
@@ -130,7 +135,7 @@ static void yagl_func_eglChooseConfig(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT4(eglChooseConfig, yagl_host_handle, void*, void*, void*, dpy, attrib_list, configs, error);
     *configs_count = 0;
-    *retval = yagl_host_eglChooseConfig(dpy, attrib_list, attrib_list_count, configs, configs_maxcount, configs_count, error);
+    *retval = yagl_host_eglChooseConfig(cur_ts, dpy, attrib_list, attrib_list_count, configs, configs_maxcount, configs_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -139,6 +144,7 @@ static void yagl_func_eglChooseConfig(struct yagl_transport *t)
  */
 static void yagl_func_eglGetConfigAttrib(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     EGLint attribute;
@@ -152,7 +158,7 @@ static void yagl_func_eglGetConfigAttrib(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglGetConfigAttrib, yagl_host_handle, yagl_host_handle, EGLint, void*, void*, dpy, config, attribute, value, error);
-    *retval = yagl_host_eglGetConfigAttrib(dpy, config, attribute, value, error);
+    *retval = yagl_host_eglGetConfigAttrib(cur_ts, dpy, config, attribute, value, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -161,6 +167,7 @@ static void yagl_func_eglGetConfigAttrib(struct yagl_transport *t)
  */
 static void yagl_func_eglDestroySurface(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     EGLint *error;
@@ -170,7 +177,7 @@ static void yagl_func_eglDestroySurface(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT3(eglDestroySurface, yagl_host_handle, yagl_host_handle, void*, dpy, surface, error);
-    *retval = yagl_host_eglDestroySurface(dpy, surface, error);
+    *retval = yagl_host_eglDestroySurface(cur_ts, dpy, surface, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -179,6 +186,7 @@ static void yagl_func_eglDestroySurface(struct yagl_transport *t)
  */
 static void yagl_func_eglQuerySurface(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     EGLint attribute;
@@ -192,7 +200,7 @@ static void yagl_func_eglQuerySurface(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglQuerySurface, yagl_host_handle, yagl_host_handle, EGLint, void*, void*, dpy, surface, attribute, value, error);
-    *retval = yagl_host_eglQuerySurface(dpy, surface, attribute, value, error);
+    *retval = yagl_host_eglQuerySurface(cur_ts, dpy, surface, attribute, value, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -201,6 +209,7 @@ static void yagl_func_eglQuerySurface(struct yagl_transport *t)
  */
 static void yagl_func_eglBindAPI(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     EGLenum api;
     api = yagl_transport_get_out_EGLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(eglBindAPI, EGLenum, api);
@@ -213,8 +222,9 @@ static void yagl_func_eglBindAPI(struct yagl_transport *t)
  */
 static void yagl_func_eglWaitClient(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(eglWaitClient);
-    (void)yagl_host_eglWaitClient();
+    (void)yagl_host_eglWaitClient(t->ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -223,12 +233,13 @@ static void yagl_func_eglWaitClient(struct yagl_transport *t)
  */
 static void yagl_func_eglReleaseThread(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     EGLint *error;
     EGLBoolean *retval;
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT1(eglReleaseThread, void*, error);
-    *retval = yagl_host_eglReleaseThread(error);
+    *retval = yagl_host_eglReleaseThread(t->ts, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -237,6 +248,7 @@ static void yagl_func_eglReleaseThread(struct yagl_transport *t)
  */
 static void yagl_func_eglSurfaceAttrib(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     EGLint attribute;
@@ -250,7 +262,7 @@ static void yagl_func_eglSurfaceAttrib(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglSurfaceAttrib, yagl_host_handle, yagl_host_handle, EGLint, EGLint, void*, dpy, surface, attribute, value, error);
-    *retval = yagl_host_eglSurfaceAttrib(dpy, surface, attribute, value, error);
+    *retval = yagl_host_eglSurfaceAttrib(cur_ts, dpy, surface, attribute, value, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -259,6 +271,7 @@ static void yagl_func_eglSurfaceAttrib(struct yagl_transport *t)
  */
 static void yagl_func_eglCreateContext(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     yagl_host_handle share_context;
@@ -273,7 +286,7 @@ static void yagl_func_eglCreateContext(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglCreateContext, yagl_host_handle, yagl_host_handle, yagl_host_handle, void*, void*, dpy, config, share_context, attrib_list, error);
-    *retval = yagl_host_eglCreateContext(dpy, config, share_context, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreateContext(cur_ts, dpy, config, share_context, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -282,6 +295,7 @@ static void yagl_func_eglCreateContext(struct yagl_transport *t)
  */
 static void yagl_func_eglDestroyContext(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle ctx;
     EGLint *error;
@@ -291,7 +305,7 @@ static void yagl_func_eglDestroyContext(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT3(eglDestroyContext, yagl_host_handle, yagl_host_handle, void*, dpy, ctx, error);
-    *retval = yagl_host_eglDestroyContext(dpy, ctx, error);
+    *retval = yagl_host_eglDestroyContext(cur_ts, dpy, ctx, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -300,6 +314,7 @@ static void yagl_func_eglDestroyContext(struct yagl_transport *t)
  */
 static void yagl_func_eglMakeCurrent(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle draw;
     yagl_host_handle read;
@@ -309,7 +324,7 @@ static void yagl_func_eglMakeCurrent(struct yagl_transport *t)
     read = yagl_transport_get_out_yagl_host_handle(t);
     ctx = yagl_transport_get_out_yagl_host_handle(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(eglMakeCurrent, yagl_host_handle, yagl_host_handle, yagl_host_handle, yagl_host_handle, dpy, draw, read, ctx);
-    (void)yagl_host_eglMakeCurrent(dpy, draw, read, ctx);
+    (void)yagl_host_eglMakeCurrent(cur_ts, dpy, draw, read, ctx);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -318,6 +333,7 @@ static void yagl_func_eglMakeCurrent(struct yagl_transport *t)
  */
 static void yagl_func_eglQueryContext(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle ctx;
     EGLint attribute;
@@ -331,7 +347,7 @@ static void yagl_func_eglQueryContext(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglQueryContext, yagl_host_handle, yagl_host_handle, EGLint, void*, void*, dpy, ctx, attribute, value, error);
-    *retval = yagl_host_eglQueryContext(dpy, ctx, attribute, value, error);
+    *retval = yagl_host_eglQueryContext(cur_ts, dpy, ctx, attribute, value, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -340,12 +356,13 @@ static void yagl_func_eglQueryContext(struct yagl_transport *t)
  */
 static void yagl_func_eglSwapBuffers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     dpy = yagl_transport_get_out_yagl_host_handle(t);
     surface = yagl_transport_get_out_yagl_host_handle(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(eglSwapBuffers, yagl_host_handle, yagl_host_handle, dpy, surface);
-    (void)yagl_host_eglSwapBuffers(dpy, surface);
+    (void)yagl_host_eglSwapBuffers(cur_ts, dpy, surface);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -354,12 +371,13 @@ static void yagl_func_eglSwapBuffers(struct yagl_transport *t)
  */
 static void yagl_func_eglCopyBuffers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     dpy = yagl_transport_get_out_yagl_host_handle(t);
     surface = yagl_transport_get_out_yagl_host_handle(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(eglCopyBuffers, yagl_host_handle, yagl_host_handle, dpy, surface);
-    (void)yagl_host_eglCopyBuffers(dpy, surface);
+    (void)yagl_host_eglCopyBuffers(cur_ts, dpy, surface);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -368,6 +386,7 @@ static void yagl_func_eglCopyBuffers(struct yagl_transport *t)
  */
 static void yagl_func_eglCreateWindowSurfaceOffscreenYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     uint32_t width;
@@ -388,7 +407,7 @@ static void yagl_func_eglCreateWindowSurfaceOffscreenYAGL(struct yagl_transport
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT8(eglCreateWindowSurfaceOffscreenYAGL, yagl_host_handle, yagl_host_handle, uint32_t, uint32_t, uint32_t, target_ulong, void*, void*, dpy, config, width, height, bpp, pixels, attrib_list, error);
-    *retval = yagl_host_eglCreateWindowSurfaceOffscreenYAGL(dpy, config, width, height, bpp, pixels, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreateWindowSurfaceOffscreenYAGL(cur_ts, dpy, config, width, height, bpp, pixels, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -397,6 +416,7 @@ static void yagl_func_eglCreateWindowSurfaceOffscreenYAGL(struct yagl_transport
  */
 static void yagl_func_eglCreatePbufferSurfaceOffscreenYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     uint32_t width;
@@ -417,7 +437,7 @@ static void yagl_func_eglCreatePbufferSurfaceOffscreenYAGL(struct yagl_transport
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT8(eglCreatePbufferSurfaceOffscreenYAGL, yagl_host_handle, yagl_host_handle, uint32_t, uint32_t, uint32_t, target_ulong, void*, void*, dpy, config, width, height, bpp, pixels, attrib_list, error);
-    *retval = yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(dpy, config, width, height, bpp, pixels, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(cur_ts, dpy, config, width, height, bpp, pixels, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -426,6 +446,7 @@ static void yagl_func_eglCreatePbufferSurfaceOffscreenYAGL(struct yagl_transport
  */
 static void yagl_func_eglCreatePixmapSurfaceOffscreenYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     uint32_t width;
@@ -446,7 +467,7 @@ static void yagl_func_eglCreatePixmapSurfaceOffscreenYAGL(struct yagl_transport
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT8(eglCreatePixmapSurfaceOffscreenYAGL, yagl_host_handle, yagl_host_handle, uint32_t, uint32_t, uint32_t, target_ulong, void*, void*, dpy, config, width, height, bpp, pixels, attrib_list, error);
-    *retval = yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(dpy, config, width, height, bpp, pixels, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(cur_ts, dpy, config, width, height, bpp, pixels, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -455,6 +476,7 @@ static void yagl_func_eglCreatePixmapSurfaceOffscreenYAGL(struct yagl_transport
  */
 static void yagl_func_eglResizeOffscreenSurfaceYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     uint32_t width;
@@ -472,7 +494,7 @@ static void yagl_func_eglResizeOffscreenSurfaceYAGL(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT7(eglResizeOffscreenSurfaceYAGL, yagl_host_handle, yagl_host_handle, uint32_t, uint32_t, uint32_t, target_ulong, void*, dpy, surface, width, height, bpp, pixels, error);
-    *retval = yagl_host_eglResizeOffscreenSurfaceYAGL(dpy, surface, width, height, bpp, pixels, error);
+    *retval = yagl_host_eglResizeOffscreenSurfaceYAGL(cur_ts, dpy, surface, width, height, bpp, pixels, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
@@ -481,6 +503,7 @@ static void yagl_func_eglResizeOffscreenSurfaceYAGL(struct yagl_transport *t)
  */
 static void yagl_func_eglCreateWindowSurfaceOnscreenYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     yagl_winsys_id win;
@@ -495,7 +518,7 @@ static void yagl_func_eglCreateWindowSurfaceOnscreenYAGL(struct yagl_transport *
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglCreateWindowSurfaceOnscreenYAGL, yagl_host_handle, yagl_host_handle, yagl_winsys_id, void*, void*, dpy, config, win, attrib_list, error);
-    *retval = yagl_host_eglCreateWindowSurfaceOnscreenYAGL(dpy, config, win, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreateWindowSurfaceOnscreenYAGL(cur_ts, dpy, config, win, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -504,6 +527,7 @@ static void yagl_func_eglCreateWindowSurfaceOnscreenYAGL(struct yagl_transport *
  */
 static void yagl_func_eglCreatePbufferSurfaceOnscreenYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     yagl_winsys_id buffer;
@@ -518,7 +542,7 @@ static void yagl_func_eglCreatePbufferSurfaceOnscreenYAGL(struct yagl_transport
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglCreatePbufferSurfaceOnscreenYAGL, yagl_host_handle, yagl_host_handle, yagl_winsys_id, void*, void*, dpy, config, buffer, attrib_list, error);
-    *retval = yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(dpy, config, buffer, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(cur_ts, dpy, config, buffer, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -527,6 +551,7 @@ static void yagl_func_eglCreatePbufferSurfaceOnscreenYAGL(struct yagl_transport
  */
 static void yagl_func_eglCreatePixmapSurfaceOnscreenYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle config;
     yagl_winsys_id pixmap;
@@ -541,7 +566,7 @@ static void yagl_func_eglCreatePixmapSurfaceOnscreenYAGL(struct yagl_transport *
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT5(eglCreatePixmapSurfaceOnscreenYAGL, yagl_host_handle, yagl_host_handle, yagl_winsys_id, void*, void*, dpy, config, pixmap, attrib_list, error);
-    *retval = yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(dpy, config, pixmap, attrib_list, attrib_list_count, error);
+    *retval = yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(cur_ts, dpy, config, pixmap, attrib_list, attrib_list_count, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, *retval);
 }
 
@@ -550,6 +575,7 @@ static void yagl_func_eglCreatePixmapSurfaceOnscreenYAGL(struct yagl_transport *
  */
 static void yagl_func_eglInvalidateOnscreenSurfaceYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     yagl_host_handle dpy;
     yagl_host_handle surface;
     yagl_winsys_id buffer;
@@ -557,7 +583,7 @@ static void yagl_func_eglInvalidateOnscreenSurfaceYAGL(struct yagl_transport *t)
     surface = yagl_transport_get_out_yagl_host_handle(t);
     buffer = yagl_transport_get_out_yagl_winsys_id(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(eglInvalidateOnscreenSurfaceYAGL, yagl_host_handle, yagl_host_handle, yagl_winsys_id, dpy, surface, buffer);
-    (void)yagl_host_eglInvalidateOnscreenSurfaceYAGL(dpy, surface, buffer);
+    (void)yagl_host_eglInvalidateOnscreenSurfaceYAGL(cur_ts, dpy, surface, buffer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -566,6 +592,7 @@ static void yagl_func_eglInvalidateOnscreenSurfaceYAGL(struct yagl_transport *t)
  */
 static void yagl_func_eglCreateImageYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     uint32_t texture;
     yagl_host_handle dpy;
     yagl_winsys_id buffer;
@@ -577,7 +604,7 @@ static void yagl_func_eglCreateImageYAGL(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&error);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT4(eglCreateImageYAGL, uint32_t, yagl_host_handle, yagl_winsys_id, void*, texture, dpy, buffer, error);
-    *retval = yagl_host_eglCreateImageYAGL(texture, dpy, buffer, error);
+    *retval = yagl_host_eglCreateImageYAGL(cur_ts, texture, dpy, buffer, error);
     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, *retval);
 }
 
index 467d521..c4d5db9 100644 (file)
@@ -51,7 +51,8 @@ static void yagl_egl_context_destroy(struct yagl_ref *ref)
 }
 
 struct yagl_egl_context
-    *yagl_egl_context_create(struct yagl_egl_display *dpy,
+    *yagl_egl_context_create(struct yagl_thread_state *cur_ts,
+                             struct yagl_egl_display *dpy,
                              struct yagl_egl_config *cfg,
                              struct yagl_eglb_context *backend_share_ctx,
                              int version)
@@ -59,7 +60,8 @@ struct yagl_egl_context
     struct yagl_eglb_context *backend_ctx;
     struct yagl_egl_context *ctx;
 
-    backend_ctx = dpy->backend_dpy->create_context(dpy->backend_dpy,
+    backend_ctx = dpy->backend_dpy->create_context(cur_ts,
+                                                   dpy->backend_dpy,
                                                    &cfg->native,
                                                    backend_share_ctx,
                                                    version);
index 1a6a939..762f633 100644 (file)
@@ -57,7 +57,8 @@ struct yagl_egl_context
  * Takes ownership of 'client_ctx'.
  */
 struct yagl_egl_context
-    *yagl_egl_context_create(struct yagl_egl_display *dpy,
+    *yagl_egl_context_create(struct yagl_thread_state *cur_ts,
+                             struct yagl_egl_display *dpy,
                              struct yagl_egl_config *cfg,
                              struct yagl_eglb_context *backend_share_ctx,
                              int version);
index 11fed52..1557fca 100644 (file)
@@ -39,7 +39,8 @@
 #include "yagl_handle_gen.h"
 
 struct yagl_egl_display
-    *yagl_egl_display_create(struct yagl_egl_backend *backend,
+    *yagl_egl_display_create(struct yagl_thread_state *cur_ts,
+                             struct yagl_egl_backend *backend,
                              uint32_t display_id)
 {
     struct yagl_eglb_display *backend_dpy;
@@ -80,7 +81,7 @@ void yagl_egl_display_destroy(struct yagl_egl_display *dpy)
     g_free(dpy);
 }
 
-void yagl_egl_display_initialize(struct yagl_egl_display *dpy)
+void yagl_egl_display_initialize(struct yagl_thread_state *cur_ts, struct yagl_egl_display *dpy)
 {
     struct yagl_egl_config **cfgs;
     int i, num_configs = 0;
index 182af02..ffc06ec 100644 (file)
@@ -64,12 +64,14 @@ struct yagl_egl_display
 };
 
 struct yagl_egl_display
-    *yagl_egl_display_create(struct yagl_egl_backend *backend,
+    *yagl_egl_display_create(struct yagl_thread_state *cur_ts,
+                             struct yagl_egl_backend *backend,
                              uint32_t display_id);
 
 void yagl_egl_display_destroy(struct yagl_egl_display *dpy);
 
-void yagl_egl_display_initialize(struct yagl_egl_display *dpy);
+void yagl_egl_display_initialize(struct yagl_thread_state *cur_ts,
+                                 struct yagl_egl_display *dpy);
 
 bool yagl_egl_display_is_initialized(struct yagl_egl_display *dpy);
 
index e52ab90..1c2849b 100644 (file)
@@ -69,6 +69,7 @@ struct yagl_egl_interface_impl
     struct yagl_egl_backend *backend;
 };
 
+// TODO remove and pass via argument
 static YAGL_DEFINE_TLS(struct yagl_egl_api_ts*, egl_api_ts);
 
 static uint32_t yagl_egl_get_ctx_id(struct yagl_egl_interface *iface)
@@ -100,7 +101,8 @@ static void yagl_egl_unensure_ctx(struct yagl_egl_interface *iface, uint32_t ctx
     }
 }
 
-static __inline bool yagl_validate_display(yagl_host_handle dpy_,
+static __inline bool yagl_validate_display(struct yagl_thread_state *cur_ts,
+                                           yagl_host_handle dpy_,
                                            struct yagl_egl_display **dpy,
                                            EGLint *error)
 {
@@ -121,7 +123,8 @@ static __inline bool yagl_validate_display(yagl_host_handle dpy_,
     return true;
 }
 
-static __inline bool yagl_validate_config(struct yagl_egl_display *dpy,
+static __inline bool yagl_validate_config(struct yagl_thread_state *cur_ts,
+                                          struct yagl_egl_display *dpy,
                                           yagl_host_handle cfg_,
                                           struct yagl_egl_config **cfg,
                                           EGLint *error)
@@ -138,7 +141,8 @@ static __inline bool yagl_validate_config(struct yagl_egl_display *dpy,
     return true;
 }
 
-static __inline bool yagl_validate_surface(struct yagl_egl_display *dpy,
+static __inline bool yagl_validate_surface(struct yagl_thread_state *cur_ts,
+                                           struct yagl_egl_display *dpy,
                                            yagl_host_handle sfc_,
                                            struct yagl_egl_surface **sfc,
                                            EGLint *error)
@@ -155,7 +159,8 @@ static __inline bool yagl_validate_surface(struct yagl_egl_display *dpy,
     return true;
 }
 
-static __inline bool yagl_validate_context(struct yagl_egl_display *dpy,
+static __inline bool yagl_validate_context(struct yagl_thread_state *cur_ts,
+                                           struct yagl_egl_display *dpy,
                                            yagl_host_handle ctx_,
                                            struct yagl_egl_context **ctx,
                                            EGLint *error)
@@ -172,13 +177,13 @@ static __inline bool yagl_validate_context(struct yagl_egl_display *dpy,
     return true;
 }
 
-static bool yagl_egl_release_current_context(struct yagl_egl_display *dpy)
+static bool yagl_egl_release_current_context(struct yagl_thread_state *cur_ts, struct yagl_egl_display *dpy)
 {
     if (!egl_api_ts->context) {
         return true;
     }
 
-    if (!egl_api_ts->backend->release_current(egl_api_ts->backend, false)) {
+    if (!egl_api_ts->backend->release_current(cur_ts, egl_api_ts->backend, false)) {
         return false;
     }
 
@@ -199,62 +204,64 @@ static yagl_api_func yagl_host_egl_get_func(struct yagl_api_ps *api_ps,
     }
 }
 
-static void yagl_host_egl_thread_init(struct yagl_api_ps *api_ps)
+static void yagl_host_egl_thread_init(struct yagl_thread_state *cur_ts, struct yagl_api_ps *api_ps)
 {
     struct yagl_egl_api_ps *egl_api_ps = (struct yagl_egl_api_ps*)api_ps;
 
     YAGL_LOG_FUNC_ENTER(yagl_host_egl_thread_init, NULL);
 
-    egl_api_ps->backend->thread_init(egl_api_ps->backend);
+    egl_api_ps->backend->thread_init(cur_ts, egl_api_ps->backend);
 
     egl_api_ts = g_malloc0(sizeof(*egl_api_ts));
 
-    yagl_egl_api_ts_init(egl_api_ts, egl_api_ps);
+    yagl_egl_api_ts_init(cur_ts, egl_api_ts, egl_api_ps);
 
     cur_ts->egl_api_ts = egl_api_ts;
 
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_host_egl_batch_start(struct yagl_api_ps *api_ps)
+static void yagl_host_egl_batch_start(struct yagl_thread_state *cur_ts, struct yagl_api_ps *api_ps)
 {
     struct yagl_egl_api_ps *egl_api_ps = (struct yagl_egl_api_ps*)api_ps;
 
+    // TODO also remove
     egl_api_ts = cur_ts->egl_api_ts;
 
-    egl_api_ps->backend->batch_start(egl_api_ps->backend);
+    egl_api_ps->backend->batch_start(cur_ts, egl_api_ps->backend);
 }
 
-static void yagl_host_egl_batch_end(struct yagl_api_ps *api_ps)
+static void yagl_host_egl_batch_end(struct yagl_thread_state *cur_ts, struct yagl_api_ps *api_ps)
 {
     struct yagl_egl_api_ps *egl_api_ps = (struct yagl_egl_api_ps*)api_ps;
 
-    egl_api_ps->backend->batch_end(egl_api_ps->backend);
+    egl_api_ps->backend->batch_end(cur_ts, egl_api_ps->backend);
 }
 
-static void yagl_host_egl_thread_fini(struct yagl_api_ps *api_ps)
+static void yagl_host_egl_thread_fini(struct yagl_thread_state *cur_ts, struct yagl_api_ps *api_ps)
 {
     struct yagl_egl_api_ps *egl_api_ps = (struct yagl_egl_api_ps*)api_ps;
 
     YAGL_LOG_FUNC_ENTER(yagl_host_egl_thread_fini, NULL);
 
+    // TODO also remove
     egl_api_ts = cur_ts->egl_api_ts;
 
-    egl_api_ps->backend->batch_start(egl_api_ps->backend);
+    egl_api_ps->backend->batch_start(cur_ts, egl_api_ps->backend);
 
-    yagl_egl_api_ts_cleanup(egl_api_ts);
+    yagl_egl_api_ts_cleanup(cur_ts, egl_api_ts);
 
     g_free(egl_api_ts);
 
     egl_api_ts = cur_ts->egl_api_ts = NULL;
 
-    egl_api_ps->backend->batch_end(egl_api_ps->backend);
-    egl_api_ps->backend->thread_fini(egl_api_ps->backend);
+    egl_api_ps->backend->batch_end(cur_ts, egl_api_ps->backend);
+    egl_api_ps->backend->thread_fini(cur_ts, egl_api_ps->backend);
 
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_host_egl_process_destroy(struct yagl_api_ps *api_ps)
+static void yagl_host_egl_process_destroy(struct yagl_thread_state *cur_ts, struct yagl_api_ps *api_ps)
 {
     struct yagl_egl_api_ps *egl_api_ps = (struct yagl_egl_api_ps*)api_ps;
 
@@ -262,6 +269,8 @@ static void yagl_host_egl_process_destroy(struct yagl_api_ps *api_ps)
 
     yagl_egl_api_ps_cleanup(egl_api_ps);
 
+    yagl_process_unregister_egl_interface(cur_ts->ps);
+
     g_free(egl_api_ps->egl_iface);
 
     yagl_api_ps_cleanup(&egl_api_ps->base);
@@ -271,11 +280,12 @@ static void yagl_host_egl_process_destroy(struct yagl_api_ps *api_ps)
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-struct yagl_api_ps *yagl_host_egl_process_init(struct yagl_api *api)
+struct yagl_api_ps *yagl_host_egl_process_init(struct yagl_process_state *ps, struct yagl_api *api)
 {
     struct yagl_egl_api *egl_api = (struct yagl_egl_api*)api;
     struct yagl_egl_interface_impl *egl_iface;
     struct yagl_egl_api_ps *egl_api_ps;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_host_egl_process_init, NULL);
 
@@ -307,22 +317,26 @@ struct yagl_api_ps *yagl_host_egl_process_init(struct yagl_api *api)
 
     yagl_egl_api_ps_init(egl_api_ps, egl_api->backend, &egl_iface->base);
 
+    yagl_process_register_egl_interface(ps, egl_api_ps->egl_iface);
+
     YAGL_LOG_FUNC_EXIT(NULL);
 
     return &egl_api_ps->base;
 }
 
-yagl_host_handle yagl_host_eglGetDisplay(uint32_t display_id,
+yagl_host_handle yagl_host_eglGetDisplay(struct yagl_thread_state *cur_ts,
+    uint32_t display_id,
     EGLint *error)
 {
     struct yagl_egl_display *dpy;
 
-    dpy = yagl_egl_api_ps_display_add(egl_api_ts->api_ps, display_id);
+    dpy = yagl_egl_api_ps_display_add(cur_ts, egl_api_ts->api_ps, display_id);
 
     return (dpy ? dpy->handle : 0);
 }
 
-EGLBoolean yagl_host_eglInitialize(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglInitialize(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     EGLint *major,
     EGLint *minor,
     EGLint *error)
@@ -338,7 +352,7 @@ EGLBoolean yagl_host_eglInitialize(yagl_host_handle dpy_,
         return EGL_FALSE;
     }
 
-    yagl_egl_display_initialize(dpy);
+    yagl_egl_display_initialize(cur_ts, dpy);
 
     if (major) {
         *major = YAGL_EGL_VERSION_MAJOR;
@@ -351,12 +365,13 @@ EGLBoolean yagl_host_eglInitialize(yagl_host_handle dpy_,
     return EGL_TRUE;
 }
 
-EGLBoolean yagl_host_eglTerminate(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglTerminate(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     EGLint *error)
 {
     struct yagl_egl_display *dpy = NULL;
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         return EGL_FALSE;
     }
 
@@ -365,13 +380,13 @@ EGLBoolean yagl_host_eglTerminate(yagl_host_handle dpy_,
     return EGL_TRUE;
 }
 
-EGLBoolean yagl_host_eglGetConfigs(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglGetConfigs(struct yagl_thread_state *cur_ts, yagl_host_handle dpy_,
     yagl_host_handle *configs, int32_t configs_maxcount, int32_t *configs_count,
     EGLint *error)
 {
     struct yagl_egl_display *dpy = NULL;
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         return EGL_FALSE;
     }
 
@@ -385,7 +400,7 @@ EGLBoolean yagl_host_eglGetConfigs(yagl_host_handle dpy_,
     return EGL_TRUE;
 }
 
-EGLBoolean yagl_host_eglChooseConfig(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglChooseConfig(struct yagl_thread_state *cur_ts, yagl_host_handle dpy_,
     const EGLint *attrib_list, int32_t attrib_list_count,
     yagl_host_handle *configs, int32_t configs_maxcount, int32_t *configs_count,
     EGLint *error)
@@ -399,7 +414,7 @@ EGLBoolean yagl_host_eglChooseConfig(yagl_host_handle dpy_,
 
     yagl_egl_native_config_init(&dummy);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
@@ -656,7 +671,8 @@ out:
     return res;
 }
 
-EGLBoolean yagl_host_eglGetConfigAttrib(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglGetConfigAttrib(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     EGLint attribute,
     EGLint *value,
@@ -669,11 +685,11 @@ EGLBoolean yagl_host_eglGetConfigAttrib(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglGetConfigAttrib);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -694,7 +710,8 @@ out:
     return res;
 }
 
-EGLBoolean yagl_host_eglDestroySurface(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglDestroySurface(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_,
     EGLint *error)
 {
@@ -704,11 +721,11 @@ EGLBoolean yagl_host_eglDestroySurface(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglDestroySurface);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, error)) {
         goto out;
     }
 
@@ -725,7 +742,8 @@ out:
     return res;
 }
 
-EGLBoolean yagl_host_eglQuerySurface(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglQuerySurface(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_,
     EGLint attribute,
     EGLint *value,
@@ -738,11 +756,11 @@ EGLBoolean yagl_host_eglQuerySurface(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglQuerySurface);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, error)) {
         goto out;
     }
 
@@ -812,7 +830,8 @@ EGLBoolean yagl_host_eglQuerySurface(yagl_host_handle dpy_,
         }
         break;
     default:
-        if (!surface->backend_sfc->query(surface->backend_sfc,
+        if (!surface->backend_sfc->query(cur_ts,
+                                         surface->backend_sfc,
                                          attribute,
                                          &tmp)) {
             YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
@@ -837,7 +856,7 @@ void yagl_host_eglBindAPI(EGLenum api)
     egl_api_ts->api = api;
 }
 
-void yagl_host_eglWaitClient(void)
+void yagl_host_eglWaitClient(struct yagl_thread_state *cur_ts)
 {
     struct yagl_egl_surface *sfc = NULL;
 
@@ -851,17 +870,18 @@ void yagl_host_eglWaitClient(void)
         return;
     }
 
-    sfc->backend_sfc->wait_gl(sfc->backend_sfc);
+    sfc->backend_sfc->wait_gl(cur_ts,
+                              sfc->backend_sfc);
 }
 
-EGLBoolean yagl_host_eglReleaseThread(EGLint *error)
+EGLBoolean yagl_host_eglReleaseThread(struct yagl_thread_state *cur_ts, EGLint *error)
 {
     EGLBoolean res = EGL_FALSE;
 
     YAGL_LOG_FUNC_SET(eglReleaseThread);
 
     if (egl_api_ts->context) {
-        if (!yagl_egl_release_current_context(egl_api_ts->context->dpy)) {
+        if (!yagl_egl_release_current_context(cur_ts, egl_api_ts->context->dpy)) {
             YAGL_SET_ERR(EGL_BAD_ACCESS);
             goto out;
         }
@@ -875,7 +895,8 @@ out:
     return res;
 }
 
-EGLBoolean yagl_host_eglSurfaceAttrib(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglSurfaceAttrib(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_,
     EGLint attribute,
     EGLint value,
@@ -885,11 +906,11 @@ EGLBoolean yagl_host_eglSurfaceAttrib(yagl_host_handle dpy_,
     struct yagl_egl_display *dpy = NULL;
     struct yagl_egl_surface *surface = NULL;
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, error)) {
         goto out;
     }
 
@@ -905,7 +926,8 @@ out:
     return res;
 }
 
-yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreateContext(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     yagl_host_handle share_context_,
     const EGLint *attrib_list, int32_t attrib_list_count,
@@ -920,11 +942,11 @@ yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglCreateContext);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -945,12 +967,13 @@ yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy_,
     }
 
     if (share_context_) {
-        if (!yagl_validate_context(dpy, share_context_, &share_context, error)) {
+        if (!yagl_validate_context(cur_ts, dpy, share_context_, &share_context, error)) {
             goto out;
         }
     }
 
-    ctx = yagl_egl_context_create(dpy,
+    ctx = yagl_egl_context_create(cur_ts,
+                                  dpy,
                                   config,
                                   (share_context ? share_context->backend_ctx
                                                  : NULL),
@@ -973,7 +996,8 @@ out:
     return res;
 }
 
-EGLBoolean yagl_host_eglDestroyContext(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglDestroyContext(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle ctx_,
     EGLint *error)
 {
@@ -983,11 +1007,11 @@ EGLBoolean yagl_host_eglDestroyContext(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglDestroyContext);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_context(dpy, ctx_, &ctx, error)) {
+    if (!yagl_validate_context(cur_ts, dpy, ctx_, &ctx, error)) {
         goto out;
     }
 
@@ -1003,7 +1027,8 @@ out:
     return res;
 }
 
-void yagl_host_eglMakeCurrent(yagl_host_handle dpy_,
+void yagl_host_eglMakeCurrent(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle draw_,
     yagl_host_handle read_,
     yagl_host_handle ctx_)
@@ -1018,7 +1043,7 @@ void yagl_host_eglMakeCurrent(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglMakeCurrent);
 
-    if (!yagl_validate_display(dpy_, &dpy, &error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, &error)) {
         goto out;
     }
 
@@ -1026,20 +1051,20 @@ void yagl_host_eglMakeCurrent(yagl_host_handle dpy_,
     yagl_egl_context_acquire(prev_ctx);
 
     if (release_context) {
-        if (!yagl_egl_release_current_context(dpy)) {
+        if (!yagl_egl_release_current_context(cur_ts, dpy)) {
             YAGL_LOG_ERROR("cannot release current context");
             goto out;
         }
     } else {
-        if (!yagl_validate_context(dpy, ctx_, &ctx, &error)) {
+        if (!yagl_validate_context(cur_ts, dpy, ctx_, &ctx, &error)) {
             goto out;
         }
 
-        if (draw_ && !yagl_validate_surface(dpy, draw_, &draw, &error)) {
+        if (draw_ && !yagl_validate_surface(cur_ts, dpy, draw_, &draw, &error)) {
             goto out;
         }
 
-        if (read_ && !yagl_validate_surface(dpy, read_, &read, &error)) {
+        if (read_ && !yagl_validate_surface(cur_ts, dpy, read_, &read, &error)) {
             goto out;
         }
 
@@ -1051,7 +1076,8 @@ void yagl_host_eglMakeCurrent(yagl_host_handle dpy_,
             release_context = true;
         }
 
-        if (!egl_api_ts->backend->make_current(egl_api_ts->backend,
+        if (!egl_api_ts->backend->make_current(cur_ts,
+                                               egl_api_ts->backend,
                                                dpy->backend_dpy,
                                                ctx->backend_ctx,
                                                (draw ? draw->backend_sfc : NULL),
@@ -1082,7 +1108,8 @@ out:
     yagl_egl_context_release(prev_ctx);
 }
 
-EGLBoolean yagl_host_eglQueryContext(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglQueryContext(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle ctx_,
     EGLint attribute,
     EGLint *value,
@@ -1094,11 +1121,11 @@ EGLBoolean yagl_host_eglQueryContext(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglQueryContext);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_context(dpy, ctx_, &ctx, error)) {
+    if (!yagl_validate_context(cur_ts, dpy, ctx_, &ctx, error)) {
         goto out;
     }
 
@@ -1145,49 +1172,52 @@ out:
     return res;
 }
 
-void yagl_host_eglSwapBuffers(yagl_host_handle dpy_,
+void yagl_host_eglSwapBuffers(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_)
 {
     EGLint error = 0;
     struct yagl_egl_display *dpy = NULL;
     struct yagl_egl_surface *surface = NULL;
 
-    if (!yagl_validate_display(dpy_, &dpy, &error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, &error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, &error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, &error)) {
         goto out;
     }
 
-    surface->backend_sfc->swap_buffers(surface->backend_sfc);
+    surface->backend_sfc->swap_buffers(cur_ts, surface->backend_sfc);
 
 out:
     yagl_egl_surface_release(surface);
 }
 
-void yagl_host_eglCopyBuffers(yagl_host_handle dpy_,
+void yagl_host_eglCopyBuffers(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_)
 {
     EGLint error = 0;
     struct yagl_egl_display *dpy = NULL;
     struct yagl_egl_surface *surface = NULL;
 
-    if (!yagl_validate_display(dpy_, &dpy, &error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, &error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, &error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, &error)) {
         goto out;
     }
 
-    surface->backend_sfc->copy_buffers(surface->backend_sfc);
+    surface->backend_sfc->copy_buffers(cur_ts, surface->backend_sfc);
 
 out:
     yagl_egl_surface_release(surface);
 }
 
-yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     uint32_t width,
     uint32_t height,
@@ -1222,11 +1252,11 @@ yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(yagl_host_handle
         }
     }
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -1236,7 +1266,8 @@ yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(yagl_host_handle
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_offscreen_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_offscreen_surface(cur_ts,
+                                                             dpy->backend_dpy,
                                                              &config->native,
                                                              EGL_WINDOW_BIT,
                                                              &attribs,
@@ -1276,7 +1307,8 @@ out:
     return res;
 }
 
-yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     uint32_t width,
     uint32_t height,
@@ -1341,11 +1373,11 @@ yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(yagl_host_handle
         }
     }
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -1355,7 +1387,8 @@ yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(yagl_host_handle
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_offscreen_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_offscreen_surface(cur_ts,
+                                                             dpy->backend_dpy,
                                                              &config->native,
                                                              EGL_PBUFFER_BIT,
                                                              &attribs,
@@ -1395,7 +1428,8 @@ out:
     return res;
 }
 
-yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     uint32_t width,
     uint32_t height,
@@ -1420,11 +1454,11 @@ yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(yagl_host_handle
         goto out;
     }
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -1434,7 +1468,8 @@ yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(yagl_host_handle
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_offscreen_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_offscreen_surface(cur_ts,
+                                                             dpy->backend_dpy,
                                                              &config->native,
                                                              EGL_PIXMAP_BIT,
                                                              &attribs,
@@ -1474,7 +1509,8 @@ out:
     return res;
 }
 
-EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy_,
+EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_,
     uint32_t width,
     uint32_t height,
@@ -1491,11 +1527,11 @@ EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy_,
 
     YAGL_LOG_FUNC_SET(eglResizeOffscreenSurfaceYAGL);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, error)) {
         goto out;
     }
 
@@ -1505,7 +1541,8 @@ EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy_,
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_offscreen_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_offscreen_surface(cur_ts,
+                                                             dpy->backend_dpy,
                                                              &surface->cfg->native,
                                                              surface->backend_sfc->type,
                                                              &surface->backend_sfc->attribs,
@@ -1535,7 +1572,8 @@ EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy_,
         }
     }
 
-    if (!egl_api_ts->backend->make_current(egl_api_ts->backend,
+    if (!egl_api_ts->backend->make_current(cur_ts,
+                                           egl_api_ts->backend,
                                            dpy->backend_dpy,
                                            egl_api_ts->context->backend_ctx,
                                            draw_sfc,
@@ -1545,7 +1583,7 @@ EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy_,
         goto out;
     }
 
-    surface->backend_sfc->replace(surface->backend_sfc, backend_sfc);
+    surface->backend_sfc->replace(cur_ts, surface->backend_sfc, backend_sfc);
 
     backend_sfc = NULL;
 
@@ -1560,7 +1598,8 @@ out:
     return res;
 }
 
-yagl_host_handle yagl_host_eglCreateWindowSurfaceOnscreenYAGL(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreateWindowSurfaceOnscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     yagl_winsys_id win,
     const EGLint *attrib_list, int32_t attrib_list_count,
@@ -1592,11 +1631,11 @@ yagl_host_handle yagl_host_eglCreateWindowSurfaceOnscreenYAGL(yagl_host_handle d
         }
     }
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -1606,7 +1645,8 @@ yagl_host_handle yagl_host_eglCreateWindowSurfaceOnscreenYAGL(yagl_host_handle d
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_onscreen_window_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_onscreen_window_surface(cur_ts,
+                                                                   dpy->backend_dpy,
                                                                    &config->native,
                                                                    &attribs,
                                                                    win);
@@ -1643,7 +1683,8 @@ out:
     return res;
 }
 
-yagl_host_handle yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     yagl_winsys_id buffer,
     const EGLint *attrib_list, int32_t attrib_list_count,
@@ -1705,11 +1746,11 @@ yagl_host_handle yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(yagl_host_handle
         }
     }
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -1719,7 +1760,8 @@ yagl_host_handle yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(yagl_host_handle
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_onscreen_pbuffer_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_onscreen_pbuffer_surface(cur_ts,
+                                                                    dpy->backend_dpy,
                                                                     &config->native,
                                                                     &attribs,
                                                                     buffer);
@@ -1755,7 +1797,8 @@ out:
     return res;
 }
 
-yagl_host_handle yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(yagl_host_handle dpy_,
+yagl_host_handle yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle config_,
     yagl_winsys_id pixmap,
     const EGLint *attrib_list, int32_t attrib_list_count,
@@ -1777,11 +1820,11 @@ yagl_host_handle yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(yagl_host_handle d
         goto out;
     }
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    if (!yagl_validate_config(dpy, config_, &config, error)) {
+    if (!yagl_validate_config(cur_ts, dpy, config_, &config, error)) {
         goto out;
     }
 
@@ -1791,7 +1834,8 @@ yagl_host_handle yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(yagl_host_handle d
         goto out;
     }
 
-    backend_sfc = dpy->backend_dpy->create_onscreen_pixmap_surface(dpy->backend_dpy,
+    backend_sfc = dpy->backend_dpy->create_onscreen_pixmap_surface(cur_ts,
+                                                                   dpy->backend_dpy,
                                                                    &config->native,
                                                                    &attribs,
                                                                    pixmap);
@@ -1828,7 +1872,8 @@ out:
     return res;
 }
 
-void yagl_host_eglInvalidateOnscreenSurfaceYAGL(yagl_host_handle dpy_,
+void yagl_host_eglInvalidateOnscreenSurfaceYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy_,
     yagl_host_handle surface_,
     yagl_winsys_id buffer)
 {
@@ -1836,21 +1881,22 @@ void yagl_host_eglInvalidateOnscreenSurfaceYAGL(yagl_host_handle dpy_,
     struct yagl_egl_display *dpy = NULL;
     struct yagl_egl_surface *surface = NULL;
 
-    if (!yagl_validate_display(dpy_, &dpy, &error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, &error)) {
         goto out;
     }
 
-    if (!yagl_validate_surface(dpy, surface_, &surface, &error)) {
+    if (!yagl_validate_surface(cur_ts, dpy, surface_, &surface, &error)) {
         goto out;
     }
 
-    surface->backend_sfc->invalidate(surface->backend_sfc, buffer);
+    surface->backend_sfc->invalidate(cur_ts, surface->backend_sfc, buffer);
 
 out:
     yagl_egl_surface_release(surface);
 }
 
-EGLBoolean yagl_host_eglCreateImageYAGL(uint32_t texture,
+EGLBoolean yagl_host_eglCreateImageYAGL(struct yagl_thread_state *cur_ts,
+    uint32_t texture,
     yagl_host_handle dpy_,
     yagl_winsys_id buffer,
     EGLint *error)
@@ -1861,11 +1907,11 @@ EGLBoolean yagl_host_eglCreateImageYAGL(uint32_t texture,
 
     YAGL_LOG_FUNC_SET(eglCreateImageYAGL);
 
-    if (!yagl_validate_display(dpy_, &dpy, error)) {
+    if (!yagl_validate_display(cur_ts, dpy_, &dpy, error)) {
         goto out;
     }
 
-    image = dpy->backend_dpy->create_image(dpy->backend_dpy, buffer);
+    image = dpy->backend_dpy->create_image(cur_ts, dpy->backend_dpy, buffer);
 
     if (!image) {
         YAGL_SET_ERR(EGL_BAD_ALLOC);
index e110a91..3a230cc 100644 (file)
 #include "yagl_api.h"
 #include <EGL/egl.h>
 
-struct yagl_api_ps *yagl_host_egl_process_init(struct yagl_api *api);
+struct yagl_api_ps *yagl_host_egl_process_init(struct yagl_process_state *ps, struct yagl_api *api);
 
-yagl_host_handle yagl_host_eglGetDisplay(uint32_t display_id,
+yagl_host_handle yagl_host_eglGetDisplay(struct yagl_thread_state *cur_ts,
+    uint32_t display_id,
     EGLint *error);
-EGLBoolean yagl_host_eglInitialize(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglInitialize(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     EGLint *major,
     EGLint *minor,
     EGLint *error);
-EGLBoolean yagl_host_eglTerminate(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglTerminate(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     EGLint *error);
-EGLBoolean yagl_host_eglGetConfigs(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglGetConfigs(struct yagl_thread_state *cur_ts, yagl_host_handle dpy,
     yagl_host_handle *configs, int32_t configs_maxcount, int32_t *configs_count,
     EGLint *error);
-EGLBoolean yagl_host_eglChooseConfig(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglChooseConfig(struct yagl_thread_state *cur_ts, yagl_host_handle dpy,
     const EGLint *attrib_list, int32_t attrib_list_count,
     yagl_host_handle *configs, int32_t configs_maxcount, int32_t *configs_count,
     EGLint *error);
-EGLBoolean yagl_host_eglGetConfigAttrib(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglGetConfigAttrib(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     EGLint attribute,
     EGLint *value,
     EGLint *error);
-EGLBoolean yagl_host_eglDestroySurface(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglDestroySurface(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface,
     EGLint *error);
-EGLBoolean yagl_host_eglQuerySurface(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglQuerySurface(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface,
     EGLint attribute,
     EGLint *value,
     EGLint *error);
 void yagl_host_eglBindAPI(EGLenum api);
-void yagl_host_eglWaitClient(void);
-EGLBoolean yagl_host_eglReleaseThread(EGLint *error);
-EGLBoolean yagl_host_eglSurfaceAttrib(yagl_host_handle dpy,
+void yagl_host_eglWaitClient(struct yagl_thread_state *cur_ts);
+EGLBoolean yagl_host_eglReleaseThread(struct yagl_thread_state *cur_ts, EGLint *error);
+EGLBoolean yagl_host_eglSurfaceAttrib(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface,
     EGLint attribute,
     EGLint value,
     EGLint *error);
-yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreateContext(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     yagl_host_handle share_context,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-EGLBoolean yagl_host_eglDestroyContext(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglDestroyContext(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle ctx,
     EGLint *error);
-void yagl_host_eglMakeCurrent(yagl_host_handle dpy,
+void yagl_host_eglMakeCurrent(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle draw,
     yagl_host_handle read,
     yagl_host_handle ctx);
-EGLBoolean yagl_host_eglQueryContext(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglQueryContext(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle ctx,
     EGLint attribute,
     EGLint *value,
     EGLint *error);
-void yagl_host_eglSwapBuffers(yagl_host_handle dpy,
+void yagl_host_eglSwapBuffers(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface);
-void yagl_host_eglCopyBuffers(yagl_host_handle dpy,
+void yagl_host_eglCopyBuffers(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface);
-yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     uint32_t width,
     uint32_t height,
@@ -100,7 +114,8 @@ yagl_host_handle yagl_host_eglCreateWindowSurfaceOffscreenYAGL(yagl_host_handle
     target_ulong pixels,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     uint32_t width,
     uint32_t height,
@@ -108,7 +123,8 @@ yagl_host_handle yagl_host_eglCreatePbufferSurfaceOffscreenYAGL(yagl_host_handle
     target_ulong pixels,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     uint32_t width,
     uint32_t height,
@@ -116,32 +132,38 @@ yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(yagl_host_handle
     target_ulong pixels,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy,
+EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface,
     uint32_t width,
     uint32_t height,
     uint32_t bpp,
     target_ulong pixels,
     EGLint *error);
-yagl_host_handle yagl_host_eglCreateWindowSurfaceOnscreenYAGL(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreateWindowSurfaceOnscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     yagl_winsys_id win,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-yagl_host_handle yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreatePbufferSurfaceOnscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     yagl_winsys_id buffer,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-yagl_host_handle yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(yagl_host_handle dpy,
+yagl_host_handle yagl_host_eglCreatePixmapSurfaceOnscreenYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle config,
     yagl_winsys_id pixmap,
     const EGLint *attrib_list, int32_t attrib_list_count,
     EGLint *error);
-void yagl_host_eglInvalidateOnscreenSurfaceYAGL(yagl_host_handle dpy,
+void yagl_host_eglInvalidateOnscreenSurfaceYAGL(struct yagl_thread_state *cur_ts,
+    yagl_host_handle dpy,
     yagl_host_handle surface,
     yagl_winsys_id buffer);
-EGLBoolean yagl_host_eglCreateImageYAGL(uint32_t texture,
+EGLBoolean yagl_host_eglCreateImageYAGL(struct yagl_thread_state *cur_ts,
+    uint32_t texture,
     yagl_host_handle dpy,
     yagl_winsys_id buffer,
     EGLint *error);
index 7285176..e7868cb 100644 (file)
@@ -36,7 +36,8 @@
 #include "yagl_thread.h"
 #include "yagl_log.h"
 
-static GLuint yagl_gles_api_ts_create_shader(struct yagl_gles_driver *driver,
+static GLuint yagl_gles_api_ts_create_shader(struct yagl_thread_state *cur_ts,
+                                             struct yagl_gles_driver *driver,
                                              const char *source,
                                              GLenum type)
 {
@@ -102,7 +103,8 @@ static GLuint yagl_gles_api_ts_create_shader(struct yagl_gles_driver *driver,
  * To (partially) work around the problem we must patch
  * index lookups by UB name.
  */
-static bool yagl_gles_api_ts_broken_ubo_test(struct yagl_gles_driver *driver)
+static bool yagl_gles_api_ts_broken_ubo_test(struct yagl_thread_state *cur_ts,
+                                             struct yagl_gles_driver *driver)
 {
     static const char *vs_source_es3 =
         "#version 300 es\n\n"
@@ -155,7 +157,7 @@ static bool yagl_gles_api_ts_broken_ubo_test(struct yagl_gles_driver *driver)
 
     YAGL_LOG_FUNC_SET(yagl_gles_api_ts_broken_ubo_test);
 
-    vs = yagl_gles_api_ts_create_shader(driver,
+    vs = yagl_gles_api_ts_create_shader(cur_ts, driver,
         ((driver->gl_version == yagl_gl_3_1_es3) ? vs_source_es3 : vs_source_3_2),
         GL_VERTEX_SHADER);
 
@@ -163,7 +165,7 @@ static bool yagl_gles_api_ts_broken_ubo_test(struct yagl_gles_driver *driver)
         goto out1;
     }
 
-    fs = yagl_gles_api_ts_create_shader(driver,
+    fs = yagl_gles_api_ts_create_shader(cur_ts, driver,
         ((driver->gl_version == yagl_gl_3_1_es3) ? fs_source_es3 : fs_source_3_2),
         GL_FRAGMENT_SHADER);
 
@@ -228,7 +230,8 @@ out1:
     return res;
 }
 
-void yagl_gles_api_ts_init(struct yagl_gles_api_ts *gles_api_ts,
+void yagl_gles_api_ts_init(struct yagl_thread_state *cur_ts,
+                           struct yagl_gles_api_ts *gles_api_ts,
                            struct yagl_gles_driver *driver,
                            struct yagl_gles_api_ps *ps)
 {
@@ -242,7 +245,7 @@ void yagl_gles_api_ts_init(struct yagl_gles_api_ts *gles_api_ts,
         return;
     }
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(cur_ts->ps, 0);
 
     if (driver->gl_version > yagl_gl_2) {
         gles_api_ts->api->use_map_buffer_range = true;
@@ -258,22 +261,23 @@ void yagl_gles_api_ts_init(struct yagl_gles_api_ts *gles_api_ts,
     }
 
     if (driver->gl_version >= yagl_gl_3_1_es3) {
-        gles_api_ts->api->broken_ubo = yagl_gles_api_ts_broken_ubo_test(driver);
+        gles_api_ts->api->broken_ubo = yagl_gles_api_ts_broken_ubo_test(cur_ts, driver);
     } else {
         gles_api_ts->api->broken_ubo = false;
     }
 
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(cur_ts->ps, 0);
 
     gles_api_ts->api->checked = true;
 }
 
-void yagl_gles_api_ts_cleanup(struct yagl_gles_api_ts *gles_api_ts)
+void yagl_gles_api_ts_cleanup(struct yagl_thread_state *cur_ts,
+                              struct yagl_gles_api_ts *gles_api_ts)
 {
     if (gles_api_ts->num_arrays > 0) {
         uint32_t i;
 
-        yagl_ensure_ctx(0);
+        yagl_ensure_ctx(cur_ts->ps, 0);
 
         if (gles_api_ts->ebo) {
             gles_api_ts->driver->DeleteBuffers(1, &gles_api_ts->ebo);
@@ -284,7 +288,7 @@ void yagl_gles_api_ts_cleanup(struct yagl_gles_api_ts *gles_api_ts)
                                                &gles_api_ts->arrays[i].vbo);
         }
 
-        yagl_unensure_ctx(0);
+        yagl_unensure_ctx(cur_ts->ps, 0);
     }
 
     g_free(gles_api_ts->arrays);
index 0a881e7..720d536 100644 (file)
@@ -68,10 +68,12 @@ struct yagl_gles_api_ts
     uint32_t ebo_size;
 };
 
-void yagl_gles_api_ts_init(struct yagl_gles_api_ts *gles_api_ts,
+void yagl_gles_api_ts_init(struct yagl_thread_state *cur_ts,
+                           struct yagl_gles_api_ts *gles_api_ts,
                            struct yagl_gles_driver *driver,
                            struct yagl_gles_api_ps *ps);
 
-void yagl_gles_api_ts_cleanup(struct yagl_gles_api_ts *gles_api_ts);
+void yagl_gles_api_ts_cleanup(struct yagl_thread_state *cur_ts,
+                              struct yagl_gles_api_ts *gles_api_ts);
 
 #endif
index 97dcff6..0063c38 100644 (file)
@@ -42,6 +42,7 @@
  */
 static void yagl_func_glDrawArrays(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     GLint first;
     GLsizei count;
@@ -49,7 +50,7 @@ static void yagl_func_glDrawArrays(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     count = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glDrawArrays, GLenum, GLint, GLsizei, mode, first, count);
-    (void)yagl_host_glDrawArrays(mode, first, count);
+    (void)yagl_host_glDrawArrays(cur_ts, mode, first, count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -58,6 +59,7 @@ static void yagl_func_glDrawArrays(struct yagl_transport *t)
  */
 static void yagl_func_glDrawElements(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     GLsizei count;
     GLenum type;
@@ -68,7 +70,7 @@ static void yagl_func_glDrawElements(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, 1, (const void**)&indices, &indices_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glDrawElements, GLenum, GLsizei, GLenum, void*, mode, count, type, indices);
-    (void)yagl_host_glDrawElements(mode, count, type, indices, indices_count);
+    (void)yagl_host_glDrawElements(cur_ts, mode, count, type, indices, indices_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -77,6 +79,7 @@ static void yagl_func_glDrawElements(struct yagl_transport *t)
  */
 static void yagl_func_glReadPixelsData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint x;
     GLint y;
     GLsizei width;
@@ -95,7 +98,7 @@ static void yagl_func_glReadPixelsData(struct yagl_transport *t)
     yagl_transport_get_in_array(t, 1, (void**)&pixels, &pixels_maxcount, &pixels_count);
     YAGL_LOG_FUNC_ENTER_SPLIT7(glReadPixelsData, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void*, x, y, width, height, format, type, pixels);
     *pixels_count = 0;
-    (void)yagl_host_glReadPixelsData(x, y, width, height, format, type, pixels, pixels_maxcount, pixels_count);
+    (void)yagl_host_glReadPixelsData(cur_ts, x, y, width, height, format, type, pixels, pixels_maxcount, pixels_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -104,6 +107,7 @@ static void yagl_func_glReadPixelsData(struct yagl_transport *t)
  */
 static void yagl_func_glReadPixelsOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint x;
     GLint y;
     GLsizei width;
@@ -119,7 +123,7 @@ static void yagl_func_glReadPixelsOffset(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     pixels = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT7(glReadPixelsOffset, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, uintptr_t, x, y, width, height, format, type, pixels);
-    (void)yagl_host_glReadPixelsOffset(x, y, width, height, format, type, pixels);
+    (void)yagl_host_glReadPixelsOffset(cur_ts, x, y, width, height, format, type, pixels);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -128,6 +132,7 @@ static void yagl_func_glReadPixelsOffset(struct yagl_transport *t)
  */
 static void yagl_func_glDrawArraysInstanced(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     GLint start;
     GLsizei count;
@@ -137,7 +142,7 @@ static void yagl_func_glDrawArraysInstanced(struct yagl_transport *t)
     count = yagl_transport_get_out_GLsizei(t);
     primcount = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glDrawArraysInstanced, GLenum, GLint, GLsizei, GLsizei, mode, start, count, primcount);
-    (void)yagl_host_glDrawArraysInstanced(mode, start, count, primcount);
+    (void)yagl_host_glDrawArraysInstanced(cur_ts, mode, start, count, primcount);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -146,6 +151,7 @@ static void yagl_func_glDrawArraysInstanced(struct yagl_transport *t)
  */
 static void yagl_func_glDrawElementsInstanced(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     GLsizei count;
     GLenum type;
@@ -158,7 +164,7 @@ static void yagl_func_glDrawElementsInstanced(struct yagl_transport *t)
     yagl_transport_get_out_array(t, 1, (const void**)&indices, &indices_count);
     primcount = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glDrawElementsInstanced, GLenum, GLsizei, GLenum, void*, GLsizei, mode, count, type, indices, primcount);
-    (void)yagl_host_glDrawElementsInstanced(mode, count, type, indices, indices_count, primcount);
+    (void)yagl_host_glDrawElementsInstanced(cur_ts, mode, count, type, indices, indices_count, primcount);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -167,6 +173,7 @@ static void yagl_func_glDrawElementsInstanced(struct yagl_transport *t)
  */
 static void yagl_func_glDrawRangeElements(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     GLuint start;
     GLuint end;
@@ -181,7 +188,7 @@ static void yagl_func_glDrawRangeElements(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, 1, (const void**)&indices, &indices_count);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glDrawRangeElements, GLenum, GLuint, GLuint, GLsizei, GLenum, void*, mode, start, end, count, type, indices);
-    (void)yagl_host_glDrawRangeElements(mode, start, end, count, type, indices, indices_count);
+    (void)yagl_host_glDrawRangeElements(cur_ts, mode, start, end, count, type, indices, indices_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -190,11 +197,12 @@ static void yagl_func_glDrawRangeElements(struct yagl_transport *t)
  */
 static void yagl_func_glGenVertexArrays(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *arrays;
     int32_t arrays_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&arrays, &arrays_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenVertexArrays, void*, arrays);
-    (void)yagl_host_glGenVertexArrays(arrays, arrays_count);
+    (void)yagl_host_glGenVertexArrays(cur_ts, arrays, arrays_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -203,10 +211,11 @@ static void yagl_func_glGenVertexArrays(struct yagl_transport *t)
  */
 static void yagl_func_glBindVertexArray(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint array;
     array = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glBindVertexArray, GLuint, array);
-    (void)yagl_host_glBindVertexArray(array);
+    (void)yagl_host_glBindVertexArray(cur_ts, array);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -215,10 +224,11 @@ static void yagl_func_glBindVertexArray(struct yagl_transport *t)
  */
 static void yagl_func_glDisableVertexAttribArray(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     index = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDisableVertexAttribArray, GLuint, index);
-    (void)yagl_host_glDisableVertexAttribArray(index);
+    (void)yagl_host_glDisableVertexAttribArray(cur_ts, index);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -227,10 +237,11 @@ static void yagl_func_glDisableVertexAttribArray(struct yagl_transport *t)
  */
 static void yagl_func_glEnableVertexAttribArray(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     index = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glEnableVertexAttribArray, GLuint, index);
-    (void)yagl_host_glEnableVertexAttribArray(index);
+    (void)yagl_host_glEnableVertexAttribArray(cur_ts, index);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -239,6 +250,7 @@ static void yagl_func_glEnableVertexAttribArray(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribPointerData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     GLint size;
     GLenum type;
@@ -255,7 +267,7 @@ static void yagl_func_glVertexAttribPointerData(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT7(glVertexAttribPointerData, GLuint, GLint, GLenum, GLboolean, GLsizei, GLint, void*, indx, size, type, normalized, stride, first, data);
-    (void)yagl_host_glVertexAttribPointerData(indx, size, type, normalized, stride, first, data, data_count);
+    (void)yagl_host_glVertexAttribPointerData(cur_ts, indx, size, type, normalized, stride, first, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -264,6 +276,7 @@ static void yagl_func_glVertexAttribPointerData(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribPointerOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     GLint size;
     GLenum type;
@@ -277,7 +290,7 @@ static void yagl_func_glVertexAttribPointerOffset(struct yagl_transport *t)
     stride = yagl_transport_get_out_GLsizei(t);
     offset = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glVertexAttribPointerOffset, GLuint, GLint, GLenum, GLboolean, GLsizei, uintptr_t, indx, size, type, normalized, stride, offset);
-    (void)yagl_host_glVertexAttribPointerOffset(indx, size, type, normalized, stride, offset);
+    (void)yagl_host_glVertexAttribPointerOffset(cur_ts, indx, size, type, normalized, stride, offset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -286,6 +299,7 @@ static void yagl_func_glVertexAttribPointerOffset(struct yagl_transport *t)
  */
 static void yagl_func_glVertexPointerData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint size;
     GLenum type;
     GLsizei stride;
@@ -298,7 +312,7 @@ static void yagl_func_glVertexPointerData(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glVertexPointerData, GLint, GLenum, GLsizei, GLint, void*, size, type, stride, first, data);
-    (void)yagl_host_glVertexPointerData(size, type, stride, first, data, data_count);
+    (void)yagl_host_glVertexPointerData(cur_ts, size, type, stride, first, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -307,6 +321,7 @@ static void yagl_func_glVertexPointerData(struct yagl_transport *t)
  */
 static void yagl_func_glVertexPointerOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint size;
     GLenum type;
     GLsizei stride;
@@ -316,7 +331,7 @@ static void yagl_func_glVertexPointerOffset(struct yagl_transport *t)
     stride = yagl_transport_get_out_GLsizei(t);
     offset = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glVertexPointerOffset, GLint, GLenum, GLsizei, uintptr_t, size, type, stride, offset);
-    (void)yagl_host_glVertexPointerOffset(size, type, stride, offset);
+    (void)yagl_host_glVertexPointerOffset(cur_ts, size, type, stride, offset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -325,6 +340,7 @@ static void yagl_func_glVertexPointerOffset(struct yagl_transport *t)
  */
 static void yagl_func_glNormalPointerData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum type;
     GLsizei stride;
     GLint first;
@@ -335,7 +351,7 @@ static void yagl_func_glNormalPointerData(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glNormalPointerData, GLenum, GLsizei, GLint, void*, type, stride, first, data);
-    (void)yagl_host_glNormalPointerData(type, stride, first, data, data_count);
+    (void)yagl_host_glNormalPointerData(cur_ts, type, stride, first, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -344,6 +360,7 @@ static void yagl_func_glNormalPointerData(struct yagl_transport *t)
  */
 static void yagl_func_glNormalPointerOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum type;
     GLsizei stride;
     uintptr_t offset;
@@ -351,7 +368,7 @@ static void yagl_func_glNormalPointerOffset(struct yagl_transport *t)
     stride = yagl_transport_get_out_GLsizei(t);
     offset = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glNormalPointerOffset, GLenum, GLsizei, uintptr_t, type, stride, offset);
-    (void)yagl_host_glNormalPointerOffset(type, stride, offset);
+    (void)yagl_host_glNormalPointerOffset(cur_ts, type, stride, offset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -360,6 +377,7 @@ static void yagl_func_glNormalPointerOffset(struct yagl_transport *t)
  */
 static void yagl_func_glColorPointerData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint size;
     GLenum type;
     GLsizei stride;
@@ -372,7 +390,7 @@ static void yagl_func_glColorPointerData(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glColorPointerData, GLint, GLenum, GLsizei, GLint, void*, size, type, stride, first, data);
-    (void)yagl_host_glColorPointerData(size, type, stride, first, data, data_count);
+    (void)yagl_host_glColorPointerData(cur_ts, size, type, stride, first, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -381,6 +399,7 @@ static void yagl_func_glColorPointerData(struct yagl_transport *t)
  */
 static void yagl_func_glColorPointerOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint size;
     GLenum type;
     GLsizei stride;
@@ -390,7 +409,7 @@ static void yagl_func_glColorPointerOffset(struct yagl_transport *t)
     stride = yagl_transport_get_out_GLsizei(t);
     offset = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glColorPointerOffset, GLint, GLenum, GLsizei, uintptr_t, size, type, stride, offset);
-    (void)yagl_host_glColorPointerOffset(size, type, stride, offset);
+    (void)yagl_host_glColorPointerOffset(cur_ts, size, type, stride, offset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -399,6 +418,7 @@ static void yagl_func_glColorPointerOffset(struct yagl_transport *t)
  */
 static void yagl_func_glTexCoordPointerData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint tex_id;
     GLint size;
     GLenum type;
@@ -413,7 +433,7 @@ static void yagl_func_glTexCoordPointerData(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glTexCoordPointerData, GLint, GLint, GLenum, GLsizei, GLint, void*, tex_id, size, type, stride, first, data);
-    (void)yagl_host_glTexCoordPointerData(tex_id, size, type, stride, first, data, data_count);
+    (void)yagl_host_glTexCoordPointerData(cur_ts, tex_id, size, type, stride, first, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -422,6 +442,7 @@ static void yagl_func_glTexCoordPointerData(struct yagl_transport *t)
  */
 static void yagl_func_glTexCoordPointerOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint size;
     GLenum type;
     GLsizei stride;
@@ -431,7 +452,7 @@ static void yagl_func_glTexCoordPointerOffset(struct yagl_transport *t)
     stride = yagl_transport_get_out_GLsizei(t);
     offset = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glTexCoordPointerOffset, GLint, GLenum, GLsizei, uintptr_t, size, type, stride, offset);
-    (void)yagl_host_glTexCoordPointerOffset(size, type, stride, offset);
+    (void)yagl_host_glTexCoordPointerOffset(cur_ts, size, type, stride, offset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -440,10 +461,11 @@ static void yagl_func_glTexCoordPointerOffset(struct yagl_transport *t)
  */
 static void yagl_func_glDisableClientState(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum array;
     array = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDisableClientState, GLenum, array);
-    (void)yagl_host_glDisableClientState(array);
+    (void)yagl_host_glDisableClientState(cur_ts, array);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -452,10 +474,11 @@ static void yagl_func_glDisableClientState(struct yagl_transport *t)
  */
 static void yagl_func_glEnableClientState(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum array;
     array = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glEnableClientState, GLenum, array);
-    (void)yagl_host_glEnableClientState(array);
+    (void)yagl_host_glEnableClientState(cur_ts, array);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -464,12 +487,13 @@ static void yagl_func_glEnableClientState(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribDivisor(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLuint divisor;
     index = yagl_transport_get_out_GLuint(t);
     divisor = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttribDivisor, GLuint, GLuint, index, divisor);
-    (void)yagl_host_glVertexAttribDivisor(index, divisor);
+    (void)yagl_host_glVertexAttribDivisor(cur_ts, index, divisor);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -478,6 +502,7 @@ static void yagl_func_glVertexAttribDivisor(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribIPointerData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLint size;
     GLenum type;
@@ -492,7 +517,7 @@ static void yagl_func_glVertexAttribIPointerData(struct yagl_transport *t)
     first = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glVertexAttribIPointerData, GLuint, GLint, GLenum, GLsizei, GLint, void*, index, size, type, stride, first, data);
-    (void)yagl_host_glVertexAttribIPointerData(index, size, type, stride, first, data, data_count);
+    (void)yagl_host_glVertexAttribIPointerData(cur_ts, index, size, type, stride, first, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -501,6 +526,7 @@ static void yagl_func_glVertexAttribIPointerData(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribIPointerOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLint size;
     GLenum type;
@@ -512,7 +538,7 @@ static void yagl_func_glVertexAttribIPointerOffset(struct yagl_transport *t)
     stride = yagl_transport_get_out_GLsizei(t);
     offset = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glVertexAttribIPointerOffset, GLuint, GLint, GLenum, GLsizei, uintptr_t, index, size, type, stride, offset);
-    (void)yagl_host_glVertexAttribIPointerOffset(index, size, type, stride, offset);
+    (void)yagl_host_glVertexAttribIPointerOffset(cur_ts, index, size, type, stride, offset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -521,11 +547,12 @@ static void yagl_func_glVertexAttribIPointerOffset(struct yagl_transport *t)
  */
 static void yagl_func_glGenBuffers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *buffers;
     int32_t buffers_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&buffers, &buffers_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenBuffers, void*, buffers);
-    (void)yagl_host_glGenBuffers(buffers, buffers_count);
+    (void)yagl_host_glGenBuffers(cur_ts, buffers, buffers_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -534,12 +561,13 @@ static void yagl_func_glGenBuffers(struct yagl_transport *t)
  */
 static void yagl_func_glBindBuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint buffer;
     target = yagl_transport_get_out_GLenum(t);
     buffer = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBindBuffer, GLenum, GLuint, target, buffer);
-    (void)yagl_host_glBindBuffer(target, buffer);
+    (void)yagl_host_glBindBuffer(cur_ts, target, buffer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -548,6 +576,7 @@ static void yagl_func_glBindBuffer(struct yagl_transport *t)
  */
 static void yagl_func_glBufferData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     const GLvoid *data;
     int32_t data_count;
@@ -556,7 +585,7 @@ static void yagl_func_glBufferData(struct yagl_transport *t)
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     usage = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glBufferData, GLenum, void*, GLenum, target, data, usage);
-    (void)yagl_host_glBufferData(target, data, data_count, usage);
+    (void)yagl_host_glBufferData(cur_ts, target, data, data_count, usage);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -565,6 +594,7 @@ static void yagl_func_glBufferData(struct yagl_transport *t)
  */
 static void yagl_func_glBufferSubData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLsizei offset;
     const GLvoid *data;
@@ -573,7 +603,7 @@ static void yagl_func_glBufferSubData(struct yagl_transport *t)
     offset = yagl_transport_get_out_GLsizei(t);
     yagl_transport_get_out_array(t, 1, (const void**)&data, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glBufferSubData, GLenum, GLsizei, void*, target, offset, data);
-    (void)yagl_host_glBufferSubData(target, offset, data, data_count);
+    (void)yagl_host_glBufferSubData(cur_ts, target, offset, data, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -582,6 +612,7 @@ static void yagl_func_glBufferSubData(struct yagl_transport *t)
  */
 static void yagl_func_glBindBufferBase(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint index;
     GLuint buffer;
@@ -589,7 +620,7 @@ static void yagl_func_glBindBufferBase(struct yagl_transport *t)
     index = yagl_transport_get_out_GLuint(t);
     buffer = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glBindBufferBase, GLenum, GLuint, GLuint, target, index, buffer);
-    (void)yagl_host_glBindBufferBase(target, index, buffer);
+    (void)yagl_host_glBindBufferBase(cur_ts, target, index, buffer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -598,6 +629,7 @@ static void yagl_func_glBindBufferBase(struct yagl_transport *t)
  */
 static void yagl_func_glBindBufferRange(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint index;
     GLuint buffer;
@@ -609,7 +641,7 @@ static void yagl_func_glBindBufferRange(struct yagl_transport *t)
     offset = yagl_transport_get_out_GLint(t);
     size = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glBindBufferRange, GLenum, GLuint, GLuint, GLint, GLsizei, target, index, buffer, offset, size);
-    (void)yagl_host_glBindBufferRange(target, index, buffer, offset, size);
+    (void)yagl_host_glBindBufferRange(cur_ts, target, index, buffer, offset, size);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -618,6 +650,7 @@ static void yagl_func_glBindBufferRange(struct yagl_transport *t)
  */
 static void yagl_func_glMapBuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint buffer;
     const GLuint *ranges;
     int32_t ranges_count;
@@ -629,7 +662,7 @@ static void yagl_func_glMapBuffer(struct yagl_transport *t)
     yagl_transport_get_in_array(t, 1, (void**)&data, &data_maxcount, &data_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glMapBuffer, GLuint, void*, void*, buffer, ranges, data);
     *data_count = 0;
-    (void)yagl_host_glMapBuffer(buffer, ranges, ranges_count, data, data_maxcount, data_count);
+    (void)yagl_host_glMapBuffer(cur_ts, buffer, ranges, ranges_count, data, data_maxcount, data_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -638,6 +671,7 @@ static void yagl_func_glMapBuffer(struct yagl_transport *t)
  */
 static void yagl_func_glCopyBufferSubData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum readTarget;
     GLenum writeTarget;
     GLintptr readOffset;
@@ -649,7 +683,7 @@ static void yagl_func_glCopyBufferSubData(struct yagl_transport *t)
     writeOffset = yagl_transport_get_out_GLintptr(t);
     size = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glCopyBufferSubData, GLenum, GLenum, GLintptr, GLintptr, GLsizei, readTarget, writeTarget, readOffset, writeOffset, size);
-    (void)yagl_host_glCopyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size);
+    (void)yagl_host_glCopyBufferSubData(cur_ts, readTarget, writeTarget, readOffset, writeOffset, size);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -658,11 +692,12 @@ static void yagl_func_glCopyBufferSubData(struct yagl_transport *t)
  */
 static void yagl_func_glGenTextures(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *textures;
     int32_t textures_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&textures, &textures_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenTextures, void*, textures);
-    (void)yagl_host_glGenTextures(textures, textures_count);
+    (void)yagl_host_glGenTextures(cur_ts, textures, textures_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -671,12 +706,13 @@ static void yagl_func_glGenTextures(struct yagl_transport *t)
  */
 static void yagl_func_glBindTexture(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint texture;
     target = yagl_transport_get_out_GLenum(t);
     texture = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBindTexture, GLenum, GLuint, target, texture);
-    (void)yagl_host_glBindTexture(target, texture);
+    (void)yagl_host_glBindTexture(cur_ts, target, texture);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -685,10 +721,11 @@ static void yagl_func_glBindTexture(struct yagl_transport *t)
  */
 static void yagl_func_glActiveTexture(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum texture;
     texture = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glActiveTexture, GLenum, texture);
-    (void)yagl_host_glActiveTexture(texture);
+    (void)yagl_host_glActiveTexture(cur_ts, texture);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -697,6 +734,7 @@ static void yagl_func_glActiveTexture(struct yagl_transport *t)
  */
 static void yagl_func_glCopyTexImage2D(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLenum internalformat;
@@ -714,7 +752,7 @@ static void yagl_func_glCopyTexImage2D(struct yagl_transport *t)
     height = yagl_transport_get_out_GLsizei(t);
     border = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT8(glCopyTexImage2D, GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint, target, level, internalformat, x, y, width, height, border);
-    (void)yagl_host_glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
+    (void)yagl_host_glCopyTexImage2D(cur_ts, target, level, internalformat, x, y, width, height, border);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -723,6 +761,7 @@ static void yagl_func_glCopyTexImage2D(struct yagl_transport *t)
  */
 static void yagl_func_glCopyTexSubImage2D(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint xoffset;
@@ -740,7 +779,7 @@ static void yagl_func_glCopyTexSubImage2D(struct yagl_transport *t)
     width = yagl_transport_get_out_GLsizei(t);
     height = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT8(glCopyTexSubImage2D, GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, target, level, xoffset, yoffset, x, y, width, height);
-    (void)yagl_host_glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+    (void)yagl_host_glCopyTexSubImage2D(cur_ts, target, level, xoffset, yoffset, x, y, width, height);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -749,6 +788,7 @@ static void yagl_func_glCopyTexSubImage2D(struct yagl_transport *t)
  */
 static void yagl_func_glGetTexParameterfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLfloat *param;
@@ -756,7 +796,7 @@ static void yagl_func_glGetTexParameterfv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_in_arg(t, (void**)&param);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTexParameterfv, GLenum, GLenum, void*, target, pname, param);
-    (void)yagl_host_glGetTexParameterfv(target, pname, param);
+    (void)yagl_host_glGetTexParameterfv(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -765,6 +805,7 @@ static void yagl_func_glGetTexParameterfv(struct yagl_transport *t)
  */
 static void yagl_func_glGetTexParameteriv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLint *param;
@@ -772,7 +813,7 @@ static void yagl_func_glGetTexParameteriv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_in_arg(t, (void**)&param);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTexParameteriv, GLenum, GLenum, void*, target, pname, param);
-    (void)yagl_host_glGetTexParameteriv(target, pname, param);
+    (void)yagl_host_glGetTexParameteriv(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -781,6 +822,7 @@ static void yagl_func_glGetTexParameteriv(struct yagl_transport *t)
  */
 static void yagl_func_glTexImage2DData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint internalformat;
@@ -801,7 +843,7 @@ static void yagl_func_glTexImage2DData(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, 1, (const void**)&pixels, &pixels_count);
     YAGL_LOG_FUNC_ENTER_SPLIT9(glTexImage2DData, GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, void*, target, level, internalformat, width, height, border, format, type, pixels);
-    (void)yagl_host_glTexImage2DData(target, level, internalformat, width, height, border, format, type, pixels, pixels_count);
+    (void)yagl_host_glTexImage2DData(cur_ts, target, level, internalformat, width, height, border, format, type, pixels, pixels_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -810,6 +852,7 @@ static void yagl_func_glTexImage2DData(struct yagl_transport *t)
  */
 static void yagl_func_glTexImage2DOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint internalformat;
@@ -829,7 +872,7 @@ static void yagl_func_glTexImage2DOffset(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     pixels = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT9(glTexImage2DOffset, GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, uintptr_t, target, level, internalformat, width, height, border, format, type, pixels);
-    (void)yagl_host_glTexImage2DOffset(target, level, internalformat, width, height, border, format, type, pixels);
+    (void)yagl_host_glTexImage2DOffset(cur_ts, target, level, internalformat, width, height, border, format, type, pixels);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -838,6 +881,7 @@ static void yagl_func_glTexImage2DOffset(struct yagl_transport *t)
  */
 static void yagl_func_glTexParameterf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLfloat param;
@@ -845,7 +889,7 @@ static void yagl_func_glTexParameterf(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameterf, GLenum, GLenum, GLfloat, target, pname, param);
-    (void)yagl_host_glTexParameterf(target, pname, param);
+    (void)yagl_host_glTexParameterf(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -854,6 +898,7 @@ static void yagl_func_glTexParameterf(struct yagl_transport *t)
  */
 static void yagl_func_glTexParameterfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     const GLfloat *params;
@@ -862,7 +907,7 @@ static void yagl_func_glTexParameterfv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameterfv, GLenum, GLenum, void*, target, pname, params);
-    (void)yagl_host_glTexParameterfv(target, pname, params, params_count);
+    (void)yagl_host_glTexParameterfv(cur_ts, target, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -871,6 +916,7 @@ static void yagl_func_glTexParameterfv(struct yagl_transport *t)
  */
 static void yagl_func_glTexParameteri(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLint param;
@@ -878,7 +924,7 @@ static void yagl_func_glTexParameteri(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameteri, GLenum, GLenum, GLint, target, pname, param);
-    (void)yagl_host_glTexParameteri(target, pname, param);
+    (void)yagl_host_glTexParameteri(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -887,6 +933,7 @@ static void yagl_func_glTexParameteri(struct yagl_transport *t)
  */
 static void yagl_func_glTexParameteriv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     const GLint *params;
@@ -895,7 +942,7 @@ static void yagl_func_glTexParameteriv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexParameteriv, GLenum, GLenum, void*, target, pname, params);
-    (void)yagl_host_glTexParameteriv(target, pname, params, params_count);
+    (void)yagl_host_glTexParameteriv(cur_ts, target, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -904,6 +951,7 @@ static void yagl_func_glTexParameteriv(struct yagl_transport *t)
  */
 static void yagl_func_glTexSubImage2DData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint xoffset;
@@ -924,7 +972,7 @@ static void yagl_func_glTexSubImage2DData(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, 1, (const void**)&pixels, &pixels_count);
     YAGL_LOG_FUNC_ENTER_SPLIT9(glTexSubImage2DData, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void*, target, level, xoffset, yoffset, width, height, format, type, pixels);
-    (void)yagl_host_glTexSubImage2DData(target, level, xoffset, yoffset, width, height, format, type, pixels, pixels_count);
+    (void)yagl_host_glTexSubImage2DData(cur_ts, target, level, xoffset, yoffset, width, height, format, type, pixels, pixels_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -933,6 +981,7 @@ static void yagl_func_glTexSubImage2DData(struct yagl_transport *t)
  */
 static void yagl_func_glTexSubImage2DOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint xoffset;
@@ -952,7 +1001,7 @@ static void yagl_func_glTexSubImage2DOffset(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     pixels = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT9(glTexSubImage2DOffset, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, uintptr_t, target, level, xoffset, yoffset, width, height, format, type, pixels);
-    (void)yagl_host_glTexSubImage2DOffset(target, level, xoffset, yoffset, width, height, format, type, pixels);
+    (void)yagl_host_glTexSubImage2DOffset(cur_ts, target, level, xoffset, yoffset, width, height, format, type, pixels);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -961,10 +1010,11 @@ static void yagl_func_glTexSubImage2DOffset(struct yagl_transport *t)
  */
 static void yagl_func_glClientActiveTexture(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum texture;
     texture = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glClientActiveTexture, GLenum, texture);
-    (void)yagl_host_glClientActiveTexture(texture);
+    (void)yagl_host_glClientActiveTexture(cur_ts, texture);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -973,6 +1023,7 @@ static void yagl_func_glClientActiveTexture(struct yagl_transport *t)
  */
 static void yagl_func_glTexEnvi(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLint param;
@@ -980,7 +1031,7 @@ static void yagl_func_glTexEnvi(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexEnvi, GLenum, GLenum, GLint, target, pname, param);
-    (void)yagl_host_glTexEnvi(target, pname, param);
+    (void)yagl_host_glTexEnvi(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -989,6 +1040,7 @@ static void yagl_func_glTexEnvi(struct yagl_transport *t)
  */
 static void yagl_func_glTexEnvf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLfloat param;
@@ -996,7 +1048,7 @@ static void yagl_func_glTexEnvf(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexEnvf, GLenum, GLenum, GLfloat, target, pname, param);
-    (void)yagl_host_glTexEnvf(target, pname, param);
+    (void)yagl_host_glTexEnvf(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1005,6 +1057,7 @@ static void yagl_func_glTexEnvf(struct yagl_transport *t)
  */
 static void yagl_func_glMultiTexCoord4f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLfloat s;
     GLfloat tt;
@@ -1016,7 +1069,7 @@ static void yagl_func_glMultiTexCoord4f(struct yagl_transport *t)
     r = yagl_transport_get_out_GLfloat(t);
     q = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glMultiTexCoord4f, GLenum, GLfloat, GLfloat, GLfloat, GLfloat, target, s, tt, r, q);
-    (void)yagl_host_glMultiTexCoord4f(target, s, tt, r, q);
+    (void)yagl_host_glMultiTexCoord4f(cur_ts, target, s, tt, r, q);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1025,6 +1078,7 @@ static void yagl_func_glMultiTexCoord4f(struct yagl_transport *t)
  */
 static void yagl_func_glTexEnviv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     const GLint *params;
@@ -1033,7 +1087,7 @@ static void yagl_func_glTexEnviv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexEnviv, GLenum, GLenum, void*, target, pname, params);
-    (void)yagl_host_glTexEnviv(target, pname, params, params_count);
+    (void)yagl_host_glTexEnviv(cur_ts, target, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1042,6 +1096,7 @@ static void yagl_func_glTexEnviv(struct yagl_transport *t)
  */
 static void yagl_func_glTexEnvfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     const GLfloat *params;
@@ -1050,7 +1105,7 @@ static void yagl_func_glTexEnvfv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTexEnvfv, GLenum, GLenum, void*, target, pname, params);
-    (void)yagl_host_glTexEnvfv(target, pname, params, params_count);
+    (void)yagl_host_glTexEnvfv(cur_ts, target, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1059,6 +1114,7 @@ static void yagl_func_glTexEnvfv(struct yagl_transport *t)
  */
 static void yagl_func_glGetTexEnviv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum env;
     GLenum pname;
     GLint *params;
@@ -1069,7 +1125,7 @@ static void yagl_func_glGetTexEnviv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTexEnviv, GLenum, GLenum, void*, env, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetTexEnviv(env, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetTexEnviv(cur_ts, env, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1078,6 +1134,7 @@ static void yagl_func_glGetTexEnviv(struct yagl_transport *t)
  */
 static void yagl_func_glGetTexEnvfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum env;
     GLenum pname;
     GLfloat *params;
@@ -1088,7 +1145,7 @@ static void yagl_func_glGetTexEnvfv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTexEnvfv, GLenum, GLenum, void*, env, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetTexEnvfv(env, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetTexEnvfv(cur_ts, env, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1097,6 +1154,7 @@ static void yagl_func_glGetTexEnvfv(struct yagl_transport *t)
  */
 static void yagl_func_glTexImage3DData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint internalformat;
@@ -1119,7 +1177,7 @@ static void yagl_func_glTexImage3DData(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, 1, (const void**)&pixels, &pixels_count);
     YAGL_LOG_FUNC_ENTER_SPLIT10(glTexImage3DData, GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, void*, target, level, internalformat, width, height, depth, border, format, type, pixels);
-    (void)yagl_host_glTexImage3DData(target, level, internalformat, width, height, depth, border, format, type, pixels, pixels_count);
+    (void)yagl_host_glTexImage3DData(cur_ts, target, level, internalformat, width, height, depth, border, format, type, pixels, pixels_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1128,6 +1186,7 @@ static void yagl_func_glTexImage3DData(struct yagl_transport *t)
  */
 static void yagl_func_glTexImage3DOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint internalformat;
@@ -1149,7 +1208,7 @@ static void yagl_func_glTexImage3DOffset(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     pixels = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT10(glTexImage3DOffset, GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, uintptr_t, target, level, internalformat, width, height, depth, border, format, type, pixels);
-    (void)yagl_host_glTexImage3DOffset(target, level, internalformat, width, height, depth, border, format, type, pixels);
+    (void)yagl_host_glTexImage3DOffset(cur_ts, target, level, internalformat, width, height, depth, border, format, type, pixels);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1158,6 +1217,7 @@ static void yagl_func_glTexImage3DOffset(struct yagl_transport *t)
  */
 static void yagl_func_glTexSubImage3DData(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint xoffset;
@@ -1182,7 +1242,7 @@ static void yagl_func_glTexSubImage3DData(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, 1, (const void**)&pixels, &pixels_count);
     YAGL_LOG_FUNC_ENTER_SPLIT11(glTexSubImage3DData, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, void*, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
-    (void)yagl_host_glTexSubImage3DData(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, pixels_count);
+    (void)yagl_host_glTexSubImage3DData(cur_ts, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, pixels_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1191,6 +1251,7 @@ static void yagl_func_glTexSubImage3DData(struct yagl_transport *t)
  */
 static void yagl_func_glTexSubImage3DOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint xoffset;
@@ -1214,7 +1275,7 @@ static void yagl_func_glTexSubImage3DOffset(struct yagl_transport *t)
     type = yagl_transport_get_out_GLenum(t);
     pixels = yagl_transport_get_out_uintptr_t(t);
     YAGL_LOG_FUNC_ENTER_SPLIT11(glTexSubImage3DOffset, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, uintptr_t, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
-    (void)yagl_host_glTexSubImage3DOffset(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
+    (void)yagl_host_glTexSubImage3DOffset(cur_ts, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1223,6 +1284,7 @@ static void yagl_func_glTexSubImage3DOffset(struct yagl_transport *t)
  */
 static void yagl_func_glCopyTexSubImage3D(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLint level;
     GLint xoffset;
@@ -1242,7 +1304,7 @@ static void yagl_func_glCopyTexSubImage3D(struct yagl_transport *t)
     width = yagl_transport_get_out_GLsizei(t);
     height = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT9(glCopyTexSubImage3D, GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, target, level, xoffset, yoffset, zoffset, x, y, width, height);
-    (void)yagl_host_glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
+    (void)yagl_host_glCopyTexSubImage3D(cur_ts, target, level, xoffset, yoffset, zoffset, x, y, width, height);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1251,11 +1313,12 @@ static void yagl_func_glCopyTexSubImage3D(struct yagl_transport *t)
  */
 static void yagl_func_glGenFramebuffers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *framebuffers;
     int32_t framebuffers_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&framebuffers, &framebuffers_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenFramebuffers, void*, framebuffers);
-    (void)yagl_host_glGenFramebuffers(framebuffers, framebuffers_count);
+    (void)yagl_host_glGenFramebuffers(cur_ts, framebuffers, framebuffers_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1264,12 +1327,13 @@ static void yagl_func_glGenFramebuffers(struct yagl_transport *t)
  */
 static void yagl_func_glBindFramebuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint framebuffer;
     target = yagl_transport_get_out_GLenum(t);
     framebuffer = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBindFramebuffer, GLenum, GLuint, target, framebuffer);
-    (void)yagl_host_glBindFramebuffer(target, framebuffer);
+    (void)yagl_host_glBindFramebuffer(cur_ts, target, framebuffer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1278,6 +1342,7 @@ static void yagl_func_glBindFramebuffer(struct yagl_transport *t)
  */
 static void yagl_func_glFramebufferTexture2D(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum attachment;
     GLenum textarget;
@@ -1289,7 +1354,7 @@ static void yagl_func_glFramebufferTexture2D(struct yagl_transport *t)
     texture = yagl_transport_get_out_GLuint(t);
     level = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glFramebufferTexture2D, GLenum, GLenum, GLenum, GLuint, GLint, target, attachment, textarget, texture, level);
-    (void)yagl_host_glFramebufferTexture2D(target, attachment, textarget, texture, level);
+    (void)yagl_host_glFramebufferTexture2D(cur_ts, target, attachment, textarget, texture, level);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1298,6 +1363,7 @@ static void yagl_func_glFramebufferTexture2D(struct yagl_transport *t)
  */
 static void yagl_func_glFramebufferRenderbuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum attachment;
     GLenum renderbuffertarget;
@@ -1307,7 +1373,7 @@ static void yagl_func_glFramebufferRenderbuffer(struct yagl_transport *t)
     renderbuffertarget = yagl_transport_get_out_GLenum(t);
     renderbuffer = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glFramebufferRenderbuffer, GLenum, GLenum, GLenum, GLuint, target, attachment, renderbuffertarget, renderbuffer);
-    (void)yagl_host_glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
+    (void)yagl_host_glFramebufferRenderbuffer(cur_ts, target, attachment, renderbuffertarget, renderbuffer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1316,6 +1382,7 @@ static void yagl_func_glFramebufferRenderbuffer(struct yagl_transport *t)
  */
 static void yagl_func_glBlitFramebuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint srcX0;
     GLint srcY0;
     GLint srcX1;
@@ -1337,7 +1404,7 @@ static void yagl_func_glBlitFramebuffer(struct yagl_transport *t)
     mask = yagl_transport_get_out_GLbitfield(t);
     filter = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT10(glBlitFramebuffer, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
-    (void)yagl_host_glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
+    (void)yagl_host_glBlitFramebuffer(cur_ts, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1346,11 +1413,12 @@ static void yagl_func_glBlitFramebuffer(struct yagl_transport *t)
  */
 static void yagl_func_glDrawBuffers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLenum *bufs;
     int32_t bufs_count;
     yagl_transport_get_out_array(t, sizeof(GLenum), (const void**)&bufs, &bufs_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDrawBuffers, void*, bufs);
-    (void)yagl_host_glDrawBuffers(bufs, bufs_count);
+    (void)yagl_host_glDrawBuffers(cur_ts, bufs, bufs_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1359,10 +1427,11 @@ static void yagl_func_glDrawBuffers(struct yagl_transport *t)
  */
 static void yagl_func_glReadBuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glReadBuffer, GLenum, mode);
-    (void)yagl_host_glReadBuffer(mode);
+    (void)yagl_host_glReadBuffer(cur_ts, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1371,6 +1440,7 @@ static void yagl_func_glReadBuffer(struct yagl_transport *t)
  */
 static void yagl_func_glFramebufferTexture3D(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum attachment;
     GLenum textarget;
@@ -1384,7 +1454,7 @@ static void yagl_func_glFramebufferTexture3D(struct yagl_transport *t)
     level = yagl_transport_get_out_GLint(t);
     zoffset = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glFramebufferTexture3D, GLenum, GLenum, GLenum, GLuint, GLint, GLint, target, attachment, textarget, texture, level, zoffset);
-    (void)yagl_host_glFramebufferTexture3D(target, attachment, textarget, texture, level, zoffset);
+    (void)yagl_host_glFramebufferTexture3D(cur_ts, target, attachment, textarget, texture, level, zoffset);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1393,6 +1463,7 @@ static void yagl_func_glFramebufferTexture3D(struct yagl_transport *t)
  */
 static void yagl_func_glFramebufferTextureLayer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum attachment;
     GLuint texture;
@@ -1404,7 +1475,7 @@ static void yagl_func_glFramebufferTextureLayer(struct yagl_transport *t)
     level = yagl_transport_get_out_GLint(t);
     layer = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glFramebufferTextureLayer, GLenum, GLenum, GLuint, GLint, GLint, target, attachment, texture, level, layer);
-    (void)yagl_host_glFramebufferTextureLayer(target, attachment, texture, level, layer);
+    (void)yagl_host_glFramebufferTextureLayer(cur_ts, target, attachment, texture, level, layer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1413,6 +1484,7 @@ static void yagl_func_glFramebufferTextureLayer(struct yagl_transport *t)
  */
 static void yagl_func_glClearBufferiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum buffer;
     GLint drawbuffer;
     const GLint *value;
@@ -1421,7 +1493,7 @@ static void yagl_func_glClearBufferiv(struct yagl_transport *t)
     drawbuffer = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glClearBufferiv, GLenum, GLint, void*, buffer, drawbuffer, value);
-    (void)yagl_host_glClearBufferiv(buffer, drawbuffer, value, value_count);
+    (void)yagl_host_glClearBufferiv(cur_ts, buffer, drawbuffer, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1430,6 +1502,7 @@ static void yagl_func_glClearBufferiv(struct yagl_transport *t)
  */
 static void yagl_func_glClearBufferuiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum buffer;
     GLint drawbuffer;
     const GLuint *value;
@@ -1438,7 +1511,7 @@ static void yagl_func_glClearBufferuiv(struct yagl_transport *t)
     drawbuffer = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glClearBufferuiv, GLenum, GLint, void*, buffer, drawbuffer, value);
-    (void)yagl_host_glClearBufferuiv(buffer, drawbuffer, value, value_count);
+    (void)yagl_host_glClearBufferuiv(cur_ts, buffer, drawbuffer, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1447,6 +1520,7 @@ static void yagl_func_glClearBufferuiv(struct yagl_transport *t)
  */
 static void yagl_func_glClearBufferfi(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum buffer;
     GLint drawbuffer;
     GLfloat depth;
@@ -1456,7 +1530,7 @@ static void yagl_func_glClearBufferfi(struct yagl_transport *t)
     depth = yagl_transport_get_out_GLfloat(t);
     stencil = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glClearBufferfi, GLenum, GLint, GLfloat, GLint, buffer, drawbuffer, depth, stencil);
-    (void)yagl_host_glClearBufferfi(buffer, drawbuffer, depth, stencil);
+    (void)yagl_host_glClearBufferfi(cur_ts, buffer, drawbuffer, depth, stencil);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1465,6 +1539,7 @@ static void yagl_func_glClearBufferfi(struct yagl_transport *t)
  */
 static void yagl_func_glClearBufferfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum buffer;
     GLint drawbuffer;
     const GLfloat *value;
@@ -1473,7 +1548,7 @@ static void yagl_func_glClearBufferfv(struct yagl_transport *t)
     drawbuffer = yagl_transport_get_out_GLint(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glClearBufferfv, GLenum, GLint, void*, buffer, drawbuffer, value);
-    (void)yagl_host_glClearBufferfv(buffer, drawbuffer, value, value_count);
+    (void)yagl_host_glClearBufferfv(cur_ts, buffer, drawbuffer, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1482,11 +1557,12 @@ static void yagl_func_glClearBufferfv(struct yagl_transport *t)
  */
 static void yagl_func_glGenRenderbuffers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *renderbuffers;
     int32_t renderbuffers_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&renderbuffers, &renderbuffers_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenRenderbuffers, void*, renderbuffers);
-    (void)yagl_host_glGenRenderbuffers(renderbuffers, renderbuffers_count);
+    (void)yagl_host_glGenRenderbuffers(cur_ts, renderbuffers, renderbuffers_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1495,12 +1571,13 @@ static void yagl_func_glGenRenderbuffers(struct yagl_transport *t)
  */
 static void yagl_func_glBindRenderbuffer(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint renderbuffer;
     target = yagl_transport_get_out_GLenum(t);
     renderbuffer = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBindRenderbuffer, GLenum, GLuint, target, renderbuffer);
-    (void)yagl_host_glBindRenderbuffer(target, renderbuffer);
+    (void)yagl_host_glBindRenderbuffer(cur_ts, target, renderbuffer);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1509,6 +1586,7 @@ static void yagl_func_glBindRenderbuffer(struct yagl_transport *t)
  */
 static void yagl_func_glRenderbufferStorage(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum internalformat;
     GLsizei width;
@@ -1518,7 +1596,7 @@ static void yagl_func_glRenderbufferStorage(struct yagl_transport *t)
     width = yagl_transport_get_out_GLsizei(t);
     height = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glRenderbufferStorage, GLenum, GLenum, GLsizei, GLsizei, target, internalformat, width, height);
-    (void)yagl_host_glRenderbufferStorage(target, internalformat, width, height);
+    (void)yagl_host_glRenderbufferStorage(cur_ts, target, internalformat, width, height);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1527,6 +1605,7 @@ static void yagl_func_glRenderbufferStorage(struct yagl_transport *t)
  */
 static void yagl_func_glGetRenderbufferParameteriv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum pname;
     GLint *param;
@@ -1534,7 +1613,7 @@ static void yagl_func_glGetRenderbufferParameteriv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_in_arg(t, (void**)&param);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetRenderbufferParameteriv, GLenum, GLenum, void*, target, pname, param);
-    (void)yagl_host_glGetRenderbufferParameteriv(target, pname, param);
+    (void)yagl_host_glGetRenderbufferParameteriv(cur_ts, target, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1543,6 +1622,7 @@ static void yagl_func_glGetRenderbufferParameteriv(struct yagl_transport *t)
  */
 static void yagl_func_glRenderbufferStorageMultisample(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLsizei samples;
     GLenum internalformat;
@@ -1554,7 +1634,7 @@ static void yagl_func_glRenderbufferStorageMultisample(struct yagl_transport *t)
     width = yagl_transport_get_out_GLsizei(t);
     height = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glRenderbufferStorageMultisample, GLenum, GLsizei, GLenum, GLsizei, GLsizei, target, samples, internalformat, width, height);
-    (void)yagl_host_glRenderbufferStorageMultisample(target, samples, internalformat, width, height);
+    (void)yagl_host_glRenderbufferStorageMultisample(cur_ts, target, samples, internalformat, width, height);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1563,10 +1643,11 @@ static void yagl_func_glRenderbufferStorageMultisample(struct yagl_transport *t)
  */
 static void yagl_func_glCreateProgram(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     program = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glCreateProgram, GLuint, program);
-    (void)yagl_host_glCreateProgram(program);
+    (void)yagl_host_glCreateProgram(cur_ts, program);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1575,12 +1656,13 @@ static void yagl_func_glCreateProgram(struct yagl_transport *t)
  */
 static void yagl_func_glCreateShader(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint shader;
     GLenum type;
     shader = yagl_transport_get_out_GLuint(t);
     type = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glCreateShader, GLuint, GLenum, shader, type);
-    (void)yagl_host_glCreateShader(shader, type);
+    (void)yagl_host_glCreateShader(cur_ts, shader, type);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1589,13 +1671,14 @@ static void yagl_func_glCreateShader(struct yagl_transport *t)
  */
 static void yagl_func_glShaderSource(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint shader;
     const GLchar *string;
     int32_t string_count;
     shader = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&string, &string_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glShaderSource, GLuint, void*, shader, string);
-    (void)yagl_host_glShaderSource(shader, string, string_count);
+    (void)yagl_host_glShaderSource(cur_ts, shader, string, string_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1604,12 +1687,13 @@ static void yagl_func_glShaderSource(struct yagl_transport *t)
  */
 static void yagl_func_glAttachShader(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint shader;
     program = yagl_transport_get_out_GLuint(t);
     shader = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glAttachShader, GLuint, GLuint, program, shader);
-    (void)yagl_host_glAttachShader(program, shader);
+    (void)yagl_host_glAttachShader(cur_ts, program, shader);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1618,12 +1702,13 @@ static void yagl_func_glAttachShader(struct yagl_transport *t)
  */
 static void yagl_func_glDetachShader(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint shader;
     program = yagl_transport_get_out_GLuint(t);
     shader = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glDetachShader, GLuint, GLuint, program, shader);
-    (void)yagl_host_glDetachShader(program, shader);
+    (void)yagl_host_glDetachShader(cur_ts, program, shader);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1632,10 +1717,11 @@ static void yagl_func_glDetachShader(struct yagl_transport *t)
  */
 static void yagl_func_glCompileShader(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint shader;
     shader = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glCompileShader, GLuint, shader);
-    (void)yagl_host_glCompileShader(shader);
+    (void)yagl_host_glCompileShader(cur_ts, shader);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1644,6 +1730,7 @@ static void yagl_func_glCompileShader(struct yagl_transport *t)
  */
 static void yagl_func_glBindAttribLocation(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint index;
     const GLchar *name;
@@ -1652,7 +1739,7 @@ static void yagl_func_glBindAttribLocation(struct yagl_transport *t)
     index = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&name, &name_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glBindAttribLocation, GLuint, GLuint, void*, program, index, name);
-    (void)yagl_host_glBindAttribLocation(program, index, name, name_count);
+    (void)yagl_host_glBindAttribLocation(cur_ts, program, index, name, name_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1661,6 +1748,7 @@ static void yagl_func_glBindAttribLocation(struct yagl_transport *t)
  */
 static void yagl_func_glGetActiveAttrib(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint index;
     GLint *size;
@@ -1675,7 +1763,7 @@ static void yagl_func_glGetActiveAttrib(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLchar), (void**)&name, &name_maxcount, &name_count);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glGetActiveAttrib, GLuint, GLuint, void*, void*, void*, program, index, size, type, name);
     *name_count = 0;
-    (void)yagl_host_glGetActiveAttrib(program, index, size, type, name, name_maxcount, name_count);
+    (void)yagl_host_glGetActiveAttrib(cur_ts, program, index, size, type, name, name_maxcount, name_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1684,6 +1772,7 @@ static void yagl_func_glGetActiveAttrib(struct yagl_transport *t)
  */
 static void yagl_func_glGetActiveUniform(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint index;
     GLint *size;
@@ -1698,7 +1787,7 @@ static void yagl_func_glGetActiveUniform(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLchar), (void**)&name, &name_maxcount, &name_count);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glGetActiveUniform, GLuint, GLuint, void*, void*, void*, program, index, size, type, name);
     *name_count = 0;
-    (void)yagl_host_glGetActiveUniform(program, index, size, type, name, name_maxcount, name_count);
+    (void)yagl_host_glGetActiveUniform(cur_ts, program, index, size, type, name, name_maxcount, name_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1707,6 +1796,7 @@ static void yagl_func_glGetActiveUniform(struct yagl_transport *t)
  */
 static void yagl_func_glGetAttribLocation(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLchar *name;
     int32_t name_count;
@@ -1715,7 +1805,7 @@ static void yagl_func_glGetAttribLocation(struct yagl_transport *t)
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&name, &name_count);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetAttribLocation, GLuint, void*, program, name);
-    *retval = yagl_host_glGetAttribLocation(program, name, name_count);
+    *retval = yagl_host_glGetAttribLocation(cur_ts, program, name, name_count);
     YAGL_LOG_FUNC_EXIT_SPLIT(int, *retval);
 }
 
@@ -1724,6 +1814,7 @@ static void yagl_func_glGetAttribLocation(struct yagl_transport *t)
  */
 static void yagl_func_glGetProgramiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLenum pname;
     GLint *param;
@@ -1731,7 +1822,7 @@ static void yagl_func_glGetProgramiv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_in_arg(t, (void**)&param);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetProgramiv, GLuint, GLenum, void*, program, pname, param);
-    (void)yagl_host_glGetProgramiv(program, pname, param);
+    (void)yagl_host_glGetProgramiv(cur_ts, program, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1740,6 +1831,7 @@ static void yagl_func_glGetProgramiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetProgramInfoLog(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLchar *infolog;
     int32_t infolog_maxcount;
@@ -1750,7 +1842,7 @@ static void yagl_func_glGetProgramInfoLog(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetProgramInfoLog, GLuint, void*, program, infolog);
     *infolog_count = 0;
-    *retval = yagl_host_glGetProgramInfoLog(program, infolog, infolog_maxcount, infolog_count);
+    *retval = yagl_host_glGetProgramInfoLog(cur_ts, program, infolog, infolog_maxcount, infolog_count);
     YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, *retval);
 }
 
@@ -1759,6 +1851,7 @@ static void yagl_func_glGetProgramInfoLog(struct yagl_transport *t)
  */
 static void yagl_func_glGetShaderiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint shader;
     GLenum pname;
     GLint *param;
@@ -1766,7 +1859,7 @@ static void yagl_func_glGetShaderiv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_in_arg(t, (void**)&param);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetShaderiv, GLuint, GLenum, void*, shader, pname, param);
-    (void)yagl_host_glGetShaderiv(shader, pname, param);
+    (void)yagl_host_glGetShaderiv(cur_ts, shader, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1775,6 +1868,7 @@ static void yagl_func_glGetShaderiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetShaderInfoLog(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint shader;
     GLchar *infolog;
     int32_t infolog_maxcount;
@@ -1785,7 +1879,7 @@ static void yagl_func_glGetShaderInfoLog(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetShaderInfoLog, GLuint, void*, shader, infolog);
     *infolog_count = 0;
-    *retval = yagl_host_glGetShaderInfoLog(shader, infolog, infolog_maxcount, infolog_count);
+    *retval = yagl_host_glGetShaderInfoLog(cur_ts, shader, infolog, infolog_maxcount, infolog_count);
     YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, *retval);
 }
 
@@ -1794,6 +1888,7 @@ static void yagl_func_glGetShaderInfoLog(struct yagl_transport *t)
  */
 static void yagl_func_glGetUniformfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     GLuint program;
     uint32_t location;
@@ -1806,7 +1901,7 @@ static void yagl_func_glGetUniformfv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glGetUniformfv, GLboolean, GLuint, uint32_t, void*, tl, program, location, params);
     *params_count = 0;
-    (void)yagl_host_glGetUniformfv(tl, program, location, params, params_maxcount, params_count);
+    (void)yagl_host_glGetUniformfv(cur_ts, tl, program, location, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1815,6 +1910,7 @@ static void yagl_func_glGetUniformfv(struct yagl_transport *t)
  */
 static void yagl_func_glGetUniformiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     GLuint program;
     uint32_t location;
@@ -1827,7 +1923,7 @@ static void yagl_func_glGetUniformiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glGetUniformiv, GLboolean, GLuint, uint32_t, void*, tl, program, location, params);
     *params_count = 0;
-    (void)yagl_host_glGetUniformiv(tl, program, location, params, params_maxcount, params_count);
+    (void)yagl_host_glGetUniformiv(cur_ts, tl, program, location, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1836,6 +1932,7 @@ static void yagl_func_glGetUniformiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetUniformLocation(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLchar *name;
     int32_t name_count;
@@ -1844,7 +1941,7 @@ static void yagl_func_glGetUniformLocation(struct yagl_transport *t)
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&name, &name_count);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetUniformLocation, GLuint, void*, program, name);
-    *retval = yagl_host_glGetUniformLocation(program, name, name_count);
+    *retval = yagl_host_glGetUniformLocation(cur_ts, program, name, name_count);
     YAGL_LOG_FUNC_EXIT_SPLIT(int, *retval);
 }
 
@@ -1853,6 +1950,7 @@ static void yagl_func_glGetUniformLocation(struct yagl_transport *t)
  */
 static void yagl_func_glGetVertexAttribfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLenum pname;
     GLfloat *params;
@@ -1863,7 +1961,7 @@ static void yagl_func_glGetVertexAttribfv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetVertexAttribfv, GLuint, GLenum, void*, index, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetVertexAttribfv(index, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetVertexAttribfv(cur_ts, index, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1872,6 +1970,7 @@ static void yagl_func_glGetVertexAttribfv(struct yagl_transport *t)
  */
 static void yagl_func_glGetVertexAttribiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLenum pname;
     GLint *params;
@@ -1882,7 +1981,7 @@ static void yagl_func_glGetVertexAttribiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetVertexAttribiv, GLuint, GLenum, void*, index, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetVertexAttribiv(index, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetVertexAttribiv(cur_ts, index, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1891,6 +1990,7 @@ static void yagl_func_glGetVertexAttribiv(struct yagl_transport *t)
  */
 static void yagl_func_glLinkProgram(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLint *params;
     int32_t params_maxcount;
@@ -1899,7 +1999,7 @@ static void yagl_func_glLinkProgram(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glLinkProgram, GLuint, void*, program, params);
     *params_count = 0;
-    (void)yagl_host_glLinkProgram(program, params, params_maxcount, params_count);
+    (void)yagl_host_glLinkProgram(cur_ts, program, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1908,6 +2008,7 @@ static void yagl_func_glLinkProgram(struct yagl_transport *t)
  */
 static void yagl_func_glUniform1f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLfloat x;
@@ -1915,7 +2016,7 @@ static void yagl_func_glUniform1f(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     x = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform1f, GLboolean, uint32_t, GLfloat, tl, location, x);
-    (void)yagl_host_glUniform1f(tl, location, x);
+    (void)yagl_host_glUniform1f(cur_ts, tl, location, x);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1924,6 +2025,7 @@ static void yagl_func_glUniform1f(struct yagl_transport *t)
  */
 static void yagl_func_glUniform1fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLfloat *v;
@@ -1932,7 +2034,7 @@ static void yagl_func_glUniform1fv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform1fv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform1fv(tl, location, v, v_count);
+    (void)yagl_host_glUniform1fv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1941,6 +2043,7 @@ static void yagl_func_glUniform1fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform1i(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLint x;
@@ -1948,7 +2051,7 @@ static void yagl_func_glUniform1i(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     x = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform1i, GLboolean, uint32_t, GLint, tl, location, x);
-    (void)yagl_host_glUniform1i(tl, location, x);
+    (void)yagl_host_glUniform1i(cur_ts, tl, location, x);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1957,6 +2060,7 @@ static void yagl_func_glUniform1i(struct yagl_transport *t)
  */
 static void yagl_func_glUniform1iv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLint *v;
@@ -1965,7 +2069,7 @@ static void yagl_func_glUniform1iv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform1iv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform1iv(tl, location, v, v_count);
+    (void)yagl_host_glUniform1iv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1974,6 +2078,7 @@ static void yagl_func_glUniform1iv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform2f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLfloat x;
@@ -1983,7 +2088,7 @@ static void yagl_func_glUniform2f(struct yagl_transport *t)
     x = yagl_transport_get_out_GLfloat(t);
     y = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniform2f, GLboolean, uint32_t, GLfloat, GLfloat, tl, location, x, y);
-    (void)yagl_host_glUniform2f(tl, location, x, y);
+    (void)yagl_host_glUniform2f(cur_ts, tl, location, x, y);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1992,6 +2097,7 @@ static void yagl_func_glUniform2f(struct yagl_transport *t)
  */
 static void yagl_func_glUniform2fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLfloat *v;
@@ -2000,7 +2106,7 @@ static void yagl_func_glUniform2fv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform2fv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform2fv(tl, location, v, v_count);
+    (void)yagl_host_glUniform2fv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2009,6 +2115,7 @@ static void yagl_func_glUniform2fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform2i(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLint x;
@@ -2018,7 +2125,7 @@ static void yagl_func_glUniform2i(struct yagl_transport *t)
     x = yagl_transport_get_out_GLint(t);
     y = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniform2i, GLboolean, uint32_t, GLint, GLint, tl, location, x, y);
-    (void)yagl_host_glUniform2i(tl, location, x, y);
+    (void)yagl_host_glUniform2i(cur_ts, tl, location, x, y);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2027,6 +2134,7 @@ static void yagl_func_glUniform2i(struct yagl_transport *t)
  */
 static void yagl_func_glUniform2iv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLint *v;
@@ -2035,7 +2143,7 @@ static void yagl_func_glUniform2iv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform2iv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform2iv(tl, location, v, v_count);
+    (void)yagl_host_glUniform2iv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2044,6 +2152,7 @@ static void yagl_func_glUniform2iv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform3f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLfloat x;
@@ -2055,7 +2164,7 @@ static void yagl_func_glUniform3f(struct yagl_transport *t)
     y = yagl_transport_get_out_GLfloat(t);
     z = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glUniform3f, GLboolean, uint32_t, GLfloat, GLfloat, GLfloat, tl, location, x, y, z);
-    (void)yagl_host_glUniform3f(tl, location, x, y, z);
+    (void)yagl_host_glUniform3f(cur_ts, tl, location, x, y, z);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2064,6 +2173,7 @@ static void yagl_func_glUniform3f(struct yagl_transport *t)
  */
 static void yagl_func_glUniform3fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLfloat *v;
@@ -2072,7 +2182,7 @@ static void yagl_func_glUniform3fv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform3fv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform3fv(tl, location, v, v_count);
+    (void)yagl_host_glUniform3fv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2081,6 +2191,7 @@ static void yagl_func_glUniform3fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform3i(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLint x;
@@ -2092,7 +2203,7 @@ static void yagl_func_glUniform3i(struct yagl_transport *t)
     y = yagl_transport_get_out_GLint(t);
     z = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glUniform3i, GLboolean, uint32_t, GLint, GLint, GLint, tl, location, x, y, z);
-    (void)yagl_host_glUniform3i(tl, location, x, y, z);
+    (void)yagl_host_glUniform3i(cur_ts, tl, location, x, y, z);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2101,6 +2212,7 @@ static void yagl_func_glUniform3i(struct yagl_transport *t)
  */
 static void yagl_func_glUniform3iv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLint *v;
@@ -2109,7 +2221,7 @@ static void yagl_func_glUniform3iv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform3iv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform3iv(tl, location, v, v_count);
+    (void)yagl_host_glUniform3iv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2118,6 +2230,7 @@ static void yagl_func_glUniform3iv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform4f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLfloat x;
@@ -2131,7 +2244,7 @@ static void yagl_func_glUniform4f(struct yagl_transport *t)
     z = yagl_transport_get_out_GLfloat(t);
     w = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glUniform4f, GLboolean, uint32_t, GLfloat, GLfloat, GLfloat, GLfloat, tl, location, x, y, z, w);
-    (void)yagl_host_glUniform4f(tl, location, x, y, z, w);
+    (void)yagl_host_glUniform4f(cur_ts, tl, location, x, y, z, w);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2140,6 +2253,7 @@ static void yagl_func_glUniform4f(struct yagl_transport *t)
  */
 static void yagl_func_glUniform4fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLfloat *v;
@@ -2148,7 +2262,7 @@ static void yagl_func_glUniform4fv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform4fv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform4fv(tl, location, v, v_count);
+    (void)yagl_host_glUniform4fv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2157,6 +2271,7 @@ static void yagl_func_glUniform4fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform4i(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLint x;
@@ -2170,7 +2285,7 @@ static void yagl_func_glUniform4i(struct yagl_transport *t)
     z = yagl_transport_get_out_GLint(t);
     w = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glUniform4i, GLboolean, uint32_t, GLint, GLint, GLint, GLint, tl, location, x, y, z, w);
-    (void)yagl_host_glUniform4i(tl, location, x, y, z, w);
+    (void)yagl_host_glUniform4i(cur_ts, tl, location, x, y, z, w);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2179,6 +2294,7 @@ static void yagl_func_glUniform4i(struct yagl_transport *t)
  */
 static void yagl_func_glUniform4iv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLint *v;
@@ -2187,7 +2303,7 @@ static void yagl_func_glUniform4iv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform4iv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform4iv(tl, location, v, v_count);
+    (void)yagl_host_glUniform4iv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2196,6 +2312,7 @@ static void yagl_func_glUniform4iv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix2fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2206,7 +2323,7 @@ static void yagl_func_glUniformMatrix2fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix2fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix2fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix2fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2215,6 +2332,7 @@ static void yagl_func_glUniformMatrix2fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix3fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2225,7 +2343,7 @@ static void yagl_func_glUniformMatrix3fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix3fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix3fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix3fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2234,6 +2352,7 @@ static void yagl_func_glUniformMatrix3fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix4fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2244,7 +2363,7 @@ static void yagl_func_glUniformMatrix4fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix4fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix4fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix4fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2253,10 +2372,11 @@ static void yagl_func_glUniformMatrix4fv(struct yagl_transport *t)
  */
 static void yagl_func_glUseProgram(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     program = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glUseProgram, GLuint, program);
-    (void)yagl_host_glUseProgram(program);
+    (void)yagl_host_glUseProgram(cur_ts, program);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2265,10 +2385,11 @@ static void yagl_func_glUseProgram(struct yagl_transport *t)
  */
 static void yagl_func_glValidateProgram(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     program = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glValidateProgram, GLuint, program);
-    (void)yagl_host_glValidateProgram(program);
+    (void)yagl_host_glValidateProgram(cur_ts, program);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2277,12 +2398,13 @@ static void yagl_func_glValidateProgram(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib1f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     GLfloat x;
     indx = yagl_transport_get_out_GLuint(t);
     x = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttrib1f, GLuint, GLfloat, indx, x);
-    (void)yagl_host_glVertexAttrib1f(indx, x);
+    (void)yagl_host_glVertexAttrib1f(cur_ts, indx, x);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2291,13 +2413,14 @@ static void yagl_func_glVertexAttrib1f(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib1fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     const GLfloat *values;
     int32_t values_count;
     indx = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&values, &values_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttrib1fv, GLuint, void*, indx, values);
-    (void)yagl_host_glVertexAttrib1fv(indx, values, values_count);
+    (void)yagl_host_glVertexAttrib1fv(cur_ts, indx, values, values_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2306,6 +2429,7 @@ static void yagl_func_glVertexAttrib1fv(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib2f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     GLfloat x;
     GLfloat y;
@@ -2313,7 +2437,7 @@ static void yagl_func_glVertexAttrib2f(struct yagl_transport *t)
     x = yagl_transport_get_out_GLfloat(t);
     y = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glVertexAttrib2f, GLuint, GLfloat, GLfloat, indx, x, y);
-    (void)yagl_host_glVertexAttrib2f(indx, x, y);
+    (void)yagl_host_glVertexAttrib2f(cur_ts, indx, x, y);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2322,13 +2446,14 @@ static void yagl_func_glVertexAttrib2f(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib2fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     const GLfloat *values;
     int32_t values_count;
     indx = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&values, &values_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttrib2fv, GLuint, void*, indx, values);
-    (void)yagl_host_glVertexAttrib2fv(indx, values, values_count);
+    (void)yagl_host_glVertexAttrib2fv(cur_ts, indx, values, values_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2337,6 +2462,7 @@ static void yagl_func_glVertexAttrib2fv(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib3f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     GLfloat x;
     GLfloat y;
@@ -2346,7 +2472,7 @@ static void yagl_func_glVertexAttrib3f(struct yagl_transport *t)
     y = yagl_transport_get_out_GLfloat(t);
     z = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glVertexAttrib3f, GLuint, GLfloat, GLfloat, GLfloat, indx, x, y, z);
-    (void)yagl_host_glVertexAttrib3f(indx, x, y, z);
+    (void)yagl_host_glVertexAttrib3f(cur_ts, indx, x, y, z);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2355,13 +2481,14 @@ static void yagl_func_glVertexAttrib3f(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib3fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     const GLfloat *values;
     int32_t values_count;
     indx = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&values, &values_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttrib3fv, GLuint, void*, indx, values);
-    (void)yagl_host_glVertexAttrib3fv(indx, values, values_count);
+    (void)yagl_host_glVertexAttrib3fv(cur_ts, indx, values, values_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2370,6 +2497,7 @@ static void yagl_func_glVertexAttrib3fv(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib4f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     GLfloat x;
     GLfloat y;
@@ -2381,7 +2509,7 @@ static void yagl_func_glVertexAttrib4f(struct yagl_transport *t)
     z = yagl_transport_get_out_GLfloat(t);
     w = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glVertexAttrib4f, GLuint, GLfloat, GLfloat, GLfloat, GLfloat, indx, x, y, z, w);
-    (void)yagl_host_glVertexAttrib4f(indx, x, y, z, w);
+    (void)yagl_host_glVertexAttrib4f(cur_ts, indx, x, y, z, w);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2390,13 +2518,14 @@ static void yagl_func_glVertexAttrib4f(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttrib4fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint indx;
     const GLfloat *values;
     int32_t values_count;
     indx = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&values, &values_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttrib4fv, GLuint, void*, indx, values);
-    (void)yagl_host_glVertexAttrib4fv(indx, values, values_count);
+    (void)yagl_host_glVertexAttrib4fv(cur_ts, indx, values, values_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2405,6 +2534,7 @@ static void yagl_func_glVertexAttrib4fv(struct yagl_transport *t)
  */
 static void yagl_func_glGetActiveUniformsiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLuint *uniformIndices;
     int32_t uniformIndices_count;
@@ -2416,7 +2546,7 @@ static void yagl_func_glGetActiveUniformsiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetActiveUniformsiv, GLuint, void*, void*, program, uniformIndices, params);
     *params_count = 0;
-    (void)yagl_host_glGetActiveUniformsiv(program, uniformIndices, uniformIndices_count, params, params_maxcount, params_count);
+    (void)yagl_host_glGetActiveUniformsiv(cur_ts, program, uniformIndices, uniformIndices_count, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2425,6 +2555,7 @@ static void yagl_func_glGetActiveUniformsiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetUniformIndices(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLchar *uniformNames;
     int32_t uniformNames_count;
@@ -2436,7 +2567,7 @@ static void yagl_func_glGetUniformIndices(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLuint), (void**)&uniformIndices, &uniformIndices_maxcount, &uniformIndices_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetUniformIndices, GLuint, void*, void*, program, uniformNames, uniformIndices);
     *uniformIndices_count = 0;
-    (void)yagl_host_glGetUniformIndices(program, uniformNames, uniformNames_count, uniformIndices, uniformIndices_maxcount, uniformIndices_count);
+    (void)yagl_host_glGetUniformIndices(cur_ts, program, uniformNames, uniformNames_count, uniformIndices, uniformIndices_maxcount, uniformIndices_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2445,6 +2576,7 @@ static void yagl_func_glGetUniformIndices(struct yagl_transport *t)
  */
 static void yagl_func_glGetUniformBlockIndex(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLchar *uniformBlockName;
     int32_t uniformBlockName_count;
@@ -2453,7 +2585,7 @@ static void yagl_func_glGetUniformBlockIndex(struct yagl_transport *t)
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&uniformBlockName, &uniformBlockName_count);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetUniformBlockIndex, GLuint, void*, program, uniformBlockName);
-    *retval = yagl_host_glGetUniformBlockIndex(program, uniformBlockName, uniformBlockName_count);
+    *retval = yagl_host_glGetUniformBlockIndex(cur_ts, program, uniformBlockName, uniformBlockName_count);
     YAGL_LOG_FUNC_EXIT_SPLIT(GLuint, *retval);
 }
 
@@ -2462,6 +2594,7 @@ static void yagl_func_glGetUniformBlockIndex(struct yagl_transport *t)
  */
 static void yagl_func_glUniformBlockBinding(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint uniformBlockIndex;
     GLuint uniformBlockBinding;
@@ -2469,7 +2602,7 @@ static void yagl_func_glUniformBlockBinding(struct yagl_transport *t)
     uniformBlockIndex = yagl_transport_get_out_GLuint(t);
     uniformBlockBinding = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniformBlockBinding, GLuint, GLuint, GLuint, program, uniformBlockIndex, uniformBlockBinding);
-    (void)yagl_host_glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
+    (void)yagl_host_glUniformBlockBinding(cur_ts, program, uniformBlockIndex, uniformBlockBinding);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2478,6 +2611,7 @@ static void yagl_func_glUniformBlockBinding(struct yagl_transport *t)
  */
 static void yagl_func_glGetActiveUniformBlockName(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint uniformBlockIndex;
     GLchar *uniformBlockName;
@@ -2488,7 +2622,7 @@ static void yagl_func_glGetActiveUniformBlockName(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLchar), (void**)&uniformBlockName, &uniformBlockName_maxcount, &uniformBlockName_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetActiveUniformBlockName, GLuint, GLuint, void*, program, uniformBlockIndex, uniformBlockName);
     *uniformBlockName_count = 0;
-    (void)yagl_host_glGetActiveUniformBlockName(program, uniformBlockIndex, uniformBlockName, uniformBlockName_maxcount, uniformBlockName_count);
+    (void)yagl_host_glGetActiveUniformBlockName(cur_ts, program, uniformBlockIndex, uniformBlockName, uniformBlockName_maxcount, uniformBlockName_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2497,6 +2631,7 @@ static void yagl_func_glGetActiveUniformBlockName(struct yagl_transport *t)
  */
 static void yagl_func_glGetActiveUniformBlockiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLuint uniformBlockIndex;
     GLenum pname;
@@ -2509,7 +2644,7 @@ static void yagl_func_glGetActiveUniformBlockiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glGetActiveUniformBlockiv, GLuint, GLuint, GLenum, void*, program, uniformBlockIndex, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetActiveUniformBlockiv(program, uniformBlockIndex, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetActiveUniformBlockiv(cur_ts, program, uniformBlockIndex, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2518,6 +2653,7 @@ static void yagl_func_glGetActiveUniformBlockiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetVertexAttribIiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLenum pname;
     GLint *params;
@@ -2528,7 +2664,7 @@ static void yagl_func_glGetVertexAttribIiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetVertexAttribIiv, GLuint, GLenum, void*, index, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetVertexAttribIiv(index, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetVertexAttribIiv(cur_ts, index, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2537,6 +2673,7 @@ static void yagl_func_glGetVertexAttribIiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetVertexAttribIuiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLenum pname;
     GLuint *params;
@@ -2547,7 +2684,7 @@ static void yagl_func_glGetVertexAttribIuiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLuint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetVertexAttribIuiv, GLuint, GLenum, void*, index, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetVertexAttribIuiv(index, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetVertexAttribIuiv(cur_ts, index, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2556,6 +2693,7 @@ static void yagl_func_glGetVertexAttribIuiv(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribI4i(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLint x;
     GLint y;
@@ -2567,7 +2705,7 @@ static void yagl_func_glVertexAttribI4i(struct yagl_transport *t)
     z = yagl_transport_get_out_GLint(t);
     w = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glVertexAttribI4i, GLuint, GLint, GLint, GLint, GLint, index, x, y, z, w);
-    (void)yagl_host_glVertexAttribI4i(index, x, y, z, w);
+    (void)yagl_host_glVertexAttribI4i(cur_ts, index, x, y, z, w);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2576,6 +2714,7 @@ static void yagl_func_glVertexAttribI4i(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribI4ui(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     GLuint x;
     GLuint y;
@@ -2587,7 +2726,7 @@ static void yagl_func_glVertexAttribI4ui(struct yagl_transport *t)
     z = yagl_transport_get_out_GLuint(t);
     w = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glVertexAttribI4ui, GLuint, GLuint, GLuint, GLuint, GLuint, index, x, y, z, w);
-    (void)yagl_host_glVertexAttribI4ui(index, x, y, z, w);
+    (void)yagl_host_glVertexAttribI4ui(cur_ts, index, x, y, z, w);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2596,13 +2735,14 @@ static void yagl_func_glVertexAttribI4ui(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribI4iv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     const GLint *v;
     int32_t v_count;
     index = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttribI4iv, GLuint, void*, index, v);
-    (void)yagl_host_glVertexAttribI4iv(index, v, v_count);
+    (void)yagl_host_glVertexAttribI4iv(cur_ts, index, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2611,13 +2751,14 @@ static void yagl_func_glVertexAttribI4iv(struct yagl_transport *t)
  */
 static void yagl_func_glVertexAttribI4uiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint index;
     const GLuint *v;
     int32_t v_count;
     index = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glVertexAttribI4uiv, GLuint, void*, index, v);
-    (void)yagl_host_glVertexAttribI4uiv(index, v, v_count);
+    (void)yagl_host_glVertexAttribI4uiv(cur_ts, index, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2626,6 +2767,7 @@ static void yagl_func_glVertexAttribI4uiv(struct yagl_transport *t)
  */
 static void yagl_func_glGetUniformuiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     GLuint program;
     uint32_t location;
@@ -2638,7 +2780,7 @@ static void yagl_func_glGetUniformuiv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLuint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glGetUniformuiv, GLboolean, GLuint, uint32_t, void*, tl, program, location, params);
     *params_count = 0;
-    (void)yagl_host_glGetUniformuiv(tl, program, location, params, params_maxcount, params_count);
+    (void)yagl_host_glGetUniformuiv(cur_ts, tl, program, location, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2647,6 +2789,7 @@ static void yagl_func_glGetUniformuiv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform1ui(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLuint v0;
@@ -2654,7 +2797,7 @@ static void yagl_func_glUniform1ui(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     v0 = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform1ui, GLboolean, uint32_t, GLuint, tl, location, v0);
-    (void)yagl_host_glUniform1ui(tl, location, v0);
+    (void)yagl_host_glUniform1ui(cur_ts, tl, location, v0);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2663,6 +2806,7 @@ static void yagl_func_glUniform1ui(struct yagl_transport *t)
  */
 static void yagl_func_glUniform2ui(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLuint v0;
@@ -2672,7 +2816,7 @@ static void yagl_func_glUniform2ui(struct yagl_transport *t)
     v0 = yagl_transport_get_out_GLuint(t);
     v1 = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniform2ui, GLboolean, uint32_t, GLuint, GLuint, tl, location, v0, v1);
-    (void)yagl_host_glUniform2ui(tl, location, v0, v1);
+    (void)yagl_host_glUniform2ui(cur_ts, tl, location, v0, v1);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2681,6 +2825,7 @@ static void yagl_func_glUniform2ui(struct yagl_transport *t)
  */
 static void yagl_func_glUniform3ui(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLuint v0;
@@ -2692,7 +2837,7 @@ static void yagl_func_glUniform3ui(struct yagl_transport *t)
     v1 = yagl_transport_get_out_GLuint(t);
     v2 = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glUniform3ui, GLboolean, uint32_t, GLuint, GLuint, GLuint, tl, location, v0, v1, v2);
-    (void)yagl_host_glUniform3ui(tl, location, v0, v1, v2);
+    (void)yagl_host_glUniform3ui(cur_ts, tl, location, v0, v1, v2);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2701,6 +2846,7 @@ static void yagl_func_glUniform3ui(struct yagl_transport *t)
  */
 static void yagl_func_glUniform4ui(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLuint v0;
@@ -2714,7 +2860,7 @@ static void yagl_func_glUniform4ui(struct yagl_transport *t)
     v2 = yagl_transport_get_out_GLuint(t);
     v3 = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glUniform4ui, GLboolean, uint32_t, GLuint, GLuint, GLuint, GLuint, tl, location, v0, v1, v2, v3);
-    (void)yagl_host_glUniform4ui(tl, location, v0, v1, v2, v3);
+    (void)yagl_host_glUniform4ui(cur_ts, tl, location, v0, v1, v2, v3);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2723,6 +2869,7 @@ static void yagl_func_glUniform4ui(struct yagl_transport *t)
  */
 static void yagl_func_glUniform1uiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLuint *v;
@@ -2731,7 +2878,7 @@ static void yagl_func_glUniform1uiv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform1uiv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform1uiv(tl, location, v, v_count);
+    (void)yagl_host_glUniform1uiv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2740,6 +2887,7 @@ static void yagl_func_glUniform1uiv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform2uiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLuint *v;
@@ -2748,7 +2896,7 @@ static void yagl_func_glUniform2uiv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform2uiv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform2uiv(tl, location, v, v_count);
+    (void)yagl_host_glUniform2uiv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2757,6 +2905,7 @@ static void yagl_func_glUniform2uiv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform3uiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLuint *v;
@@ -2765,7 +2914,7 @@ static void yagl_func_glUniform3uiv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform3uiv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform3uiv(tl, location, v, v_count);
+    (void)yagl_host_glUniform3uiv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2774,6 +2923,7 @@ static void yagl_func_glUniform3uiv(struct yagl_transport *t)
  */
 static void yagl_func_glUniform4uiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     const GLuint *v;
@@ -2782,7 +2932,7 @@ static void yagl_func_glUniform4uiv(struct yagl_transport *t)
     location = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&v, &v_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glUniform4uiv, GLboolean, uint32_t, void*, tl, location, v);
-    (void)yagl_host_glUniform4uiv(tl, location, v, v_count);
+    (void)yagl_host_glUniform4uiv(cur_ts, tl, location, v, v_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2791,6 +2941,7 @@ static void yagl_func_glUniform4uiv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix2x3fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2801,7 +2952,7 @@ static void yagl_func_glUniformMatrix2x3fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix2x3fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix2x3fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix2x3fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2810,6 +2961,7 @@ static void yagl_func_glUniformMatrix2x3fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix2x4fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2820,7 +2972,7 @@ static void yagl_func_glUniformMatrix2x4fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix2x4fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix2x4fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix2x4fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2829,6 +2981,7 @@ static void yagl_func_glUniformMatrix2x4fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix3x2fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2839,7 +2992,7 @@ static void yagl_func_glUniformMatrix3x2fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix3x2fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix3x2fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix3x2fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2848,6 +3001,7 @@ static void yagl_func_glUniformMatrix3x2fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix3x4fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2858,7 +3012,7 @@ static void yagl_func_glUniformMatrix3x4fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix3x4fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix3x4fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix3x4fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2867,6 +3021,7 @@ static void yagl_func_glUniformMatrix3x4fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix4x2fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2877,7 +3032,7 @@ static void yagl_func_glUniformMatrix4x2fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix4x2fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix4x2fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix4x2fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2886,6 +3041,7 @@ static void yagl_func_glUniformMatrix4x2fv(struct yagl_transport *t)
  */
 static void yagl_func_glUniformMatrix4x3fv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean tl;
     uint32_t location;
     GLboolean transpose;
@@ -2896,7 +3052,7 @@ static void yagl_func_glUniformMatrix4x3fv(struct yagl_transport *t)
     transpose = yagl_transport_get_out_GLboolean(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&value, &value_count);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glUniformMatrix4x3fv, GLboolean, uint32_t, GLboolean, void*, tl, location, transpose, value);
-    (void)yagl_host_glUniformMatrix4x3fv(tl, location, transpose, value, value_count);
+    (void)yagl_host_glUniformMatrix4x3fv(cur_ts, tl, location, transpose, value, value_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2905,6 +3061,7 @@ static void yagl_func_glUniformMatrix4x3fv(struct yagl_transport *t)
  */
 static void yagl_func_glGetFragDataLocation(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLchar *name;
     int32_t name_count;
@@ -2913,7 +3070,7 @@ static void yagl_func_glGetFragDataLocation(struct yagl_transport *t)
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&name, &name_count);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetFragDataLocation, GLuint, void*, program, name);
-    *retval = yagl_host_glGetFragDataLocation(program, name, name_count);
+    *retval = yagl_host_glGetFragDataLocation(cur_ts, program, name, name_count);
     YAGL_LOG_FUNC_EXIT_SPLIT(int, *retval);
 }
 
@@ -2922,6 +3079,7 @@ static void yagl_func_glGetFragDataLocation(struct yagl_transport *t)
  */
 static void yagl_func_glGetIntegerv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLint *params;
     int32_t params_maxcount;
@@ -2930,7 +3088,7 @@ static void yagl_func_glGetIntegerv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLint), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetIntegerv, GLenum, void*, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetIntegerv(pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetIntegerv(cur_ts, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2939,6 +3097,7 @@ static void yagl_func_glGetIntegerv(struct yagl_transport *t)
  */
 static void yagl_func_glGetFloatv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLfloat *params;
     int32_t params_maxcount;
@@ -2947,7 +3106,7 @@ static void yagl_func_glGetFloatv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetFloatv, GLenum, void*, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetFloatv(pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetFloatv(cur_ts, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2956,6 +3115,7 @@ static void yagl_func_glGetFloatv(struct yagl_transport *t)
  */
 static void yagl_func_glGetString(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum name;
     GLchar *str;
     int32_t str_maxcount;
@@ -2964,7 +3124,7 @@ static void yagl_func_glGetString(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLchar), (void**)&str, &str_maxcount, &str_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetString, GLenum, void*, name, str);
     *str_count = 0;
-    (void)yagl_host_glGetString(name, str, str_maxcount, str_count);
+    (void)yagl_host_glGetString(cur_ts, name, str, str_maxcount, str_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -2973,12 +3133,13 @@ static void yagl_func_glGetString(struct yagl_transport *t)
  */
 static void yagl_func_glIsEnabled(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum cap;
     GLboolean *retval;
     cap = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glIsEnabled, GLenum, cap);
-    *retval = yagl_host_glIsEnabled(cap);
+    *retval = yagl_host_glIsEnabled(cur_ts, cap);
     YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, *retval);
 }
 
@@ -2987,11 +3148,12 @@ static void yagl_func_glIsEnabled(struct yagl_transport *t)
  */
 static void yagl_func_glGenTransformFeedbacks(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *ids;
     int32_t ids_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&ids, &ids_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenTransformFeedbacks, void*, ids);
-    (void)yagl_host_glGenTransformFeedbacks(ids, ids_count);
+    (void)yagl_host_glGenTransformFeedbacks(cur_ts, ids, ids_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3000,12 +3162,13 @@ static void yagl_func_glGenTransformFeedbacks(struct yagl_transport *t)
  */
 static void yagl_func_glBindTransformFeedback(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint id;
     target = yagl_transport_get_out_GLenum(t);
     id = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBindTransformFeedback, GLenum, GLuint, target, id);
-    (void)yagl_host_glBindTransformFeedback(target, id);
+    (void)yagl_host_glBindTransformFeedback(cur_ts, target, id);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3014,10 +3177,11 @@ static void yagl_func_glBindTransformFeedback(struct yagl_transport *t)
  */
 static void yagl_func_glBeginTransformFeedback(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum primitiveMode;
     primitiveMode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glBeginTransformFeedback, GLenum, primitiveMode);
-    (void)yagl_host_glBeginTransformFeedback(primitiveMode);
+    (void)yagl_host_glBeginTransformFeedback(cur_ts, primitiveMode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3026,8 +3190,9 @@ static void yagl_func_glBeginTransformFeedback(struct yagl_transport *t)
  */
 static void yagl_func_glEndTransformFeedback(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glEndTransformFeedback);
-    (void)yagl_host_glEndTransformFeedback();
+    (void)yagl_host_glEndTransformFeedback(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3036,8 +3201,9 @@ static void yagl_func_glEndTransformFeedback(struct yagl_transport *t)
  */
 static void yagl_func_glPauseTransformFeedback(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glPauseTransformFeedback);
-    (void)yagl_host_glPauseTransformFeedback();
+    (void)yagl_host_glPauseTransformFeedback(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3046,8 +3212,9 @@ static void yagl_func_glPauseTransformFeedback(struct yagl_transport *t)
  */
 static void yagl_func_glResumeTransformFeedback(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glResumeTransformFeedback);
-    (void)yagl_host_glResumeTransformFeedback();
+    (void)yagl_host_glResumeTransformFeedback(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3056,6 +3223,7 @@ static void yagl_func_glResumeTransformFeedback(struct yagl_transport *t)
  */
 static void yagl_func_glTransformFeedbackVaryings(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     const GLchar *varyings;
     int32_t varyings_count;
@@ -3064,15 +3232,17 @@ static void yagl_func_glTransformFeedbackVaryings(struct yagl_transport *t)
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&varyings, &varyings_count);
     bufferMode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTransformFeedbackVaryings, GLuint, void*, GLenum, program, varyings, bufferMode);
-    (void)yagl_host_glTransformFeedbackVaryings(program, varyings, varyings_count, bufferMode);
+    (void)yagl_host_glTransformFeedbackVaryings(cur_ts, t, program, varyings, varyings_count, bufferMode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
+
 /*
  * glGetTransformFeedbackVaryings dispatcher. id = 169
  */
 static void yagl_func_glGetTransformFeedbackVaryings(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint program;
     GLsizei *sizes;
     int32_t sizes_maxcount;
@@ -3086,7 +3256,7 @@ static void yagl_func_glGetTransformFeedbackVaryings(struct yagl_transport *t)
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetTransformFeedbackVaryings, GLuint, void*, void*, program, sizes, types);
     *sizes_count = 0;
     *types_count = 0;
-    (void)yagl_host_glGetTransformFeedbackVaryings(program, sizes, sizes_maxcount, sizes_count, types, types_maxcount, types_count);
+    (void)yagl_host_glGetTransformFeedbackVaryings(cur_ts, program, sizes, sizes_maxcount, sizes_count, types, types_maxcount, types_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3095,11 +3265,12 @@ static void yagl_func_glGetTransformFeedbackVaryings(struct yagl_transport *t)
  */
 static void yagl_func_glGenQueries(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *ids;
     int32_t ids_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&ids, &ids_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenQueries, void*, ids);
-    (void)yagl_host_glGenQueries(ids, ids_count);
+    (void)yagl_host_glGenQueries(cur_ts, ids, ids_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3108,12 +3279,13 @@ static void yagl_func_glGenQueries(struct yagl_transport *t)
  */
 static void yagl_func_glBeginQuery(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLuint id;
     target = yagl_transport_get_out_GLenum(t);
     id = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBeginQuery, GLenum, GLuint, target, id);
-    (void)yagl_host_glBeginQuery(target, id);
+    (void)yagl_host_glBeginQuery(cur_ts, target, id);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3122,10 +3294,11 @@ static void yagl_func_glBeginQuery(struct yagl_transport *t)
  */
 static void yagl_func_glEndQuery(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     target = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glEndQuery, GLenum, target);
-    (void)yagl_host_glEndQuery(target);
+    (void)yagl_host_glEndQuery(cur_ts, target);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3134,6 +3307,7 @@ static void yagl_func_glEndQuery(struct yagl_transport *t)
  */
 static void yagl_func_glGetQueryObjectuiv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint id;
     GLenum pname;
     GLuint *result;
@@ -3143,7 +3317,7 @@ static void yagl_func_glGetQueryObjectuiv(struct yagl_transport *t)
     yagl_transport_get_in_arg(t, (void**)&result);
     yagl_transport_get_in_arg(t, (void**)&retval);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetQueryObjectuiv, GLuint, GLenum, void*, id, pname, result);
-    *retval = yagl_host_glGetQueryObjectuiv(id, pname, result);
+    *retval = yagl_host_glGetQueryObjectuiv(cur_ts, id, pname, result);
     YAGL_LOG_FUNC_EXIT_SPLIT(GLboolean, *retval);
 }
 
@@ -3152,11 +3326,12 @@ static void yagl_func_glGetQueryObjectuiv(struct yagl_transport *t)
  */
 static void yagl_func_glGenSamplers(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *samplers;
     int32_t samplers_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&samplers, &samplers_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenSamplers, void*, samplers);
-    (void)yagl_host_glGenSamplers(samplers, samplers_count);
+    (void)yagl_host_glGenSamplers(cur_ts, samplers, samplers_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3165,12 +3340,13 @@ static void yagl_func_glGenSamplers(struct yagl_transport *t)
  */
 static void yagl_func_glBindSampler(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint unit;
     GLuint sampler;
     unit = yagl_transport_get_out_GLuint(t);
     sampler = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBindSampler, GLuint, GLuint, unit, sampler);
-    (void)yagl_host_glBindSampler(unit, sampler);
+    (void)yagl_host_glBindSampler(cur_ts, unit, sampler);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3179,6 +3355,7 @@ static void yagl_func_glBindSampler(struct yagl_transport *t)
  */
 static void yagl_func_glSamplerParameteri(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint sampler;
     GLenum pname;
     GLint param;
@@ -3186,7 +3363,7 @@ static void yagl_func_glSamplerParameteri(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glSamplerParameteri, GLuint, GLenum, GLint, sampler, pname, param);
-    (void)yagl_host_glSamplerParameteri(sampler, pname, param);
+    (void)yagl_host_glSamplerParameteri(cur_ts, sampler, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3195,6 +3372,7 @@ static void yagl_func_glSamplerParameteri(struct yagl_transport *t)
  */
 static void yagl_func_glSamplerParameteriv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint sampler;
     GLenum pname;
     const GLint *param;
@@ -3203,7 +3381,7 @@ static void yagl_func_glSamplerParameteriv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLint), (const void**)&param, &param_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glSamplerParameteriv, GLuint, GLenum, void*, sampler, pname, param);
-    (void)yagl_host_glSamplerParameteriv(sampler, pname, param, param_count);
+    (void)yagl_host_glSamplerParameteriv(cur_ts, sampler, pname, param, param_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3212,6 +3390,7 @@ static void yagl_func_glSamplerParameteriv(struct yagl_transport *t)
  */
 static void yagl_func_glSamplerParameterf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint sampler;
     GLenum pname;
     GLfloat param;
@@ -3219,7 +3398,7 @@ static void yagl_func_glSamplerParameterf(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glSamplerParameterf, GLuint, GLenum, GLfloat, sampler, pname, param);
-    (void)yagl_host_glSamplerParameterf(sampler, pname, param);
+    (void)yagl_host_glSamplerParameterf(cur_ts, sampler, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3228,6 +3407,7 @@ static void yagl_func_glSamplerParameterf(struct yagl_transport *t)
  */
 static void yagl_func_glSamplerParameterfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint sampler;
     GLenum pname;
     const GLfloat *param;
@@ -3236,7 +3416,7 @@ static void yagl_func_glSamplerParameterfv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&param, &param_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glSamplerParameterfv, GLuint, GLenum, void*, sampler, pname, param);
-    (void)yagl_host_glSamplerParameterfv(sampler, pname, param, param_count);
+    (void)yagl_host_glSamplerParameterfv(cur_ts, sampler, pname, param, param_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3245,11 +3425,12 @@ static void yagl_func_glSamplerParameterfv(struct yagl_transport *t)
  */
 static void yagl_func_glDeleteObjects(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLuint *objects;
     int32_t objects_count;
     yagl_transport_get_out_array(t, sizeof(GLuint), (const void**)&objects, &objects_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDeleteObjects, void*, objects);
-    (void)yagl_host_glDeleteObjects(objects, objects_count);
+    (void)yagl_host_glDeleteObjects(cur_ts, objects, objects_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3258,10 +3439,11 @@ static void yagl_func_glDeleteObjects(struct yagl_transport *t)
  */
 static void yagl_func_glBlendEquation(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glBlendEquation, GLenum, mode);
-    (void)yagl_host_glBlendEquation(mode);
+    (void)yagl_host_glBlendEquation(cur_ts, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3270,12 +3452,13 @@ static void yagl_func_glBlendEquation(struct yagl_transport *t)
  */
 static void yagl_func_glBlendEquationSeparate(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum modeRGB;
     GLenum modeAlpha;
     modeRGB = yagl_transport_get_out_GLenum(t);
     modeAlpha = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBlendEquationSeparate, GLenum, GLenum, modeRGB, modeAlpha);
-    (void)yagl_host_glBlendEquationSeparate(modeRGB, modeAlpha);
+    (void)yagl_host_glBlendEquationSeparate(cur_ts, modeRGB, modeAlpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3284,12 +3467,13 @@ static void yagl_func_glBlendEquationSeparate(struct yagl_transport *t)
  */
 static void yagl_func_glBlendFunc(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum sfactor;
     GLenum dfactor;
     sfactor = yagl_transport_get_out_GLenum(t);
     dfactor = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glBlendFunc, GLenum, GLenum, sfactor, dfactor);
-    (void)yagl_host_glBlendFunc(sfactor, dfactor);
+    (void)yagl_host_glBlendFunc(cur_ts, sfactor, dfactor);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3298,6 +3482,7 @@ static void yagl_func_glBlendFunc(struct yagl_transport *t)
  */
 static void yagl_func_glBlendFuncSeparate(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum srcRGB;
     GLenum dstRGB;
     GLenum srcAlpha;
@@ -3307,7 +3492,7 @@ static void yagl_func_glBlendFuncSeparate(struct yagl_transport *t)
     srcAlpha = yagl_transport_get_out_GLenum(t);
     dstAlpha = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glBlendFuncSeparate, GLenum, GLenum, GLenum, GLenum, srcRGB, dstRGB, srcAlpha, dstAlpha);
-    (void)yagl_host_glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
+    (void)yagl_host_glBlendFuncSeparate(cur_ts, srcRGB, dstRGB, srcAlpha, dstAlpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3316,6 +3501,7 @@ static void yagl_func_glBlendFuncSeparate(struct yagl_transport *t)
  */
 static void yagl_func_glBlendColor(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLclampf red;
     GLclampf green;
     GLclampf blue;
@@ -3325,7 +3511,7 @@ static void yagl_func_glBlendColor(struct yagl_transport *t)
     blue = yagl_transport_get_out_GLclampf(t);
     alpha = yagl_transport_get_out_GLclampf(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glBlendColor, GLclampf, GLclampf, GLclampf, GLclampf, red, green, blue, alpha);
-    (void)yagl_host_glBlendColor(red, green, blue, alpha);
+    (void)yagl_host_glBlendColor(cur_ts, red, green, blue, alpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3334,10 +3520,11 @@ static void yagl_func_glBlendColor(struct yagl_transport *t)
  */
 static void yagl_func_glClear(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLbitfield mask;
     mask = yagl_transport_get_out_GLbitfield(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glClear, GLbitfield, mask);
-    (void)yagl_host_glClear(mask);
+    (void)yagl_host_glClear(cur_ts, mask);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3346,6 +3533,7 @@ static void yagl_func_glClear(struct yagl_transport *t)
  */
 static void yagl_func_glClearColor(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLclampf red;
     GLclampf green;
     GLclampf blue;
@@ -3355,7 +3543,7 @@ static void yagl_func_glClearColor(struct yagl_transport *t)
     blue = yagl_transport_get_out_GLclampf(t);
     alpha = yagl_transport_get_out_GLclampf(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glClearColor, GLclampf, GLclampf, GLclampf, GLclampf, red, green, blue, alpha);
-    (void)yagl_host_glClearColor(red, green, blue, alpha);
+    (void)yagl_host_glClearColor(cur_ts, red, green, blue, alpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3364,10 +3552,11 @@ static void yagl_func_glClearColor(struct yagl_transport *t)
  */
 static void yagl_func_glClearDepthf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLclampf depth;
     depth = yagl_transport_get_out_GLclampf(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glClearDepthf, GLclampf, depth);
-    (void)yagl_host_glClearDepthf(depth);
+    (void)yagl_host_glClearDepthf(cur_ts, depth);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3376,10 +3565,11 @@ static void yagl_func_glClearDepthf(struct yagl_transport *t)
  */
 static void yagl_func_glClearStencil(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint s;
     s = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glClearStencil, GLint, s);
-    (void)yagl_host_glClearStencil(s);
+    (void)yagl_host_glClearStencil(cur_ts, s);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3388,6 +3578,7 @@ static void yagl_func_glClearStencil(struct yagl_transport *t)
  */
 static void yagl_func_glColorMask(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean red;
     GLboolean green;
     GLboolean blue;
@@ -3397,7 +3588,7 @@ static void yagl_func_glColorMask(struct yagl_transport *t)
     blue = yagl_transport_get_out_GLboolean(t);
     alpha = yagl_transport_get_out_GLboolean(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glColorMask, GLboolean, GLboolean, GLboolean, GLboolean, red, green, blue, alpha);
-    (void)yagl_host_glColorMask(red, green, blue, alpha);
+    (void)yagl_host_glColorMask(cur_ts, red, green, blue, alpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3406,10 +3597,11 @@ static void yagl_func_glColorMask(struct yagl_transport *t)
  */
 static void yagl_func_glCullFace(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glCullFace, GLenum, mode);
-    (void)yagl_host_glCullFace(mode);
+    (void)yagl_host_glCullFace(cur_ts, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3418,10 +3610,11 @@ static void yagl_func_glCullFace(struct yagl_transport *t)
  */
 static void yagl_func_glDepthFunc(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum func;
     func = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDepthFunc, GLenum, func);
-    (void)yagl_host_glDepthFunc(func);
+    (void)yagl_host_glDepthFunc(cur_ts, func);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3430,10 +3623,11 @@ static void yagl_func_glDepthFunc(struct yagl_transport *t)
  */
 static void yagl_func_glDepthMask(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLboolean flag;
     flag = yagl_transport_get_out_GLboolean(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDepthMask, GLboolean, flag);
-    (void)yagl_host_glDepthMask(flag);
+    (void)yagl_host_glDepthMask(cur_ts, flag);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3442,12 +3636,13 @@ static void yagl_func_glDepthMask(struct yagl_transport *t)
  */
 static void yagl_func_glDepthRangef(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLclampf zNear;
     GLclampf zFar;
     zNear = yagl_transport_get_out_GLclampf(t);
     zFar = yagl_transport_get_out_GLclampf(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glDepthRangef, GLclampf, GLclampf, zNear, zFar);
-    (void)yagl_host_glDepthRangef(zNear, zFar);
+    (void)yagl_host_glDepthRangef(cur_ts, zNear, zFar);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3456,10 +3651,11 @@ static void yagl_func_glDepthRangef(struct yagl_transport *t)
  */
 static void yagl_func_glEnable(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum cap;
     cap = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glEnable, GLenum, cap);
-    (void)yagl_host_glEnable(cap);
+    (void)yagl_host_glEnable(cur_ts, cap);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3468,10 +3664,11 @@ static void yagl_func_glEnable(struct yagl_transport *t)
  */
 static void yagl_func_glDisable(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum cap;
     cap = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDisable, GLenum, cap);
-    (void)yagl_host_glDisable(cap);
+    (void)yagl_host_glDisable(cur_ts, cap);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3480,8 +3677,9 @@ static void yagl_func_glDisable(struct yagl_transport *t)
  */
 static void yagl_func_glFlush(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glFlush);
-    (void)yagl_host_glFlush();
+    (void)yagl_host_glFlush(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3490,10 +3688,11 @@ static void yagl_func_glFlush(struct yagl_transport *t)
  */
 static void yagl_func_glFrontFace(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glFrontFace, GLenum, mode);
-    (void)yagl_host_glFrontFace(mode);
+    (void)yagl_host_glFrontFace(cur_ts, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3502,10 +3701,11 @@ static void yagl_func_glFrontFace(struct yagl_transport *t)
  */
 static void yagl_func_glGenerateMipmap(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     target = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glGenerateMipmap, GLenum, target);
-    (void)yagl_host_glGenerateMipmap(target);
+    (void)yagl_host_glGenerateMipmap(cur_ts, target);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3514,12 +3714,13 @@ static void yagl_func_glGenerateMipmap(struct yagl_transport *t)
  */
 static void yagl_func_glHint(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum target;
     GLenum mode;
     target = yagl_transport_get_out_GLenum(t);
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glHint, GLenum, GLenum, target, mode);
-    (void)yagl_host_glHint(target, mode);
+    (void)yagl_host_glHint(cur_ts, target, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3528,10 +3729,11 @@ static void yagl_func_glHint(struct yagl_transport *t)
  */
 static void yagl_func_glLineWidth(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat width;
     width = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glLineWidth, GLfloat, width);
-    (void)yagl_host_glLineWidth(width);
+    (void)yagl_host_glLineWidth(cur_ts, width);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3540,12 +3742,13 @@ static void yagl_func_glLineWidth(struct yagl_transport *t)
  */
 static void yagl_func_glPixelStorei(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLint param;
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glPixelStorei, GLenum, GLint, pname, param);
-    (void)yagl_host_glPixelStorei(pname, param);
+    (void)yagl_host_glPixelStorei(cur_ts, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3554,12 +3757,13 @@ static void yagl_func_glPixelStorei(struct yagl_transport *t)
  */
 static void yagl_func_glPolygonOffset(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat factor;
     GLfloat units;
     factor = yagl_transport_get_out_GLfloat(t);
     units = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glPolygonOffset, GLfloat, GLfloat, factor, units);
-    (void)yagl_host_glPolygonOffset(factor, units);
+    (void)yagl_host_glPolygonOffset(cur_ts, factor, units);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3568,6 +3772,7 @@ static void yagl_func_glPolygonOffset(struct yagl_transport *t)
  */
 static void yagl_func_glScissor(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint x;
     GLint y;
     GLsizei width;
@@ -3577,7 +3782,7 @@ static void yagl_func_glScissor(struct yagl_transport *t)
     width = yagl_transport_get_out_GLsizei(t);
     height = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glScissor, GLint, GLint, GLsizei, GLsizei, x, y, width, height);
-    (void)yagl_host_glScissor(x, y, width, height);
+    (void)yagl_host_glScissor(cur_ts, x, y, width, height);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3586,6 +3791,7 @@ static void yagl_func_glScissor(struct yagl_transport *t)
  */
 static void yagl_func_glStencilFunc(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum func;
     GLint ref;
     GLuint mask;
@@ -3593,7 +3799,7 @@ static void yagl_func_glStencilFunc(struct yagl_transport *t)
     ref = yagl_transport_get_out_GLint(t);
     mask = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glStencilFunc, GLenum, GLint, GLuint, func, ref, mask);
-    (void)yagl_host_glStencilFunc(func, ref, mask);
+    (void)yagl_host_glStencilFunc(cur_ts, func, ref, mask);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3602,10 +3808,11 @@ static void yagl_func_glStencilFunc(struct yagl_transport *t)
  */
 static void yagl_func_glStencilMask(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint mask;
     mask = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glStencilMask, GLuint, mask);
-    (void)yagl_host_glStencilMask(mask);
+    (void)yagl_host_glStencilMask(cur_ts, mask);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3614,6 +3821,7 @@ static void yagl_func_glStencilMask(struct yagl_transport *t)
  */
 static void yagl_func_glStencilOp(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum fail;
     GLenum zfail;
     GLenum zpass;
@@ -3621,7 +3829,7 @@ static void yagl_func_glStencilOp(struct yagl_transport *t)
     zfail = yagl_transport_get_out_GLenum(t);
     zpass = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glStencilOp, GLenum, GLenum, GLenum, fail, zfail, zpass);
-    (void)yagl_host_glStencilOp(fail, zfail, zpass);
+    (void)yagl_host_glStencilOp(cur_ts, fail, zfail, zpass);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3630,12 +3838,13 @@ static void yagl_func_glStencilOp(struct yagl_transport *t)
  */
 static void yagl_func_glSampleCoverage(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLclampf value;
     GLboolean invert;
     value = yagl_transport_get_out_GLclampf(t);
     invert = yagl_transport_get_out_GLboolean(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glSampleCoverage, GLclampf, GLboolean, value, invert);
-    (void)yagl_host_glSampleCoverage(value, invert);
+    (void)yagl_host_glSampleCoverage(cur_ts, value, invert);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3644,6 +3853,7 @@ static void yagl_func_glSampleCoverage(struct yagl_transport *t)
  */
 static void yagl_func_glViewport(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLint x;
     GLint y;
     GLsizei width;
@@ -3653,7 +3863,7 @@ static void yagl_func_glViewport(struct yagl_transport *t)
     width = yagl_transport_get_out_GLsizei(t);
     height = yagl_transport_get_out_GLsizei(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glViewport, GLint, GLint, GLsizei, GLsizei, x, y, width, height);
-    (void)yagl_host_glViewport(x, y, width, height);
+    (void)yagl_host_glViewport(cur_ts, x, y, width, height);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3662,6 +3872,7 @@ static void yagl_func_glViewport(struct yagl_transport *t)
  */
 static void yagl_func_glStencilFuncSeparate(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum face;
     GLenum func;
     GLint ref;
@@ -3671,7 +3882,7 @@ static void yagl_func_glStencilFuncSeparate(struct yagl_transport *t)
     ref = yagl_transport_get_out_GLint(t);
     mask = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glStencilFuncSeparate, GLenum, GLenum, GLint, GLuint, face, func, ref, mask);
-    (void)yagl_host_glStencilFuncSeparate(face, func, ref, mask);
+    (void)yagl_host_glStencilFuncSeparate(cur_ts, face, func, ref, mask);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3680,12 +3891,13 @@ static void yagl_func_glStencilFuncSeparate(struct yagl_transport *t)
  */
 static void yagl_func_glStencilMaskSeparate(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum face;
     GLuint mask;
     face = yagl_transport_get_out_GLenum(t);
     mask = yagl_transport_get_out_GLuint(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glStencilMaskSeparate, GLenum, GLuint, face, mask);
-    (void)yagl_host_glStencilMaskSeparate(face, mask);
+    (void)yagl_host_glStencilMaskSeparate(cur_ts, face, mask);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3694,6 +3906,7 @@ static void yagl_func_glStencilMaskSeparate(struct yagl_transport *t)
  */
 static void yagl_func_glStencilOpSeparate(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum face;
     GLenum fail;
     GLenum zfail;
@@ -3703,7 +3916,7 @@ static void yagl_func_glStencilOpSeparate(struct yagl_transport *t)
     zfail = yagl_transport_get_out_GLenum(t);
     zpass = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glStencilOpSeparate, GLenum, GLenum, GLenum, GLenum, face, fail, zfail, zpass);
-    (void)yagl_host_glStencilOpSeparate(face, fail, zfail, zpass);
+    (void)yagl_host_glStencilOpSeparate(cur_ts, face, fail, zfail, zpass);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3712,10 +3925,11 @@ static void yagl_func_glStencilOpSeparate(struct yagl_transport *t)
  */
 static void yagl_func_glPointSize(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat size;
     size = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glPointSize, GLfloat, size);
-    (void)yagl_host_glPointSize(size);
+    (void)yagl_host_glPointSize(cur_ts, size);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3724,12 +3938,13 @@ static void yagl_func_glPointSize(struct yagl_transport *t)
  */
 static void yagl_func_glAlphaFunc(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum func;
     GLclampf ref;
     func = yagl_transport_get_out_GLenum(t);
     ref = yagl_transport_get_out_GLclampf(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glAlphaFunc, GLenum, GLclampf, func, ref);
-    (void)yagl_host_glAlphaFunc(func, ref);
+    (void)yagl_host_glAlphaFunc(cur_ts, func, ref);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3738,10 +3953,11 @@ static void yagl_func_glAlphaFunc(struct yagl_transport *t)
  */
 static void yagl_func_glMatrixMode(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glMatrixMode, GLenum, mode);
-    (void)yagl_host_glMatrixMode(mode);
+    (void)yagl_host_glMatrixMode(cur_ts, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3750,8 +3966,9 @@ static void yagl_func_glMatrixMode(struct yagl_transport *t)
  */
 static void yagl_func_glLoadIdentity(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glLoadIdentity);
-    (void)yagl_host_glLoadIdentity();
+    (void)yagl_host_glLoadIdentity(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3760,8 +3977,9 @@ static void yagl_func_glLoadIdentity(struct yagl_transport *t)
  */
 static void yagl_func_glPopMatrix(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glPopMatrix);
-    (void)yagl_host_glPopMatrix();
+    (void)yagl_host_glPopMatrix(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3770,8 +3988,9 @@ static void yagl_func_glPopMatrix(struct yagl_transport *t)
  */
 static void yagl_func_glPushMatrix(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     YAGL_LOG_FUNC_ENTER_SPLIT0(glPushMatrix);
-    (void)yagl_host_glPushMatrix();
+    (void)yagl_host_glPushMatrix(cur_ts);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3780,6 +3999,7 @@ static void yagl_func_glPushMatrix(struct yagl_transport *t)
  */
 static void yagl_func_glRotatef(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat angle;
     GLfloat x;
     GLfloat y;
@@ -3789,7 +4009,7 @@ static void yagl_func_glRotatef(struct yagl_transport *t)
     y = yagl_transport_get_out_GLfloat(t);
     z = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glRotatef, GLfloat, GLfloat, GLfloat, GLfloat, angle, x, y, z);
-    (void)yagl_host_glRotatef(angle, x, y, z);
+    (void)yagl_host_glRotatef(cur_ts, angle, x, y, z);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3798,6 +4018,7 @@ static void yagl_func_glRotatef(struct yagl_transport *t)
  */
 static void yagl_func_glTranslatef(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat x;
     GLfloat y;
     GLfloat z;
@@ -3805,7 +4026,7 @@ static void yagl_func_glTranslatef(struct yagl_transport *t)
     y = yagl_transport_get_out_GLfloat(t);
     z = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glTranslatef, GLfloat, GLfloat, GLfloat, x, y, z);
-    (void)yagl_host_glTranslatef(x, y, z);
+    (void)yagl_host_glTranslatef(cur_ts, x, y, z);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3814,6 +4035,7 @@ static void yagl_func_glTranslatef(struct yagl_transport *t)
  */
 static void yagl_func_glScalef(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat x;
     GLfloat y;
     GLfloat z;
@@ -3821,7 +4043,7 @@ static void yagl_func_glScalef(struct yagl_transport *t)
     y = yagl_transport_get_out_GLfloat(t);
     z = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glScalef, GLfloat, GLfloat, GLfloat, x, y, z);
-    (void)yagl_host_glScalef(x, y, z);
+    (void)yagl_host_glScalef(cur_ts, x, y, z);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3830,6 +4052,7 @@ static void yagl_func_glScalef(struct yagl_transport *t)
  */
 static void yagl_func_glOrthof(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat left;
     GLfloat right;
     GLfloat bottom;
@@ -3843,7 +4066,7 @@ static void yagl_func_glOrthof(struct yagl_transport *t)
     zNear = yagl_transport_get_out_GLfloat(t);
     zFar = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glOrthof, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, left, right, bottom, top, zNear, zFar);
-    (void)yagl_host_glOrthof(left, right, bottom, top, zNear, zFar);
+    (void)yagl_host_glOrthof(cur_ts, left, right, bottom, top, zNear, zFar);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3852,6 +4075,7 @@ static void yagl_func_glOrthof(struct yagl_transport *t)
  */
 static void yagl_func_glColor4f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat red;
     GLfloat green;
     GLfloat blue;
@@ -3861,7 +4085,7 @@ static void yagl_func_glColor4f(struct yagl_transport *t)
     blue = yagl_transport_get_out_GLfloat(t);
     alpha = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glColor4f, GLfloat, GLfloat, GLfloat, GLfloat, red, green, blue, alpha);
-    (void)yagl_host_glColor4f(red, green, blue, alpha);
+    (void)yagl_host_glColor4f(cur_ts, red, green, blue, alpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3870,6 +4094,7 @@ static void yagl_func_glColor4f(struct yagl_transport *t)
  */
 static void yagl_func_glColor4ub(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLubyte red;
     GLubyte green;
     GLubyte blue;
@@ -3879,7 +4104,7 @@ static void yagl_func_glColor4ub(struct yagl_transport *t)
     blue = yagl_transport_get_out_GLubyte(t);
     alpha = yagl_transport_get_out_GLubyte(t);
     YAGL_LOG_FUNC_ENTER_SPLIT4(glColor4ub, GLubyte, GLubyte, GLubyte, GLubyte, red, green, blue, alpha);
-    (void)yagl_host_glColor4ub(red, green, blue, alpha);
+    (void)yagl_host_glColor4ub(cur_ts, red, green, blue, alpha);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3888,6 +4113,7 @@ static void yagl_func_glColor4ub(struct yagl_transport *t)
  */
 static void yagl_func_glNormal3f(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat nx;
     GLfloat ny;
     GLfloat nz;
@@ -3895,7 +4121,7 @@ static void yagl_func_glNormal3f(struct yagl_transport *t)
     ny = yagl_transport_get_out_GLfloat(t);
     nz = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glNormal3f, GLfloat, GLfloat, GLfloat, nx, ny, nz);
-    (void)yagl_host_glNormal3f(nx, ny, nz);
+    (void)yagl_host_glNormal3f(cur_ts, nx, ny, nz);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3904,12 +4130,13 @@ static void yagl_func_glNormal3f(struct yagl_transport *t)
  */
 static void yagl_func_glPointParameterf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLfloat param;
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glPointParameterf, GLenum, GLfloat, pname, param);
-    (void)yagl_host_glPointParameterf(pname, param);
+    (void)yagl_host_glPointParameterf(cur_ts, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3918,13 +4145,14 @@ static void yagl_func_glPointParameterf(struct yagl_transport *t)
  */
 static void yagl_func_glPointParameterfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     const GLfloat *params;
     int32_t params_count;
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glPointParameterfv, GLenum, void*, pname, params);
-    (void)yagl_host_glPointParameterfv(pname, params, params_count);
+    (void)yagl_host_glPointParameterfv(cur_ts, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3933,12 +4161,13 @@ static void yagl_func_glPointParameterfv(struct yagl_transport *t)
  */
 static void yagl_func_glFogf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLfloat param;
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glFogf, GLenum, GLfloat, pname, param);
-    (void)yagl_host_glFogf(pname, param);
+    (void)yagl_host_glFogf(cur_ts, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3947,13 +4176,14 @@ static void yagl_func_glFogf(struct yagl_transport *t)
  */
 static void yagl_func_glFogfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     const GLfloat *params;
     int32_t params_count;
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glFogfv, GLenum, void*, pname, params);
-    (void)yagl_host_glFogfv(pname, params, params_count);
+    (void)yagl_host_glFogfv(cur_ts, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3962,6 +4192,7 @@ static void yagl_func_glFogfv(struct yagl_transport *t)
  */
 static void yagl_func_glFrustumf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLfloat left;
     GLfloat right;
     GLfloat bottom;
@@ -3975,7 +4206,7 @@ static void yagl_func_glFrustumf(struct yagl_transport *t)
     zNear = yagl_transport_get_out_GLfloat(t);
     zFar = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT6(glFrustumf, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, left, right, bottom, top, zNear, zFar);
-    (void)yagl_host_glFrustumf(left, right, bottom, top, zNear, zFar);
+    (void)yagl_host_glFrustumf(cur_ts, left, right, bottom, top, zNear, zFar);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -3984,6 +4215,7 @@ static void yagl_func_glFrustumf(struct yagl_transport *t)
  */
 static void yagl_func_glLightf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum light;
     GLenum pname;
     GLfloat param;
@@ -3991,7 +4223,7 @@ static void yagl_func_glLightf(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glLightf, GLenum, GLenum, GLfloat, light, pname, param);
-    (void)yagl_host_glLightf(light, pname, param);
+    (void)yagl_host_glLightf(cur_ts, light, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4000,6 +4232,7 @@ static void yagl_func_glLightf(struct yagl_transport *t)
  */
 static void yagl_func_glLightfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum light;
     GLenum pname;
     const GLfloat *params;
@@ -4008,7 +4241,7 @@ static void yagl_func_glLightfv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glLightfv, GLenum, GLenum, void*, light, pname, params);
-    (void)yagl_host_glLightfv(light, pname, params, params_count);
+    (void)yagl_host_glLightfv(cur_ts, light, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4017,6 +4250,7 @@ static void yagl_func_glLightfv(struct yagl_transport *t)
  */
 static void yagl_func_glGetLightfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum light;
     GLenum pname;
     GLfloat *params;
@@ -4027,7 +4261,7 @@ static void yagl_func_glGetLightfv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetLightfv, GLenum, GLenum, void*, light, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetLightfv(light, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetLightfv(cur_ts, light, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4036,12 +4270,13 @@ static void yagl_func_glGetLightfv(struct yagl_transport *t)
  */
 static void yagl_func_glLightModelf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLfloat param;
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glLightModelf, GLenum, GLfloat, pname, param);
-    (void)yagl_host_glLightModelf(pname, param);
+    (void)yagl_host_glLightModelf(cur_ts, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4050,13 +4285,14 @@ static void yagl_func_glLightModelf(struct yagl_transport *t)
  */
 static void yagl_func_glLightModelfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     const GLfloat *params;
     int32_t params_count;
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glLightModelfv, GLenum, void*, pname, params);
-    (void)yagl_host_glLightModelfv(pname, params, params_count);
+    (void)yagl_host_glLightModelfv(cur_ts, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4065,6 +4301,7 @@ static void yagl_func_glLightModelfv(struct yagl_transport *t)
  */
 static void yagl_func_glMaterialf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum face;
     GLenum pname;
     GLfloat param;
@@ -4072,7 +4309,7 @@ static void yagl_func_glMaterialf(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     param = yagl_transport_get_out_GLfloat(t);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glMaterialf, GLenum, GLenum, GLfloat, face, pname, param);
-    (void)yagl_host_glMaterialf(face, pname, param);
+    (void)yagl_host_glMaterialf(cur_ts, face, pname, param);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4081,6 +4318,7 @@ static void yagl_func_glMaterialf(struct yagl_transport *t)
  */
 static void yagl_func_glMaterialfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum face;
     GLenum pname;
     const GLfloat *params;
@@ -4089,7 +4327,7 @@ static void yagl_func_glMaterialfv(struct yagl_transport *t)
     pname = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&params, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glMaterialfv, GLenum, GLenum, void*, face, pname, params);
-    (void)yagl_host_glMaterialfv(face, pname, params, params_count);
+    (void)yagl_host_glMaterialfv(cur_ts, face, pname, params, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4098,6 +4336,7 @@ static void yagl_func_glMaterialfv(struct yagl_transport *t)
  */
 static void yagl_func_glGetMaterialfv(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum face;
     GLenum pname;
     GLfloat *params;
@@ -4108,7 +4347,7 @@ static void yagl_func_glGetMaterialfv(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&params, &params_maxcount, &params_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGetMaterialfv, GLenum, GLenum, void*, face, pname, params);
     *params_count = 0;
-    (void)yagl_host_glGetMaterialfv(face, pname, params, params_maxcount, params_count);
+    (void)yagl_host_glGetMaterialfv(cur_ts, face, pname, params, params_maxcount, params_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4117,10 +4356,11 @@ static void yagl_func_glGetMaterialfv(struct yagl_transport *t)
  */
 static void yagl_func_glShadeModel(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum mode;
     mode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glShadeModel, GLenum, mode);
-    (void)yagl_host_glShadeModel(mode);
+    (void)yagl_host_glShadeModel(cur_ts, mode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4129,10 +4369,11 @@ static void yagl_func_glShadeModel(struct yagl_transport *t)
  */
 static void yagl_func_glLogicOp(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum opcode;
     opcode = yagl_transport_get_out_GLenum(t);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glLogicOp, GLenum, opcode);
-    (void)yagl_host_glLogicOp(opcode);
+    (void)yagl_host_glLogicOp(cur_ts, opcode);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4141,11 +4382,12 @@ static void yagl_func_glLogicOp(struct yagl_transport *t)
  */
 static void yagl_func_glMultMatrixf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLfloat *m;
     int32_t m_count;
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&m, &m_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glMultMatrixf, void*, m);
-    (void)yagl_host_glMultMatrixf(m, m_count);
+    (void)yagl_host_glMultMatrixf(cur_ts, m, m_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4154,11 +4396,12 @@ static void yagl_func_glMultMatrixf(struct yagl_transport *t)
  */
 static void yagl_func_glLoadMatrixf(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const GLfloat *m;
     int32_t m_count;
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&m, &m_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glLoadMatrixf, void*, m);
-    (void)yagl_host_glLoadMatrixf(m, m_count);
+    (void)yagl_host_glLoadMatrixf(cur_ts, m, m_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4167,13 +4410,14 @@ static void yagl_func_glLoadMatrixf(struct yagl_transport *t)
  */
 static void yagl_func_glClipPlanef(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum plane;
     const GLfloat *equation;
     int32_t equation_count;
     plane = yagl_transport_get_out_GLenum(t);
     yagl_transport_get_out_array(t, sizeof(GLfloat), (const void**)&equation, &equation_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glClipPlanef, GLenum, void*, plane, equation);
-    (void)yagl_host_glClipPlanef(plane, equation, equation_count);
+    (void)yagl_host_glClipPlanef(cur_ts, plane, equation, equation_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4182,6 +4426,7 @@ static void yagl_func_glClipPlanef(struct yagl_transport *t)
  */
 static void yagl_func_glGetClipPlanef(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLenum pname;
     GLfloat *eqn;
     int32_t eqn_maxcount;
@@ -4190,7 +4435,7 @@ static void yagl_func_glGetClipPlanef(struct yagl_transport *t)
     yagl_transport_get_in_array(t, sizeof(GLfloat), (void**)&eqn, &eqn_maxcount, &eqn_count);
     YAGL_LOG_FUNC_ENTER_SPLIT2(glGetClipPlanef, GLenum, void*, pname, eqn);
     *eqn_count = 0;
-    (void)yagl_host_glGetClipPlanef(pname, eqn, eqn_maxcount, eqn_count);
+    (void)yagl_host_glGetClipPlanef(cur_ts, pname, eqn, eqn_maxcount, eqn_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4199,6 +4444,7 @@ static void yagl_func_glGetClipPlanef(struct yagl_transport *t)
  */
 static void yagl_func_glUpdateOffscreenImageYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     GLuint texture;
     uint32_t width;
     uint32_t height;
@@ -4211,7 +4457,7 @@ static void yagl_func_glUpdateOffscreenImageYAGL(struct yagl_transport *t)
     bpp = yagl_transport_get_out_uint32_t(t);
     yagl_transport_get_out_array(t, 1, (const void**)&pixels, &pixels_count);
     YAGL_LOG_FUNC_ENTER_SPLIT5(glUpdateOffscreenImageYAGL, GLuint, uint32_t, uint32_t, uint32_t, void*, texture, width, height, bpp, pixels);
-    (void)yagl_host_glUpdateOffscreenImageYAGL(texture, width, height, bpp, pixels, pixels_count);
+    (void)yagl_host_glUpdateOffscreenImageYAGL(cur_ts, texture, width, height, bpp, pixels, pixels_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4220,6 +4466,7 @@ static void yagl_func_glUpdateOffscreenImageYAGL(struct yagl_transport *t)
  */
 static void yagl_func_glGenUniformLocationYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     uint32_t location;
     GLuint program;
     const GLchar *name;
@@ -4228,7 +4475,7 @@ static void yagl_func_glGenUniformLocationYAGL(struct yagl_transport *t)
     program = yagl_transport_get_out_GLuint(t);
     yagl_transport_get_out_array(t, sizeof(GLchar), (const void**)&name, &name_count);
     YAGL_LOG_FUNC_ENTER_SPLIT3(glGenUniformLocationYAGL, uint32_t, GLuint, void*, location, program, name);
-    (void)yagl_host_glGenUniformLocationYAGL(location, program, name, name_count);
+    (void)yagl_host_glGenUniformLocationYAGL(cur_ts, location, program, name, name_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -4237,11 +4484,12 @@ static void yagl_func_glGenUniformLocationYAGL(struct yagl_transport *t)
  */
 static void yagl_func_glDeleteUniformLocationsYAGL(struct yagl_transport *t)
 {
+    struct yagl_thread_state *cur_ts = t->ts;
     const uint32_t *locations;
     int32_t locations_count;
     yagl_transport_get_out_array(t, sizeof(uint32_t), (const void**)&locations, &locations_count);
     YAGL_LOG_FUNC_ENTER_SPLIT1(glDeleteUniformLocationsYAGL, void*, locations);
-    (void)yagl_host_glDeleteUniformLocationsYAGL(locations, locations_count);
+    (void)yagl_host_glDeleteUniformLocationsYAGL(cur_ts, locations, locations_count);
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
index 66bd7a4..e46f32e 100644 (file)
@@ -41,6 +41,7 @@
 #include "yagl_object_map.h"
 #include "yagl_transport.h"
 
+// TODO remove and pass via argument
 static YAGL_DEFINE_TLS(struct yagl_gles_api_ts*, gles_api_ts);
 
 struct yagl_gles_object
@@ -61,7 +62,8 @@ typedef enum
     yagl_gles1_array_texcoord,
 } yagl_gles1_array_type;
 
-static GLuint yagl_gles_bind_array(uint32_t indx,
+static GLuint yagl_gles_bind_array(struct yagl_thread_state *cur_ts,
+                                   uint32_t indx,
                                    GLint first,
                                    GLsizei stride,
                                    const GLvoid *data,
@@ -141,7 +143,8 @@ static GLuint yagl_gles_bind_array(uint32_t indx,
     return current_vbo;
 }
 
-static GLuint yagl_gles_bind_ebo(const GLvoid *data, int32_t size)
+static GLuint yagl_gles_bind_ebo(struct yagl_thread_state *cur_ts,
+                                 const GLvoid *data, int32_t size)
 {
     GLuint current_ebo;
     void *ptr;
@@ -195,7 +198,8 @@ static GLuint yagl_gles_bind_ebo(const GLvoid *data, int32_t size)
     return current_ebo;
 }
 
-static bool yagl_gles_program_get_uniform_type(GLuint program,
+static bool yagl_gles_program_get_uniform_type(struct yagl_thread_state *cur_ts,
+                                               GLuint program,
                                                GLint location,
                                                GLenum *type)
 {
@@ -317,7 +321,8 @@ static bool yagl_gles_get_array_param_count(GLenum pname, int *count)
     return true;
 }
 
-static void yagl_gles_object_add(GLuint local_name,
+static void yagl_gles_object_add(struct yagl_process_state *ps,
+                                 GLuint local_name,
                                  GLuint global_name,
                                  uint32_t ctx_id,
                                  void (*destroy_func)(struct yagl_object */*obj*/))
@@ -327,11 +332,12 @@ static void yagl_gles_object_add(GLuint local_name,
     obj = g_malloc(sizeof(*obj));
 
     obj->base.global_name = global_name;
+    obj->base.ps = ps;
     obj->base.destroy = destroy_func;
     obj->driver = gles_api_ts->driver;
     obj->ctx_id = ctx_id;
 
-    yagl_object_map_add(cur_ts->ps->object_map,
+    yagl_object_map_add(ps->object_map,
                         local_name,
                         &obj->base);
 }
@@ -339,12 +345,13 @@ static void yagl_gles_object_add(GLuint local_name,
 static void yagl_gles_buffer_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_buffer_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     gles_obj->driver->DeleteBuffers(1, &obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(gles_obj);
 
@@ -354,12 +361,13 @@ static void yagl_gles_buffer_destroy(struct yagl_object *obj)
 static void yagl_gles_texture_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_texture_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     gles_obj->driver->DeleteTextures(1, &obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(gles_obj);
 
@@ -369,12 +377,13 @@ static void yagl_gles_texture_destroy(struct yagl_object *obj)
 static void yagl_gles_framebuffer_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_framebuffer_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(gles_obj->ctx_id);
+    yagl_ensure_ctx(obj->ps, gles_obj->ctx_id);
     gles_obj->driver->DeleteFramebuffers(1, &obj->global_name);
-    yagl_unensure_ctx(gles_obj->ctx_id);
+    yagl_unensure_ctx(obj->ps, gles_obj->ctx_id);
 
     g_free(gles_obj);
 
@@ -384,12 +393,13 @@ static void yagl_gles_framebuffer_destroy(struct yagl_object *obj)
 static void yagl_gles_renderbuffer_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_renderbuffer_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     gles_obj->driver->DeleteRenderbuffers(1, &obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(gles_obj);
 
@@ -399,12 +409,13 @@ static void yagl_gles_renderbuffer_destroy(struct yagl_object *obj)
 static void yagl_gles_program_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_program_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     gles_obj->driver->DeleteProgram(obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(gles_obj);
 
@@ -414,12 +425,13 @@ static void yagl_gles_program_destroy(struct yagl_object *obj)
 static void yagl_gles_shader_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_shader_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     gles_obj->driver->DeleteShader(obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(gles_obj);
 
@@ -429,12 +441,13 @@ static void yagl_gles_shader_destroy(struct yagl_object *obj)
 static void yagl_gles_vertex_array_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_vertex_array_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(gles_obj->ctx_id);
+    yagl_ensure_ctx(obj->ps, gles_obj->ctx_id);
     gles_obj->driver->DeleteVertexArrays(1, &obj->global_name);
-    yagl_unensure_ctx(gles_obj->ctx_id);
+    yagl_unensure_ctx(obj->ps, gles_obj->ctx_id);
 
     g_free(gles_obj);
 
@@ -444,12 +457,13 @@ static void yagl_gles_vertex_array_destroy(struct yagl_object *obj)
 static void yagl_gles_transform_feedback_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_transform_feedback_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(gles_obj->ctx_id);
+    yagl_ensure_ctx(obj->ps, gles_obj->ctx_id);
     gles_obj->driver->DeleteTransformFeedbacks(1, &obj->global_name);
-    yagl_unensure_ctx(gles_obj->ctx_id);
+    yagl_unensure_ctx(obj->ps, gles_obj->ctx_id);
 
     g_free(gles_obj);
 
@@ -459,12 +473,13 @@ static void yagl_gles_transform_feedback_destroy(struct yagl_object *obj)
 static void yagl_gles_query_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_query_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(gles_obj->ctx_id);
+    yagl_ensure_ctx(obj->ps, gles_obj->ctx_id);
     gles_obj->driver->DeleteQueries(1, &obj->global_name);
-    yagl_unensure_ctx(gles_obj->ctx_id);
+    yagl_unensure_ctx(obj->ps, gles_obj->ctx_id);
 
     g_free(gles_obj);
 
@@ -474,19 +489,21 @@ static void yagl_gles_query_destroy(struct yagl_object *obj)
 static void yagl_gles_sampler_destroy(struct yagl_object *obj)
 {
     struct yagl_gles_object *gles_obj = (struct yagl_gles_object*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_sampler_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     gles_obj->driver->DeleteSamplers(1, &obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(gles_obj);
 
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static __inline GLuint yagl_gles_object_get(GLuint local_name)
+static __inline GLuint yagl_gles_object_get(struct yagl_thread_state *cur_ts,
+                                            GLuint local_name)
 {
     return (local_name > 0) ? yagl_object_map_get(cur_ts->ps->object_map, local_name) : 0;
 }
@@ -501,7 +518,8 @@ static yagl_api_func yagl_host_gles_get_func(struct yagl_api_ps *api_ps,
     }
 }
 
-static void yagl_host_gles_thread_init(struct yagl_api_ps *api_ps)
+static void yagl_host_gles_thread_init(struct yagl_thread_state *cur_ts,
+                                       struct yagl_api_ps *api_ps)
 {
     struct yagl_gles_api_ps *gles_api_ps = (struct yagl_gles_api_ps*)api_ps;
 
@@ -509,29 +527,32 @@ static void yagl_host_gles_thread_init(struct yagl_api_ps *api_ps)
 
     gles_api_ts = g_malloc0(sizeof(*gles_api_ts));
 
-    yagl_gles_api_ts_init(gles_api_ts, gles_api_ps->driver, gles_api_ps);
+    yagl_gles_api_ts_init(cur_ts, gles_api_ts, gles_api_ps->driver, gles_api_ps);
 
     cur_ts->gles_api_ts = gles_api_ts;
 
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_host_gles_batch_start(struct yagl_api_ps *api_ps)
+static void yagl_host_gles_batch_start(struct yagl_thread_state *cur_ts,
+                                       struct yagl_api_ps *api_ps)
 {
     gles_api_ts = cur_ts->gles_api_ts;
 }
 
-static void yagl_host_gles_batch_end(struct yagl_api_ps *api_ps)
+static void yagl_host_gles_batch_end(struct yagl_thread_state *cur_ts,
+                                     struct yagl_api_ps *api_ps)
 {
 }
 
-static void yagl_host_gles_thread_fini(struct yagl_api_ps *api_ps)
+static void yagl_host_gles_thread_fini(struct yagl_thread_state *cur_ts,
+                                       struct yagl_api_ps *api_ps)
 {
     YAGL_LOG_FUNC_ENTER(yagl_host_gles_thread_fini, NULL);
 
     gles_api_ts = cur_ts->gles_api_ts;
 
-    yagl_gles_api_ts_cleanup(gles_api_ts);
+    yagl_gles_api_ts_cleanup(cur_ts, gles_api_ts);
 
     g_free(gles_api_ts);
 
@@ -540,7 +561,8 @@ static void yagl_host_gles_thread_fini(struct yagl_api_ps *api_ps)
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_host_gles_process_destroy(struct yagl_api_ps *api_ps)
+static void yagl_host_gles_process_destroy(struct yagl_thread_state *cur_ts,
+                                           struct yagl_api_ps *api_ps)
 {
     struct yagl_gles_api_ps *gles_api_ps = (struct yagl_gles_api_ps*)api_ps;
 
@@ -554,10 +576,12 @@ static void yagl_host_gles_process_destroy(struct yagl_api_ps *api_ps)
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-struct yagl_api_ps *yagl_host_gles_process_init(struct yagl_api *api)
+struct yagl_api_ps *yagl_host_gles_process_init(struct yagl_process_state *ps,
+                                                struct yagl_api *api)
 {
     struct yagl_gles_api *gles_api = (struct yagl_gles_api*)api;
     struct yagl_gles_api_ps *gles_api_ps;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_host_gles_process_init, NULL);
 
@@ -579,20 +603,22 @@ struct yagl_api_ps *yagl_host_gles_process_init(struct yagl_api *api)
     return &gles_api_ps->base;
 }
 
-void yagl_host_glDrawArrays(GLenum mode,
+void yagl_host_glDrawArrays(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLint first,
     GLsizei count)
 {
     gles_api_ts->driver->DrawArrays(mode, first, count);
 }
 
-void yagl_host_glDrawElements(GLenum mode,
+void yagl_host_glDrawElements(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLsizei count,
     GLenum type,
     const GLvoid *indices, int32_t indices_count)
 {
     if (indices) {
-        GLuint current_ebo = yagl_gles_bind_ebo(indices, indices_count);
+        GLuint current_ebo = yagl_gles_bind_ebo(cur_ts, indices, indices_count);
 
         gles_api_ts->driver->DrawElements(mode, count, type, NULL);
 
@@ -603,7 +629,8 @@ void yagl_host_glDrawElements(GLenum mode,
     }
 }
 
-void yagl_host_glReadPixelsData(GLint x,
+void yagl_host_glReadPixelsData(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height,
@@ -622,7 +649,8 @@ void yagl_host_glReadPixelsData(GLint x,
     *pixels_count = pixels_maxcount;
 }
 
-void yagl_host_glReadPixelsOffset(GLint x,
+void yagl_host_glReadPixelsOffset(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height,
@@ -639,7 +667,8 @@ void yagl_host_glReadPixelsOffset(GLint x,
                                     (GLvoid*)pixels);
 }
 
-void yagl_host_glDrawArraysInstanced(GLenum mode,
+void yagl_host_glDrawArraysInstanced(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLint start,
     GLsizei count,
     GLsizei primcount)
@@ -647,14 +676,15 @@ void yagl_host_glDrawArraysInstanced(GLenum mode,
     gles_api_ts->driver->DrawArraysInstanced(mode, start, count, primcount);
 }
 
-void yagl_host_glDrawElementsInstanced(GLenum mode,
+void yagl_host_glDrawElementsInstanced(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLsizei count,
     GLenum type,
     const void *indices, int32_t indices_count,
     GLsizei primcount)
 {
     if (indices) {
-        GLuint current_ebo = yagl_gles_bind_ebo(indices, indices_count);
+        GLuint current_ebo = yagl_gles_bind_ebo(cur_ts, indices, indices_count);
 
         gles_api_ts->driver->DrawElementsInstanced(mode, count, type, NULL, primcount);
 
@@ -668,7 +698,8 @@ void yagl_host_glDrawElementsInstanced(GLenum mode,
     }
 }
 
-void yagl_host_glDrawRangeElements(GLenum mode,
+void yagl_host_glDrawRangeElements(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLuint start,
     GLuint end,
     GLsizei count,
@@ -676,7 +707,7 @@ void yagl_host_glDrawRangeElements(GLenum mode,
     const GLvoid *indices, int32_t indices_count)
 {
     if (indices) {
-        GLuint current_ebo = yagl_gles_bind_ebo(indices, indices_count);
+        GLuint current_ebo = yagl_gles_bind_ebo(cur_ts, indices, indices_count);
 
         gles_api_ts->driver->DrawRangeElements(mode, start, end, count, type, NULL);
 
@@ -687,7 +718,8 @@ void yagl_host_glDrawRangeElements(GLenum mode,
     }
 }
 
-void yagl_host_glGenVertexArrays(const GLuint *arrays, int32_t arrays_count)
+void yagl_host_glGenVertexArrays(struct yagl_thread_state *cur_ts,
+    const GLuint *arrays, int32_t arrays_count)
 {
     int i;
 
@@ -696,29 +728,34 @@ void yagl_host_glGenVertexArrays(const GLuint *arrays, int32_t arrays_count)
 
         gles_api_ts->driver->GenVertexArrays(1, &global_name);
 
-        yagl_gles_object_add(arrays[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             arrays[i],
                              global_name,
-                             yagl_get_ctx_id(),
+                             yagl_get_ctx_id(cur_ts->ps),
                              &yagl_gles_vertex_array_destroy);
     }
 }
 
-void yagl_host_glBindVertexArray(GLuint array)
+void yagl_host_glBindVertexArray(struct yagl_thread_state *cur_ts,
+    GLuint array)
 {
-    gles_api_ts->driver->BindVertexArray(yagl_gles_object_get(array));
+    gles_api_ts->driver->BindVertexArray(yagl_gles_object_get(cur_ts, array));
 }
 
-void yagl_host_glDisableVertexAttribArray(GLuint index)
+void yagl_host_glDisableVertexAttribArray(struct yagl_thread_state *cur_ts,
+    GLuint index)
 {
     gles_api_ts->driver->DisableVertexAttribArray(index);
 }
 
-void yagl_host_glEnableVertexAttribArray(GLuint index)
+void yagl_host_glEnableVertexAttribArray(struct yagl_thread_state *cur_ts,
+    GLuint index)
 {
     gles_api_ts->driver->EnableVertexAttribArray(index);
 }
 
-void yagl_host_glVertexAttribPointerData(GLuint indx,
+void yagl_host_glVertexAttribPointerData(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLint size,
     GLenum type,
     GLboolean normalized,
@@ -726,7 +763,7 @@ void yagl_host_glVertexAttribPointerData(GLuint indx,
     GLint first,
     const GLvoid *data, int32_t data_count)
 {
-    GLuint current_vbo = yagl_gles_bind_array(indx, first, stride,
+    GLuint current_vbo = yagl_gles_bind_array(cur_ts, indx, first, stride,
                                               data, data_count);
 
     gles_api_ts->driver->VertexAttribPointer(indx, size, type, normalized,
@@ -736,7 +773,8 @@ void yagl_host_glVertexAttribPointerData(GLuint indx,
     gles_api_ts->driver->BindBuffer(GL_ARRAY_BUFFER, current_vbo);
 }
 
-void yagl_host_glVertexAttribPointerOffset(GLuint indx,
+void yagl_host_glVertexAttribPointerOffset(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLint size,
     GLenum type,
     GLboolean normalized,
@@ -748,13 +786,14 @@ void yagl_host_glVertexAttribPointerOffset(GLuint indx,
                                              (const GLvoid*)offset);
 }
 
-void yagl_host_glVertexPointerData(GLint size,
+void yagl_host_glVertexPointerData(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count)
 {
-    GLuint current_vbo = yagl_gles_bind_array(yagl_gles1_array_vertex,
+    GLuint current_vbo = yagl_gles_bind_array(cur_ts, yagl_gles1_array_vertex,
                                               first, stride,
                                               data, data_count);
 
@@ -763,7 +802,8 @@ void yagl_host_glVertexPointerData(GLint size,
     gles_api_ts->driver->BindBuffer(GL_ARRAY_BUFFER, current_vbo);
 }
 
-void yagl_host_glVertexPointerOffset(GLint size,
+void yagl_host_glVertexPointerOffset(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset)
@@ -771,12 +811,13 @@ void yagl_host_glVertexPointerOffset(GLint size,
     gles_api_ts->driver->VertexPointer(size, type, stride, (const GLvoid*)offset);
 }
 
-void yagl_host_glNormalPointerData(GLenum type,
+void yagl_host_glNormalPointerData(struct yagl_thread_state *cur_ts,
+    GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count)
 {
-    GLuint current_vbo = yagl_gles_bind_array(yagl_gles1_array_normal,
+    GLuint current_vbo = yagl_gles_bind_array(cur_ts, yagl_gles1_array_normal,
                                               first, stride,
                                               data, data_count);
 
@@ -785,20 +826,22 @@ void yagl_host_glNormalPointerData(GLenum type,
     gles_api_ts->driver->BindBuffer(GL_ARRAY_BUFFER, current_vbo);
 }
 
-void yagl_host_glNormalPointerOffset(GLenum type,
+void yagl_host_glNormalPointerOffset(struct yagl_thread_state *cur_ts,
+    GLenum type,
     GLsizei stride,
     uintptr_t offset)
 {
     gles_api_ts->driver->NormalPointer(type, stride, (const GLvoid*)offset);
 }
 
-void yagl_host_glColorPointerData(GLint size,
+void yagl_host_glColorPointerData(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count)
 {
-    GLuint current_vbo = yagl_gles_bind_array(yagl_gles1_array_color,
+    GLuint current_vbo = yagl_gles_bind_array(cur_ts, yagl_gles1_array_color,
                                               first, stride,
                                               data, data_count);
 
@@ -807,7 +850,8 @@ void yagl_host_glColorPointerData(GLint size,
     gles_api_ts->driver->BindBuffer(GL_ARRAY_BUFFER, current_vbo);
 }
 
-void yagl_host_glColorPointerOffset(GLint size,
+void yagl_host_glColorPointerOffset(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset)
@@ -815,14 +859,15 @@ void yagl_host_glColorPointerOffset(GLint size,
     gles_api_ts->driver->ColorPointer(size, type, stride, (const GLvoid*)offset);
 }
 
-void yagl_host_glTexCoordPointerData(GLint tex_id,
+void yagl_host_glTexCoordPointerData(struct yagl_thread_state *cur_ts,
+    GLint tex_id,
     GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count)
 {
-    GLuint current_vbo = yagl_gles_bind_array(yagl_gles1_array_texcoord + tex_id,
+    GLuint current_vbo = yagl_gles_bind_array(cur_ts, yagl_gles1_array_texcoord + tex_id,
                                               first, stride,
                                               data, data_count);
 
@@ -831,7 +876,8 @@ void yagl_host_glTexCoordPointerData(GLint tex_id,
     gles_api_ts->driver->BindBuffer(GL_ARRAY_BUFFER, current_vbo);
 }
 
-void yagl_host_glTexCoordPointerOffset(GLint size,
+void yagl_host_glTexCoordPointerOffset(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset)
@@ -839,30 +885,34 @@ void yagl_host_glTexCoordPointerOffset(GLint size,
     gles_api_ts->driver->TexCoordPointer(size, type, stride, (const GLvoid*)offset);
 }
 
-void yagl_host_glDisableClientState(GLenum array)
+void yagl_host_glDisableClientState(struct yagl_thread_state *cur_ts,
+    GLenum array)
 {
     gles_api_ts->driver->DisableClientState(array);
 }
 
-void yagl_host_glEnableClientState(GLenum array)
+void yagl_host_glEnableClientState(struct yagl_thread_state *cur_ts,
+    GLenum array)
 {
     gles_api_ts->driver->EnableClientState(array);
 }
 
-void yagl_host_glVertexAttribDivisor(GLuint index,
+void yagl_host_glVertexAttribDivisor(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLuint divisor)
 {
     gles_api_ts->driver->VertexAttribDivisor(index, divisor);
 }
 
-void yagl_host_glVertexAttribIPointerData(GLuint index,
+void yagl_host_glVertexAttribIPointerData(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count)
 {
-    GLuint current_vbo = yagl_gles_bind_array(index, first, stride,
+    GLuint current_vbo = yagl_gles_bind_array(cur_ts, index, first, stride,
                                               data, data_count);
 
     gles_api_ts->driver->VertexAttribIPointer(index, size, type, stride, NULL);
@@ -870,7 +920,8 @@ void yagl_host_glVertexAttribIPointerData(GLuint index,
     gles_api_ts->driver->BindBuffer(GL_ARRAY_BUFFER, current_vbo);
 }
 
-void yagl_host_glVertexAttribIPointerOffset(GLuint index,
+void yagl_host_glVertexAttribIPointerOffset(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLint size,
     GLenum type,
     GLsizei stride,
@@ -881,7 +932,8 @@ void yagl_host_glVertexAttribIPointerOffset(GLuint index,
                                               (const GLvoid*)offset);
 }
 
-void yagl_host_glGenBuffers(const GLuint *buffers, int32_t buffers_count)
+void yagl_host_glGenBuffers(struct yagl_thread_state *cur_ts,
+    const GLuint *buffers, int32_t buffers_count)
 {
     int i;
 
@@ -890,27 +942,31 @@ void yagl_host_glGenBuffers(const GLuint *buffers, int32_t buffers_count)
 
         gles_api_ts->driver->GenBuffers(1, &global_name);
 
-        yagl_gles_object_add(buffers[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             buffers[i],
                              global_name,
                              0,
                              &yagl_gles_buffer_destroy);
     }
 }
 
-void yagl_host_glBindBuffer(GLenum target,
+void yagl_host_glBindBuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint buffer)
 {
-    gles_api_ts->driver->BindBuffer(target, yagl_gles_object_get(buffer));
+    gles_api_ts->driver->BindBuffer(target, yagl_gles_object_get(cur_ts, buffer));
 }
 
-void yagl_host_glBufferData(GLenum target,
+void yagl_host_glBufferData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     const GLvoid *data, int32_t data_count,
     GLenum usage)
 {
     gles_api_ts->driver->BufferData(target, data_count, data, usage);
 }
 
-void yagl_host_glBufferSubData(GLenum target,
+void yagl_host_glBufferSubData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLsizei offset,
     const GLvoid *data, int32_t data_count)
 {
@@ -954,26 +1010,29 @@ void yagl_host_glBufferSubData(GLenum target,
     }
 }
 
-void yagl_host_glBindBufferBase(GLenum target,
+void yagl_host_glBindBufferBase(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint index,
     GLuint buffer)
 {
     gles_api_ts->driver->BindBufferBase(target, index,
-                                        yagl_gles_object_get(buffer));
+                                        yagl_gles_object_get(cur_ts, buffer));
 }
 
-void yagl_host_glBindBufferRange(GLenum target,
+void yagl_host_glBindBufferRange(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint index,
     GLuint buffer,
     GLint offset,
     GLsizei size)
 {
     gles_api_ts->driver->BindBufferRange(target, index,
-                                         yagl_gles_object_get(buffer),
+                                         yagl_gles_object_get(cur_ts, buffer),
                                          offset, size);
 }
 
-void yagl_host_glMapBuffer(GLuint buffer,
+void yagl_host_glMapBuffer(struct yagl_thread_state *cur_ts,
+    GLuint buffer,
     const GLuint *ranges, int32_t ranges_count,
     GLvoid *data, int32_t data_maxcount, int32_t *data_count)
 {
@@ -986,7 +1045,7 @@ void yagl_host_glMapBuffer(GLuint buffer,
     gles_api_ts->driver->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING_ARB,
                                      (GLint*)&current_pbo);
 
-    gles_api_ts->driver->BindBuffer(GL_PIXEL_PACK_BUFFER_ARB, yagl_gles_object_get(buffer));
+    gles_api_ts->driver->BindBuffer(GL_PIXEL_PACK_BUFFER_ARB, yagl_gles_object_get(cur_ts, buffer));
 
     map_ptr = gles_api_ts->driver->MapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
 
@@ -1023,7 +1082,8 @@ out1:
     gles_api_ts->driver->BindBuffer(GL_PIXEL_PACK_BUFFER_ARB, current_pbo);
 }
 
-void yagl_host_glCopyBufferSubData(GLenum readTarget,
+void yagl_host_glCopyBufferSubData(struct yagl_thread_state *cur_ts,
+    GLenum readTarget,
     GLenum writeTarget,
     GLintptr readOffset,
     GLintptr writeOffset,
@@ -1033,7 +1093,8 @@ void yagl_host_glCopyBufferSubData(GLenum readTarget,
                                            readOffset, writeOffset, size);
 }
 
-void yagl_host_glGenTextures(const GLuint *textures, int32_t textures_count)
+void yagl_host_glGenTextures(struct yagl_thread_state *cur_ts,
+    const GLuint *textures, int32_t textures_count)
 {
     int i;
 
@@ -1045,29 +1106,33 @@ void yagl_host_glGenTextures(const GLuint *textures, int32_t textures_count)
          * might be called without an active context, but
          * which needs to create a texture.
          */
-        yagl_ensure_ctx(0);
+        yagl_ensure_ctx(cur_ts->ps, 0);
         gles_api_ts->driver->GenTextures(1, &global_name);
-        yagl_unensure_ctx(0);
+        yagl_unensure_ctx(cur_ts->ps, 0);
 
-        yagl_gles_object_add(textures[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             textures[i],
                              global_name,
                              0,
                              &yagl_gles_texture_destroy);
     }
 }
 
-void yagl_host_glBindTexture(GLenum target,
+void yagl_host_glBindTexture(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint texture)
 {
-    gles_api_ts->driver->BindTexture(target, yagl_gles_object_get(texture));
+    gles_api_ts->driver->BindTexture(target, yagl_gles_object_get(cur_ts, texture));
 }
 
-void yagl_host_glActiveTexture(GLenum texture)
+void yagl_host_glActiveTexture(struct yagl_thread_state *cur_ts,
+    GLenum texture)
 {
     gles_api_ts->driver->ActiveTexture(texture);
 }
 
-void yagl_host_glCopyTexImage2D(GLenum target,
+void yagl_host_glCopyTexImage2D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLenum internalformat,
     GLint x,
@@ -1086,7 +1151,8 @@ void yagl_host_glCopyTexImage2D(GLenum target,
                                         border);
 }
 
-void yagl_host_glCopyTexSubImage2D(GLenum target,
+void yagl_host_glCopyTexSubImage2D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -1105,7 +1171,8 @@ void yagl_host_glCopyTexSubImage2D(GLenum target,
                                            height);
 }
 
-void yagl_host_glGetTexParameterfv(GLenum target,
+void yagl_host_glGetTexParameterfv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLfloat *param)
 {
@@ -1120,7 +1187,8 @@ void yagl_host_glGetTexParameterfv(GLenum target,
     }
 }
 
-void yagl_host_glGetTexParameteriv(GLenum target,
+void yagl_host_glGetTexParameteriv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint *param)
 {
@@ -1135,7 +1203,8 @@ void yagl_host_glGetTexParameteriv(GLenum target,
     }
 }
 
-void yagl_host_glTexImage2DData(GLenum target,
+void yagl_host_glTexImage2DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -1156,7 +1225,8 @@ void yagl_host_glTexImage2DData(GLenum target,
                                     pixels);
 }
 
-void yagl_host_glTexImage2DOffset(GLenum target,
+void yagl_host_glTexImage2DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -1177,14 +1247,16 @@ void yagl_host_glTexImage2DOffset(GLenum target,
                                     (const GLvoid*)pixels);
 }
 
-void yagl_host_glTexParameterf(GLenum target,
+void yagl_host_glTexParameterf(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->TexParameterf(target, pname, param);
 }
 
-void yagl_host_glTexParameterfv(GLenum target,
+void yagl_host_glTexParameterfv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
@@ -1201,14 +1273,16 @@ void yagl_host_glTexParameterfv(GLenum target,
                                         (params ? tmp : NULL));
 }
 
-void yagl_host_glTexParameteri(GLenum target,
+void yagl_host_glTexParameteri(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint param)
 {
     gles_api_ts->driver->TexParameteri(target, pname, param);
 }
 
-void yagl_host_glTexParameteriv(GLenum target,
+void yagl_host_glTexParameteriv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLint *params, int32_t params_count)
 {
@@ -1225,7 +1299,8 @@ void yagl_host_glTexParameteriv(GLenum target,
                                         (params ? tmp : NULL));
 }
 
-void yagl_host_glTexSubImage2DData(GLenum target,
+void yagl_host_glTexSubImage2DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -1271,7 +1346,8 @@ void yagl_host_glTexSubImage2DData(GLenum target,
     }
 }
 
-void yagl_host_glTexSubImage2DOffset(GLenum target,
+void yagl_host_glTexSubImage2DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -1317,26 +1393,30 @@ void yagl_host_glTexSubImage2DOffset(GLenum target,
     }
 }
 
-void yagl_host_glClientActiveTexture(GLenum texture)
+void yagl_host_glClientActiveTexture(struct yagl_thread_state *cur_ts,
+    GLenum texture)
 {
     gles_api_ts->driver->ClientActiveTexture(texture);
 }
 
-void yagl_host_glTexEnvi(GLenum target,
+void yagl_host_glTexEnvi(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint param)
 {
     gles_api_ts->driver->TexEnvi(target, pname, param);
 }
 
-void yagl_host_glTexEnvf(GLenum target,
+void yagl_host_glTexEnvf(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->TexEnvf(target, pname, param);
 }
 
-void yagl_host_glMultiTexCoord4f(GLenum target,
+void yagl_host_glMultiTexCoord4f(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLfloat s,
     GLfloat tt,
     GLfloat r,
@@ -1345,21 +1425,24 @@ void yagl_host_glMultiTexCoord4f(GLenum target,
     gles_api_ts->driver->MultiTexCoord4f(target, s, tt, r, q);
 }
 
-void yagl_host_glTexEnviv(GLenum target,
+void yagl_host_glTexEnviv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLint *params, int32_t params_count)
 {
     gles_api_ts->driver->TexEnviv(target, pname, params);
 }
 
-void yagl_host_glTexEnvfv(GLenum target,
+void yagl_host_glTexEnvfv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
     gles_api_ts->driver->TexEnvfv(target, pname, params);
 }
 
-void yagl_host_glGetTexEnviv(GLenum env,
+void yagl_host_glGetTexEnviv(struct yagl_thread_state *cur_ts,
+    GLenum env,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -1367,7 +1450,8 @@ void yagl_host_glGetTexEnviv(GLenum env,
     *params_count = params_maxcount;
 }
 
-void yagl_host_glGetTexEnvfv(GLenum env,
+void yagl_host_glGetTexEnvfv(struct yagl_thread_state *cur_ts,
+    GLenum env,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -1375,7 +1459,8 @@ void yagl_host_glGetTexEnvfv(GLenum env,
     *params_count = params_maxcount;
 }
 
-void yagl_host_glTexImage3DData(GLenum target,
+void yagl_host_glTexImage3DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -1398,7 +1483,8 @@ void yagl_host_glTexImage3DData(GLenum target,
                                     pixels);
 }
 
-void yagl_host_glTexImage3DOffset(GLenum target,
+void yagl_host_glTexImage3DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -1421,7 +1507,8 @@ void yagl_host_glTexImage3DOffset(GLenum target,
                                     (const void*)pixels);
 }
 
-void yagl_host_glTexSubImage3DData(GLenum target,
+void yagl_host_glTexSubImage3DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -1446,7 +1533,8 @@ void yagl_host_glTexSubImage3DData(GLenum target,
                                        pixels);
 }
 
-void yagl_host_glTexSubImage3DOffset(GLenum target,
+void yagl_host_glTexSubImage3DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -1471,7 +1559,8 @@ void yagl_host_glTexSubImage3DOffset(GLenum target,
                                        (const void*)pixels);
 }
 
-void yagl_host_glCopyTexSubImage3D(GLenum target,
+void yagl_host_glCopyTexSubImage3D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -1492,7 +1581,8 @@ void yagl_host_glCopyTexSubImage3D(GLenum target,
                                            height);
 }
 
-void yagl_host_glGenFramebuffers(const GLuint *framebuffers, int32_t framebuffers_count)
+void yagl_host_glGenFramebuffers(struct yagl_thread_state *cur_ts,
+    const GLuint *framebuffers, int32_t framebuffers_count)
 {
     int i;
 
@@ -1501,21 +1591,24 @@ void yagl_host_glGenFramebuffers(const GLuint *framebuffers, int32_t framebuffer
 
         gles_api_ts->driver->GenFramebuffers(1, &global_name);
 
-        yagl_gles_object_add(framebuffers[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             framebuffers[i],
                              global_name,
-                             yagl_get_ctx_id(),
+                             yagl_get_ctx_id(cur_ts->ps),
                              &yagl_gles_framebuffer_destroy);
     }
 }
 
-void yagl_host_glBindFramebuffer(GLenum target,
+void yagl_host_glBindFramebuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint framebuffer)
 {
     gles_api_ts->driver->BindFramebuffer(target,
-                                         yagl_gles_object_get(framebuffer));
+                                         yagl_gles_object_get(cur_ts, framebuffer));
 }
 
-void yagl_host_glFramebufferTexture2D(GLenum target,
+void yagl_host_glFramebufferTexture2D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLenum textarget,
     GLuint texture,
@@ -1523,11 +1616,12 @@ void yagl_host_glFramebufferTexture2D(GLenum target,
 {
     gles_api_ts->driver->FramebufferTexture2D(target, attachment,
                                               textarget,
-                                              yagl_gles_object_get(texture),
+                                              yagl_gles_object_get(cur_ts, texture),
                                               level);
 }
 
-void yagl_host_glFramebufferRenderbuffer(GLenum target,
+void yagl_host_glFramebufferRenderbuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLenum renderbuffertarget,
     GLuint renderbuffer)
@@ -1535,10 +1629,11 @@ void yagl_host_glFramebufferRenderbuffer(GLenum target,
     gles_api_ts->driver->FramebufferRenderbuffer(target,
                                                  attachment,
                                                  renderbuffertarget,
-                                                 yagl_gles_object_get(renderbuffer));
+                                                 yagl_gles_object_get(cur_ts, renderbuffer));
 }
 
-void yagl_host_glBlitFramebuffer(GLint srcX0,
+void yagl_host_glBlitFramebuffer(struct yagl_thread_state *cur_ts,
+    GLint srcX0,
     GLint srcY0,
     GLint srcX1,
     GLint srcY1,
@@ -1554,17 +1649,20 @@ void yagl_host_glBlitFramebuffer(GLint srcX0,
                                          mask, filter);
 }
 
-void yagl_host_glDrawBuffers(const GLenum *bufs, int32_t bufs_count)
+void yagl_host_glDrawBuffers(struct yagl_thread_state *cur_ts,
+    const GLenum *bufs, int32_t bufs_count)
 {
     gles_api_ts->driver->DrawBuffers(bufs_count, bufs);
 }
 
-void yagl_host_glReadBuffer(GLenum mode)
+void yagl_host_glReadBuffer(struct yagl_thread_state *cur_ts,
+    GLenum mode)
 {
     gles_api_ts->driver->ReadBuffer(mode);
 }
 
-void yagl_host_glFramebufferTexture3D(GLenum target,
+void yagl_host_glFramebufferTexture3D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLenum textarget,
     GLuint texture,
@@ -1573,36 +1671,40 @@ void yagl_host_glFramebufferTexture3D(GLenum target,
 {
     gles_api_ts->driver->FramebufferTexture3D(target, attachment,
                                               textarget,
-                                              yagl_gles_object_get(texture),
+                                              yagl_gles_object_get(cur_ts, texture),
                                               level, zoffset);
 }
 
-void yagl_host_glFramebufferTextureLayer(GLenum target,
+void yagl_host_glFramebufferTextureLayer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLuint texture,
     GLint level,
     GLint layer)
 {
     gles_api_ts->driver->FramebufferTextureLayer(target, attachment,
-                                                 yagl_gles_object_get(texture),
+                                                 yagl_gles_object_get(cur_ts, texture),
                                                  level, layer);
 }
 
-void yagl_host_glClearBufferiv(GLenum buffer,
+void yagl_host_glClearBufferiv(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     const GLint *value, int32_t value_count)
 {
     gles_api_ts->driver->ClearBufferiv(buffer, drawbuffer, value);
 }
 
-void yagl_host_glClearBufferuiv(GLenum buffer,
+void yagl_host_glClearBufferuiv(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     const GLuint *value, int32_t value_count)
 {
     gles_api_ts->driver->ClearBufferuiv(buffer, drawbuffer, value);
 }
 
-void yagl_host_glClearBufferfi(GLenum buffer,
+void yagl_host_glClearBufferfi(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     GLfloat depth,
     GLint stencil)
@@ -1610,14 +1712,16 @@ void yagl_host_glClearBufferfi(GLenum buffer,
     gles_api_ts->driver->ClearBufferfi(buffer, drawbuffer, depth, stencil);
 }
 
-void yagl_host_glClearBufferfv(GLenum buffer,
+void yagl_host_glClearBufferfv(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     const GLfloat *value, int32_t value_count)
 {
     gles_api_ts->driver->ClearBufferfv(buffer, drawbuffer, value);
 }
 
-void yagl_host_glGenRenderbuffers(const GLuint *renderbuffers, int32_t renderbuffers_count)
+void yagl_host_glGenRenderbuffers(struct yagl_thread_state *cur_ts,
+    const GLuint *renderbuffers, int32_t renderbuffers_count)
 {
     int i;
 
@@ -1626,21 +1730,24 @@ void yagl_host_glGenRenderbuffers(const GLuint *renderbuffers, int32_t renderbuf
 
         gles_api_ts->driver->GenRenderbuffers(1, &global_name);
 
-        yagl_gles_object_add(renderbuffers[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             renderbuffers[i],
                              global_name,
                              0,
                              &yagl_gles_renderbuffer_destroy);
     }
 }
 
-void yagl_host_glBindRenderbuffer(GLenum target,
+void yagl_host_glBindRenderbuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint renderbuffer)
 {
     gles_api_ts->driver->BindRenderbuffer(target,
-                                          yagl_gles_object_get(renderbuffer));
+                                          yagl_gles_object_get(cur_ts, renderbuffer));
 }
 
-void yagl_host_glRenderbufferStorage(GLenum target,
+void yagl_host_glRenderbufferStorage(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum internalformat,
     GLsizei width,
     GLsizei height)
@@ -1648,7 +1755,8 @@ void yagl_host_glRenderbufferStorage(GLenum target,
     gles_api_ts->driver->RenderbufferStorage(target, internalformat, width, height);
 }
 
-void yagl_host_glGetRenderbufferParameteriv(GLenum target,
+void yagl_host_glGetRenderbufferParameteriv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint *param)
 {
@@ -1663,7 +1771,8 @@ void yagl_host_glGetRenderbufferParameteriv(GLenum target,
     }
 }
 
-void yagl_host_glRenderbufferStorageMultisample(GLenum target,
+void yagl_host_glRenderbufferStorageMultisample(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLsizei samples,
     GLenum internalformat,
     GLsizei width,
@@ -1672,28 +1781,33 @@ void yagl_host_glRenderbufferStorageMultisample(GLenum target,
     gles_api_ts->driver->RenderbufferStorageMultisample(target, samples, internalformat, width, height);
 }
 
-void yagl_host_glCreateProgram(GLuint program)
+void yagl_host_glCreateProgram(struct yagl_thread_state *cur_ts,
+    GLuint program)
 {
     GLuint global_name = gles_api_ts->driver->CreateProgram();
 
-    yagl_gles_object_add(program,
+    yagl_gles_object_add(cur_ts->ps,
+                         program,
                          global_name,
                          0,
                          &yagl_gles_program_destroy);
 }
 
-void yagl_host_glCreateShader(GLuint shader,
+void yagl_host_glCreateShader(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     GLenum type)
 {
     GLuint global_name = gles_api_ts->driver->CreateShader(type);
 
-    yagl_gles_object_add(shader,
+    yagl_gles_object_add(cur_ts->ps,
+                         shader,
                          global_name,
                          0,
                          &yagl_gles_shader_destroy);
 }
 
-void yagl_host_glShaderSource(GLuint shader,
+void yagl_host_glShaderSource(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     const GLchar *string, int32_t string_count)
 {
     const GLchar *strings[1];
@@ -1702,38 +1816,41 @@ void yagl_host_glShaderSource(GLuint shader,
     strings[0] = string;
     lenghts[0] = string_count - 1;
 
-    gles_api_ts->driver->ShaderSource(yagl_gles_object_get(shader),
+    gles_api_ts->driver->ShaderSource(yagl_gles_object_get(cur_ts, shader),
                                       1,
                                       strings,
                                       lenghts);
 }
 
-void yagl_host_glAttachShader(GLuint program,
+void yagl_host_glAttachShader(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint shader)
 {
-    gles_api_ts->driver->AttachShader(yagl_gles_object_get(program),
-                                      yagl_gles_object_get(shader));
+    gles_api_ts->driver->AttachShader(yagl_gles_object_get(cur_ts, program),
+                                      yagl_gles_object_get(cur_ts, shader));
 }
 
-void yagl_host_glDetachShader(GLuint program,
+void yagl_host_glDetachShader(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint shader)
 {
-    gles_api_ts->driver->DetachShader(yagl_gles_object_get(program),
-                                      yagl_gles_object_get(shader));
+    gles_api_ts->driver->DetachShader(yagl_gles_object_get(cur_ts, program),
+                                      yagl_gles_object_get(cur_ts, shader));
 }
 
-void yagl_host_glCompileShader(GLuint shader)
+void yagl_host_glCompileShader(struct yagl_thread_state *cur_ts,
+    GLuint shader)
 {
 #ifndef CONFIG_DARWIN
-    gles_api_ts->driver->CompileShader(yagl_gles_object_get(shader));
+    gles_api_ts->driver->CompileShader(yagl_gles_object_get(cur_ts, shader));
 #else
     GLint tmp = 0;
 
     YAGL_LOG_FUNC_SET(glCompileShader);
 
-    gles_api_ts->driver->CompileShader(yagl_gles_object_get(shader));
+    gles_api_ts->driver->CompileShader(yagl_gles_object_get(cur_ts, shader));
 
-    gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_COMPILE_STATUS, &tmp);
+    gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(cur_ts, shader), GL_COMPILE_STATUS, &tmp);
     if (tmp == GL_FALSE) {
         char *buff;
         char *substring;
@@ -1741,9 +1858,9 @@ void yagl_host_glCompileShader(GLuint shader)
         const char texture_lookup_define[] = "#define TextureLookup texture2D";
 
         tmp = 0;
-        gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_INFO_LOG_LENGTH, &tmp);
+        gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(cur_ts, shader), GL_INFO_LOG_LENGTH, &tmp);
         buff = g_malloc0(tmp);
-        gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(shader), tmp, NULL, buff);
+        gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(cur_ts, shader), tmp, NULL, buff);
         if (gles_api_ts->driver->gl_version < yagl_gl_3_2 ||
             strstr(buff, textue2d_err) == NULL) {
             YAGL_LOG_ERROR("Unable to compile shader %s", buff);
@@ -1754,9 +1871,9 @@ void yagl_host_glCompileShader(GLuint shader)
         g_free(buff);
 
         tmp = 0;
-        gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_SHADER_SOURCE_LENGTH, &tmp);
+        gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(cur_ts, shader), GL_SHADER_SOURCE_LENGTH, &tmp);
         buff = g_malloc0(tmp);
-        gles_api_ts->driver->GetShaderSource(yagl_gles_object_get(shader), tmp, NULL, buff);
+        gles_api_ts->driver->GetShaderSource(yagl_gles_object_get(cur_ts, shader), tmp, NULL, buff);
         YAGL_LOG_DEBUG("Shader Source: \n%s", buff);
 
         substring = strstr(buff, texture_lookup_define);
@@ -1771,20 +1888,20 @@ void yagl_host_glCompileShader(GLuint shader)
             strings[0] = buff;
             lenghts[0] = tmp - 1;
 
-            gles_api_ts->driver->ShaderSource(yagl_gles_object_get(shader),
+            gles_api_ts->driver->ShaderSource(yagl_gles_object_get(cur_ts, shader),
                                               1,
                                               strings,
                                               lenghts);
-            gles_api_ts->driver->CompileShader(yagl_gles_object_get(shader));
-            gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_COMPILE_STATUS, &tmp);
+            gles_api_ts->driver->CompileShader(yagl_gles_object_get(cur_ts, shader));
+            gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(cur_ts, shader), GL_COMPILE_STATUS, &tmp);
             if (!tmp) {
                 YAGL_LOG_ERROR("Unable to compile the patched shader source: \n%s", buff);
                 g_free(buff);
 
                 tmp = 0;
-                gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader), GL_INFO_LOG_LENGTH, &tmp);
+                gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(cur_ts, shader), GL_INFO_LOG_LENGTH, &tmp);
                 buff = g_malloc0(tmp);
-                gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(shader), tmp, NULL, buff);
+                gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(cur_ts, shader), tmp, NULL, buff);
                 YAGL_LOG_ERROR("Cause of compilation failure: %s", buff);
             }
         }
@@ -1793,16 +1910,18 @@ void yagl_host_glCompileShader(GLuint shader)
 #endif
 }
 
-void yagl_host_glBindAttribLocation(GLuint program,
+void yagl_host_glBindAttribLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint index,
     const GLchar *name, int32_t name_count)
 {
-    gles_api_ts->driver->BindAttribLocation(yagl_gles_object_get(program),
+    gles_api_ts->driver->BindAttribLocation(yagl_gles_object_get(cur_ts, program),
                                             index,
                                             name);
 }
 
-void yagl_host_glGetActiveAttrib(GLuint program,
+void yagl_host_glGetActiveAttrib(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint index,
     GLint *size,
     GLenum *type,
@@ -1810,7 +1929,7 @@ void yagl_host_glGetActiveAttrib(GLuint program,
 {
     GLsizei tmp = -1;
 
-    gles_api_ts->driver->GetActiveAttrib(yagl_gles_object_get(program),
+    gles_api_ts->driver->GetActiveAttrib(yagl_gles_object_get(cur_ts, program),
                                          index,
                                          name_maxcount,
                                          &tmp,
@@ -1823,7 +1942,8 @@ void yagl_host_glGetActiveAttrib(GLuint program,
     }
 }
 
-void yagl_host_glGetActiveUniform(GLuint program,
+void yagl_host_glGetActiveUniform(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint index,
     GLint *size,
     GLenum *type,
@@ -1831,7 +1951,7 @@ void yagl_host_glGetActiveUniform(GLuint program,
 {
     GLsizei tmp = -1;
 
-    gles_api_ts->driver->GetActiveUniform(yagl_gles_object_get(program),
+    gles_api_ts->driver->GetActiveUniform(yagl_gles_object_get(cur_ts, program),
                                           index,
                                           name_maxcount,
                                           &tmp,
@@ -1844,28 +1964,31 @@ void yagl_host_glGetActiveUniform(GLuint program,
     }
 }
 
-int yagl_host_glGetAttribLocation(GLuint program,
+int yagl_host_glGetAttribLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *name, int32_t name_count)
 {
-    return gles_api_ts->driver->GetAttribLocation(yagl_gles_object_get(program),
+    return gles_api_ts->driver->GetAttribLocation(yagl_gles_object_get(cur_ts, program),
                                                   name);
 }
 
-void yagl_host_glGetProgramiv(GLuint program,
+void yagl_host_glGetProgramiv(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLenum pname,
     GLint *param)
 {
-    gles_api_ts->driver->GetProgramiv(yagl_gles_object_get(program),
+    gles_api_ts->driver->GetProgramiv(yagl_gles_object_get(cur_ts, program),
                                       pname,
                                       param);
 }
 
-GLboolean yagl_host_glGetProgramInfoLog(GLuint program,
+GLboolean yagl_host_glGetProgramInfoLog(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLchar *infolog, int32_t infolog_maxcount, int32_t *infolog_count)
 {
     GLsizei tmp = -1;
 
-    gles_api_ts->driver->GetProgramInfoLog(yagl_gles_object_get(program),
+    gles_api_ts->driver->GetProgramInfoLog(yagl_gles_object_get(cur_ts, program),
                                            infolog_maxcount,
                                            &tmp,
                                            infolog);
@@ -1878,21 +2001,23 @@ GLboolean yagl_host_glGetProgramInfoLog(GLuint program,
     }
 }
 
-void yagl_host_glGetShaderiv(GLuint shader,
+void yagl_host_glGetShaderiv(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     GLenum pname,
     GLint *param)
 {
-    gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(shader),
+    gles_api_ts->driver->GetShaderiv(yagl_gles_object_get(cur_ts, shader),
                                      pname,
                                      param);
 }
 
-GLboolean yagl_host_glGetShaderInfoLog(GLuint shader,
+GLboolean yagl_host_glGetShaderInfoLog(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     GLchar *infolog, int32_t infolog_maxcount, int32_t *infolog_count)
 {
     GLsizei tmp = -1;
 
-    gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(shader),
+    gles_api_ts->driver->GetShaderInfoLog(yagl_gles_object_get(cur_ts, shader),
                                           infolog_maxcount,
                                           &tmp,
                                           infolog);
@@ -1905,18 +2030,20 @@ GLboolean yagl_host_glGetShaderInfoLog(GLuint shader,
     }
 }
 
-void yagl_host_glGetUniformfv(GLboolean tl,
+void yagl_host_glGetUniformfv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     GLuint program,
     uint32_t location,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count)
 {
     GLenum type;
-    GLuint global_name = yagl_gles_object_get(program);
+    GLuint global_name = yagl_gles_object_get(cur_ts, program);
     GLint actual_location = yagl_gles_api_ps_translate_location(gles_api_ts->ps,
                                                                 tl,
                                                                 location);
 
-    if (!yagl_gles_program_get_uniform_type(global_name,
+    if (!yagl_gles_program_get_uniform_type(cur_ts,
+                                            global_name,
                                             actual_location,
                                             &type)) {
         return;
@@ -1931,18 +2058,20 @@ void yagl_host_glGetUniformfv(GLboolean tl,
                                       params);
 }
 
-void yagl_host_glGetUniformiv(GLboolean tl,
+void yagl_host_glGetUniformiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     GLuint program,
     uint32_t location,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
     GLenum type;
-    GLuint global_name = yagl_gles_object_get(program);
+    GLuint global_name = yagl_gles_object_get(cur_ts, program);
     GLint actual_location = yagl_gles_api_ps_translate_location(gles_api_ts->ps,
                                                                 tl,
                                                                 location);
 
-    if (!yagl_gles_program_get_uniform_type(global_name,
+    if (!yagl_gles_program_get_uniform_type(cur_ts,
+                                            global_name,
                                             actual_location,
                                             &type)) {
         return;
@@ -1957,14 +2086,16 @@ void yagl_host_glGetUniformiv(GLboolean tl,
                                       params);
 }
 
-int yagl_host_glGetUniformLocation(GLuint program,
+int yagl_host_glGetUniformLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *name, int32_t name_count)
 {
-    return gles_api_ts->driver->GetUniformLocation(yagl_gles_object_get(program),
+    return gles_api_ts->driver->GetUniformLocation(yagl_gles_object_get(cur_ts, program),
                                                    name);
 }
 
-void yagl_host_glGetVertexAttribfv(GLuint index,
+void yagl_host_glGetVertexAttribfv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -1975,7 +2106,8 @@ void yagl_host_glGetVertexAttribfv(GLuint index,
     gles_api_ts->driver->GetVertexAttribfv(index, pname, params);
 }
 
-void yagl_host_glGetVertexAttribiv(GLuint index,
+void yagl_host_glGetVertexAttribiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -1986,10 +2118,11 @@ void yagl_host_glGetVertexAttribiv(GLuint index,
     gles_api_ts->driver->GetVertexAttribiv(index, pname, params);
 }
 
-void yagl_host_glLinkProgram(GLuint program,
+void yagl_host_glLinkProgram(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
-    GLuint obj = yagl_gles_object_get(program);
+    GLuint obj = yagl_gles_object_get(cur_ts, program);
 
     gles_api_ts->driver->LinkProgram(obj);
 
@@ -2014,7 +2147,8 @@ void yagl_host_glLinkProgram(GLuint program,
     }
 }
 
-void yagl_host_glUniform1f(GLboolean tl,
+void yagl_host_glUniform1f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x)
 {
@@ -2022,7 +2156,8 @@ void yagl_host_glUniform1f(GLboolean tl,
         yagl_gles_api_ps_translate_location(gles_api_ts->ps, tl, location), x);
 }
 
-void yagl_host_glUniform1fv(GLboolean tl,
+void yagl_host_glUniform1fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count)
 {
@@ -2031,7 +2166,8 @@ void yagl_host_glUniform1fv(GLboolean tl,
         v_count, v);
 }
 
-void yagl_host_glUniform1i(GLboolean tl,
+void yagl_host_glUniform1i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x)
 {
@@ -2040,7 +2176,8 @@ void yagl_host_glUniform1i(GLboolean tl,
         x);
 }
 
-void yagl_host_glUniform1iv(GLboolean tl,
+void yagl_host_glUniform1iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count)
 {
@@ -2049,7 +2186,8 @@ void yagl_host_glUniform1iv(GLboolean tl,
         v_count, v);
 }
 
-void yagl_host_glUniform2f(GLboolean tl,
+void yagl_host_glUniform2f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x,
     GLfloat y)
@@ -2059,7 +2197,8 @@ void yagl_host_glUniform2f(GLboolean tl,
         x, y);
 }
 
-void yagl_host_glUniform2fv(GLboolean tl,
+void yagl_host_glUniform2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count)
 {
@@ -2068,7 +2207,8 @@ void yagl_host_glUniform2fv(GLboolean tl,
         (v_count / 2), v);
 }
 
-void yagl_host_glUniform2i(GLboolean tl,
+void yagl_host_glUniform2i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x,
     GLint y)
@@ -2078,7 +2218,8 @@ void yagl_host_glUniform2i(GLboolean tl,
         x, y);
 }
 
-void yagl_host_glUniform2iv(GLboolean tl,
+void yagl_host_glUniform2iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count)
 {
@@ -2087,7 +2228,8 @@ void yagl_host_glUniform2iv(GLboolean tl,
         (v_count / 2), v);
 }
 
-void yagl_host_glUniform3f(GLboolean tl,
+void yagl_host_glUniform3f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x,
     GLfloat y,
@@ -2098,7 +2240,8 @@ void yagl_host_glUniform3f(GLboolean tl,
         x, y, z);
 }
 
-void yagl_host_glUniform3fv(GLboolean tl,
+void yagl_host_glUniform3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count)
 {
@@ -2107,7 +2250,8 @@ void yagl_host_glUniform3fv(GLboolean tl,
         (v_count / 3), v);
 }
 
-void yagl_host_glUniform3i(GLboolean tl,
+void yagl_host_glUniform3i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x,
     GLint y,
@@ -2118,7 +2262,8 @@ void yagl_host_glUniform3i(GLboolean tl,
         x, y, z);
 }
 
-void yagl_host_glUniform3iv(GLboolean tl,
+void yagl_host_glUniform3iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count)
 {
@@ -2127,7 +2272,8 @@ void yagl_host_glUniform3iv(GLboolean tl,
         (v_count / 3), v);
 }
 
-void yagl_host_glUniform4f(GLboolean tl,
+void yagl_host_glUniform4f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x,
     GLfloat y,
@@ -2139,7 +2285,8 @@ void yagl_host_glUniform4f(GLboolean tl,
         x, y, z, w);
 }
 
-void yagl_host_glUniform4fv(GLboolean tl,
+void yagl_host_glUniform4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count)
 {
@@ -2148,7 +2295,8 @@ void yagl_host_glUniform4fv(GLboolean tl,
         (v_count / 4), v);
 }
 
-void yagl_host_glUniform4i(GLboolean tl,
+void yagl_host_glUniform4i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x,
     GLint y,
@@ -2160,7 +2308,8 @@ void yagl_host_glUniform4i(GLboolean tl,
         x, y, z, w);
 }
 
-void yagl_host_glUniform4iv(GLboolean tl,
+void yagl_host_glUniform4iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count)
 {
@@ -2169,7 +2318,8 @@ void yagl_host_glUniform4iv(GLboolean tl,
         (v_count / 4), v);
 }
 
-void yagl_host_glUniformMatrix2fv(GLboolean tl,
+void yagl_host_glUniformMatrix2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2179,7 +2329,8 @@ void yagl_host_glUniformMatrix2fv(GLboolean tl,
         value_count / (2 * 2), transpose, value);
 }
 
-void yagl_host_glUniformMatrix3fv(GLboolean tl,
+void yagl_host_glUniformMatrix3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2189,7 +2340,8 @@ void yagl_host_glUniformMatrix3fv(GLboolean tl,
         value_count / (3 * 3), transpose, value);
 }
 
-void yagl_host_glUniformMatrix4fv(GLboolean tl,
+void yagl_host_glUniformMatrix4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2199,42 +2351,49 @@ void yagl_host_glUniformMatrix4fv(GLboolean tl,
         value_count / (4 * 4), transpose, value);
 }
 
-void yagl_host_glUseProgram(GLuint program)
+void yagl_host_glUseProgram(struct yagl_thread_state *cur_ts,
+    GLuint program)
 {
-    gles_api_ts->driver->UseProgram(yagl_gles_object_get(program));
+    gles_api_ts->driver->UseProgram(yagl_gles_object_get(cur_ts, program));
 }
 
-void yagl_host_glValidateProgram(GLuint program)
+void yagl_host_glValidateProgram(struct yagl_thread_state *cur_ts,
+    GLuint program)
 {
-    gles_api_ts->driver->ValidateProgram(yagl_gles_object_get(program));
+    gles_api_ts->driver->ValidateProgram(yagl_gles_object_get(cur_ts, program));
 }
 
-void yagl_host_glVertexAttrib1f(GLuint indx,
+void yagl_host_glVertexAttrib1f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x)
 {
     gles_api_ts->driver->VertexAttrib1f(indx, x);
 }
 
-void yagl_host_glVertexAttrib1fv(GLuint indx,
+void yagl_host_glVertexAttrib1fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count)
 {
     gles_api_ts->driver->VertexAttrib1fv(indx, values);
 }
 
-void yagl_host_glVertexAttrib2f(GLuint indx,
+void yagl_host_glVertexAttrib2f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x,
     GLfloat y)
 {
     gles_api_ts->driver->VertexAttrib2f(indx, x, y);
 }
 
-void yagl_host_glVertexAttrib2fv(GLuint indx,
+void yagl_host_glVertexAttrib2fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count)
 {
     gles_api_ts->driver->VertexAttrib2fv(indx, values);
 }
 
-void yagl_host_glVertexAttrib3f(GLuint indx,
+void yagl_host_glVertexAttrib3f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x,
     GLfloat y,
     GLfloat z)
@@ -2242,13 +2401,15 @@ void yagl_host_glVertexAttrib3f(GLuint indx,
     gles_api_ts->driver->VertexAttrib3f(indx, x, y, z);
 }
 
-void yagl_host_glVertexAttrib3fv(GLuint indx,
+void yagl_host_glVertexAttrib3fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count)
 {
     gles_api_ts->driver->VertexAttrib3fv(indx, values);
 }
 
-void yagl_host_glVertexAttrib4f(GLuint indx,
+void yagl_host_glVertexAttrib4f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x,
     GLfloat y,
     GLfloat z,
@@ -2257,13 +2418,15 @@ void yagl_host_glVertexAttrib4f(GLuint indx,
     gles_api_ts->driver->VertexAttrib4f(indx, x, y, z, w);
 }
 
-void yagl_host_glVertexAttrib4fv(GLuint indx,
+void yagl_host_glVertexAttrib4fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count)
 {
     gles_api_ts->driver->VertexAttrib4fv(indx, values);
 }
 
-void yagl_host_glGetActiveUniformsiv(GLuint program,
+void yagl_host_glGetActiveUniformsiv(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLuint *uniformIndices, int32_t uniformIndices_count,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -2278,7 +2441,7 @@ void yagl_host_glGetActiveUniformsiv(GLuint program,
         GL_UNIFORM_MATRIX_STRIDE,
         GL_UNIFORM_IS_ROW_MAJOR
     };
-    GLuint obj = yagl_gles_object_get(program);
+    GLuint obj = yagl_gles_object_get(cur_ts, program);
     int i, num_pnames = sizeof(pnames)/sizeof(pnames[0]);
 
     if (params_maxcount != (uniformIndices_count * num_pnames)) {
@@ -2297,7 +2460,8 @@ void yagl_host_glGetActiveUniformsiv(GLuint program,
     *params_count = uniformIndices_count * num_pnames;
 }
 
-void yagl_host_glGetUniformIndices(GLuint program,
+void yagl_host_glGetUniformIndices(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *uniformNames, int32_t uniformNames_count,
     GLuint *uniformIndices, int32_t uniformIndices_maxcount, int32_t *uniformIndices_count)
 {
@@ -2309,7 +2473,7 @@ void yagl_host_glGetUniformIndices(GLuint program,
 
     YAGL_LOG_FUNC_SET(glGetUniformIndices);
 
-    obj = yagl_gles_object_get(program);
+    obj = yagl_gles_object_get(cur_ts, program);
 
     gles_api_ts->driver->GetProgramiv(obj,
                                       GL_ACTIVE_UNIFORM_MAX_LENGTH,
@@ -2424,29 +2588,32 @@ void yagl_host_glGetUniformIndices(GLuint program,
     g_free(uniform_name);
 }
 
-GLuint yagl_host_glGetUniformBlockIndex(GLuint program,
+GLuint yagl_host_glGetUniformBlockIndex(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *uniformBlockName, int32_t uniformBlockName_count)
 {
-    return gles_api_ts->driver->GetUniformBlockIndex(yagl_gles_object_get(program),
+    return gles_api_ts->driver->GetUniformBlockIndex(yagl_gles_object_get(cur_ts, program),
                                                      uniformBlockName);
 }
 
-void yagl_host_glUniformBlockBinding(GLuint program,
+void yagl_host_glUniformBlockBinding(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint uniformBlockIndex,
     GLuint uniformBlockBinding)
 {
-    gles_api_ts->driver->UniformBlockBinding(yagl_gles_object_get(program),
+    gles_api_ts->driver->UniformBlockBinding(yagl_gles_object_get(cur_ts, program),
                                              uniformBlockIndex,
                                              uniformBlockBinding);
 }
 
-void yagl_host_glGetActiveUniformBlockName(GLuint program,
+void yagl_host_glGetActiveUniformBlockName(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint uniformBlockIndex,
     GLchar *uniformBlockName, int32_t uniformBlockName_maxcount, int32_t *uniformBlockName_count)
 {
     GLsizei tmp = -1;
 
-    gles_api_ts->driver->GetActiveUniformBlockName(yagl_gles_object_get(program),
+    gles_api_ts->driver->GetActiveUniformBlockName(yagl_gles_object_get(cur_ts, program),
                                                    uniformBlockIndex,
                                                    uniformBlockName_maxcount,
                                                    &tmp,
@@ -2457,7 +2624,8 @@ void yagl_host_glGetActiveUniformBlockName(GLuint program,
     }
 }
 
-void yagl_host_glGetActiveUniformBlockiv(GLuint program,
+void yagl_host_glGetActiveUniformBlockiv(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint uniformBlockIndex,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
@@ -2477,7 +2645,7 @@ void yagl_host_glGetActiveUniformBlockiv(GLuint program,
         return;
     }
 
-    obj = yagl_gles_object_get(program);
+    obj = yagl_gles_object_get(cur_ts, program);
 
     switch (pname) {
     case 0:
@@ -2516,7 +2684,8 @@ void yagl_host_glGetActiveUniformBlockiv(GLuint program,
     }
 }
 
-void yagl_host_glGetVertexAttribIiv(GLuint index,
+void yagl_host_glGetVertexAttribIiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -2527,7 +2696,8 @@ void yagl_host_glGetVertexAttribIiv(GLuint index,
     gles_api_ts->driver->GetVertexAttribIiv(index, pname, params);
 }
 
-void yagl_host_glGetVertexAttribIuiv(GLuint index,
+void yagl_host_glGetVertexAttribIuiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLuint *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -2538,7 +2708,8 @@ void yagl_host_glGetVertexAttribIuiv(GLuint index,
     gles_api_ts->driver->GetVertexAttribIuiv(index, pname, params);
 }
 
-void yagl_host_glVertexAttribI4i(GLuint index,
+void yagl_host_glVertexAttribI4i(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLint x,
     GLint y,
     GLint z,
@@ -2547,7 +2718,8 @@ void yagl_host_glVertexAttribI4i(GLuint index,
     gles_api_ts->driver->VertexAttribI4i(index, x, y, z, w);
 }
 
-void yagl_host_glVertexAttribI4ui(GLuint index,
+void yagl_host_glVertexAttribI4ui(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLuint x,
     GLuint y,
     GLuint z,
@@ -2556,30 +2728,34 @@ void yagl_host_glVertexAttribI4ui(GLuint index,
     gles_api_ts->driver->VertexAttribI4ui(index, x, y, z, w);
 }
 
-void yagl_host_glVertexAttribI4iv(GLuint index,
+void yagl_host_glVertexAttribI4iv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     const GLint *v, int32_t v_count)
 {
     gles_api_ts->driver->VertexAttribI4iv(index, v);
 }
 
-void yagl_host_glVertexAttribI4uiv(GLuint index,
+void yagl_host_glVertexAttribI4uiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     const GLuint *v, int32_t v_count)
 {
     gles_api_ts->driver->VertexAttribI4uiv(index, v);
 }
 
-void yagl_host_glGetUniformuiv(GLboolean tl,
+void yagl_host_glGetUniformuiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     GLuint program,
     uint32_t location,
     GLuint *params, int32_t params_maxcount, int32_t *params_count)
 {
     GLenum type;
-    GLuint global_name = yagl_gles_object_get(program);
+    GLuint global_name = yagl_gles_object_get(cur_ts, program);
     GLint actual_location = yagl_gles_api_ps_translate_location(gles_api_ts->ps,
                                                                 tl,
                                                                 location);
 
-    if (!yagl_gles_program_get_uniform_type(global_name,
+    if (!yagl_gles_program_get_uniform_type(cur_ts,
+                                            global_name,
                                             actual_location,
                                             &type)) {
         return;
@@ -2594,7 +2770,8 @@ void yagl_host_glGetUniformuiv(GLboolean tl,
                                        params);
 }
 
-void yagl_host_glUniform1ui(GLboolean tl,
+void yagl_host_glUniform1ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0)
 {
@@ -2603,7 +2780,8 @@ void yagl_host_glUniform1ui(GLboolean tl,
         v0);
 }
 
-void yagl_host_glUniform2ui(GLboolean tl,
+void yagl_host_glUniform2ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0,
     GLuint v1)
@@ -2613,7 +2791,8 @@ void yagl_host_glUniform2ui(GLboolean tl,
         v0, v1);
 }
 
-void yagl_host_glUniform3ui(GLboolean tl,
+void yagl_host_glUniform3ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0,
     GLuint v1,
@@ -2624,7 +2803,8 @@ void yagl_host_glUniform3ui(GLboolean tl,
         v0, v1, v2);
 }
 
-void yagl_host_glUniform4ui(GLboolean tl,
+void yagl_host_glUniform4ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0,
     GLuint v1,
@@ -2636,7 +2816,8 @@ void yagl_host_glUniform4ui(GLboolean tl,
         v0, v1, v2, v3);
 }
 
-void yagl_host_glUniform1uiv(GLboolean tl,
+void yagl_host_glUniform1uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count)
 {
@@ -2645,7 +2826,8 @@ void yagl_host_glUniform1uiv(GLboolean tl,
         v_count, v);
 }
 
-void yagl_host_glUniform2uiv(GLboolean tl,
+void yagl_host_glUniform2uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count)
 {
@@ -2654,7 +2836,8 @@ void yagl_host_glUniform2uiv(GLboolean tl,
         (v_count / 2), v);
 }
 
-void yagl_host_glUniform3uiv(GLboolean tl,
+void yagl_host_glUniform3uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count)
 {
@@ -2663,7 +2846,8 @@ void yagl_host_glUniform3uiv(GLboolean tl,
         (v_count / 3), v);
 }
 
-void yagl_host_glUniform4uiv(GLboolean tl,
+void yagl_host_glUniform4uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count)
 {
@@ -2672,7 +2856,8 @@ void yagl_host_glUniform4uiv(GLboolean tl,
         (v_count / 4), v);
 }
 
-void yagl_host_glUniformMatrix2x3fv(GLboolean tl,
+void yagl_host_glUniformMatrix2x3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2682,7 +2867,8 @@ void yagl_host_glUniformMatrix2x3fv(GLboolean tl,
         value_count / (2 * 3), transpose, value);
 }
 
-void yagl_host_glUniformMatrix2x4fv(GLboolean tl,
+void yagl_host_glUniformMatrix2x4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2692,7 +2878,8 @@ void yagl_host_glUniformMatrix2x4fv(GLboolean tl,
         value_count / (2 * 4), transpose, value);
 }
 
-void yagl_host_glUniformMatrix3x2fv(GLboolean tl,
+void yagl_host_glUniformMatrix3x2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2702,7 +2889,8 @@ void yagl_host_glUniformMatrix3x2fv(GLboolean tl,
         value_count / (3 * 2), transpose, value);
 }
 
-void yagl_host_glUniformMatrix3x4fv(GLboolean tl,
+void yagl_host_glUniformMatrix3x4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2712,7 +2900,8 @@ void yagl_host_glUniformMatrix3x4fv(GLboolean tl,
         value_count / (3 * 4), transpose, value);
 }
 
-void yagl_host_glUniformMatrix4x2fv(GLboolean tl,
+void yagl_host_glUniformMatrix4x2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2722,7 +2911,8 @@ void yagl_host_glUniformMatrix4x2fv(GLboolean tl,
         value_count / (4 * 2), transpose, value);
 }
 
-void yagl_host_glUniformMatrix4x3fv(GLboolean tl,
+void yagl_host_glUniformMatrix4x3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count)
@@ -2732,14 +2922,16 @@ void yagl_host_glUniformMatrix4x3fv(GLboolean tl,
         value_count / (4 * 3), transpose, value);
 }
 
-int yagl_host_glGetFragDataLocation(GLuint program,
+int yagl_host_glGetFragDataLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *name, int32_t name_count)
 {
-    return gles_api_ts->driver->GetFragDataLocation(yagl_gles_object_get(program),
+    return gles_api_ts->driver->GetFragDataLocation(yagl_gles_object_get(cur_ts, program),
                                                     name);
 }
 
-void yagl_host_glGetIntegerv(GLenum pname,
+void yagl_host_glGetIntegerv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count)
 {
     gles_api_ts->driver->GetIntegerv(pname, params);
@@ -2747,7 +2939,8 @@ void yagl_host_glGetIntegerv(GLenum pname,
     *params_count = params_maxcount;
 }
 
-void yagl_host_glGetFloatv(GLenum pname,
+void yagl_host_glGetFloatv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count)
 {
     gles_api_ts->driver->GetFloatv(pname, params);
@@ -2755,7 +2948,8 @@ void yagl_host_glGetFloatv(GLenum pname,
     *params_count = params_maxcount;
 }
 
-void yagl_host_glGetString(GLenum name,
+void yagl_host_glGetString(struct yagl_thread_state *cur_ts,
+    GLenum name,
     GLchar *str, int32_t str_maxcount, int32_t *str_count)
 {
     const char *tmp;
@@ -2812,12 +3006,14 @@ void yagl_host_glGetString(GLenum name,
     }
 }
 
-GLboolean yagl_host_glIsEnabled(GLenum cap)
+GLboolean yagl_host_glIsEnabled(struct yagl_thread_state *cur_ts,
+    GLenum cap)
 {
     return gles_api_ts->driver->IsEnabled(cap);
 }
 
-void yagl_host_glGenTransformFeedbacks(const GLuint *ids, int32_t ids_count)
+void yagl_host_glGenTransformFeedbacks(struct yagl_thread_state *cur_ts,
+    const GLuint *ids, int32_t ids_count)
 {
     int i;
 
@@ -2826,52 +3022,57 @@ void yagl_host_glGenTransformFeedbacks(const GLuint *ids, int32_t ids_count)
 
         gles_api_ts->driver->GenTransformFeedbacks(1, &global_name);
 
-        yagl_gles_object_add(ids[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             ids[i],
                              global_name,
-                             yagl_get_ctx_id(),
+                             yagl_get_ctx_id(cur_ts->ps),
                              &yagl_gles_transform_feedback_destroy);
     }
 }
 
-void yagl_host_glBindTransformFeedback(GLenum target,
+void yagl_host_glBindTransformFeedback(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint id)
 {
     gles_api_ts->driver->BindTransformFeedback(target,
-                                               yagl_gles_object_get(id));
+                                               yagl_gles_object_get(cur_ts, id));
 }
 
-void yagl_host_glBeginTransformFeedback(GLenum primitiveMode)
+void yagl_host_glBeginTransformFeedback(struct yagl_thread_state *cur_ts,
+    GLenum primitiveMode)
 {
     gles_api_ts->driver->BeginTransformFeedback(primitiveMode);
 }
 
-void yagl_host_glEndTransformFeedback(void)
+void yagl_host_glEndTransformFeedback(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->EndTransformFeedback();
 }
 
-void yagl_host_glPauseTransformFeedback(void)
+void yagl_host_glPauseTransformFeedback(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->PauseTransformFeedback();
 }
 
-void yagl_host_glResumeTransformFeedback(void)
+void yagl_host_glResumeTransformFeedback(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->ResumeTransformFeedback();
 }
 
-void yagl_host_glTransformFeedbackVaryings(GLuint program,
+void yagl_host_glTransformFeedbackVaryings(struct yagl_thread_state *cur_ts,
+    struct yagl_transport *t,
+    GLuint program,
     const GLchar *varyings, int32_t varyings_count,
     GLenum bufferMode)
 {
     const char **strings;
     int32_t num_strings = 0;
 
-    strings = yagl_transport_get_out_string_array(varyings,
+    strings = yagl_transport_get_out_string_array(t, varyings,
                                                   varyings_count,
                                                   &num_strings);
 
-    gles_api_ts->driver->TransformFeedbackVaryings(yagl_gles_object_get(program),
+    gles_api_ts->driver->TransformFeedbackVaryings(yagl_gles_object_get(cur_ts, program),
                                                    num_strings,
                                                    strings,
                                                    bufferMode);
@@ -2879,11 +3080,12 @@ void yagl_host_glTransformFeedbackVaryings(GLuint program,
     g_free(strings);
 }
 
-void yagl_host_glGetTransformFeedbackVaryings(GLuint program,
+void yagl_host_glGetTransformFeedbackVaryings(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLsizei *sizes, int32_t sizes_maxcount, int32_t *sizes_count,
     GLenum *types, int32_t types_maxcount, int32_t *types_count)
 {
-    GLuint obj = yagl_gles_object_get(program);
+    GLuint obj = yagl_gles_object_get(cur_ts, program);
     int32_t i;
 
     if (sizes_maxcount != types_maxcount) {
@@ -2908,7 +3110,8 @@ void yagl_host_glGetTransformFeedbackVaryings(GLuint program,
     *sizes_count = *types_count = sizes_maxcount;
 }
 
-void yagl_host_glGenQueries(const GLuint *ids, int32_t ids_count)
+void yagl_host_glGenQueries(struct yagl_thread_state *cur_ts,
+    const GLuint *ids, int32_t ids_count)
 {
     int i;
 
@@ -2917,28 +3120,32 @@ void yagl_host_glGenQueries(const GLuint *ids, int32_t ids_count)
 
         gles_api_ts->driver->GenQueries(1, &global_name);
 
-        yagl_gles_object_add(ids[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             ids[i],
                              global_name,
-                             yagl_get_ctx_id(),
+                             yagl_get_ctx_id(cur_ts->ps),
                              &yagl_gles_query_destroy);
     }
 }
 
-void yagl_host_glBeginQuery(GLenum target,
+void yagl_host_glBeginQuery(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint id)
 {
-    gles_api_ts->driver->BeginQuery(target, yagl_gles_object_get(id));
+    gles_api_ts->driver->BeginQuery(target, yagl_gles_object_get(cur_ts, id));
 }
 
-void yagl_host_glEndQuery(GLenum target)
+void yagl_host_glEndQuery(struct yagl_thread_state *cur_ts,
+    GLenum target)
 {
     gles_api_ts->driver->EndQuery(target);
 }
 
-GLboolean yagl_host_glGetQueryObjectuiv(GLuint id,
+GLboolean yagl_host_glGetQueryObjectuiv(struct yagl_thread_state *cur_ts,
+    GLuint id,
     GLenum pname, GLuint *result)
 {
-    GLuint obj = yagl_gles_object_get(id);
+    GLuint obj = yagl_gles_object_get(cur_ts, id);
     GLuint tmp = 0;
 
     if (pname == GL_QUERY_RESULT_AVAILABLE) {
@@ -2954,7 +3161,8 @@ GLboolean yagl_host_glGetQueryObjectuiv(GLuint id,
     return tmp;
 }
 
-void yagl_host_glGenSamplers(const GLuint *samplers, int32_t samplers_count)
+void yagl_host_glGenSamplers(struct yagl_thread_state *cur_ts,
+    const GLuint *samplers, int32_t samplers_count)
 {
     int i;
 
@@ -2963,48 +3171,55 @@ void yagl_host_glGenSamplers(const GLuint *samplers, int32_t samplers_count)
 
         gles_api_ts->driver->GenSamplers(1, &global_name);
 
-        yagl_gles_object_add(samplers[i],
+        yagl_gles_object_add(cur_ts->ps,
+                             samplers[i],
                              global_name,
                              0,
                              &yagl_gles_sampler_destroy);
     }
 }
 
-void yagl_host_glBindSampler(GLuint unit,
+void yagl_host_glBindSampler(struct yagl_thread_state *cur_ts,
+    GLuint unit,
     GLuint sampler)
 {
-    gles_api_ts->driver->BindSampler(unit, yagl_gles_object_get(sampler));
+    gles_api_ts->driver->BindSampler(unit, yagl_gles_object_get(cur_ts, sampler));
 }
 
-void yagl_host_glSamplerParameteri(GLuint sampler,
+void yagl_host_glSamplerParameteri(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     GLint param)
 {
-    gles_api_ts->driver->SamplerParameteri(yagl_gles_object_get(sampler), pname, param);
+    gles_api_ts->driver->SamplerParameteri(yagl_gles_object_get(cur_ts, sampler), pname, param);
 }
 
-void yagl_host_glSamplerParameteriv(GLuint sampler,
+void yagl_host_glSamplerParameteriv(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     const GLint *param, int32_t param_count)
 {
-    gles_api_ts->driver->SamplerParameteriv(yagl_gles_object_get(sampler), pname, param);
+    gles_api_ts->driver->SamplerParameteriv(yagl_gles_object_get(cur_ts, sampler), pname, param);
 }
 
-void yagl_host_glSamplerParameterf(GLuint sampler,
+void yagl_host_glSamplerParameterf(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     GLfloat param)
 {
-    gles_api_ts->driver->SamplerParameterf(yagl_gles_object_get(sampler), pname, param);
+    gles_api_ts->driver->SamplerParameterf(yagl_gles_object_get(cur_ts, sampler), pname, param);
 }
 
-void yagl_host_glSamplerParameterfv(GLuint sampler,
+void yagl_host_glSamplerParameterfv(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     const GLfloat *param, int32_t param_count)
 {
-    gles_api_ts->driver->SamplerParameterfv(yagl_gles_object_get(sampler), pname, param);
+    gles_api_ts->driver->SamplerParameterfv(yagl_gles_object_get(cur_ts, sampler), pname, param);
 }
 
-void yagl_host_glDeleteObjects(const GLuint *objects, int32_t objects_count)
+void yagl_host_glDeleteObjects(struct yagl_thread_state *cur_ts,
+    const GLuint *objects, int32_t objects_count)
 {
     int i;
 
@@ -3013,24 +3228,28 @@ void yagl_host_glDeleteObjects(const GLuint *objects, int32_t objects_count)
     }
 }
 
-void yagl_host_glBlendEquation(GLenum mode)
+void yagl_host_glBlendEquation(struct yagl_thread_state *cur_ts,
+    GLenum mode)
 {
     gles_api_ts->driver->BlendEquation(mode);
 }
 
-void yagl_host_glBlendEquationSeparate(GLenum modeRGB,
+void yagl_host_glBlendEquationSeparate(struct yagl_thread_state *cur_ts,
+    GLenum modeRGB,
     GLenum modeAlpha)
 {
     gles_api_ts->driver->BlendEquationSeparate(modeRGB, modeAlpha);
 }
 
-void yagl_host_glBlendFunc(GLenum sfactor,
+void yagl_host_glBlendFunc(struct yagl_thread_state *cur_ts,
+    GLenum sfactor,
     GLenum dfactor)
 {
     gles_api_ts->driver->BlendFunc(sfactor, dfactor);
 }
 
-void yagl_host_glBlendFuncSeparate(GLenum srcRGB,
+void yagl_host_glBlendFuncSeparate(struct yagl_thread_state *cur_ts,
+    GLenum srcRGB,
     GLenum dstRGB,
     GLenum srcAlpha,
     GLenum dstAlpha)
@@ -3041,7 +3260,8 @@ void yagl_host_glBlendFuncSeparate(GLenum srcRGB,
                                            dstAlpha);
 }
 
-void yagl_host_glBlendColor(GLclampf red,
+void yagl_host_glBlendColor(struct yagl_thread_state *cur_ts,
+    GLclampf red,
     GLclampf green,
     GLclampf blue,
     GLclampf alpha)
@@ -3049,12 +3269,14 @@ void yagl_host_glBlendColor(GLclampf red,
     gles_api_ts->driver->BlendColor(red, green, blue, alpha);
 }
 
-void yagl_host_glClear(GLbitfield mask)
+void yagl_host_glClear(struct yagl_thread_state *cur_ts,
+    GLbitfield mask)
 {
     gles_api_ts->driver->Clear(mask);
 }
 
-void yagl_host_glClearColor(GLclampf red,
+void yagl_host_glClearColor(struct yagl_thread_state *cur_ts,
+    GLclampf red,
     GLclampf green,
     GLclampf blue,
     GLclampf alpha)
@@ -3062,17 +3284,20 @@ void yagl_host_glClearColor(GLclampf red,
     gles_api_ts->driver->ClearColor(red, green, blue, alpha);
 }
 
-void yagl_host_glClearDepthf(GLclampf depth)
+void yagl_host_glClearDepthf(struct yagl_thread_state *cur_ts,
+    GLclampf depth)
 {
     gles_api_ts->driver->ClearDepth(depth);
 }
 
-void yagl_host_glClearStencil(GLint s)
+void yagl_host_glClearStencil(struct yagl_thread_state *cur_ts,
+    GLint s)
 {
     gles_api_ts->driver->ClearStencil(s);
 }
 
-void yagl_host_glColorMask(GLboolean red,
+void yagl_host_glColorMask(struct yagl_thread_state *cur_ts,
+    GLboolean red,
     GLboolean green,
     GLboolean blue,
     GLboolean alpha)
@@ -3080,76 +3305,89 @@ void yagl_host_glColorMask(GLboolean red,
     gles_api_ts->driver->ColorMask(red, green, blue, alpha);
 }
 
-void yagl_host_glCullFace(GLenum mode)
+void yagl_host_glCullFace(struct yagl_thread_state *cur_ts,
+    GLenum mode)
 {
     gles_api_ts->driver->CullFace(mode);
 }
 
-void yagl_host_glDepthFunc(GLenum func)
+void yagl_host_glDepthFunc(struct yagl_thread_state *cur_ts,
+    GLenum func)
 {
     gles_api_ts->driver->DepthFunc(func);
 }
 
-void yagl_host_glDepthMask(GLboolean flag)
+void yagl_host_glDepthMask(struct yagl_thread_state *cur_ts,
+    GLboolean flag)
 {
     gles_api_ts->driver->DepthMask(flag);
 }
 
-void yagl_host_glDepthRangef(GLclampf zNear,
+void yagl_host_glDepthRangef(struct yagl_thread_state *cur_ts,
+    GLclampf zNear,
     GLclampf zFar)
 {
     gles_api_ts->driver->DepthRange(zNear, zFar);
 }
 
-void yagl_host_glEnable(GLenum cap)
+void yagl_host_glEnable(struct yagl_thread_state *cur_ts,
+    GLenum cap)
 {
     gles_api_ts->driver->Enable(cap);
 }
 
-void yagl_host_glDisable(GLenum cap)
+void yagl_host_glDisable(struct yagl_thread_state *cur_ts,
+    GLenum cap)
 {
     gles_api_ts->driver->Disable(cap);
 }
 
-void yagl_host_glFlush(void)
+void yagl_host_glFlush(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->Flush();
 }
 
-void yagl_host_glFrontFace(GLenum mode)
+void yagl_host_glFrontFace(struct yagl_thread_state *cur_ts,
+    GLenum mode)
 {
     gles_api_ts->driver->FrontFace(mode);
 }
 
-void yagl_host_glGenerateMipmap(GLenum target)
+void yagl_host_glGenerateMipmap(struct yagl_thread_state *cur_ts,
+    GLenum target)
 {
     gles_api_ts->driver->GenerateMipmap(target);
 }
 
-void yagl_host_glHint(GLenum target,
+void yagl_host_glHint(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum mode)
 {
     gles_api_ts->driver->Hint(target, mode);
 }
 
-void yagl_host_glLineWidth(GLfloat width)
+void yagl_host_glLineWidth(struct yagl_thread_state *cur_ts,
+    GLfloat width)
 {
     gles_api_ts->driver->LineWidth(width);
 }
 
-void yagl_host_glPixelStorei(GLenum pname,
+void yagl_host_glPixelStorei(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLint param)
 {
     gles_api_ts->driver->PixelStorei(pname, param);
 }
 
-void yagl_host_glPolygonOffset(GLfloat factor,
+void yagl_host_glPolygonOffset(struct yagl_thread_state *cur_ts,
+    GLfloat factor,
     GLfloat units)
 {
     gles_api_ts->driver->PolygonOffset(factor, units);
 }
 
-void yagl_host_glScissor(GLint x,
+void yagl_host_glScissor(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height)
@@ -3157,32 +3395,37 @@ void yagl_host_glScissor(GLint x,
     gles_api_ts->driver->Scissor(x, y, width, height);
 }
 
-void yagl_host_glStencilFunc(GLenum func,
+void yagl_host_glStencilFunc(struct yagl_thread_state *cur_ts,
+    GLenum func,
     GLint ref,
     GLuint mask)
 {
     gles_api_ts->driver->StencilFunc(func, ref, mask);
 }
 
-void yagl_host_glStencilMask(GLuint mask)
+void yagl_host_glStencilMask(struct yagl_thread_state *cur_ts,
+    GLuint mask)
 {
     gles_api_ts->driver->StencilMask(mask);
 }
 
-void yagl_host_glStencilOp(GLenum fail,
+void yagl_host_glStencilOp(struct yagl_thread_state *cur_ts,
+    GLenum fail,
     GLenum zfail,
     GLenum zpass)
 {
     gles_api_ts->driver->StencilOp(fail, zfail, zpass);
 }
 
-void yagl_host_glSampleCoverage(GLclampf value,
+void yagl_host_glSampleCoverage(struct yagl_thread_state *cur_ts,
+    GLclampf value,
     GLboolean invert)
 {
     gles_api_ts->driver->SampleCoverage(value, invert);
 }
 
-void yagl_host_glViewport(GLint x,
+void yagl_host_glViewport(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height)
@@ -3190,7 +3433,8 @@ void yagl_host_glViewport(GLint x,
     gles_api_ts->driver->Viewport(x, y, width, height);
 }
 
-void yagl_host_glStencilFuncSeparate(GLenum face,
+void yagl_host_glStencilFuncSeparate(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum func,
     GLint ref,
     GLuint mask)
@@ -3198,13 +3442,15 @@ void yagl_host_glStencilFuncSeparate(GLenum face,
     gles_api_ts->driver->StencilFuncSeparate(face, func, ref, mask);
 }
 
-void yagl_host_glStencilMaskSeparate(GLenum face,
+void yagl_host_glStencilMaskSeparate(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLuint mask)
 {
     gles_api_ts->driver->StencilMaskSeparate(face, mask);
 }
 
-void yagl_host_glStencilOpSeparate(GLenum face,
+void yagl_host_glStencilOpSeparate(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum fail,
     GLenum zfail,
     GLenum zpass)
@@ -3212,38 +3458,42 @@ void yagl_host_glStencilOpSeparate(GLenum face,
     gles_api_ts->driver->StencilOpSeparate(face, fail, zfail, zpass);
 }
 
-void yagl_host_glPointSize(GLfloat size)
+void yagl_host_glPointSize(struct yagl_thread_state *cur_ts,
+    GLfloat size)
 {
     gles_api_ts->driver->PointSize(size);
 }
 
-void yagl_host_glAlphaFunc(GLenum func,
+void yagl_host_glAlphaFunc(struct yagl_thread_state *cur_ts,
+    GLenum func,
     GLclampf ref)
 {
     gles_api_ts->driver->AlphaFunc(func, ref);
 }
 
-void yagl_host_glMatrixMode(GLenum mode)
+void yagl_host_glMatrixMode(struct yagl_thread_state *cur_ts,
+    GLenum mode)
 {
     gles_api_ts->driver->MatrixMode(mode);
 }
 
-void yagl_host_glLoadIdentity(void)
+void yagl_host_glLoadIdentity(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->LoadIdentity();
 }
 
-void yagl_host_glPopMatrix(void)
+void yagl_host_glPopMatrix(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->PopMatrix();
 }
 
-void yagl_host_glPushMatrix(void)
+void yagl_host_glPushMatrix(struct yagl_thread_state *cur_ts)
 {
     gles_api_ts->driver->PushMatrix();
 }
 
-void yagl_host_glRotatef(GLfloat angle,
+void yagl_host_glRotatef(struct yagl_thread_state *cur_ts,
+    GLfloat angle,
     GLfloat x,
     GLfloat y,
     GLfloat z)
@@ -3251,21 +3501,24 @@ void yagl_host_glRotatef(GLfloat angle,
     gles_api_ts->driver->Rotatef(angle, x, y, z);
 }
 
-void yagl_host_glTranslatef(GLfloat x,
+void yagl_host_glTranslatef(struct yagl_thread_state *cur_ts,
+    GLfloat x,
     GLfloat y,
     GLfloat z)
 {
     gles_api_ts->driver->Translatef(x, y, z);
 }
 
-void yagl_host_glScalef(GLfloat x,
+void yagl_host_glScalef(struct yagl_thread_state *cur_ts,
+    GLfloat x,
     GLfloat y,
     GLfloat z)
 {
     gles_api_ts->driver->Scalef(x, y, z);
 }
 
-void yagl_host_glOrthof(GLfloat left,
+void yagl_host_glOrthof(struct yagl_thread_state *cur_ts,
+    GLfloat left,
     GLfloat right,
     GLfloat bottom,
     GLfloat top,
@@ -3275,7 +3528,8 @@ void yagl_host_glOrthof(GLfloat left,
     gles_api_ts->driver->Ortho(left, right, bottom, top, zNear, zFar);
 }
 
-void yagl_host_glColor4f(GLfloat red,
+void yagl_host_glColor4f(struct yagl_thread_state *cur_ts,
+    GLfloat red,
     GLfloat green,
     GLfloat blue,
     GLfloat alpha)
@@ -3283,7 +3537,8 @@ void yagl_host_glColor4f(GLfloat red,
     gles_api_ts->driver->Color4f(red, green, blue, alpha);
 }
 
-void yagl_host_glColor4ub(GLubyte red,
+void yagl_host_glColor4ub(struct yagl_thread_state *cur_ts,
+    GLubyte red,
     GLubyte green,
     GLubyte blue,
     GLubyte alpha)
@@ -3291,38 +3546,44 @@ void yagl_host_glColor4ub(GLubyte red,
     gles_api_ts->driver->Color4ub(red, green, blue, alpha);
 }
 
-void yagl_host_glNormal3f(GLfloat nx,
+void yagl_host_glNormal3f(struct yagl_thread_state *cur_ts,
+    GLfloat nx,
     GLfloat ny,
     GLfloat nz)
 {
     gles_api_ts->driver->Normal3f(nx, ny, nz);
 }
 
-void yagl_host_glPointParameterf(GLenum pname,
+void yagl_host_glPointParameterf(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->PointParameterf(pname, param);
 }
 
-void yagl_host_glPointParameterfv(GLenum pname,
+void yagl_host_glPointParameterfv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
     gles_api_ts->driver->PointParameterfv(pname, params);
 }
 
-void yagl_host_glFogf(GLenum pname,
+void yagl_host_glFogf(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->Fogf(pname, param);
 }
 
-void yagl_host_glFogfv(GLenum pname,
+void yagl_host_glFogfv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
     gles_api_ts->driver->Fogfv(pname, params);
 }
 
-void yagl_host_glFrustumf(GLfloat left,
+void yagl_host_glFrustumf(struct yagl_thread_state *cur_ts,
+    GLfloat left,
     GLfloat right,
     GLfloat bottom,
     GLfloat top,
@@ -3332,21 +3593,24 @@ void yagl_host_glFrustumf(GLfloat left,
     gles_api_ts->driver->Frustum(left, right, bottom, top, zNear, zFar);
 }
 
-void yagl_host_glLightf(GLenum light,
+void yagl_host_glLightf(struct yagl_thread_state *cur_ts,
+    GLenum light,
     GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->Lightf(light, pname, param);
 }
 
-void yagl_host_glLightfv(GLenum light,
+void yagl_host_glLightfv(struct yagl_thread_state *cur_ts,
+    GLenum light,
     GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
     gles_api_ts->driver->Lightfv(light, pname, params);
 }
 
-void yagl_host_glGetLightfv(GLenum light,
+void yagl_host_glGetLightfv(struct yagl_thread_state *cur_ts,
+    GLenum light,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -3354,33 +3618,38 @@ void yagl_host_glGetLightfv(GLenum light,
     *params_count = params_maxcount;
 }
 
-void yagl_host_glLightModelf(GLenum pname,
+void yagl_host_glLightModelf(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->LightModelf(pname, param);
 }
 
-void yagl_host_glLightModelfv(GLenum pname,
+void yagl_host_glLightModelfv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
     gles_api_ts->driver->LightModelfv(pname, params);
 }
 
-void yagl_host_glMaterialf(GLenum face,
+void yagl_host_glMaterialf(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum pname,
     GLfloat param)
 {
     gles_api_ts->driver->Materialf(face, pname, param);
 }
 
-void yagl_host_glMaterialfv(GLenum face,
+void yagl_host_glMaterialfv(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum pname,
     const GLfloat *params, int32_t params_count)
 {
     gles_api_ts->driver->Materialfv(face, pname, params);
 }
 
-void yagl_host_glGetMaterialfv(GLenum face,
+void yagl_host_glGetMaterialfv(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count)
 {
@@ -3388,27 +3657,32 @@ void yagl_host_glGetMaterialfv(GLenum face,
     *params_count = params_maxcount;
 }
 
-void yagl_host_glShadeModel(GLenum mode)
+void yagl_host_glShadeModel(struct yagl_thread_state *cur_ts,
+    GLenum mode)
 {
     gles_api_ts->driver->ShadeModel(mode);
 }
 
-void yagl_host_glLogicOp(GLenum opcode)
+void yagl_host_glLogicOp(struct yagl_thread_state *cur_ts,
+    GLenum opcode)
 {
     gles_api_ts->driver->LogicOp(opcode);
 }
 
-void yagl_host_glMultMatrixf(const GLfloat *m, int32_t m_count)
+void yagl_host_glMultMatrixf(struct yagl_thread_state *cur_ts,
+    const GLfloat *m, int32_t m_count)
 {
     gles_api_ts->driver->MultMatrixf(m);
 }
 
-void yagl_host_glLoadMatrixf(const GLfloat *m, int32_t m_count)
+void yagl_host_glLoadMatrixf(struct yagl_thread_state *cur_ts,
+    const GLfloat *m, int32_t m_count)
 {
     gles_api_ts->driver->LoadMatrixf(m);
 }
 
-void yagl_host_glClipPlanef(GLenum plane,
+void yagl_host_glClipPlanef(struct yagl_thread_state *cur_ts,
+    GLenum plane,
     const GLfloat *equation, int32_t equation_count)
 {
     yagl_GLdouble equationd[4];
@@ -3424,7 +3698,8 @@ void yagl_host_glClipPlanef(GLenum plane,
     }
 }
 
-void yagl_host_glGetClipPlanef(GLenum pname,
+void yagl_host_glGetClipPlanef(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat *eqn, int32_t eqn_maxcount, int32_t *eqn_count)
 {
     yagl_GLdouble eqnd[4];
@@ -3440,7 +3715,8 @@ void yagl_host_glGetClipPlanef(GLenum pname,
     }
 }
 
-void yagl_host_glUpdateOffscreenImageYAGL(GLuint texture,
+void yagl_host_glUpdateOffscreenImageYAGL(struct yagl_thread_state *cur_ts,
+    GLuint texture,
     uint32_t width,
     uint32_t height,
     uint32_t bpp,
@@ -3476,7 +3752,7 @@ void yagl_host_glUpdateOffscreenImageYAGL(GLuint texture,
     gles_api_ts->driver->PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
 
     gles_api_ts->driver->BindTexture(GL_TEXTURE_2D,
-                                     yagl_gles_object_get(texture));
+                                     yagl_gles_object_get(cur_ts, texture));
 
     gles_api_ts->driver->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     gles_api_ts->driver->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -3498,16 +3774,18 @@ void yagl_host_glUpdateOffscreenImageYAGL(GLuint texture,
     gles_api_ts->driver->BindTexture(GL_TEXTURE_2D, cur_tex);
 }
 
-void yagl_host_glGenUniformLocationYAGL(uint32_t location,
+void yagl_host_glGenUniformLocationYAGL(struct yagl_thread_state *cur_ts,
+    uint32_t location,
     GLuint program,
     const GLchar *name, int32_t name_count)
 {
     yagl_gles_api_ps_add_location(gles_api_ts->ps,
         location,
-        gles_api_ts->driver->GetUniformLocation(yagl_gles_object_get(program), name));
+        gles_api_ts->driver->GetUniformLocation(yagl_gles_object_get(cur_ts, program), name));
 }
 
-void yagl_host_glDeleteUniformLocationsYAGL(const uint32_t *locations, int32_t locations_count)
+void yagl_host_glDeleteUniformLocationsYAGL(struct yagl_thread_state *cur_ts,
+    const uint32_t *locations, int32_t locations_count)
 {
     int i;
 
index cc87ee5..ddb212a 100644 (file)
 #include "yagl_api.h"
 #include <GL/gl.h>
 
-struct yagl_api_ps *yagl_host_gles_process_init(struct yagl_api *api);
+struct yagl_api_ps *yagl_host_gles_process_init(struct yagl_process_state *ps, struct yagl_api *api);
 
-void yagl_host_glDrawArrays(GLenum mode,
+void yagl_host_glDrawArrays(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLint first,
     GLsizei count);
-void yagl_host_glDrawElements(GLenum mode,
+void yagl_host_glDrawElements(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLsizei count,
     GLenum type,
     const GLvoid *indices, int32_t indices_count);
-void yagl_host_glReadPixelsData(GLint x,
+void yagl_host_glReadPixelsData(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height,
     GLenum format,
     GLenum type,
     GLvoid *pixels, int32_t pixels_maxcount, int32_t *pixels_count);
-void yagl_host_glReadPixelsOffset(GLint x,
+void yagl_host_glReadPixelsOffset(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height,
     GLenum format,
     GLenum type,
     uintptr_t pixels);
-void yagl_host_glDrawArraysInstanced(GLenum mode,
+void yagl_host_glDrawArraysInstanced(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLint start,
     GLsizei count,
     GLsizei primcount);
-void yagl_host_glDrawElementsInstanced(GLenum mode,
+void yagl_host_glDrawElementsInstanced(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLsizei count,
     GLenum type,
     const void *indices, int32_t indices_count,
     GLsizei primcount);
-void yagl_host_glDrawRangeElements(GLenum mode,
+void yagl_host_glDrawRangeElements(struct yagl_thread_state *cur_ts,
+    GLenum mode,
     GLuint start,
     GLuint end,
     GLsizei count,
     GLenum type,
     const GLvoid *indices, int32_t indices_count);
-void yagl_host_glGenVertexArrays(const GLuint *arrays, int32_t arrays_count);
-void yagl_host_glBindVertexArray(GLuint array);
-void yagl_host_glDisableVertexAttribArray(GLuint index);
-void yagl_host_glEnableVertexAttribArray(GLuint index);
-void yagl_host_glVertexAttribPointerData(GLuint indx,
+void yagl_host_glGenVertexArrays(struct yagl_thread_state *cur_ts,
+    const GLuint *arrays, int32_t arrays_count);
+void yagl_host_glBindVertexArray(struct yagl_thread_state *cur_ts,
+    GLuint array);
+void yagl_host_glDisableVertexAttribArray(struct yagl_thread_state *cur_ts,
+    GLuint index);
+void yagl_host_glEnableVertexAttribArray(struct yagl_thread_state *cur_ts,
+    GLuint index);
+void yagl_host_glVertexAttribPointerData(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLint size,
     GLenum type,
     GLboolean normalized,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glVertexAttribPointerOffset(GLuint indx,
+void yagl_host_glVertexAttribPointerOffset(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLint size,
     GLenum type,
     GLboolean normalized,
     GLsizei stride,
     uintptr_t offset);
-void yagl_host_glVertexPointerData(GLint size,
+void yagl_host_glVertexPointerData(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glVertexPointerOffset(GLint size,
+void yagl_host_glVertexPointerOffset(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset);
-void yagl_host_glNormalPointerData(GLenum type,
+void yagl_host_glNormalPointerData(struct yagl_thread_state *cur_ts,
+    GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glNormalPointerOffset(GLenum type,
+void yagl_host_glNormalPointerOffset(struct yagl_thread_state *cur_ts,
+    GLenum type,
     GLsizei stride,
     uintptr_t offset);
-void yagl_host_glColorPointerData(GLint size,
+void yagl_host_glColorPointerData(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glColorPointerOffset(GLint size,
+void yagl_host_glColorPointerOffset(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset);
-void yagl_host_glTexCoordPointerData(GLint tex_id,
+void yagl_host_glTexCoordPointerData(struct yagl_thread_state *cur_ts,
+    GLint tex_id,
     GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glTexCoordPointerOffset(GLint size,
+void yagl_host_glTexCoordPointerOffset(struct yagl_thread_state *cur_ts,
+    GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset);
-void yagl_host_glDisableClientState(GLenum array);
-void yagl_host_glEnableClientState(GLenum array);
-void yagl_host_glVertexAttribDivisor(GLuint index,
+void yagl_host_glDisableClientState(struct yagl_thread_state *cur_ts,
+    GLenum array);
+void yagl_host_glEnableClientState(struct yagl_thread_state *cur_ts,
+    GLenum array);
+void yagl_host_glVertexAttribDivisor(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLuint divisor);
-void yagl_host_glVertexAttribIPointerData(GLuint index,
+void yagl_host_glVertexAttribIPointerData(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLint size,
     GLenum type,
     GLsizei stride,
     GLint first,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glVertexAttribIPointerOffset(GLuint index,
+void yagl_host_glVertexAttribIPointerOffset(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLint size,
     GLenum type,
     GLsizei stride,
     uintptr_t offset);
-void yagl_host_glGenBuffers(const GLuint *buffers, int32_t buffers_count);
-void yagl_host_glBindBuffer(GLenum target,
+void yagl_host_glGenBuffers(struct yagl_thread_state *cur_ts,
+    const GLuint *buffers, int32_t buffers_count);
+void yagl_host_glBindBuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint buffer);
-void yagl_host_glBufferData(GLenum target,
+void yagl_host_glBufferData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     const GLvoid *data, int32_t data_count,
     GLenum usage);
-void yagl_host_glBufferSubData(GLenum target,
+void yagl_host_glBufferSubData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLsizei offset,
     const GLvoid *data, int32_t data_count);
-void yagl_host_glBindBufferBase(GLenum target,
+void yagl_host_glBindBufferBase(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint index,
     GLuint buffer);
-void yagl_host_glBindBufferRange(GLenum target,
+void yagl_host_glBindBufferRange(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint index,
     GLuint buffer,
     GLint offset,
     GLsizei size);
-void yagl_host_glMapBuffer(GLuint buffer,
+void yagl_host_glMapBuffer(struct yagl_thread_state *cur_ts,
+    GLuint buffer,
     const GLuint *ranges, int32_t ranges_count,
     GLvoid *data, int32_t data_maxcount, int32_t *data_count);
-void yagl_host_glCopyBufferSubData(GLenum readTarget,
+void yagl_host_glCopyBufferSubData(struct yagl_thread_state *cur_ts,
+    GLenum readTarget,
     GLenum writeTarget,
     GLintptr readOffset,
     GLintptr writeOffset,
     GLsizei size);
-void yagl_host_glGenTextures(const GLuint *textures, int32_t textures_count);
-void yagl_host_glBindTexture(GLenum target,
+void yagl_host_glGenTextures(struct yagl_thread_state *cur_ts,
+    const GLuint *textures, int32_t textures_count);
+void yagl_host_glBindTexture(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint texture);
-void yagl_host_glActiveTexture(GLenum texture);
-void yagl_host_glCopyTexImage2D(GLenum target,
+void yagl_host_glActiveTexture(struct yagl_thread_state *cur_ts,
+    GLenum texture);
+void yagl_host_glCopyTexImage2D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLenum internalformat,
     GLint x,
@@ -175,7 +213,8 @@ void yagl_host_glCopyTexImage2D(GLenum target,
     GLsizei width,
     GLsizei height,
     GLint border);
-void yagl_host_glCopyTexSubImage2D(GLenum target,
+void yagl_host_glCopyTexSubImage2D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -183,13 +222,16 @@ void yagl_host_glCopyTexSubImage2D(GLenum target,
     GLint y,
     GLsizei width,
     GLsizei height);
-void yagl_host_glGetTexParameterfv(GLenum target,
+void yagl_host_glGetTexParameterfv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLfloat *param);
-void yagl_host_glGetTexParameteriv(GLenum target,
+void yagl_host_glGetTexParameteriv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint *param);
-void yagl_host_glTexImage2DData(GLenum target,
+void yagl_host_glTexImage2DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -198,7 +240,8 @@ void yagl_host_glTexImage2DData(GLenum target,
     GLenum format,
     GLenum type,
     const GLvoid *pixels, int32_t pixels_count);
-void yagl_host_glTexImage2DOffset(GLenum target,
+void yagl_host_glTexImage2DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -207,19 +250,24 @@ void yagl_host_glTexImage2DOffset(GLenum target,
     GLenum format,
     GLenum type,
     uintptr_t pixels);
-void yagl_host_glTexParameterf(GLenum target,
+void yagl_host_glTexParameterf(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLfloat param);
-void yagl_host_glTexParameterfv(GLenum target,
+void yagl_host_glTexParameterfv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glTexParameteri(GLenum target,
+void yagl_host_glTexParameteri(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint param);
-void yagl_host_glTexParameteriv(GLenum target,
+void yagl_host_glTexParameteriv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLint *params, int32_t params_count);
-void yagl_host_glTexSubImage2DData(GLenum target,
+void yagl_host_glTexSubImage2DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -228,7 +276,8 @@ void yagl_host_glTexSubImage2DData(GLenum target,
     GLenum format,
     GLenum type,
     const GLvoid *pixels, int32_t pixels_count);
-void yagl_host_glTexSubImage2DOffset(GLenum target,
+void yagl_host_glTexSubImage2DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -237,31 +286,40 @@ void yagl_host_glTexSubImage2DOffset(GLenum target,
     GLenum format,
     GLenum type,
     uintptr_t pixels);
-void yagl_host_glClientActiveTexture(GLenum texture);
-void yagl_host_glTexEnvi(GLenum target,
+void yagl_host_glClientActiveTexture(struct yagl_thread_state *cur_ts,
+    GLenum texture);
+void yagl_host_glTexEnvi(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint param);
-void yagl_host_glTexEnvf(GLenum target,
+void yagl_host_glTexEnvf(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLfloat param);
-void yagl_host_glMultiTexCoord4f(GLenum target,
+void yagl_host_glMultiTexCoord4f(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLfloat s,
     GLfloat tt,
     GLfloat r,
     GLfloat q);
-void yagl_host_glTexEnviv(GLenum target,
+void yagl_host_glTexEnviv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLint *params, int32_t params_count);
-void yagl_host_glTexEnvfv(GLenum target,
+void yagl_host_glTexEnvfv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glGetTexEnviv(GLenum env,
+void yagl_host_glGetTexEnviv(struct yagl_thread_state *cur_ts,
+    GLenum env,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetTexEnvfv(GLenum env,
+void yagl_host_glGetTexEnvfv(struct yagl_thread_state *cur_ts,
+    GLenum env,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glTexImage3DData(GLenum target,
+void yagl_host_glTexImage3DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -271,7 +329,8 @@ void yagl_host_glTexImage3DData(GLenum target,
     GLenum format,
     GLenum type,
     const void *pixels, int32_t pixels_count);
-void yagl_host_glTexImage3DOffset(GLenum target,
+void yagl_host_glTexImage3DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint internalformat,
     GLsizei width,
@@ -281,7 +340,8 @@ void yagl_host_glTexImage3DOffset(GLenum target,
     GLenum format,
     GLenum type,
     uintptr_t pixels);
-void yagl_host_glTexSubImage3DData(GLenum target,
+void yagl_host_glTexSubImage3DData(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -292,7 +352,8 @@ void yagl_host_glTexSubImage3DData(GLenum target,
     GLenum format,
     GLenum type,
     const void *pixels, int32_t pixels_count);
-void yagl_host_glTexSubImage3DOffset(GLenum target,
+void yagl_host_glTexSubImage3DOffset(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -303,7 +364,8 @@ void yagl_host_glTexSubImage3DOffset(GLenum target,
     GLenum format,
     GLenum type,
     uintptr_t pixels);
-void yagl_host_glCopyTexSubImage3D(GLenum target,
+void yagl_host_glCopyTexSubImage3D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
@@ -312,19 +374,24 @@ void yagl_host_glCopyTexSubImage3D(GLenum target,
     GLint y,
     GLsizei width,
     GLsizei height);
-void yagl_host_glGenFramebuffers(const GLuint *framebuffers, int32_t framebuffers_count);
-void yagl_host_glBindFramebuffer(GLenum target,
+void yagl_host_glGenFramebuffers(struct yagl_thread_state *cur_ts,
+    const GLuint *framebuffers, int32_t framebuffers_count);
+void yagl_host_glBindFramebuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint framebuffer);
-void yagl_host_glFramebufferTexture2D(GLenum target,
+void yagl_host_glFramebufferTexture2D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLenum textarget,
     GLuint texture,
     GLint level);
-void yagl_host_glFramebufferRenderbuffer(GLenum target,
+void yagl_host_glFramebufferRenderbuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLenum renderbuffertarget,
     GLuint renderbuffer);
-void yagl_host_glBlitFramebuffer(GLint srcX0,
+void yagl_host_glBlitFramebuffer(struct yagl_thread_state *cur_ts,
+    GLint srcX0,
     GLint srcY0,
     GLint srcX1,
     GLint srcY1,
@@ -334,490 +401,663 @@ void yagl_host_glBlitFramebuffer(GLint srcX0,
     GLint dstY1,
     GLbitfield mask,
     GLenum filter);
-void yagl_host_glDrawBuffers(const GLenum *bufs, int32_t bufs_count);
-void yagl_host_glReadBuffer(GLenum mode);
-void yagl_host_glFramebufferTexture3D(GLenum target,
+void yagl_host_glDrawBuffers(struct yagl_thread_state *cur_ts,
+    const GLenum *bufs, int32_t bufs_count);
+void yagl_host_glReadBuffer(struct yagl_thread_state *cur_ts,
+    GLenum mode);
+void yagl_host_glFramebufferTexture3D(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLenum textarget,
     GLuint texture,
     GLint level,
     GLint zoffset);
-void yagl_host_glFramebufferTextureLayer(GLenum target,
+void yagl_host_glFramebufferTextureLayer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum attachment,
     GLuint texture,
     GLint level,
     GLint layer);
-void yagl_host_glClearBufferiv(GLenum buffer,
+void yagl_host_glClearBufferiv(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     const GLint *value, int32_t value_count);
-void yagl_host_glClearBufferuiv(GLenum buffer,
+void yagl_host_glClearBufferuiv(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     const GLuint *value, int32_t value_count);
-void yagl_host_glClearBufferfi(GLenum buffer,
+void yagl_host_glClearBufferfi(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     GLfloat depth,
     GLint stencil);
-void yagl_host_glClearBufferfv(GLenum buffer,
+void yagl_host_glClearBufferfv(struct yagl_thread_state *cur_ts,
+    GLenum buffer,
     GLint drawbuffer,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glGenRenderbuffers(const GLuint *renderbuffers, int32_t renderbuffers_count);
-void yagl_host_glBindRenderbuffer(GLenum target,
+void yagl_host_glGenRenderbuffers(struct yagl_thread_state *cur_ts,
+    const GLuint *renderbuffers, int32_t renderbuffers_count);
+void yagl_host_glBindRenderbuffer(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint renderbuffer);
-void yagl_host_glRenderbufferStorage(GLenum target,
+void yagl_host_glRenderbufferStorage(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum internalformat,
     GLsizei width,
     GLsizei height);
-void yagl_host_glGetRenderbufferParameteriv(GLenum target,
+void yagl_host_glGetRenderbufferParameteriv(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum pname,
     GLint *param);
-void yagl_host_glRenderbufferStorageMultisample(GLenum target,
+void yagl_host_glRenderbufferStorageMultisample(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLsizei samples,
     GLenum internalformat,
     GLsizei width,
     GLsizei height);
-void yagl_host_glCreateProgram(GLuint program);
-void yagl_host_glCreateShader(GLuint shader,
+void yagl_host_glCreateProgram(struct yagl_thread_state *cur_ts,
+    GLuint program);
+void yagl_host_glCreateShader(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     GLenum type);
-void yagl_host_glShaderSource(GLuint shader,
+void yagl_host_glShaderSource(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     const GLchar *string, int32_t string_count);
-void yagl_host_glAttachShader(GLuint program,
+void yagl_host_glAttachShader(struct yagl_thread_state *cur_ts,
+    GLuint program,
+    GLuint shader);
+void yagl_host_glDetachShader(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint shader);
-void yagl_host_glDetachShader(GLuint program,
+void yagl_host_glCompileShader(struct yagl_thread_state *cur_ts,
     GLuint shader);
-void yagl_host_glCompileShader(GLuint shader);
-void yagl_host_glBindAttribLocation(GLuint program,
+void yagl_host_glBindAttribLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint index,
     const GLchar *name, int32_t name_count);
-void yagl_host_glGetActiveAttrib(GLuint program,
+void yagl_host_glGetActiveAttrib(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint index,
     GLint *size,
     GLenum *type,
     GLchar *name, int32_t name_maxcount, int32_t *name_count);
-void yagl_host_glGetActiveUniform(GLuint program,
+void yagl_host_glGetActiveUniform(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint index,
     GLint *size,
     GLenum *type,
     GLchar *name, int32_t name_maxcount, int32_t *name_count);
-int yagl_host_glGetAttribLocation(GLuint program,
+int yagl_host_glGetAttribLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *name, int32_t name_count);
-void yagl_host_glGetProgramiv(GLuint program,
+void yagl_host_glGetProgramiv(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLenum pname,
     GLint *param);
-GLboolean yagl_host_glGetProgramInfoLog(GLuint program,
+GLboolean yagl_host_glGetProgramInfoLog(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLchar *infolog, int32_t infolog_maxcount, int32_t *infolog_count);
-void yagl_host_glGetShaderiv(GLuint shader,
+void yagl_host_glGetShaderiv(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     GLenum pname,
     GLint *param);
-GLboolean yagl_host_glGetShaderInfoLog(GLuint shader,
+GLboolean yagl_host_glGetShaderInfoLog(struct yagl_thread_state *cur_ts,
+    GLuint shader,
     GLchar *infolog, int32_t infolog_maxcount, int32_t *infolog_count);
-void yagl_host_glGetUniformfv(GLboolean tl,
+void yagl_host_glGetUniformfv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     GLuint program,
     uint32_t location,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetUniformiv(GLboolean tl,
+void yagl_host_glGetUniformiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     GLuint program,
     uint32_t location,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-int yagl_host_glGetUniformLocation(GLuint program,
+int yagl_host_glGetUniformLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *name, int32_t name_count);
-void yagl_host_glGetVertexAttribfv(GLuint index,
+void yagl_host_glGetVertexAttribfv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetVertexAttribiv(GLuint index,
+void yagl_host_glGetVertexAttribiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glLinkProgram(GLuint program,
+void yagl_host_glLinkProgram(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glUniform1f(GLboolean tl,
+void yagl_host_glUniform1f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x);
-void yagl_host_glUniform1fv(GLboolean tl,
+void yagl_host_glUniform1fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count);
-void yagl_host_glUniform1i(GLboolean tl,
+void yagl_host_glUniform1i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x);
-void yagl_host_glUniform1iv(GLboolean tl,
+void yagl_host_glUniform1iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count);
-void yagl_host_glUniform2f(GLboolean tl,
+void yagl_host_glUniform2f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x,
     GLfloat y);
-void yagl_host_glUniform2fv(GLboolean tl,
+void yagl_host_glUniform2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count);
-void yagl_host_glUniform2i(GLboolean tl,
+void yagl_host_glUniform2i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x,
     GLint y);
-void yagl_host_glUniform2iv(GLboolean tl,
+void yagl_host_glUniform2iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count);
-void yagl_host_glUniform3f(GLboolean tl,
+void yagl_host_glUniform3f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x,
     GLfloat y,
     GLfloat z);
-void yagl_host_glUniform3fv(GLboolean tl,
+void yagl_host_glUniform3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count);
-void yagl_host_glUniform3i(GLboolean tl,
+void yagl_host_glUniform3i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x,
     GLint y,
     GLint z);
-void yagl_host_glUniform3iv(GLboolean tl,
+void yagl_host_glUniform3iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count);
-void yagl_host_glUniform4f(GLboolean tl,
+void yagl_host_glUniform4f(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLfloat x,
     GLfloat y,
     GLfloat z,
     GLfloat w);
-void yagl_host_glUniform4fv(GLboolean tl,
+void yagl_host_glUniform4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLfloat *v, int32_t v_count);
-void yagl_host_glUniform4i(GLboolean tl,
+void yagl_host_glUniform4i(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLint x,
     GLint y,
     GLint z,
     GLint w);
-void yagl_host_glUniform4iv(GLboolean tl,
+void yagl_host_glUniform4iv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLint *v, int32_t v_count);
-void yagl_host_glUniformMatrix2fv(GLboolean tl,
+void yagl_host_glUniformMatrix2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix3fv(GLboolean tl,
+void yagl_host_glUniformMatrix3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix4fv(GLboolean tl,
+void yagl_host_glUniformMatrix4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUseProgram(GLuint program);
-void yagl_host_glValidateProgram(GLuint program);
-void yagl_host_glVertexAttrib1f(GLuint indx,
+void yagl_host_glUseProgram(struct yagl_thread_state *cur_ts,
+    GLuint program);
+void yagl_host_glValidateProgram(struct yagl_thread_state *cur_ts,
+    GLuint program);
+void yagl_host_glVertexAttrib1f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x);
-void yagl_host_glVertexAttrib1fv(GLuint indx,
+void yagl_host_glVertexAttrib1fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count);
-void yagl_host_glVertexAttrib2f(GLuint indx,
+void yagl_host_glVertexAttrib2f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x,
     GLfloat y);
-void yagl_host_glVertexAttrib2fv(GLuint indx,
+void yagl_host_glVertexAttrib2fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count);
-void yagl_host_glVertexAttrib3f(GLuint indx,
+void yagl_host_glVertexAttrib3f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x,
     GLfloat y,
     GLfloat z);
-void yagl_host_glVertexAttrib3fv(GLuint indx,
+void yagl_host_glVertexAttrib3fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count);
-void yagl_host_glVertexAttrib4f(GLuint indx,
+void yagl_host_glVertexAttrib4f(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     GLfloat x,
     GLfloat y,
     GLfloat z,
     GLfloat w);
-void yagl_host_glVertexAttrib4fv(GLuint indx,
+void yagl_host_glVertexAttrib4fv(struct yagl_thread_state *cur_ts,
+    GLuint indx,
     const GLfloat *values, int32_t values_count);
-void yagl_host_glGetActiveUniformsiv(GLuint program,
+void yagl_host_glGetActiveUniformsiv(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLuint *uniformIndices, int32_t uniformIndices_count,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetUniformIndices(GLuint program,
+void yagl_host_glGetUniformIndices(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *uniformNames, int32_t uniformNames_count,
     GLuint *uniformIndices, int32_t uniformIndices_maxcount, int32_t *uniformIndices_count);
-GLuint yagl_host_glGetUniformBlockIndex(GLuint program,
+GLuint yagl_host_glGetUniformBlockIndex(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *uniformBlockName, int32_t uniformBlockName_count);
-void yagl_host_glUniformBlockBinding(GLuint program,
+void yagl_host_glUniformBlockBinding(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint uniformBlockIndex,
     GLuint uniformBlockBinding);
-void yagl_host_glGetActiveUniformBlockName(GLuint program,
+void yagl_host_glGetActiveUniformBlockName(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint uniformBlockIndex,
     GLchar *uniformBlockName, int32_t uniformBlockName_maxcount, int32_t *uniformBlockName_count);
-void yagl_host_glGetActiveUniformBlockiv(GLuint program,
+void yagl_host_glGetActiveUniformBlockiv(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLuint uniformBlockIndex,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetVertexAttribIiv(GLuint index,
+void yagl_host_glGetVertexAttribIiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetVertexAttribIuiv(GLuint index,
+void yagl_host_glGetVertexAttribIuiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLenum pname,
     GLuint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glVertexAttribI4i(GLuint index,
+void yagl_host_glVertexAttribI4i(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLint x,
     GLint y,
     GLint z,
     GLint w);
-void yagl_host_glVertexAttribI4ui(GLuint index,
+void yagl_host_glVertexAttribI4ui(struct yagl_thread_state *cur_ts,
+    GLuint index,
     GLuint x,
     GLuint y,
     GLuint z,
     GLuint w);
-void yagl_host_glVertexAttribI4iv(GLuint index,
+void yagl_host_glVertexAttribI4iv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     const GLint *v, int32_t v_count);
-void yagl_host_glVertexAttribI4uiv(GLuint index,
+void yagl_host_glVertexAttribI4uiv(struct yagl_thread_state *cur_ts,
+    GLuint index,
     const GLuint *v, int32_t v_count);
-void yagl_host_glGetUniformuiv(GLboolean tl,
+void yagl_host_glGetUniformuiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     GLuint program,
     uint32_t location,
     GLuint *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glUniform1ui(GLboolean tl,
+void yagl_host_glUniform1ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0);
-void yagl_host_glUniform2ui(GLboolean tl,
+void yagl_host_glUniform2ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0,
     GLuint v1);
-void yagl_host_glUniform3ui(GLboolean tl,
+void yagl_host_glUniform3ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0,
     GLuint v1,
     GLuint v2);
-void yagl_host_glUniform4ui(GLboolean tl,
+void yagl_host_glUniform4ui(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLuint v0,
     GLuint v1,
     GLuint v2,
     GLuint v3);
-void yagl_host_glUniform1uiv(GLboolean tl,
+void yagl_host_glUniform1uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count);
-void yagl_host_glUniform2uiv(GLboolean tl,
+void yagl_host_glUniform2uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count);
-void yagl_host_glUniform3uiv(GLboolean tl,
+void yagl_host_glUniform3uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count);
-void yagl_host_glUniform4uiv(GLboolean tl,
+void yagl_host_glUniform4uiv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     const GLuint *v, int32_t v_count);
-void yagl_host_glUniformMatrix2x3fv(GLboolean tl,
+void yagl_host_glUniformMatrix2x3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix2x4fv(GLboolean tl,
+void yagl_host_glUniformMatrix2x4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix3x2fv(GLboolean tl,
+void yagl_host_glUniformMatrix3x2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix3x4fv(GLboolean tl,
+void yagl_host_glUniformMatrix3x4fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix4x2fv(GLboolean tl,
+void yagl_host_glUniformMatrix4x2fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glUniformMatrix4x3fv(GLboolean tl,
+void yagl_host_glUniformMatrix4x3fv(struct yagl_thread_state *cur_ts,
+    GLboolean tl,
     uint32_t location,
     GLboolean transpose,
     const GLfloat *value, int32_t value_count);
-void yagl_host_glGetIntegerv(GLenum pname,
+void yagl_host_glGetIntegerv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLint *params, int32_t params_maxcount, int32_t *params_count);
-int yagl_host_glGetFragDataLocation(GLuint program,
+int yagl_host_glGetFragDataLocation(struct yagl_thread_state *cur_ts,
+    GLuint program,
     const GLchar *name, int32_t name_count);
-void yagl_host_glGetFloatv(GLenum pname,
+void yagl_host_glGetFloatv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glGetString(GLenum name,
+void yagl_host_glGetString(struct yagl_thread_state *cur_ts,
+    GLenum name,
     GLchar *str, int32_t str_maxcount, int32_t *str_count);
-GLboolean yagl_host_glIsEnabled(GLenum cap);
-void yagl_host_glGenTransformFeedbacks(const GLuint *ids, int32_t ids_count);
-void yagl_host_glBindTransformFeedback(GLenum target,
+GLboolean yagl_host_glIsEnabled(struct yagl_thread_state *cur_ts, GLenum cap);
+void yagl_host_glGenTransformFeedbacks(struct yagl_thread_state *cur_ts,
+    const GLuint *ids, int32_t ids_count);
+void yagl_host_glBindTransformFeedback(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint id);
-void yagl_host_glBeginTransformFeedback(GLenum primitiveMode);
-void yagl_host_glEndTransformFeedback(void);
-void yagl_host_glPauseTransformFeedback(void);
-void yagl_host_glResumeTransformFeedback(void);
-void yagl_host_glTransformFeedbackVaryings(GLuint program,
+void yagl_host_glBeginTransformFeedback(struct yagl_thread_state *cur_ts,
+    GLenum primitiveMode);
+void yagl_host_glEndTransformFeedback(struct yagl_thread_state *cur_ts);
+void yagl_host_glPauseTransformFeedback(struct yagl_thread_state *cur_ts);
+void yagl_host_glResumeTransformFeedback(struct yagl_thread_state *cur_ts);
+void yagl_host_glTransformFeedbackVaryings(struct yagl_thread_state *cur_ts,
+    struct yagl_transport *t,
+    GLuint program,
     const GLchar *varyings, int32_t varyings_count,
     GLenum bufferMode);
-void yagl_host_glGetTransformFeedbackVaryings(GLuint program,
+void yagl_host_glGetTransformFeedbackVaryings(struct yagl_thread_state *cur_ts,
+    GLuint program,
     GLsizei *sizes, int32_t sizes_maxcount, int32_t *sizes_count,
     GLenum *types, int32_t types_maxcount, int32_t *types_count);
-void yagl_host_glGenQueries(const GLuint *ids, int32_t ids_count);
-void yagl_host_glBeginQuery(GLenum target,
+void yagl_host_glGenQueries(struct yagl_thread_state *cur_ts,
+    const GLuint *ids, int32_t ids_count);
+void yagl_host_glBeginQuery(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLuint id);
-void yagl_host_glEndQuery(GLenum target);
-GLboolean yagl_host_glGetQueryObjectuiv(GLuint id,
+void yagl_host_glEndQuery(struct yagl_thread_state *cur_ts,
+    GLenum target);
+GLboolean yagl_host_glGetQueryObjectuiv(struct yagl_thread_state *cur_ts,
+    GLuint id,
     GLenum pname, GLuint *result);
-void yagl_host_glGenSamplers(const GLuint *samplers, int32_t samplers_count);
-void yagl_host_glBindSampler(GLuint unit,
+void yagl_host_glGenSamplers(struct yagl_thread_state *cur_ts,
+    const GLuint *samplers, int32_t samplers_count);
+void yagl_host_glBindSampler(struct yagl_thread_state *cur_ts,
+    GLuint unit,
     GLuint sampler);
-void yagl_host_glSamplerParameteri(GLuint sampler,
+void yagl_host_glSamplerParameteri(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     GLint param);
-void yagl_host_glSamplerParameteriv(GLuint sampler,
+void yagl_host_glSamplerParameteriv(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     const GLint *param, int32_t param_count);
-void yagl_host_glSamplerParameterf(GLuint sampler,
+void yagl_host_glSamplerParameterf(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     GLfloat param);
-void yagl_host_glSamplerParameterfv(GLuint sampler,
+void yagl_host_glSamplerParameterfv(struct yagl_thread_state *cur_ts,
+    GLuint sampler,
     GLenum pname,
     const GLfloat *param, int32_t param_count);
-void yagl_host_glDeleteObjects(const GLuint *objects, int32_t objects_count);
-void yagl_host_glBlendEquation(GLenum mode);
-void yagl_host_glBlendEquationSeparate(GLenum modeRGB,
+void yagl_host_glDeleteObjects(struct yagl_thread_state *cur_ts,
+    const GLuint *objects, int32_t objects_count);
+void yagl_host_glBlendEquation(struct yagl_thread_state *cur_ts,
+    GLenum mode);
+void yagl_host_glBlendEquationSeparate(struct yagl_thread_state *cur_ts,
+    GLenum modeRGB,
     GLenum modeAlpha);
-void yagl_host_glBlendFunc(GLenum sfactor,
+void yagl_host_glBlendFunc(struct yagl_thread_state *cur_ts,
+    GLenum sfactor,
     GLenum dfactor);
-void yagl_host_glBlendFuncSeparate(GLenum srcRGB,
+void yagl_host_glBlendFuncSeparate(struct yagl_thread_state *cur_ts,
+    GLenum srcRGB,
     GLenum dstRGB,
     GLenum srcAlpha,
     GLenum dstAlpha);
-void yagl_host_glBlendColor(GLclampf red,
+void yagl_host_glBlendColor(struct yagl_thread_state *cur_ts,
+    GLclampf red,
     GLclampf green,
     GLclampf blue,
     GLclampf alpha);
-void yagl_host_glClear(GLbitfield mask);
-void yagl_host_glClearColor(GLclampf red,
+void yagl_host_glClear(struct yagl_thread_state *cur_ts,
+    GLbitfield mask);
+void yagl_host_glClearColor(struct yagl_thread_state *cur_ts,
+    GLclampf red,
     GLclampf green,
     GLclampf blue,
     GLclampf alpha);
-void yagl_host_glClearDepthf(GLclampf depth);
-void yagl_host_glClearStencil(GLint s);
-void yagl_host_glColorMask(GLboolean red,
+void yagl_host_glClearDepthf(struct yagl_thread_state *cur_ts,
+    GLclampf depth);
+void yagl_host_glClearStencil(struct yagl_thread_state *cur_ts,
+    GLint s);
+void yagl_host_glColorMask(struct yagl_thread_state *cur_ts,
+    GLboolean red,
     GLboolean green,
     GLboolean blue,
     GLboolean alpha);
-void yagl_host_glCullFace(GLenum mode);
-void yagl_host_glDepthFunc(GLenum func);
-void yagl_host_glDepthMask(GLboolean flag);
-void yagl_host_glDepthRangef(GLclampf zNear,
+void yagl_host_glCullFace(struct yagl_thread_state *cur_ts,
+    GLenum mode);
+void yagl_host_glDepthFunc(struct yagl_thread_state *cur_ts,
+    GLenum func);
+void yagl_host_glDepthMask(struct yagl_thread_state *cur_ts,
+    GLboolean flag);
+void yagl_host_glDepthRangef(struct yagl_thread_state *cur_ts,
+    GLclampf zNear,
     GLclampf zFar);
-void yagl_host_glEnable(GLenum cap);
-void yagl_host_glDisable(GLenum cap);
-void yagl_host_glFlush(void);
-void yagl_host_glFrontFace(GLenum mode);
-void yagl_host_glGenerateMipmap(GLenum target);
-void yagl_host_glHint(GLenum target,
+void yagl_host_glEnable(struct yagl_thread_state *cur_ts,
+    GLenum cap);
+void yagl_host_glDisable(struct yagl_thread_state *cur_ts,
+    GLenum cap);
+void yagl_host_glFlush(struct yagl_thread_state *cur_ts);
+void yagl_host_glFrontFace(struct yagl_thread_state *cur_ts,
+    GLenum mode);
+void yagl_host_glGenerateMipmap(struct yagl_thread_state *cur_ts,
+    GLenum target);
+void yagl_host_glHint(struct yagl_thread_state *cur_ts,
+    GLenum target,
     GLenum mode);
-void yagl_host_glLineWidth(GLfloat width);
-void yagl_host_glPixelStorei(GLenum pname,
+void yagl_host_glLineWidth(struct yagl_thread_state *cur_ts,
+    GLfloat width);
+void yagl_host_glPixelStorei(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLint param);
-void yagl_host_glPolygonOffset(GLfloat factor,
+void yagl_host_glPolygonOffset(struct yagl_thread_state *cur_ts,
+    GLfloat factor,
     GLfloat units);
-void yagl_host_glScissor(GLint x,
+void yagl_host_glScissor(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height);
-void yagl_host_glStencilFunc(GLenum func,
+void yagl_host_glStencilFunc(struct yagl_thread_state *cur_ts,
+    GLenum func,
     GLint ref,
     GLuint mask);
-void yagl_host_glStencilMask(GLuint mask);
-void yagl_host_glStencilOp(GLenum fail,
+void yagl_host_glStencilMask(struct yagl_thread_state *cur_ts,
+    GLuint mask);
+void yagl_host_glStencilOp(struct yagl_thread_state *cur_ts,
+    GLenum fail,
     GLenum zfail,
     GLenum zpass);
-void yagl_host_glSampleCoverage(GLclampf value,
+void yagl_host_glSampleCoverage(struct yagl_thread_state *cur_ts,
+    GLclampf value,
     GLboolean invert);
-void yagl_host_glViewport(GLint x,
+void yagl_host_glViewport(struct yagl_thread_state *cur_ts,
+    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height);
-void yagl_host_glStencilFuncSeparate(GLenum face,
+void yagl_host_glStencilFuncSeparate(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum func,
     GLint ref,
     GLuint mask);
-void yagl_host_glStencilMaskSeparate(GLenum face,
+void yagl_host_glStencilMaskSeparate(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLuint mask);
-void yagl_host_glStencilOpSeparate(GLenum face,
+void yagl_host_glStencilOpSeparate(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum fail,
     GLenum zfail,
     GLenum zpass);
-void yagl_host_glPointSize(GLfloat size);
-void yagl_host_glAlphaFunc(GLenum func,
+void yagl_host_glPointSize(struct yagl_thread_state *cur_ts,
+    GLfloat size);
+void yagl_host_glAlphaFunc(struct yagl_thread_state *cur_ts,
+    GLenum func,
     GLclampf ref);
-void yagl_host_glMatrixMode(GLenum mode);
-void yagl_host_glLoadIdentity(void);
-void yagl_host_glPopMatrix(void);
-void yagl_host_glPushMatrix(void);
-void yagl_host_glRotatef(GLfloat angle,
+void yagl_host_glMatrixMode(struct yagl_thread_state *cur_ts,
+    GLenum mode);
+void yagl_host_glLoadIdentity(struct yagl_thread_state *cur_ts);
+void yagl_host_glPopMatrix(struct yagl_thread_state *cur_ts);
+void yagl_host_glPushMatrix(struct yagl_thread_state *cur_ts);
+void yagl_host_glRotatef(struct yagl_thread_state *cur_ts,
+    GLfloat angle,
     GLfloat x,
     GLfloat y,
     GLfloat z);
-void yagl_host_glTranslatef(GLfloat x,
+void yagl_host_glTranslatef(struct yagl_thread_state *cur_ts,
+    GLfloat x,
     GLfloat y,
     GLfloat z);
-void yagl_host_glScalef(GLfloat x,
+void yagl_host_glScalef(struct yagl_thread_state *cur_ts,
+    GLfloat x,
     GLfloat y,
     GLfloat z);
-void yagl_host_glOrthof(GLfloat left,
+void yagl_host_glOrthof(struct yagl_thread_state *cur_ts,
+    GLfloat left,
     GLfloat right,
     GLfloat bottom,
     GLfloat top,
     GLfloat zNear,
     GLfloat zFar);
-void yagl_host_glColor4f(GLfloat red,
+void yagl_host_glColor4f(struct yagl_thread_state *cur_ts,
+    GLfloat red,
     GLfloat green,
     GLfloat blue,
     GLfloat alpha);
-void yagl_host_glColor4ub(GLubyte red,
+void yagl_host_glColor4ub(struct yagl_thread_state *cur_ts,
+    GLubyte red,
     GLubyte green,
     GLubyte blue,
     GLubyte alpha);
-void yagl_host_glNormal3f(GLfloat nx,
+void yagl_host_glNormal3f(struct yagl_thread_state *cur_ts,
+    GLfloat nx,
     GLfloat ny,
     GLfloat nz);
-void yagl_host_glPointParameterf(GLenum pname,
+void yagl_host_glPointParameterf(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat param);
-void yagl_host_glPointParameterfv(GLenum pname,
+void yagl_host_glPointParameterfv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glFogf(GLenum pname,
+void yagl_host_glFogf(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat param);
-void yagl_host_glFogfv(GLenum pname,
+void yagl_host_glFogfv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glFrustumf(GLfloat left,
+void yagl_host_glFrustumf(struct yagl_thread_state *cur_ts,
+    GLfloat left,
     GLfloat right,
     GLfloat bottom,
     GLfloat top,
     GLfloat zNear,
     GLfloat zFar);
-void yagl_host_glLightf(GLenum light,
+void yagl_host_glLightf(struct yagl_thread_state *cur_ts,
+    GLenum light,
     GLenum pname,
     GLfloat param);
-void yagl_host_glLightfv(GLenum light,
+void yagl_host_glLightfv(struct yagl_thread_state *cur_ts,
+    GLenum light,
     GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glGetLightfv(GLenum light,
+void yagl_host_glGetLightfv(struct yagl_thread_state *cur_ts,
+    GLenum light,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glLightModelf(GLenum pname,
+void yagl_host_glLightModelf(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat param);
-void yagl_host_glLightModelfv(GLenum pname,
+void yagl_host_glLightModelfv(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glMaterialf(GLenum face,
+void yagl_host_glMaterialf(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum pname,
     GLfloat param);
-void yagl_host_glMaterialfv(GLenum face,
+void yagl_host_glMaterialfv(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum pname,
     const GLfloat *params, int32_t params_count);
-void yagl_host_glGetMaterialfv(GLenum face,
+void yagl_host_glGetMaterialfv(struct yagl_thread_state *cur_ts,
+    GLenum face,
     GLenum pname,
     GLfloat *params, int32_t params_maxcount, int32_t *params_count);
-void yagl_host_glShadeModel(GLenum mode);
-void yagl_host_glLogicOp(GLenum opcode);
-void yagl_host_glMultMatrixf(const GLfloat *m, int32_t m_count);
-void yagl_host_glLoadMatrixf(const GLfloat *m, int32_t m_count);
-void yagl_host_glClipPlanef(GLenum plane,
+void yagl_host_glShadeModel(struct yagl_thread_state *cur_ts,
+    GLenum mode);
+void yagl_host_glLogicOp(struct yagl_thread_state *cur_ts,
+    GLenum opcode);
+void yagl_host_glMultMatrixf(struct yagl_thread_state *cur_ts,
+    const GLfloat *m, int32_t m_count);
+void yagl_host_glLoadMatrixf(struct yagl_thread_state *cur_ts,
+    const GLfloat *m, int32_t m_count);
+void yagl_host_glClipPlanef(struct yagl_thread_state *cur_ts,
+    GLenum plane,
     const GLfloat *equation, int32_t equation_count);
-void yagl_host_glGetClipPlanef(GLenum pname,
+void yagl_host_glGetClipPlanef(struct yagl_thread_state *cur_ts,
+    GLenum pname,
     GLfloat *eqn, int32_t eqn_maxcount, int32_t *eqn_count);
-void yagl_host_glUpdateOffscreenImageYAGL(GLuint texture,
+void yagl_host_glUpdateOffscreenImageYAGL(struct yagl_thread_state *cur_ts,
+    GLuint texture,
     uint32_t width,
     uint32_t height,
     uint32_t bpp,
     const void *pixels, int32_t pixels_count);
-void yagl_host_glGenUniformLocationYAGL(uint32_t location,
+void yagl_host_glGenUniformLocationYAGL(struct yagl_thread_state *cur_ts,
+    uint32_t location,
     GLuint program,
     const GLchar *name, int32_t name_count);
-void yagl_host_glDeleteUniformLocationsYAGL(const uint32_t *locations, int32_t locations_count);
+void yagl_host_glDeleteUniformLocationsYAGL(struct yagl_thread_state *cur_ts,
+    const uint32_t *locations, int32_t locations_count);
 
 #endif
index 8645ba1..b4d4260 100644 (file)
 #include "yagl_thread.h"
 #include "yagl_gles_driver.h"
 
+// TODO remove and pass via argument
 YAGL_DEFINE_TLS(struct yagl_egl_offscreen_ts*, egl_offscreen_ts);
 
-static void yagl_egl_offscreen_thread_init(struct yagl_egl_backend *backend)
+static void yagl_egl_offscreen_thread_init(struct yagl_thread_state *cur_ts,
+                                           struct yagl_egl_backend *backend)
 {
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_thread_init, NULL);
 
@@ -51,7 +53,8 @@ static void yagl_egl_offscreen_thread_init(struct yagl_egl_backend *backend)
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_egl_offscreen_batch_start(struct yagl_egl_backend *backend)
+static void yagl_egl_offscreen_batch_start(struct yagl_thread_state *cur_ts,
+                                           struct yagl_egl_backend *backend)
 {
     struct yagl_egl_offscreen *egl_offscreen = (struct yagl_egl_offscreen*)backend;
 
@@ -68,7 +71,8 @@ static void yagl_egl_offscreen_batch_start(struct yagl_egl_backend *backend)
                                             egl_offscreen_ts->ctx->native_ctx);
 }
 
-static void yagl_egl_offscreen_batch_end(struct yagl_egl_backend *backend)
+static void yagl_egl_offscreen_batch_end(struct yagl_thread_state *cur_ts,
+                                         struct yagl_egl_backend *backend)
 {
     struct yagl_egl_offscreen *egl_offscreen = (struct yagl_egl_offscreen*)backend;
 
@@ -92,7 +96,8 @@ static struct yagl_eglb_display *yagl_egl_offscreen_create_display(struct yagl_e
     return dpy ? &dpy->base : NULL;
 }
 
-static bool yagl_egl_offscreen_make_current(struct yagl_egl_backend *backend,
+static bool yagl_egl_offscreen_make_current(struct yagl_thread_state *cur_ts,
+                                            struct yagl_egl_backend *backend,
                                             struct yagl_eglb_display *dpy,
                                             struct yagl_eglb_context *ctx,
                                             struct yagl_eglb_surface *draw,
@@ -137,7 +142,9 @@ static bool yagl_egl_offscreen_make_current(struct yagl_egl_backend *backend,
     return res;
 }
 
-static bool yagl_egl_offscreen_release_current(struct yagl_egl_backend *backend, bool force)
+static bool yagl_egl_offscreen_release_current(struct yagl_thread_state *cur_ts,
+                                               struct yagl_egl_backend *backend,
+                                               bool force)
 {
     struct yagl_egl_offscreen *egl_offscreen = (struct yagl_egl_offscreen*)backend;
     bool res;
@@ -170,7 +177,8 @@ static bool yagl_egl_offscreen_release_current(struct yagl_egl_backend *backend,
     return res || force;
 }
 
-static void yagl_egl_offscreen_thread_fini(struct yagl_egl_backend *backend)
+static void yagl_egl_offscreen_thread_fini(struct yagl_thread_state *cur_ts,
+                                           struct yagl_egl_backend *backend)
 {
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_thread_fini, NULL);
 
@@ -213,6 +221,7 @@ static void yagl_egl_offscreen_unensure_current(struct yagl_egl_backend *backend
 static void yagl_egl_offscreen_destroy(struct yagl_egl_backend *backend)
 {
     struct yagl_egl_offscreen *egl_offscreen = (struct yagl_egl_offscreen*)backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_destroy, NULL);
 
@@ -253,6 +262,7 @@ struct yagl_egl_backend *yagl_egl_offscreen_create(struct yagl_egl_driver *egl_d
     EGLSurface sfc = EGL_NO_SURFACE;
     EGLContext ctx = EGL_NO_CONTEXT;
     EGLContext global_ctx = EGL_NO_CONTEXT;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_create, NULL);
 
index e60f832..1da33c2 100644 (file)
@@ -46,13 +46,14 @@ static void yagl_egl_offscreen_context_destroy(struct yagl_eglb_context *ctx)
         (struct yagl_egl_offscreen_display*)ctx->dpy;
     struct yagl_egl_offscreen *egl_offscreen =
         (struct yagl_egl_offscreen*)ctx->dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_context_destroy, NULL);
 
     if (egl_offscreen_ctx->rp_pbo) {
-        yagl_ensure_ctx(0);
+        yagl_ensure_ctx(ctx->ps, 0);
         egl_offscreen->gles_driver->DeleteBuffers(1, &egl_offscreen_ctx->rp_pbo);
-        yagl_unensure_ctx(0);
+        yagl_unensure_ctx(ctx->ps, 0);
     }
 
     egl_offscreen->egl_driver->context_destroy(egl_offscreen->egl_driver,
@@ -67,7 +68,8 @@ static void yagl_egl_offscreen_context_destroy(struct yagl_eglb_context *ctx)
 }
 
 struct yagl_egl_offscreen_context
-    *yagl_egl_offscreen_context_create(struct yagl_egl_offscreen_display *dpy,
+    *yagl_egl_offscreen_context_create(struct yagl_thread_state *cur_ts,
+                                       struct yagl_egl_offscreen_display *dpy,
                                        const struct yagl_egl_native_config *cfg,
                                        struct yagl_egl_offscreen_context *share_context,
                                        int version)
@@ -100,6 +102,7 @@ struct yagl_egl_offscreen_context
     yagl_eglb_context_init(&ctx->base, &dpy->base);
 
     ctx->base.destroy = &yagl_egl_offscreen_context_destroy;
+    ctx->base.ps = cur_ts->ps;
 
     ctx->native_ctx = native_ctx;
 
@@ -108,7 +111,8 @@ struct yagl_egl_offscreen_context
     return ctx;
 }
 
-bool yagl_egl_offscreen_context_read_pixels(struct yagl_egl_offscreen_context *ctx,
+bool yagl_egl_offscreen_context_read_pixels(struct yagl_thread_state *cur_ts,
+                                            struct yagl_egl_offscreen_context *ctx,
                                             uint32_t width,
                                             uint32_t height,
                                             uint32_t bpp,
index 647c271..40d536d 100644 (file)
@@ -49,12 +49,14 @@ struct yagl_egl_offscreen_context
 };
 
 struct yagl_egl_offscreen_context
-    *yagl_egl_offscreen_context_create(struct yagl_egl_offscreen_display *dpy,
+    *yagl_egl_offscreen_context_create(struct yagl_thread_state *cur_ts,
+                                       struct yagl_egl_offscreen_display *dpy,
                                        const struct yagl_egl_native_config *cfg,
                                        struct yagl_egl_offscreen_context *share_context,
                                        int version);
 
-bool yagl_egl_offscreen_context_read_pixels(struct yagl_egl_offscreen_context *ctx,
+bool yagl_egl_offscreen_context_read_pixels(struct yagl_thread_state *cur_ts,
+                                            struct yagl_egl_offscreen_context *ctx,
                                             uint32_t width,
                                             uint32_t height,
                                             uint32_t bpp,
index 0a1f62f..9f2f8de 100644 (file)
@@ -50,12 +50,13 @@ struct yagl_egl_offscreen_image
 static void yagl_egl_offscreen_image_destroy(struct yagl_object *obj)
 {
     struct yagl_egl_offscreen_image *image = (struct yagl_egl_offscreen_image*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_image_destroy, "%u", obj->global_name);
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(obj->ps, 0);
     image->driver->DeleteTextures(1, &obj->global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(obj->ps, 0);
 
     g_free(image);
 
@@ -71,6 +72,7 @@ static struct yagl_egl_native_config
     struct yagl_egl_offscreen *egl_offscreen =
         (struct yagl_egl_offscreen*)dpy->backend;
     struct yagl_egl_native_config *native_configs;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_display_config_enum,
                         "dpy = %p", dpy);
@@ -92,6 +94,7 @@ static void yagl_egl_offscreen_display_config_cleanup(struct yagl_eglb_display *
         (struct yagl_egl_offscreen_display*)dpy;
     struct yagl_egl_offscreen *egl_offscreen =
         (struct yagl_egl_offscreen*)dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_display_config_cleanup,
                         "dpy = %p, cfg = %d",
@@ -106,7 +109,8 @@ static void yagl_egl_offscreen_display_config_cleanup(struct yagl_eglb_display *
 }
 
 static struct yagl_eglb_context
-    *yagl_egl_offscreen_display_create_context(struct yagl_eglb_display *dpy,
+    *yagl_egl_offscreen_display_create_context(struct yagl_thread_state *cur_ts,
+                                               struct yagl_eglb_display *dpy,
                                                const struct yagl_egl_native_config *cfg,
                                                struct yagl_eglb_context *share_context,
                                                int version)
@@ -114,7 +118,8 @@ static struct yagl_eglb_context
     struct yagl_egl_offscreen_display *egl_offscreen_dpy =
         (struct yagl_egl_offscreen_display*)dpy;
     struct yagl_egl_offscreen_context *ctx =
-        yagl_egl_offscreen_context_create(egl_offscreen_dpy,
+        yagl_egl_offscreen_context_create(cur_ts,
+                                          egl_offscreen_dpy,
                                           cfg,
                                           (struct yagl_egl_offscreen_context*)share_context,
                                           version);
@@ -123,7 +128,8 @@ static struct yagl_eglb_context
 }
 
 static struct yagl_eglb_surface
-    *yagl_egl_offscreen_display_create_surface(struct yagl_eglb_display *dpy,
+    *yagl_egl_offscreen_display_create_surface(struct yagl_thread_state *cur_ts,
+                                               struct yagl_eglb_display *dpy,
                                                const struct yagl_egl_native_config *cfg,
                                                EGLenum type,
                                                const void *attribs,
@@ -135,7 +141,8 @@ static struct yagl_eglb_surface
     struct yagl_egl_offscreen_display *egl_offscreen_dpy =
         (struct yagl_egl_offscreen_display*)dpy;
     struct yagl_egl_offscreen_surface *sfc =
-        yagl_egl_offscreen_surface_create(egl_offscreen_dpy,
+        yagl_egl_offscreen_surface_create(cur_ts,
+                                          egl_offscreen_dpy,
                                           cfg,
                                           type,
                                           attribs,
@@ -147,7 +154,8 @@ static struct yagl_eglb_surface
     return sfc ? &sfc->base : NULL;
 }
 
-static struct yagl_object *yagl_egl_offscreen_display_create_image(struct yagl_eglb_display *dpy,
+static struct yagl_object *yagl_egl_offscreen_display_create_image(struct yagl_thread_state *cur_ts,
+                                                                   struct yagl_eglb_display *dpy,
                                                                    yagl_winsys_id buffer)
 {
     struct yagl_egl_offscreen *egl_offscreen =
@@ -156,10 +164,11 @@ static struct yagl_object *yagl_egl_offscreen_display_create_image(struct yagl_e
 
     image = g_malloc(sizeof(*image));
 
-    yagl_ensure_ctx(0);
+    yagl_ensure_ctx(cur_ts->ps, 0);
     egl_offscreen->gles_driver->GenTextures(1, &image->base.global_name);
-    yagl_unensure_ctx(0);
+    yagl_unensure_ctx(cur_ts->ps, 0);
     image->base.destroy = &yagl_egl_offscreen_image_destroy;
+    image->base.ps = cur_ts->ps;
     image->driver = egl_offscreen->gles_driver;
 
     return &image->base;
@@ -171,6 +180,7 @@ static void yagl_egl_offscreen_display_destroy(struct yagl_eglb_display *dpy)
         (struct yagl_egl_offscreen_display*)dpy;
     struct yagl_egl_offscreen *egl_offscreen =
         (struct yagl_egl_offscreen*)dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_display_destroy,
                         "dpy = %p", dpy);
@@ -190,6 +200,7 @@ struct yagl_egl_offscreen_display
 {
     struct yagl_egl_offscreen_display *dpy;
     EGLNativeDisplayType native_dpy;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_display_create, NULL);
 
index 3351f22..1d7a16c 100644 (file)
@@ -40,6 +40,7 @@
 #include "yagl_thread.h"
 #include "yagl_compiled_transfer.h"
 
+// TODO remove and pass via argument
 YAGL_DECLARE_TLS(struct yagl_egl_offscreen_ts*, egl_offscreen_ts);
 
 static void yagl_egl_offscreen_surface_cleanup(struct yagl_egl_offscreen_surface *sfc)
@@ -48,6 +49,7 @@ static void yagl_egl_offscreen_surface_cleanup(struct yagl_egl_offscreen_surface
         (struct yagl_egl_offscreen_display*)sfc->base.dpy;
     struct yagl_egl_offscreen *egl_offscreen =
         (struct yagl_egl_offscreen*)sfc->base.dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_surface_cleanup, NULL);
 
@@ -67,12 +69,14 @@ static void yagl_egl_offscreen_surface_cleanup(struct yagl_egl_offscreen_surface
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_egl_offscreen_surface_invalidate(struct yagl_eglb_surface *sfc,
+static void yagl_egl_offscreen_surface_invalidate(struct yagl_thread_state *cur_ts,
+                                                  struct yagl_eglb_surface *sfc,
                                                   yagl_winsys_id id)
 {
 }
 
-static void yagl_egl_offscreen_surface_replace(struct yagl_eglb_surface *sfc,
+static void yagl_egl_offscreen_surface_replace(struct yagl_thread_state *cur_ts,
+                                               struct yagl_eglb_surface *sfc,
                                                struct yagl_eglb_surface *with)
 {
     struct yagl_egl_offscreen_surface *osfc =
@@ -95,7 +99,8 @@ static void yagl_egl_offscreen_surface_replace(struct yagl_eglb_surface *sfc,
     g_free(owith);
 }
 
-static bool yagl_egl_offscreen_surface_query(struct yagl_eglb_surface *sfc,
+static bool yagl_egl_offscreen_surface_query(struct yagl_thread_state *cur_ts,
+                                             struct yagl_eglb_surface *sfc,
                                              EGLint attribute,
                                              EGLint *value)
 {
@@ -116,17 +121,19 @@ static bool yagl_egl_offscreen_surface_query(struct yagl_eglb_surface *sfc,
     return true;
 }
 
-static void yagl_egl_offscreen_surface_swap_buffers(struct yagl_eglb_surface *sfc)
+static void yagl_egl_offscreen_surface_swap_buffers(struct yagl_thread_state *cur_ts,
+                                                    struct yagl_eglb_surface *sfc)
 {
     struct yagl_egl_offscreen_surface *osfc =
         (struct yagl_egl_offscreen_surface*)sfc;
-    struct yagl_egl_offscreen_context *octx = egl_offscreen_ts->ctx;
+    struct yagl_egl_offscreen_context *octx = egl_offscreen_ts->ctx; // TODO get from cur_ts
 
     YAGL_LOG_FUNC_SET(yagl_egl_offscreen_surface_swap_buffers);
 
     assert(octx);
 
-    if (!yagl_egl_offscreen_context_read_pixels(octx,
+    if (!yagl_egl_offscreen_context_read_pixels(cur_ts,
+                                                octx,
                                                 osfc->width,
                                                 osfc->height,
                                                 osfc->bpp,
@@ -140,17 +147,19 @@ static void yagl_egl_offscreen_surface_swap_buffers(struct yagl_eglb_surface *sf
     yagl_compiled_transfer_exec(osfc->bimage_ct, osfc->host_pixels);
 }
 
-static void yagl_egl_offscreen_surface_copy_buffers(struct yagl_eglb_surface *sfc)
+static void yagl_egl_offscreen_surface_copy_buffers(struct yagl_thread_state *cur_ts,
+                                                    struct yagl_eglb_surface *sfc)
 {
     struct yagl_egl_offscreen_surface *osfc =
         (struct yagl_egl_offscreen_surface*)sfc;
-    struct yagl_egl_offscreen_context *octx = egl_offscreen_ts->ctx;
+    struct yagl_egl_offscreen_context *octx = egl_offscreen_ts->ctx; // TODO get from cur_ts
 
     YAGL_LOG_FUNC_SET(yagl_egl_offscreen_surface_copy_buffers);
 
     assert(octx);
 
-    if (!yagl_egl_offscreen_context_read_pixels(octx,
+    if (!yagl_egl_offscreen_context_read_pixels(cur_ts,
+                                                octx,
                                                 osfc->width,
                                                 osfc->height,
                                                 osfc->bpp,
@@ -164,7 +173,8 @@ static void yagl_egl_offscreen_surface_copy_buffers(struct yagl_eglb_surface *sf
     yagl_compiled_transfer_exec(osfc->bimage_ct, osfc->host_pixels);
 }
 
-static void yagl_egl_offscreen_surface_wait_gl(struct yagl_eglb_surface *sfc)
+static void yagl_egl_offscreen_surface_wait_gl(struct yagl_thread_state *cur_ts,
+                                               struct yagl_eglb_surface *sfc)
 {
 }
 
@@ -172,6 +182,7 @@ static void yagl_egl_offscreen_surface_destroy(struct yagl_eglb_surface *sfc)
 {
     struct yagl_egl_offscreen_surface *egl_offscreen_sfc =
         (struct yagl_egl_offscreen_surface*)sfc;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_surface_destroy, NULL);
 
@@ -185,7 +196,8 @@ static void yagl_egl_offscreen_surface_destroy(struct yagl_eglb_surface *sfc)
 }
 
 struct yagl_egl_offscreen_surface
-    *yagl_egl_offscreen_surface_create(struct yagl_egl_offscreen_display *dpy,
+    *yagl_egl_offscreen_surface_create(struct yagl_thread_state *cur_ts,
+                                       struct yagl_egl_offscreen_display *dpy,
                                        const struct yagl_egl_native_config *cfg,
                                        EGLenum type,
                                        const void *attribs,
@@ -224,7 +236,8 @@ struct yagl_egl_offscreen_surface
         return NULL;
     }
 
-    bimage_ct = yagl_compiled_transfer_create(pixels,
+    bimage_ct = yagl_compiled_transfer_create(cur_ts,
+                                              pixels,
                                               (width * height * bpp),
                                               true);
 
@@ -265,6 +278,7 @@ struct yagl_egl_offscreen_surface
     sfc->base.copy_buffers = &yagl_egl_offscreen_surface_copy_buffers;
     sfc->base.wait_gl = &yagl_egl_offscreen_surface_wait_gl;
     sfc->base.destroy = &yagl_egl_offscreen_surface_destroy;
+    sfc->base.ps = cur_ts->ps;
 
     YAGL_LOG_FUNC_EXIT(NULL);
 
index 789b56c..ef3115f 100644 (file)
@@ -69,7 +69,8 @@ struct yagl_egl_offscreen_surface
 };
 
 struct yagl_egl_offscreen_surface
-    *yagl_egl_offscreen_surface_create(struct yagl_egl_offscreen_display *dpy,
+    *yagl_egl_offscreen_surface_create(struct yagl_thread_state *cur_ts,
+                                       struct yagl_egl_offscreen_display *dpy,
                                        const struct yagl_egl_native_config *cfg,
                                        EGLenum type,
                                        const void *attribs,
index 958e807..31b8161 100644 (file)
@@ -40,6 +40,7 @@
 #include "yagl_gles_driver.h"
 #include "hw/vigs/winsys_gl.h"
 
+// TODO remove and pass via argument
 YAGL_DEFINE_TLS(struct yagl_egl_onscreen_ts*, egl_onscreen_ts);
 
 static void yagl_egl_onscreen_setup_framebuffer_zero(struct yagl_egl_onscreen *egl_onscreen)
@@ -69,7 +70,8 @@ static void yagl_egl_onscreen_setup_framebuffer_zero(struct yagl_egl_onscreen *e
                                                cur_fb);
 }
 
-static void yagl_egl_onscreen_thread_init(struct yagl_egl_backend *backend)
+static void yagl_egl_onscreen_thread_init(struct yagl_thread_state *cur_ts,
+                                          struct yagl_egl_backend *backend)
 {
     struct yagl_egl_onscreen *egl_onscreen = (struct yagl_egl_onscreen*)backend;
 
@@ -82,7 +84,8 @@ static void yagl_egl_onscreen_thread_init(struct yagl_egl_backend *backend)
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static void yagl_egl_onscreen_batch_start(struct yagl_egl_backend *backend)
+static void yagl_egl_onscreen_batch_start(struct yagl_thread_state *cur_ts,
+                                          struct yagl_egl_backend *backend)
 {
     struct yagl_egl_onscreen *egl_onscreen = (struct yagl_egl_onscreen*)backend;
 
@@ -107,7 +110,8 @@ static void yagl_egl_onscreen_batch_start(struct yagl_egl_backend *backend)
     }
 }
 
-static void yagl_egl_onscreen_batch_end(struct yagl_egl_backend *backend)
+static void yagl_egl_onscreen_batch_end(struct yagl_thread_state *cur_ts,
+                                        struct yagl_egl_backend *backend)
 {
     struct yagl_egl_onscreen *egl_onscreen = (struct yagl_egl_onscreen*)backend;
 
@@ -131,7 +135,8 @@ static struct yagl_eglb_display *yagl_egl_onscreen_create_display(struct yagl_eg
     return dpy ? &dpy->base : NULL;
 }
 
-static bool yagl_egl_onscreen_make_current(struct yagl_egl_backend *backend,
+static bool yagl_egl_onscreen_make_current(struct yagl_thread_state *cur_ts,
+                                           struct yagl_egl_backend *backend,
                                            struct yagl_eglb_display *dpy,
                                            struct yagl_eglb_context *ctx,
                                            struct yagl_eglb_surface *draw,
@@ -219,7 +224,9 @@ static bool yagl_egl_onscreen_make_current(struct yagl_egl_backend *backend,
     return res;
 }
 
-static bool yagl_egl_onscreen_release_current(struct yagl_egl_backend *backend, bool force)
+static bool yagl_egl_onscreen_release_current(struct yagl_thread_state *cur_ts,
+                                              struct yagl_egl_backend *backend,
+                                              bool force)
 {
     struct yagl_egl_onscreen *egl_onscreen = (struct yagl_egl_onscreen*)backend;
     bool res;
@@ -252,7 +259,8 @@ static bool yagl_egl_onscreen_release_current(struct yagl_egl_backend *backend,
     return res || force;
 }
 
-static void yagl_egl_onscreen_thread_fini(struct yagl_egl_backend *backend)
+static void yagl_egl_onscreen_thread_fini(struct yagl_thread_state *cur_ts,
+                                          struct yagl_egl_backend *backend)
 {
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_thread_fini, NULL);
 
@@ -303,6 +311,7 @@ static void yagl_egl_onscreen_unensure_current(struct yagl_egl_backend *backend)
 static void yagl_egl_onscreen_destroy(struct yagl_egl_backend *backend)
 {
     struct yagl_egl_onscreen *egl_onscreen = (struct yagl_egl_onscreen*)backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_destroy, NULL);
 
@@ -345,6 +354,7 @@ struct yagl_egl_backend *yagl_egl_onscreen_create(struct winsys_interface *wsi,
     EGLContext ctx = EGL_NO_CONTEXT;
     EGLContext global_ctx = EGL_NO_CONTEXT;
     struct winsys_gl_info *ws_info = (struct winsys_gl_info*)wsi->ws_info;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_create, NULL);
 
index 018ea61..899f3ec 100644 (file)
@@ -46,13 +46,14 @@ static void yagl_egl_onscreen_context_destroy(struct yagl_eglb_context *ctx)
         (struct yagl_egl_onscreen_display*)ctx->dpy;
     struct yagl_egl_onscreen *egl_onscreen =
         (struct yagl_egl_onscreen*)ctx->dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_context_destroy, NULL);
 
     if (egl_onscreen_ctx->fb) {
-        yagl_ensure_ctx(egl_onscreen_ctx->fb_ctx_id);
+        yagl_ensure_ctx(ctx->ps, egl_onscreen_ctx->fb_ctx_id);
         egl_onscreen->gles_driver->DeleteFramebuffers(1, &egl_onscreen_ctx->fb);
-        yagl_unensure_ctx(egl_onscreen_ctx->fb_ctx_id);
+        yagl_unensure_ctx(ctx->ps, egl_onscreen_ctx->fb_ctx_id);
     }
 
     if (egl_onscreen_ctx->null_sfc != EGL_NO_SURFACE) {
@@ -75,7 +76,8 @@ static void yagl_egl_onscreen_context_destroy(struct yagl_eglb_context *ctx)
 }
 
 struct yagl_egl_onscreen_context
-    *yagl_egl_onscreen_context_create(struct yagl_egl_onscreen_display *dpy,
+    *yagl_egl_onscreen_context_create(struct yagl_thread_state *cur_ts,
+                                      struct yagl_egl_onscreen_display *dpy,
                                       const struct yagl_egl_native_config *cfg,
                                       struct yagl_egl_onscreen_context *share_context,
                                       int version)
@@ -108,6 +110,7 @@ struct yagl_egl_onscreen_context
     yagl_eglb_context_init(&ctx->base, &dpy->base);
 
     ctx->base.destroy = &yagl_egl_onscreen_context_destroy;
+    ctx->base.ps = cur_ts->ps;
 
     ctx->native_ctx = native_ctx;
 
@@ -130,7 +133,7 @@ void yagl_egl_onscreen_context_setup(struct yagl_egl_onscreen_context *ctx)
     }
 
     egl_onscreen->gles_driver->GenFramebuffers(1, &ctx->fb);
-    ctx->fb_ctx_id = yagl_get_ctx_id();
+    ctx->fb_ctx_id = yagl_get_ctx_id(ctx->base.ps);
 }
 
 bool yagl_egl_onscreen_context_setup_surfaceless(struct yagl_egl_onscreen_context *ctx)
index 1954735..10018c3 100644 (file)
@@ -72,7 +72,8 @@ struct yagl_egl_onscreen_context
 };
 
 struct yagl_egl_onscreen_context
-    *yagl_egl_onscreen_context_create(struct yagl_egl_onscreen_display *dpy,
+    *yagl_egl_onscreen_context_create(struct yagl_thread_state *cur_ts,
+                                      struct yagl_egl_onscreen_display *dpy,
                                       const struct yagl_egl_native_config *cfg,
                                       struct yagl_egl_onscreen_context *share_context,
                                       int version);
index 1fc73a4..f8861cc 100644 (file)
@@ -50,6 +50,7 @@ struct yagl_egl_onscreen_image
 static void yagl_egl_onscreen_image_destroy(struct yagl_object *obj)
 {
     struct yagl_egl_onscreen_image *image = (struct yagl_egl_onscreen_image*)obj;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_image_destroy, "%u", obj->global_name);
 
@@ -69,6 +70,7 @@ static struct yagl_egl_native_config
     struct yagl_egl_onscreen *egl_onscreen =
         (struct yagl_egl_onscreen*)dpy->backend;
     struct yagl_egl_native_config *native_configs;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_display_config_enum,
                         "dpy = %p", dpy);
@@ -90,6 +92,7 @@ static void yagl_egl_onscreen_display_config_cleanup(struct yagl_eglb_display *d
         (struct yagl_egl_onscreen_display*)dpy;
     struct yagl_egl_onscreen *egl_onscreen =
         (struct yagl_egl_onscreen*)dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_display_config_cleanup,
                         "dpy = %p, cfg = %d",
@@ -104,7 +107,8 @@ static void yagl_egl_onscreen_display_config_cleanup(struct yagl_eglb_display *d
 }
 
 static struct yagl_eglb_context
-    *yagl_egl_onscreen_display_create_context(struct yagl_eglb_display *dpy,
+    *yagl_egl_onscreen_display_create_context(struct yagl_thread_state *cur_ts,
+                                              struct yagl_eglb_display *dpy,
                                               const struct yagl_egl_native_config *cfg,
                                               struct yagl_eglb_context *share_context,
                                               int version)
@@ -112,7 +116,8 @@ static struct yagl_eglb_context
     struct yagl_egl_onscreen_display *egl_onscreen_dpy =
         (struct yagl_egl_onscreen_display*)dpy;
     struct yagl_egl_onscreen_context *ctx =
-        yagl_egl_onscreen_context_create(egl_onscreen_dpy,
+        yagl_egl_onscreen_context_create(cur_ts,
+                                         egl_onscreen_dpy,
                                          cfg,
                                          (struct yagl_egl_onscreen_context*)share_context,
                                          version);
@@ -121,7 +126,8 @@ static struct yagl_eglb_context
 }
 
 static struct yagl_eglb_surface
-    *yagl_egl_onscreen_display_create_window_surface(struct yagl_eglb_display *dpy,
+    *yagl_egl_onscreen_display_create_window_surface(struct yagl_thread_state *cur_ts,
+                                                     struct yagl_eglb_display *dpy,
                                                      const struct yagl_egl_native_config *cfg,
                                                      const struct yagl_egl_window_attribs *attribs,
                                                      yagl_winsys_id id)
@@ -129,7 +135,8 @@ static struct yagl_eglb_surface
     struct yagl_egl_onscreen_display *egl_onscreen_dpy =
         (struct yagl_egl_onscreen_display*)dpy;
     struct yagl_egl_onscreen_surface *sfc =
-        yagl_egl_onscreen_surface_create_window(egl_onscreen_dpy,
+        yagl_egl_onscreen_surface_create_window(cur_ts,
+                                                egl_onscreen_dpy,
                                                 cfg,
                                                 attribs,
                                                 id);
@@ -138,7 +145,8 @@ static struct yagl_eglb_surface
 }
 
 static struct yagl_eglb_surface
-    *yagl_egl_onscreen_display_create_pixmap_surface(struct yagl_eglb_display *dpy,
+    *yagl_egl_onscreen_display_create_pixmap_surface(struct yagl_thread_state *cur_ts,
+                                                     struct yagl_eglb_display *dpy,
                                                      const struct yagl_egl_native_config *cfg,
                                                      const struct yagl_egl_pixmap_attribs *attribs,
                                                      yagl_winsys_id id)
@@ -146,7 +154,8 @@ static struct yagl_eglb_surface
     struct yagl_egl_onscreen_display *egl_onscreen_dpy =
         (struct yagl_egl_onscreen_display*)dpy;
     struct yagl_egl_onscreen_surface *sfc =
-        yagl_egl_onscreen_surface_create_pixmap(egl_onscreen_dpy,
+        yagl_egl_onscreen_surface_create_pixmap(cur_ts,
+                                                egl_onscreen_dpy,
                                                 cfg,
                                                 attribs,
                                                 id);
@@ -155,7 +164,8 @@ static struct yagl_eglb_surface
 }
 
 static struct yagl_eglb_surface
-    *yagl_egl_onscreen_display_create_pbuffer_surface(struct yagl_eglb_display *dpy,
+    *yagl_egl_onscreen_display_create_pbuffer_surface(struct yagl_thread_state *cur_ts,
+                                                     struct yagl_eglb_display *dpy,
                                                       const struct yagl_egl_native_config *cfg,
                                                       const struct yagl_egl_pbuffer_attribs *attribs,
                                                       yagl_winsys_id id)
@@ -163,7 +173,8 @@ static struct yagl_eglb_surface
     struct yagl_egl_onscreen_display *egl_onscreen_dpy =
         (struct yagl_egl_onscreen_display*)dpy;
     struct yagl_egl_onscreen_surface *sfc =
-        yagl_egl_onscreen_surface_create_pbuffer(egl_onscreen_dpy,
+        yagl_egl_onscreen_surface_create_pbuffer(cur_ts,
+                                                 egl_onscreen_dpy,
                                                  cfg,
                                                  attribs,
                                                  id);
@@ -171,7 +182,8 @@ static struct yagl_eglb_surface
     return sfc ? &sfc->base : NULL;
 }
 
-static struct yagl_object *yagl_egl_onscreen_display_create_image(struct yagl_eglb_display *dpy,
+static struct yagl_object *yagl_egl_onscreen_display_create_image(struct yagl_thread_state *cur_ts,
+                                                                  struct yagl_eglb_display *dpy,
                                                                   yagl_winsys_id buffer)
 {
     struct yagl_egl_onscreen *egl_onscreen =
@@ -200,6 +212,7 @@ static void yagl_egl_onscreen_display_destroy(struct yagl_eglb_display *dpy)
         (struct yagl_egl_onscreen_display*)dpy;
     struct yagl_egl_onscreen *egl_onscreen =
         (struct yagl_egl_onscreen*)dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_display_destroy,
                         "dpy = %p", dpy);
@@ -219,6 +232,7 @@ struct yagl_egl_onscreen_display
 {
     struct yagl_egl_onscreen_display *dpy;
     EGLNativeDisplayType native_dpy;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_display_create, NULL);
 
index 501dc66..105db72 100644 (file)
 #include "yagl_gles_driver.h"
 #include "hw/vigs/winsys_gl.h"
 
+// TODO remove and pass via argument
 YAGL_DECLARE_TLS(struct yagl_egl_onscreen_ts*, egl_onscreen_ts);
 
-static void yagl_egl_onscreen_surface_invalidate(struct yagl_eglb_surface *sfc,
+static void yagl_egl_onscreen_surface_invalidate(struct yagl_thread_state *cur_ts,
+                                                 struct yagl_eglb_surface *sfc,
                                                  yagl_winsys_id id)
 {
     struct yagl_egl_onscreen_surface *osfc =
@@ -69,9 +71,9 @@ static void yagl_egl_onscreen_surface_invalidate(struct yagl_eglb_surface *sfc,
     if (((osfc->ws_sfc->base.width != ws_sfc->base.width) ||
          (osfc->ws_sfc->base.height != ws_sfc->base.height)) &&
          osfc->rb) {
-        yagl_ensure_ctx(0);
+        yagl_ensure_ctx(cur_ts->ps, 0);
         egl_onscreen->gles_driver->DeleteRenderbuffers(1, &osfc->rb);
-        yagl_unensure_ctx(0);
+        yagl_unensure_ctx(cur_ts->ps, 0);
         osfc->rb = 0;
     }
 
@@ -99,9 +101,10 @@ static void yagl_egl_onscreen_surface_invalidate(struct yagl_eglb_surface *sfc,
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
-static bool yagl_egl_onscreen_surface_query(struct yagl_eglb_surface *sfc,
-                                             EGLint attribute,
-                                             EGLint *value)
+static bool yagl_egl_onscreen_surface_query(struct yagl_thread_state *cur_ts,
+                                            struct yagl_eglb_surface *sfc,
+                                            EGLint attribute,
+                                            EGLint *value)
 {
     struct yagl_egl_onscreen_surface *osfc =
         (struct yagl_egl_onscreen_surface*)sfc;
@@ -120,7 +123,8 @@ static bool yagl_egl_onscreen_surface_query(struct yagl_eglb_surface *sfc,
     return true;
 }
 
-static void yagl_egl_onscreen_surface_swap_buffers(struct yagl_eglb_surface *sfc)
+static void yagl_egl_onscreen_surface_swap_buffers(struct yagl_thread_state *cur_ts,
+                                                   struct yagl_eglb_surface *sfc)
 {
     struct yagl_egl_onscreen_surface *osfc =
         (struct yagl_egl_onscreen_surface*)sfc;
@@ -132,7 +136,8 @@ static void yagl_egl_onscreen_surface_swap_buffers(struct yagl_eglb_surface *sfc
     osfc->ws_sfc->base.set_dirty(&osfc->ws_sfc->base);
 }
 
-static void yagl_egl_onscreen_surface_copy_buffers(struct yagl_eglb_surface *sfc)
+static void yagl_egl_onscreen_surface_copy_buffers(struct yagl_thread_state *cur_ts,
+                                                   struct yagl_eglb_surface *sfc)
 {
     struct yagl_egl_onscreen_surface *osfc =
         (struct yagl_egl_onscreen_surface*)sfc;
@@ -144,7 +149,8 @@ static void yagl_egl_onscreen_surface_copy_buffers(struct yagl_eglb_surface *sfc
     osfc->ws_sfc->base.set_dirty(&osfc->ws_sfc->base);
 }
 
-static void yagl_egl_onscreen_surface_wait_gl(struct yagl_eglb_surface *sfc)
+static void yagl_egl_onscreen_surface_wait_gl(struct yagl_thread_state *cur_ts,
+                                              struct yagl_eglb_surface *sfc)
 {
     struct yagl_egl_onscreen_surface *osfc =
         (struct yagl_egl_onscreen_surface*)sfc;
@@ -162,6 +168,7 @@ static void yagl_egl_onscreen_surface_destroy(struct yagl_eglb_surface *sfc)
         (struct yagl_egl_onscreen_surface*)sfc;
     struct yagl_egl_onscreen *egl_onscreen =
         (struct yagl_egl_onscreen*)sfc->dpy->backend;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_surface_destroy, NULL);
 
@@ -177,9 +184,9 @@ static void yagl_egl_onscreen_surface_destroy(struct yagl_eglb_surface *sfc)
     }
 
     if (osfc->rb) {
-        yagl_ensure_ctx(0);
+        yagl_ensure_ctx(sfc->ps, 0);
         egl_onscreen->gles_driver->DeleteRenderbuffers(1, &osfc->rb);
-        yagl_unensure_ctx(0);
+        yagl_unensure_ctx(sfc->ps, 0);
     }
 
     yagl_eglb_surface_cleanup(sfc);
@@ -190,7 +197,8 @@ static void yagl_egl_onscreen_surface_destroy(struct yagl_eglb_surface *sfc)
 }
 
 struct yagl_egl_onscreen_surface
-    *yagl_egl_onscreen_surface_create_window(struct yagl_egl_onscreen_display *dpy,
+    *yagl_egl_onscreen_surface_create_window(struct yagl_thread_state *cur_ts,
+                                             struct yagl_egl_onscreen_display *dpy,
                                              const struct yagl_egl_native_config *cfg,
                                              const struct yagl_egl_window_attribs *attribs,
                                              yagl_winsys_id id)
@@ -240,6 +248,7 @@ struct yagl_egl_onscreen_surface
     sfc->base.copy_buffers = &yagl_egl_onscreen_surface_copy_buffers;
     sfc->base.wait_gl = &yagl_egl_onscreen_surface_wait_gl;
     sfc->base.destroy = &yagl_egl_onscreen_surface_destroy;
+    sfc->base.ps = cur_ts->ps;
 
     YAGL_LOG_FUNC_EXIT(NULL);
 
@@ -256,7 +265,8 @@ fail:
 }
 
 struct yagl_egl_onscreen_surface
-    *yagl_egl_onscreen_surface_create_pixmap(struct yagl_egl_onscreen_display *dpy,
+    *yagl_egl_onscreen_surface_create_pixmap(struct yagl_thread_state *cur_ts,
+                                             struct yagl_egl_onscreen_display *dpy,
                                              const struct yagl_egl_native_config *cfg,
                                              const struct yagl_egl_pixmap_attribs *attribs,
                                              yagl_winsys_id id)
@@ -306,6 +316,7 @@ struct yagl_egl_onscreen_surface
     sfc->base.copy_buffers = &yagl_egl_onscreen_surface_copy_buffers;
     sfc->base.wait_gl = &yagl_egl_onscreen_surface_wait_gl;
     sfc->base.destroy = &yagl_egl_onscreen_surface_destroy;
+    sfc->base.ps = cur_ts->ps;
 
     YAGL_LOG_FUNC_EXIT(NULL);
 
@@ -322,10 +333,11 @@ fail:
 }
 
 struct yagl_egl_onscreen_surface
-    *yagl_egl_onscreen_surface_create_pbuffer(struct yagl_egl_onscreen_display *dpy,
-                                             const struct yagl_egl_native_config *cfg,
-                                             const struct yagl_egl_pbuffer_attribs *attribs,
-                                             yagl_winsys_id id)
+    *yagl_egl_onscreen_surface_create_pbuffer(struct yagl_thread_state *cur_ts,
+                                              struct yagl_egl_onscreen_display *dpy,
+                                              const struct yagl_egl_native_config *cfg,
+                                              const struct yagl_egl_pbuffer_attribs *attribs,
+                                              yagl_winsys_id id)
 {
     struct yagl_egl_onscreen *egl_onscreen =
         (struct yagl_egl_onscreen*)dpy->base.backend;
@@ -372,6 +384,7 @@ struct yagl_egl_onscreen_surface
     sfc->base.copy_buffers = &yagl_egl_onscreen_surface_copy_buffers;
     sfc->base.wait_gl = &yagl_egl_onscreen_surface_wait_gl;
     sfc->base.destroy = &yagl_egl_onscreen_surface_destroy;
+    sfc->base.ps = cur_ts->ps;
 
     YAGL_LOG_FUNC_EXIT(NULL);
 
index 179d7a4..20945aa 100644 (file)
@@ -61,22 +61,25 @@ struct yagl_egl_onscreen_surface
 };
 
 struct yagl_egl_onscreen_surface
-    *yagl_egl_onscreen_surface_create_window(struct yagl_egl_onscreen_display *dpy,
+    *yagl_egl_onscreen_surface_create_window(struct yagl_thread_state *cur_ts,
+                                             struct yagl_egl_onscreen_display *dpy,
                                              const struct yagl_egl_native_config *cfg,
                                              const struct yagl_egl_window_attribs *attribs,
                                              yagl_winsys_id id);
 
 struct yagl_egl_onscreen_surface
-    *yagl_egl_onscreen_surface_create_pixmap(struct yagl_egl_onscreen_display *dpy,
+    *yagl_egl_onscreen_surface_create_pixmap(struct yagl_thread_state *cur_ts,
+                                             struct yagl_egl_onscreen_display *dpy,
                                              const struct yagl_egl_native_config *cfg,
                                              const struct yagl_egl_pixmap_attribs *attribs,
                                              yagl_winsys_id id);
 
 struct yagl_egl_onscreen_surface
-    *yagl_egl_onscreen_surface_create_pbuffer(struct yagl_egl_onscreen_display *dpy,
-                                             const struct yagl_egl_native_config *cfg,
-                                             const struct yagl_egl_pbuffer_attribs *attribs,
-                                             yagl_winsys_id id);
+    *yagl_egl_onscreen_surface_create_pbuffer(struct yagl_thread_state *cur_ts,
+                                              struct yagl_egl_onscreen_display *dpy,
+                                              const struct yagl_egl_native_config *cfg,
+                                              const struct yagl_egl_pbuffer_attribs *attribs,
+                                              yagl_winsys_id id);
 
 void yagl_egl_onscreen_surface_setup(struct yagl_egl_onscreen_surface *sfc);
 
index bdf383e..0159ea6 100644 (file)
@@ -52,7 +52,8 @@ static hwaddr yagl_pa(target_ulong va)
 }
 
 struct yagl_compiled_transfer
-    *yagl_compiled_transfer_create(target_ulong va,
+    *yagl_compiled_transfer_create(struct yagl_thread_state *cur_ts,
+                                   target_ulong va,
                                    uint32_t len,
                                    bool is_write)
 {
@@ -67,6 +68,7 @@ struct yagl_compiled_transfer
     QLIST_INSERT_HEAD(&cur_ts->t->compiled_transfers, ct, entry);
 
     ct->in_list = true;
+    ct->ts = cur_ts;
 
     return ct;
 }
@@ -95,7 +97,8 @@ void yagl_compiled_transfer_destroy(struct yagl_compiled_transfer *ct)
     g_free(ct);
 }
 
-void yagl_compiled_transfer_prepare(struct yagl_compiled_transfer *ct)
+void yagl_compiled_transfer_prepare(struct yagl_thread_state *cur_ts,
+                                    struct yagl_compiled_transfer *ct)
 {
     struct yagl_vector v;
     target_ulong last_page_va = YAGL_TARGET_PAGE_VA(ct->va + ct->len - 1);
index 50580d8..43821ac 100644 (file)
@@ -51,6 +51,7 @@ struct yagl_compiled_transfer_section
 struct yagl_compiled_transfer
 {
     QLIST_ENTRY(yagl_compiled_transfer) entry;
+    struct yagl_thread_state *ts;
 
     target_ulong va;
     uint32_t len;
@@ -63,13 +64,15 @@ struct yagl_compiled_transfer
 };
 
 struct yagl_compiled_transfer
-    *yagl_compiled_transfer_create(target_ulong va,
+    *yagl_compiled_transfer_create(struct yagl_thread_state *cur_ts,
+                                   target_ulong va,
                                    uint32_t len,
                                    bool is_write);
 
 void yagl_compiled_transfer_destroy(struct yagl_compiled_transfer *ct);
 
-void yagl_compiled_transfer_prepare(struct yagl_compiled_transfer *ct);
+void yagl_compiled_transfer_prepare(struct yagl_thread_state *cur_ts,
+                                    struct yagl_compiled_transfer *ct);
 
 void yagl_compiled_transfer_exec(struct yagl_compiled_transfer *ct, void* data);
 
index 3cee269..f1ac3a4 100644 (file)
@@ -90,6 +90,7 @@ static void yagl_device_operate(YaGLState *s, int user_index, hwaddr buff_pa)
     yagl_tid target_tid;
     hwaddr buff_len = TARGET_PAGE_SIZE;
     uint8_t *buff = NULL;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_device_operate,
                         "user_index = %d, buff_pa = %" PRIx64,
@@ -167,6 +168,8 @@ out:
 
 static void yagl_device_trigger(YaGLState *s, int user_index, bool sync)
 {
+    YAGL_LOG_NO_TS;
+
     YAGL_LOG_FUNC_ENTER(yagl_device_trigger, "%d, %d", user_index, sync);
 
     if (s->users[user_index].activated) {
@@ -230,6 +233,7 @@ static int yagl_device_init(PCIDevice *dev)
     struct yagl_egl_driver *egl_driver = NULL;
     struct yagl_egl_backend *egl_backend = NULL;
     struct yagl_gles_driver *gles_driver = NULL;
+    YAGL_LOG_NO_TS;
 
     if (s->protocol > 0) {
         yagl_protocol_version = s->protocol;
@@ -374,6 +378,7 @@ static void yagl_device_reset(DeviceState *d)
 {
     YaGLState *s = container_of(d, YaGLState, dev.qdev);
     int i;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_device_reset, NULL);
 
@@ -391,6 +396,7 @@ static void yagl_device_reset(DeviceState *d)
 static void yagl_device_exit(PCIDevice *dev)
 {
     YaGLState *s = DO_UPCAST(YaGLState, dev, dev);
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_device_exit, NULL);
 
index 51d333e..d71a7a0 100644 (file)
@@ -38,6 +38,7 @@
 #include <GL/glx.h>
 
 #define YAGL_EGL_GLX_ENTER(func, format, ...) \
+    YAGL_LOG_NO_TS; \
     YAGL_LOG_FUNC_ENTER(func, format,##__VA_ARGS__)
 
 #define YAGL_EGL_GLX_GET_PROC(proc_type, proc_name) \
@@ -722,6 +723,7 @@ static bool yagl_egl_glx_make_current(struct yagl_egl_driver *driver,
 static void yagl_egl_glx_destroy(struct yagl_egl_driver *driver)
 {
     struct yagl_egl_glx *egl_glx = (struct yagl_egl_glx*)driver;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_glx_destroy, NULL);
 
@@ -738,6 +740,7 @@ struct yagl_egl_driver *yagl_egl_driver_create(void *display,
     struct yagl_egl_driver *egl_driver;
     struct yagl_egl_glx *egl_glx;
     Display *x_display = display;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_glx_create, NULL);
 
index 70e2558..b3855bb 100644 (file)
@@ -38,6 +38,8 @@
 
 static void yagl_gles_ogl_destroy(struct yagl_gles_driver *driver)
 {
+    YAGL_LOG_NO_TS;
+
     YAGL_LOG_FUNC_ENTER(yagl_gles_ogl_destroy, NULL);
 
     yagl_gles_driver_cleanup(driver);
@@ -50,6 +52,7 @@ struct yagl_gles_driver *yagl_gles_ogl_create(struct yagl_dyn_lib *dyn_lib,
                                               yagl_gl_version gl_version)
 {
     struct yagl_gles_driver *driver = NULL;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_ogl_create, NULL);
 
index a406bae..2da307e 100644 (file)
@@ -44,6 +44,7 @@ struct yagl_gles_onscreen
     struct yagl_gles_driver *orig_driver;
 };
 
+// TODO remove and pass via argument
 YAGL_DECLARE_TLS(struct yagl_egl_onscreen_ts*, egl_onscreen_ts);
 
 static void YAGL_GLES_APIENTRY yagl_gles_onscreen_BindFramebuffer(GLenum target,
@@ -65,6 +66,7 @@ static void YAGL_GLES_APIENTRY yagl_gles_onscreen_BindFramebuffer(GLenum target,
 static void yagl_gles_onscreen_destroy(struct yagl_gles_driver *driver)
 {
     struct yagl_gles_onscreen *gles_onscreen = (struct yagl_gles_onscreen*)driver;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_onscreen_destroy, NULL);
 
@@ -81,6 +83,7 @@ struct yagl_gles_driver
     *yagl_gles_onscreen_create(struct yagl_gles_driver *orig_driver)
 {
     struct yagl_gles_onscreen *driver = NULL;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_gles_onscreen_create, NULL);
 
index ce66e57..686f41a 100644 (file)
@@ -47,24 +47,26 @@ struct yagl_egl_backend
 
     yagl_gl_version gl_version;
 
-    void (*thread_init)(struct yagl_egl_backend */*backend*/);
+    void (*thread_init)(struct yagl_thread_state */*cur_ts*/, struct yagl_egl_backend */*backend*/);
 
-    void (*batch_start)(struct yagl_egl_backend */*backend*/);
+    void (*batch_start)(struct yagl_thread_state */*cur_ts*/, struct yagl_egl_backend */*backend*/);
 
     struct yagl_eglb_display *(*create_display)(struct yagl_egl_backend */*backend*/);
 
-    bool (*make_current)(struct yagl_egl_backend */*backend*/,
+    bool (*make_current)(struct yagl_thread_state */*cur_ts*/,
+                         struct yagl_egl_backend */*backend*/,
                          struct yagl_eglb_display */*dpy*/,
                          struct yagl_eglb_context */*ctx*/,
                          struct yagl_eglb_surface */*draw*/,
                          struct yagl_eglb_surface */*read*/);
 
-    bool (*release_current)(struct yagl_egl_backend */*backend*/,
+    bool (*release_current)(struct yagl_thread_state */*cur_ts*/,
+                            struct yagl_egl_backend */*backend*/,
                             bool /*force*/);
 
-    void (*batch_end)(struct yagl_egl_backend */*backend*/);
+    void (*batch_end)(struct yagl_thread_state */*cur_ts*/, struct yagl_egl_backend */*backend*/);
 
-    void (*thread_fini)(struct yagl_egl_backend */*backend*/);
+    void (*thread_fini)(struct yagl_thread_state */*cur_ts*/, struct yagl_egl_backend */*backend*/);
 
     /*
      * Make sure that some GL context is currently active. Can
index 75131c0..84c93aa 100644 (file)
@@ -37,6 +37,7 @@ struct yagl_eglb_display;
 struct yagl_eglb_context
 {
     struct yagl_eglb_display *dpy;
+    struct yagl_process_state *ps;
 
     void (*destroy)(struct yagl_eglb_context */*ctx*/);
 };
index 85866e1..8527021 100644 (file)
@@ -52,7 +52,8 @@ struct yagl_eglb_display
     void (*config_cleanup)(struct yagl_eglb_display */*dpy*/,
                            const struct yagl_egl_native_config */*cfg*/);
 
-    struct yagl_eglb_context *(*create_context)(struct yagl_eglb_display */*dpy*/,
+    struct yagl_eglb_context *(*create_context)(struct yagl_thread_state */*cur_ts*/,
+                                                struct yagl_eglb_display */*dpy*/,
                                                 const struct yagl_egl_native_config */*cfg*/,
                                                 struct yagl_eglb_context */*share_context*/,
                                                 int /*version*/);
@@ -60,7 +61,8 @@ struct yagl_eglb_display
     /*
      * 'pixels' are locked in target's memory, no page fault possible.
      */
-    struct yagl_eglb_surface *(*create_offscreen_surface)(struct yagl_eglb_display */*dpy*/,
+    struct yagl_eglb_surface *(*create_offscreen_surface)(struct yagl_thread_state */*cur_ts*/,
+                                                          struct yagl_eglb_display */*dpy*/,
                                                           const struct yagl_egl_native_config */*cfg*/,
                                                           EGLenum /*type*/,
                                                           const void */*attribs*/,
@@ -69,22 +71,26 @@ struct yagl_eglb_display
                                                           uint32_t /*bpp*/,
                                                           target_ulong /*pixels*/);
 
-    struct yagl_eglb_surface *(*create_onscreen_window_surface)(struct yagl_eglb_display */*dpy*/,
+    struct yagl_eglb_surface *(*create_onscreen_window_surface)(struct yagl_thread_state */*cur_ts*/,
+                                                                struct yagl_eglb_display */*dpy*/,
                                                                 const struct yagl_egl_native_config */*cfg*/,
                                                                 const struct yagl_egl_window_attribs */*attribs*/,
                                                                 yagl_winsys_id /*id*/);
 
-    struct yagl_eglb_surface *(*create_onscreen_pixmap_surface)(struct yagl_eglb_display */*dpy*/,
+    struct yagl_eglb_surface *(*create_onscreen_pixmap_surface)(struct yagl_thread_state */*cur_ts*/,
+                                                                struct yagl_eglb_display */*dpy*/,
                                                                 const struct yagl_egl_native_config */*cfg*/,
                                                                 const struct yagl_egl_pixmap_attribs */*attribs*/,
                                                                 yagl_winsys_id /*id*/);
 
-    struct yagl_eglb_surface *(*create_onscreen_pbuffer_surface)(struct yagl_eglb_display */*dpy*/,
+    struct yagl_eglb_surface *(*create_onscreen_pbuffer_surface)(struct yagl_thread_state */*cur_ts*/,
+                                                                 struct yagl_eglb_display */*dpy*/,
                                                                  const struct yagl_egl_native_config */*cfg*/,
                                                                  const struct yagl_egl_pbuffer_attribs */*attribs*/,
                                                                  yagl_winsys_id /*id*/);
 
-    struct yagl_object *(*create_image)(struct yagl_eglb_display */*dpy*/,
+    struct yagl_object *(*create_image)(struct yagl_thread_state */*cur_ts*/,
+                                        struct yagl_eglb_display */*dpy*/,
                                         yagl_winsys_id /*buffer*/);
 
     void (*destroy)(struct yagl_eglb_display */*dpy*/);
index 67ecdd8..2a67281 100644 (file)
@@ -40,6 +40,8 @@ struct yagl_eglb_surface
 {
     struct yagl_eglb_display *dpy;
 
+    struct yagl_process_state *ps;
+
     EGLenum type;
 
     union
@@ -53,7 +55,8 @@ struct yagl_eglb_surface
      * Surface has been invalidated on target, update it
      * from 'id'.
      */
-    void (*invalidate)(struct yagl_eglb_surface */*sfc*/,
+    void (*invalidate)(struct yagl_thread_state */*cur_ts*/,
+                       struct yagl_eglb_surface */*sfc*/,
                        yagl_winsys_id /*id*/);
 
     /*
@@ -61,21 +64,26 @@ struct yagl_eglb_surface
      * 'sfc' and 'with' must be of same type, but can have
      * different formats.
      */
-    void (*replace)(struct yagl_eglb_surface */*sfc*/,
+    void (*replace)(struct yagl_thread_state */*cur_ts*/,
+                    struct yagl_eglb_surface */*sfc*/,
                     struct yagl_eglb_surface */*with*/);
 
     /*
      * Can be called for surfaces that were reset.
      */
-    bool (*query)(struct yagl_eglb_surface */*sfc*/,
+    bool (*query)(struct yagl_thread_state */*cur_ts*/,
+                  struct yagl_eglb_surface */*sfc*/,
                   EGLint /*attribute*/,
                   EGLint */*value*/);
 
-    void (*swap_buffers)(struct yagl_eglb_surface */*sfc*/);
+    void (*swap_buffers)(struct yagl_thread_state */*cur_ts*/,
+                         struct yagl_eglb_surface */*sfc*/);
 
-    void (*copy_buffers)(struct yagl_eglb_surface */*sfc*/);
+    void (*copy_buffers)(struct yagl_thread_state */*cur_ts*/,
+                         struct yagl_eglb_surface */*sfc*/);
 
-    void (*wait_gl)(struct yagl_eglb_surface */*sfc*/);
+    void (*wait_gl)(struct yagl_thread_state */*cur_ts*/,
+                    struct yagl_eglb_surface */*sfc*/);
 
     void (*destroy)(struct yagl_eglb_surface */*sfc*/);
 };
index a8cf89b..1f69b17 100644 (file)
@@ -43,20 +43,20 @@ void yagl_gles_driver_cleanup(struct yagl_gles_driver *driver)
 {
 }
 
-uint32_t yagl_get_ctx_id(void)
+uint32_t yagl_get_ctx_id(struct yagl_process_state *ps)
 {
-    assert(cur_ts);
-    return cur_ts->ps->egl_iface->get_ctx_id(cur_ts->ps->egl_iface);
+    assert(ps);
+    return ps->egl_iface->get_ctx_id(ps->egl_iface);
 }
 
-void yagl_ensure_ctx(uint32_t ctx_id)
+void yagl_ensure_ctx(struct yagl_process_state *ps, uint32_t ctx_id)
 {
-    assert(cur_ts);
-    cur_ts->ps->egl_iface->ensure_ctx(cur_ts->ps->egl_iface, ctx_id);
+    assert(ps);
+    ps->egl_iface->ensure_ctx(ps->egl_iface, ctx_id);
 }
 
-void yagl_unensure_ctx(uint32_t ctx_id)
+void yagl_unensure_ctx(struct yagl_process_state *ps, uint32_t ctx_id)
 {
-    assert(cur_ts);
-    cur_ts->ps->egl_iface->unensure_ctx(cur_ts->ps->egl_iface, ctx_id);
+    assert(ps);
+    ps->egl_iface->unensure_ctx(ps->egl_iface, ctx_id);
 }
index 6e64f7a..c4bf142 100644 (file)
@@ -409,9 +409,9 @@ void yagl_gles_driver_cleanup(struct yagl_gles_driver *driver);
  * @{
  */
 
-uint32_t yagl_get_ctx_id(void);
-void yagl_ensure_ctx(uint32_t ctx_id);
-void yagl_unensure_ctx(uint32_t ctx_id);
+uint32_t yagl_get_ctx_id(struct yagl_process_state *ps);
+void yagl_ensure_ctx(struct yagl_process_state *ps, uint32_t ctx_id);
+void yagl_unensure_ctx(struct yagl_process_state *ps, uint32_t ctx_id);
 
 /*
  * @}
index 4479108..38ab24e 100644 (file)
@@ -112,6 +112,11 @@ bool yagl_log_is_enabled_for_facility(const char* facility);
 
 bool yagl_log_is_enabled_for_func_tracing(void);
 
+// a helper to allow logging where acquiring PID/TID is not possible
+// ie. on a main server thread. This could be replaced with getting
+// PID/TID via getpid()/gettid()/Windows equivalents.
+#define YAGL_LOG_NO_TS struct yagl_thread_state *cur_ts = NULL
+
 #ifndef YAGL_LOG_DISABLE
 #define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...) \
     do \
@@ -123,12 +128,23 @@ bool yagl_log_is_enabled_for_func_tracing(void);
         } \
     } while(0)
 
-// TODO _yagl_log_current_pid/tid must be restored to proper form
-//      PID/TID must be read in a different way than via global cur_ts
-#define YAGL_LOG_FUNC_SET(func) \
-    const char* _yagl_log_current_func = #func; \
-    yagl_pid _yagl_log_current_pid = 0; \
-    yagl_tid _yagl_log_current_tid = 0
+#define YAGL_LOG_FUNC_SET_TS(__func, __ts) \
+    const char* _yagl_log_current_func = #__func; \
+    yagl_pid _yagl_log_current_pid = (__ts ? __ts->ps->id : 0); \
+    yagl_tid _yagl_log_current_tid = (__ts ? __ts->id : 0)
+
+#define YAGL_LOG_FUNC_SET(__func) YAGL_LOG_FUNC_SET_TS(__func, cur_ts)
+
+#define YAGL_LOG_FUNC_ENTER_TS(func, __ts, format, ...) \
+    YAGL_LOG_FUNC_SET_TS(func, __ts); \
+    do \
+    { \
+        if ( yagl_log_is_enabled_for_func_tracing() && \
+             yagl_log_is_enabled_for_facility(_yagl_log_current_func) ) \
+        { \
+            yagl_log_func_enter(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, format,##__VA_ARGS__); \
+        } \
+    } while(0)
 
 #define YAGL_LOG_FUNC_ENTER(func, format, ...) \
     YAGL_LOG_FUNC_SET(func); \
index 6ca7966..6650cee 100644 (file)
@@ -33,7 +33,7 @@
 #include "yagl_log.h"
 #include "exec/cpu-all.h"
 
-bool yagl_mem_put(target_ulong va, const void* data, uint32_t len)
+bool yagl_mem_put(struct yagl_thread_state* cur_ts, target_ulong va, const void* data, uint32_t len)
 {
     int ret;
 
@@ -50,7 +50,7 @@ bool yagl_mem_put(target_ulong va, const void* data, uint32_t len)
     return ret != -1;
 }
 
-bool yagl_mem_get(target_ulong va, uint32_t len, void* data)
+bool yagl_mem_get(struct yagl_thread_state* cur_ts, target_ulong va, uint32_t len, void* data)
 {
     int ret;
 
index 80dae0c..2b3fff9 100644 (file)
@@ -32,8 +32,8 @@
 
 #include "yagl_types.h"
 
-bool yagl_mem_put(target_ulong va, const void *data, uint32_t len);
+bool yagl_mem_put(struct yagl_thread_state* cur_ts, target_ulong va, const void *data, uint32_t len);
 
-bool yagl_mem_get(target_ulong va, uint32_t len, void *data);
+bool yagl_mem_get(struct yagl_thread_state* cur_ts, target_ulong va, uint32_t len, void *data);
 
 #endif
index c4d8c3c..373f9a4 100644 (file)
@@ -36,6 +36,7 @@
 struct yagl_object
 {
     yagl_object_name global_name;
+    struct yagl_process_state *ps;
 
     void (*destroy)(struct yagl_object */*obj*/);
 };
@@ -43,6 +44,7 @@ struct yagl_object
 struct yagl_object_map
 {
     GHashTable *entries;
+    // TODO object map is per process, might be touched by multiple threads - add mutex
 };
 
 struct yagl_object_map *yagl_object_map_create(void);
index 1e6844f..1b38ed4 100644 (file)
@@ -70,7 +70,8 @@ struct yagl_process_state
 
 void yagl_process_state_destroy(struct yagl_process_state *ps)
 {
-    struct yagl_thread_state *ts, *next;
+    struct yagl_thread_state *ts = NULL, *next = NULL;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_process_state_destroy, NULL);
 
@@ -95,6 +96,8 @@ void yagl_process_state_destroy(struct yagl_process_state *ps)
 void yagl_process_register_egl_interface(struct yagl_process_state *ps,
                                          struct yagl_egl_interface *egl_iface)
 {
+    YAGL_LOG_NO_TS;
+
     YAGL_LOG_FUNC_ENTER(yagl_process_register_egl_interface, NULL);
 
     assert(egl_iface);
@@ -115,6 +118,8 @@ void yagl_process_register_egl_interface(struct yagl_process_state *ps,
 
 void yagl_process_unregister_egl_interface(struct yagl_process_state *ps)
 {
+    YAGL_LOG_NO_TS;
+
     YAGL_LOG_FUNC_ENTER(yagl_process_unregister_egl_interface, NULL);
 
     assert(ps->egl_iface);
index 3e65ac1..b2f09a1 100644 (file)
@@ -168,6 +168,7 @@ bool yagl_server_dispatch_init(struct yagl_server_state *ss,
     struct yagl_process_state *ps = NULL;
     struct yagl_thread_state *ts = NULL;
     uint8_t **pages;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_server_dispatch_init, NULL);
 
@@ -296,9 +297,10 @@ void yagl_server_dispatch_update(struct yagl_server_state *ss,
                                  yagl_tid target_tid,
                                  uint8_t *buff)
 {
-    struct yagl_thread_state *ts;
+    struct yagl_thread_state *ts = NULL;
     uint32_t i, count = 0;
     uint8_t **pages = NULL;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_server_dispatch_update, NULL);
 
@@ -363,6 +365,7 @@ void yagl_server_dispatch_batch(struct yagl_server_state *ss,
                                 bool sync)
 {
     struct yagl_thread_state *ts;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_server_dispatch_batch, NULL);
 
@@ -385,6 +388,7 @@ void yagl_server_dispatch_exit(struct yagl_server_state *ss,
     struct yagl_thread_state *ts =
         yagl_server_find_thread(ss, target_pid, target_tid);
     struct yagl_process_state *ps = NULL;
+    YAGL_LOG_NO_TS;
 
     YAGL_LOG_FUNC_ENTER(yagl_server_dispatch_exit, NULL);
 
index b965e32..2615d02 100644 (file)
@@ -39,8 +39,6 @@
 #include "sysemu/kvm.h"
 #include "sysemu/hax.h"
 
-YAGL_DEFINE_TLS(struct yagl_thread_state*, cur_ts);
-
 struct yagl_thread_work_item
 {
     struct work_queue_item base;
@@ -73,20 +71,19 @@ static __inline void yagl_cpu_synchronize_state(struct yagl_process_state *ps)
 static void yagl_thread_work(struct work_queue_item *wq_item)
 {
     struct yagl_thread_work_item *item = (struct yagl_thread_work_item*)wq_item;
+    struct yagl_thread_state *ts = item->ts;
     int i;
     uint32_t num_calls = 0;
-    struct yagl_transport *t = item->ts->t;
-    struct winsys_interface *wsi = item->ts->ps->ss->wsi;
-
-    cur_ts = item->ts;
+    struct yagl_transport *t = ts->t;
+    struct winsys_interface *wsi = ts->ps->ss->wsi;
 
-    YAGL_LOG_FUNC_SET(yagl_thread_work);
+    YAGL_LOG_FUNC_SET_TS(yagl_thread_work, ts);
 
     YAGL_LOG_TRACE("batch started");
 
     for (i = 0; i < YAGL_NUM_APIS; ++i) {
-        if (cur_ts->ps->api_states[i]) {
-            cur_ts->ps->api_states[i]->batch_start(cur_ts->ps->api_states[i]);
+        if (ts->ps->api_states[i]) {
+            ts->ps->api_states[i]->batch_start(ts, ts->ps->api_states[i]);
         }
     }
 
@@ -111,7 +108,7 @@ static void yagl_thread_work(struct work_queue_item *wq_item)
             break;
         }
 
-        api_ps = cur_ts->ps->api_states[api_id - 1];
+        api_ps = ts->ps->api_states[api_id - 1];
 
         if (!api_ps) {
             YAGL_LOG_CRITICAL("uninitialized api - %u. host logic error", api_id);
@@ -136,14 +133,12 @@ static void yagl_thread_work(struct work_queue_item *wq_item)
     YAGL_LOG_TRACE("batch ended: %u calls", num_calls);
 
     for (i = 0; i < YAGL_NUM_APIS; ++i) {
-        if (cur_ts->ps->api_states[i]) {
-            cur_ts->ps->api_states[i]->batch_end(cur_ts->ps->api_states[i]);
+        if (ts->ps->api_states[i]) {
+            ts->ps->api_states[i]->batch_end(ts, ts->ps->api_states[i]);
         }
     }
 
-    cur_ts = NULL;
-
-    --item->ts->num_in_progress;
+    --ts->num_in_progress;
 
     if (wsi && item->fence_seq) {
         wsi->fence_ack(wsi, item->fence_seq);
@@ -165,8 +160,7 @@ struct yagl_thread_state
     ts->ps = ps;
     ts->id = id;
     ts->t = yagl_transport_create();
-
-    cur_ts = ts;
+    ts->t->ts = ts;
 
     if (is_first) {
         /*
@@ -174,9 +168,9 @@ struct yagl_thread_state
          */
 
         for (i = 0; i < YAGL_NUM_APIS; ++i) {
-            if (ts->ps->ss->apis[i]) {
-                ts->ps->api_states[i] = ts->ps->ss->apis[i]->process_init(ts->ps->ss->apis[i]);
-                assert(ts->ps->api_states[i]);
+            if (ps->ss->apis[i]) {
+                ps->api_states[i] = ps->ss->apis[i]->process_init(ps, ps->ss->apis[i]);
+                assert(ps->api_states[i]);
             }
         }
     }
@@ -186,8 +180,8 @@ struct yagl_thread_state
      */
 
     for (i = 0; i < YAGL_NUM_APIS; ++i) {
-        if (ts->ps->api_states[i]) {
-            ts->ps->api_states[i]->thread_init(ts->ps->api_states[i]);
+        if (ps->api_states[i]) {
+            ps->api_states[i]->thread_init(ts, ps->api_states[i]);
         }
     }
 
@@ -199,15 +193,13 @@ void yagl_thread_state_destroy(struct yagl_thread_state *ts,
 {
     int i;
 
-    cur_ts = ts;
-
     /*
      * Fini APIs (thread).
      */
 
     for (i = 0; i < YAGL_NUM_APIS; ++i) {
         if (ts->ps->api_states[i]) {
-            ts->ps->api_states[i]->thread_fini(ts->ps->api_states[i]);
+            ts->ps->api_states[i]->thread_fini(ts, ts->ps->api_states[i]);
         }
     }
 
@@ -224,14 +216,12 @@ void yagl_thread_state_destroy(struct yagl_thread_state *ts,
 
         for (i = 0; i < YAGL_NUM_APIS; ++i) {
             if (ts->ps->api_states[i]) {
-                ts->ps->api_states[i]->destroy(ts->ps->api_states[i]);
+                ts->ps->api_states[i]->destroy(ts, ts->ps->api_states[i]);
                 ts->ps->api_states[i] = NULL;
             }
         }
     }
 
-    cur_ts = NULL;
-
     yagl_thread_set_buffer(ts, NULL);
 
     yagl_transport_destroy(ts->t);
index 0dfa297..c848914 100644 (file)
@@ -65,8 +65,6 @@ struct yagl_thread_state
      */
 };
 
-YAGL_DECLARE_TLS(struct yagl_thread_state*, cur_ts);
-
 struct yagl_thread_state
     *yagl_thread_state_create(struct yagl_process_state *ps,
                               yagl_tid id,
index ce1a841..0ae51d2 100644 (file)
@@ -172,7 +172,7 @@ uint8_t *yagl_transport_begin(struct yagl_transport *t,
         uint32_t size = yagl_transport_uint32_t_at(t,
             YAGL_TRANSPORT_BATCH_HEADER_SIZE + *batch_size + ((2 * i + 1) * 8));
 
-        if (!yagl_mem_get(va, size, tmp)) {
+        if (!yagl_mem_get(t->ts, va, size, tmp)) {
             yagl_transport_uint32_t_to(t, 0, yagl_call_result_retry);
             g_free(batch_data);
             return NULL;
@@ -200,7 +200,8 @@ void yagl_transport_end(struct yagl_transport *t)
         struct yagl_transport_in_array *in_array = &t->in_arrays[i];
 
         if ((*in_array->count > 0) && t->direct) {
-            if (!yagl_mem_put(in_array->va,
+            if (!yagl_mem_put(t->ts,
+                              in_array->va,
                               yagl_vector_data(&in_array->v),
                               *in_array->count * in_array->el_size)) {
                 yagl_transport_uint32_t_to(t, 0, yagl_call_result_retry);
@@ -210,7 +211,7 @@ void yagl_transport_end(struct yagl_transport *t)
     }
 
     QLIST_FOREACH_SAFE(ct, &t->compiled_transfers, entry, tmp) {
-        yagl_compiled_transfer_prepare(ct);
+        yagl_compiled_transfer_prepare(t->ts, ct);
     }
 
     t->direct = false;
@@ -339,14 +340,15 @@ void yagl_transport_get_in_array(struct yagl_transport *t,
     }
 }
 
-const char **yagl_transport_get_out_string_array(const char *data,
+const char **yagl_transport_get_out_string_array(struct yagl_transport *t,
+                                                 const char *data,
                                                  int32_t data_count,
                                                  int32_t *array_count)
 {
     struct yagl_vector v;
     char *tmp;
 
-    YAGL_LOG_FUNC_SET(yagl_transport_get_out_string_array);
+    YAGL_LOG_FUNC_SET_TS(yagl_transport_get_out_string_array, t->ts);
 
     if (!data) {
         *array_count = 0;
index 8fe9ec6..2aeea53 100644 (file)
@@ -61,6 +61,7 @@ struct yagl_transport
      */
 
     uint8_t **pages;
+    struct yagl_thread_state *ts;
 
     /*
      * @}
@@ -136,7 +137,8 @@ void yagl_transport_get_in_array(struct yagl_transport *t,
                                  int32_t *maxcount,
                                  int32_t **count);
 
-const char **yagl_transport_get_out_string_array(const char *data,
+const char **yagl_transport_get_out_string_array(struct yagl_transport *t,
+                                                 const char *data,
                                                  int32_t data_count,
                                                  int32_t *array_count);
 
index f7a76f8..bddd6a4 100644 (file)
@@ -42,6 +42,8 @@ typedef uint32_t yagl_object_name;
 typedef uint32_t yagl_winsys_id;
 
 struct yagl_transport;
+struct yagl_thread_state;
+struct yagl_process_state;
 
 /*
  * YaGL supported render types.