clean up code related to dispatch table initialization

This commit is contained in:
Brian Paul 2004-11-27 05:05:32 +00:00
parent 13435525c4
commit 21f6978c53
5 changed files with 51 additions and 72 deletions

View file

@ -1390,6 +1390,45 @@ add_newer_entrypoints(void)
}
/**
* This is the default function we plug into all dispatch table slots
* This helps prevents a segfault when someone calls a GL function without
* first checking if the extension's supported.
*/
static int
generic_nop(void)
{
_mesa_problem(NULL, "User called no-op dispatch function (an unsupported extension function?)");
return 0;
}
/**
* Allocate and initialize a new dispatch table.
*/
static struct _glapi_table *
alloc_dispatch_table(void)
{
/* Find the larger of Mesa's dispatch table and libGL's dispatch table.
* In practice, this'll be the same for stand-alone Mesa. But for DRI
* Mesa we do this to accomodate different versions of libGL and various
* DRI drivers.
*/
GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
sizeof(struct _glapi_table) / sizeof(_glapi_proc));
struct _glapi_table *table =
(struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc));
if (table) {
_glapi_proc *entry = (_glapi_proc *) table;
GLuint i;
for (i = 0; i < numEntries; i++) {
entry[i] = (_glapi_proc) generic_nop;
}
}
return table;
}
/**
* Initialize a GLcontext struct (rendering context).
*
@ -1423,8 +1462,6 @@ _mesa_initialize_context( GLcontext *ctx,
const struct dd_function_table *driverFunctions,
void *driverContext )
{
GLuint dispatchSize;
ASSERT(driverContext);
assert(driverFunctions->NewTextureObject);
@ -1473,30 +1510,19 @@ _mesa_initialize_context( GLcontext *ctx,
/* libGL ABI coordination */
add_newer_entrypoints();
/* Find the larger of Mesa's dispatch table and libGL's dispatch table.
* In practice, this'll be the same for stand-alone Mesa. But for DRI
* Mesa we do this to accomodate different versions of libGL and various
* DRI drivers.
*/
dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
sizeof(struct _glapi_table) / sizeof(void *));
/* setup API dispatch tables */
ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
/* setup the API dispatch tables */
ctx->Exec = alloc_dispatch_table();
ctx->Save = alloc_dispatch_table();
if (!ctx->Exec || !ctx->Save) {
free_shared_state(ctx, ctx->Shared);
if (ctx->Exec)
FREE( ctx->Exec );
_mesa_free(ctx->Exec);
}
_mesa_init_exec_table(ctx->Exec, dispatchSize);
_mesa_init_exec_table(ctx->Exec);
ctx->CurrentDispatch = ctx->Exec;
#if _HAVE_FULL_GL
_mesa_init_dlist_table(ctx->Save, dispatchSize);
_mesa_init_dlist_table(ctx->Save);
_mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
/* Neutral tnl module stuff */
_mesa_init_exec_vtxfmt( ctx );
ctx->TnlModule.Current = NULL;

View file

@ -7154,10 +7154,8 @@ static void GLAPIENTRY exec_MultiModeDrawElementsIBM(const GLenum *mode,
* struct.
*/
void
_mesa_init_dlist_table( struct _glapi_table *table, GLuint tableSize )
_mesa_init_dlist_table( struct _glapi_table *table )
{
_mesa_init_no_op_table(table, tableSize);
_mesa_loopback_init_api_table( table );
/* GL 1.0 */

View file

@ -58,8 +58,7 @@ extern void GLAPIENTRY _mesa_ListBase( GLuint base );
extern void GLAPIENTRY _mesa_NewList( GLuint list, GLenum mode );
extern void _mesa_init_dlist_table( struct _glapi_table *table,
GLuint tableSize );
extern void _mesa_init_dlist_table( struct _glapi_table *table );
extern void _mesa_save_error( GLcontext *ctx, GLenum error, const char *s );

View file

@ -91,43 +91,6 @@
/**********************************************************************/
/** \name Dispatch table setup */
/*@{*/
/**
* Generic no-op dispatch function.
*
* Used in replacement of the functions which are not part of Mesa subset.
*
* Displays a message.
*/
static int
generic_noop(void)
{
_mesa_problem(NULL, "User called no-op dispatch function (an unsupported extension function?)");
return 0;
}
/**
* Set all pointers in the given dispatch table to point to a
* generic no-op function - generic_noop().
*
* \param table dispatch table.
* \param tableSize dispatch table size.
*/
void
_mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
{
GLuint i;
_glapi_proc *dispatch = (_glapi_proc *) table;
for (i = 0; i < tableSize; i++) {
dispatch[i] = (_glapi_proc) generic_noop;
}
}
/**
* Initialize a dispatch table with pointers to Mesa's immediate-mode
* commands.
@ -139,11 +102,8 @@ _mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
* \param tableSize dispatch table size.
*/
void
_mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
_mesa_init_exec_table(struct _glapi_table *exec)
{
/* first initialize all dispatch slots to no-op */
_mesa_init_no_op_table(exec, tableSize);
#if _HAVE_FULL_GL
_mesa_loopback_init_api_table( exec );
#endif
@ -787,7 +747,6 @@ _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
#endif /* FEATURE_ARB_shader_objects */
}
/*@}*/
/**********************************************************************/

View file

@ -5,9 +5,9 @@
/*
* Mesa 3-D graphics library
* Version: 3.5
* Version: 6.3
*
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -34,10 +34,7 @@
#include "mtypes.h"
extern void
_mesa_init_no_op_table(struct _glapi_table *exec, GLuint tableSize);
extern void
_mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize);
_mesa_init_exec_table(struct _glapi_table *exec);
extern void
_mesa_update_state( GLcontext *ctx );