return table;
}
-void
+/**
+ * Allocate dispatch tables and set all functions to nop.
+ * It also makes the OutsideBeginEnd dispatch table current within gl_dispatch.
+ *
+ * \param glthread Whether to set nop dispatch for glthread or regular dispatch
+ */
+bool
+_mesa_alloc_dispatch_tables(gl_api api, struct gl_dispatch *d, bool glthread)
+{
+ d->OutsideBeginEnd = _mesa_alloc_dispatch_table(glthread);
+ if (!d->OutsideBeginEnd)
+ return false;
+
+ if (api == API_OPENGL_COMPAT) {
+ d->BeginEnd = _mesa_alloc_dispatch_table(glthread);
+ d->Save = _mesa_alloc_dispatch_table(glthread);
+ if (!d->BeginEnd || !d->Save)
+ return false;
+ }
+
+ d->Current = d->Exec = d->OutsideBeginEnd;
+ return true;
+}
+
+static void
+_mesa_free_dispatch_tables(struct gl_dispatch *d)
+{
+ free(d->OutsideBeginEnd);
+ free(d->BeginEnd);
+ free(d->HWSelectModeBeginEnd);
+ free(d->Save);
+ free(d->ContextLost);
+}
+
+bool
_mesa_initialize_dispatch_tables(struct gl_context *ctx)
{
- /* Do the code-generated setup of the exec table in api_exec_init.c. */
+ if (!_mesa_alloc_dispatch_tables(ctx->API, &ctx->Dispatch, false))
+ return false;
+
+ /* Do the code-generated initialization of dispatch tables. */
_mesa_init_dispatch(ctx);
+ vbo_init_dispatch_begin_end(ctx);
- if (ctx->Dispatch.Save)
+ if (_mesa_is_desktop_gl_compat(ctx)) {
_mesa_init_dispatch_save(ctx);
-
- vbo_init_dispatch_begin_end(ctx);
- if (_mesa_is_desktop_gl_compat(ctx))
_mesa_init_dispatch_save_begin_end(ctx);
+ }
+
+ /* This binds the dispatch table to the context, but MakeCurrent will
+ * bind it for the user. If glthread is enabled, it will override it.
+ */
+ ctx->GLApi = ctx->Dispatch.Current;
+ return true;
}
/**
if (no_error)
ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
- /* setup the API dispatch tables with all nop functions */
- ctx->Dispatch.OutsideBeginEnd = _mesa_alloc_dispatch_table(false);
- if (!ctx->Dispatch.OutsideBeginEnd)
- goto fail;
- ctx->Dispatch.Exec = ctx->Dispatch.OutsideBeginEnd;
- ctx->GLApi = ctx->Dispatch.Current = ctx->Dispatch.OutsideBeginEnd;
-
_mesa_reset_vertex_processing_mode(ctx);
/* Mesa core handles all the formats that mesa core knows about.
switch (ctx->API) {
case API_OPENGL_COMPAT:
- ctx->Dispatch.BeginEnd = _mesa_alloc_dispatch_table(false);
- ctx->Dispatch.Save = _mesa_alloc_dispatch_table(false);
- if (!ctx->Dispatch.BeginEnd || !ctx->Dispatch.Save)
- goto fail;
-
- FALLTHROUGH;
case API_OPENGL_CORE:
case API_OPENGLES2:
break;
fail:
_mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
- free(ctx->Dispatch.BeginEnd);
- free(ctx->Dispatch.OutsideBeginEnd);
- free(ctx->Dispatch.Save);
return GL_FALSE;
}
_mesa_free_buffer_objects(ctx);
/* free dispatch tables */
- free(ctx->Dispatch.BeginEnd);
- free(ctx->Dispatch.OutsideBeginEnd);
- free(ctx->Dispatch.Save);
- free(ctx->Dispatch.ContextLost);
+ _mesa_free_dispatch_tables(&ctx->Dispatch);
free(ctx->MarshalExec);
- free(ctx->Dispatch.HWSelectModeBeginEnd);
/* Shared context state (display lists, textures, etc) */
_mesa_reference_shared_state(ctx, &ctx->Shared, NULL);