From 2ab18d63cb71d988265eeab431e4363081978144 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Apr 2010 09:25:51 -0400 Subject: mesa: Track the OpenGL API we're implementing in the context This introduces a new way to create or initialize a context: _mesa_create_context_for_api and _mesa_initialize_context_for_api which in addition to the current arguments take an api enum to indicate which OpenGL API the context should implement. At this point the API field in GLcontext isn't used anywhere, but later commits will key certain functionality off of it. The _mesa_create_context and _mesa_initialize_context functions are kept in place as wrappers around the *_for_api versions, passing in API_OPENGL to get the same behavior as before. --- src/mesa/main/context.c | 52 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'src/mesa/main/context.c') diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 1707e229c9..87e5a88fad 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -791,6 +791,7 @@ alloc_dispatch_table(void) * for debug flags. * * \param ctx the context to initialize + * \param api the GL API type to create the context for * \param visual describes the visual attributes for this context * \param share_list points to context to share textures, display lists, * etc with, or NULL @@ -799,11 +800,12 @@ alloc_dispatch_table(void) * \param driverContext pointer to driver-specific context data */ GLboolean -_mesa_initialize_context(GLcontext *ctx, - const GLvisual *visual, - GLcontext *share_list, - const struct dd_function_table *driverFunctions, - void *driverContext) +_mesa_initialize_context_for_api(GLcontext *ctx, + gl_api api, + const GLvisual *visual, + GLcontext *share_list, + const struct dd_function_table *driverFunctions, + void *driverContext) { struct gl_shared_state *shared; @@ -814,6 +816,7 @@ _mesa_initialize_context(GLcontext *ctx, /* misc one-time initializations */ one_time_init(ctx); + ctx->API = api; ctx->Visual = *visual; ctx->DrawBuffer = NULL; ctx->ReadBuffer = NULL; @@ -892,6 +895,20 @@ _mesa_initialize_context(GLcontext *ctx, return GL_TRUE; } +GLboolean +_mesa_initialize_context(GLcontext *ctx, + const GLvisual *visual, + GLcontext *share_list, + const struct dd_function_table *driverFunctions, + void *driverContext) +{ + return _mesa_initialize_context_for_api(ctx, + API_OPENGL, + visual, + share_list, + driverFunctions, + driverContext); +} /** * Allocate and initialize a GLcontext structure. @@ -899,6 +916,7 @@ _mesa_initialize_context(GLcontext *ctx, * we need to at least call driverFunctions->NewTextureObject to initialize * the rendering context. * + * \param api the GL API type to create the context for * \param visual a GLvisual pointer (we copy the struct contents) * \param share_list another context to share display lists with or NULL * \param driverFunctions points to the dd_function_table into which the @@ -908,10 +926,11 @@ _mesa_initialize_context(GLcontext *ctx, * \return pointer to a new __GLcontextRec or NULL if error. */ GLcontext * -_mesa_create_context(const GLvisual *visual, - GLcontext *share_list, - const struct dd_function_table *driverFunctions, - void *driverContext) +_mesa_create_context_for_api(gl_api api, + const GLvisual *visual, + GLcontext *share_list, + const struct dd_function_table *driverFunctions, + void *driverContext) { GLcontext *ctx; @@ -922,8 +941,8 @@ _mesa_create_context(const GLvisual *visual, if (!ctx) return NULL; - if (_mesa_initialize_context(ctx, visual, share_list, - driverFunctions, driverContext)) { + if (_mesa_initialize_context_for_api(ctx, api, visual, share_list, + driverFunctions, driverContext)) { return ctx; } else { @@ -932,6 +951,17 @@ _mesa_create_context(const GLvisual *visual, } } +GLcontext * +_mesa_create_context(const GLvisual *visual, + GLcontext *share_list, + const struct dd_function_table *driverFunctions, + void *driverContext) +{ + return _mesa_create_context_for_api(API_OPENGL, visual, + share_list, + driverFunctions, + driverContext); +} /** * Free the data associated with the given context. -- cgit v1.2.3 From 218ceb3e1874a5a28f36a8df3ca0e881cdf213d5 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Apr 2010 11:07:45 -0400 Subject: mesa: Move API specific context intialization into context.c --- src/mesa/es/main/specials_es1.c | 21 --------------------- src/mesa/es/main/specials_es2.c | 10 ---------- src/mesa/main/context.c | 28 +++++++++++++++++++++++++--- src/mesa/main/context.h | 3 --- 4 files changed, 25 insertions(+), 37 deletions(-) (limited to 'src/mesa/main/context.c') diff --git a/src/mesa/es/main/specials_es1.c b/src/mesa/es/main/specials_es1.c index 92e24a03fe..88f77177c8 100644 --- a/src/mesa/es/main/specials_es1.c +++ b/src/mesa/es/main/specials_es1.c @@ -195,24 +195,3 @@ _es_GetString(GLenum name) return _mesa_GetString(name); } } - - -void -_mesa_initialize_context_extra(GLcontext *ctx) -{ - GLuint i; - - /** - * GL_OES_texture_cube_map says - * "Initially all texture generation modes are set to REFLECTION_MAP_OES" - */ - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i]; - texUnit->GenS.Mode = GL_REFLECTION_MAP_NV; - texUnit->GenT.Mode = GL_REFLECTION_MAP_NV; - texUnit->GenR.Mode = GL_REFLECTION_MAP_NV; - texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV; - texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV; - texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV; - } -} diff --git a/src/mesa/es/main/specials_es2.c b/src/mesa/es/main/specials_es2.c index 046cda6fc1..75ceaff2c2 100644 --- a/src/mesa/es/main/specials_es2.c +++ b/src/mesa/es/main/specials_es2.c @@ -167,13 +167,3 @@ _es_GetString(GLenum name) return _mesa_GetString(name); } } - - -void -_mesa_initialize_context_extra(GLcontext *ctx) -{ - ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; - - ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */ -} diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 87e5a88fad..25288a4e9c 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -808,6 +808,7 @@ _mesa_initialize_context_for_api(GLcontext *ctx, void *driverContext) { struct gl_shared_state *shared; + int i; /*ASSERT(driverContext);*/ assert(driverFunctions->NewTextureObject); @@ -886,9 +887,30 @@ _mesa_initialize_context_for_api(GLcontext *ctx, ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; } -#if FEATURE_extra_context_init - _mesa_initialize_context_extra(ctx); -#endif + switch (ctx->API) { + case API_OPENGL: + break; + case API_OPENGLES: + /** + * GL_OES_texture_cube_map says + * "Initially all texture generation modes are set to REFLECTION_MAP_OES" + */ + for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i]; + texUnit->GenS.Mode = GL_REFLECTION_MAP_NV; + texUnit->GenT.Mode = GL_REFLECTION_MAP_NV; + texUnit->GenR.Mode = GL_REFLECTION_MAP_NV; + texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV; + texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV; + texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV; + } + break; + case API_OPENGLES2: + ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; + ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */ + break; + } ctx->FirstTimeCurrent = GL_TRUE; diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index e9405c8bc2..c9f4d433a5 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -127,9 +127,6 @@ _mesa_initialize_context_for_api(GLcontext *ctx, const struct dd_function_table *driverFunctions, void *driverContext); -extern void -_mesa_initialize_context_extra(GLcontext *ctx); - extern void _mesa_free_context_data( GLcontext *ctx ); -- cgit v1.2.3 From fa416106307dc193e2133aa6a29b9bcfc91f8b39 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Apr 2010 12:40:47 -0400 Subject: mesa: Move struct _glapi_table allocation out of context.c We now allocate the table from api_exec.c and dlist.c where we fill out the table. This way, context.c doesn't need to know the actual contents of struct _glapi_table. --- src/mesa/es/main/es_generator.py | 12 ++++++++++-- src/mesa/main/api_exec.c | 12 ++++++++++-- src/mesa/main/api_exec.h | 6 ++++-- src/mesa/main/context.c | 26 +++++++++++++------------- src/mesa/main/dlist.c | 12 ++++++++++-- src/mesa/main/dlist.h | 2 +- 6 files changed, 48 insertions(+), 22 deletions(-) (limited to 'src/mesa/main/context.c') diff --git a/src/mesa/es/main/es_generator.py b/src/mesa/es/main/es_generator.py index f736792dec..dbb516a4c1 100644 --- a/src/mesa/es/main/es_generator.py +++ b/src/mesa/es/main/es_generator.py @@ -667,9 +667,15 @@ for funcName in keys: # end for each function -print "void" -print "_mesa_init_exec_table(struct _glapi_table *exec)" +print "struct _glapi_table *" +print "_mesa_create_exec_table(void)" print "{" +print " struct _glapi_table *exec;" +print " exec = _mesa_alloc_dispatch_table(sizeof *exec);" +print " if (exec == NULL)" +print " return NULL;" +print "" + for func in keys: prefix = "_es_" if func not in allSpecials else "_check_" for spec in apiutil.Categories(func): @@ -682,4 +688,6 @@ for func in keys: suffix = ext[0].split("_")[0] entry += suffix print " SET_%s(exec, %s%s);" % (entry, prefix, entry) +print "" +print " return exec;" print "}" diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c index 1e1aa41611..7b3f3d9ea1 100644 --- a/src/mesa/main/api_exec.c +++ b/src/mesa/main/api_exec.c @@ -119,9 +119,15 @@ * \param ctx GL context to which \c exec belongs. * \param exec dispatch table. */ -void -_mesa_init_exec_table(struct _glapi_table *exec) +struct _glapi_table * +_mesa_create_exec_table(void) { + struct _glapi_table *exec; + + exec = _mesa_alloc_dispatch_table(sizeof *exec); + if (exec == NULL) + return NULL; + #if _HAVE_FULL_GL _mesa_loopback_init_api_table( exec ); #endif @@ -777,4 +783,6 @@ _mesa_init_exec_table(struct _glapi_table *exec) SET_ObjectUnpurgeableAPPLE(exec, _mesa_ObjectUnpurgeableAPPLE); SET_GetObjectParameterivAPPLE(exec, _mesa_GetObjectParameterivAPPLE); #endif + + return exec; } diff --git a/src/mesa/main/api_exec.h b/src/mesa/main/api_exec.h index 4bd715053a..dd8d500865 100644 --- a/src/mesa/main/api_exec.h +++ b/src/mesa/main/api_exec.h @@ -29,9 +29,11 @@ struct _glapi_table; +extern struct _glapi_table * +_mesa_alloc_dispatch_table(int size); -extern void -_mesa_init_exec_table(struct _glapi_table *exec); +extern struct _glapi_table * +_mesa_create_exec_table(void); #endif diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 25288a4e9c..8d71cefdcf 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -129,8 +129,6 @@ #include "version.h" #include "viewport.h" #include "vtxfmt.h" -#include "glapi/glthread.h" -#include "glapi/glapitable.h" #include "shader/program.h" #include "shader/prog_print.h" #include "shader/shader_api.h" @@ -749,8 +747,8 @@ generic_nop(void) /** * Allocate and initialize a new dispatch table. */ -static struct _glapi_table * -alloc_dispatch_table(void) +struct _glapi_table * +_mesa_alloc_dispatch_table(int size) { /* 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 @@ -758,7 +756,7 @@ alloc_dispatch_table(void) * DRI drivers. */ GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), - sizeof(struct _glapi_table) / sizeof(_glapi_proc)); + size / sizeof(_glapi_proc)); struct _glapi_table *table = (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc)); if (table) { @@ -853,22 +851,24 @@ _mesa_initialize_context_for_api(GLcontext *ctx, return GL_FALSE; } +#if FEATURE_dispatch /* setup the API dispatch tables */ - ctx->Exec = alloc_dispatch_table(); - ctx->Save = alloc_dispatch_table(); - if (!ctx->Exec || !ctx->Save) { + ctx->Exec = _mesa_create_exec_table(); + if (!ctx->Exec) { _mesa_release_shared_state(ctx, ctx->Shared); - if (ctx->Exec) - free(ctx->Exec); return GL_FALSE; } -#if FEATURE_dispatch - _mesa_init_exec_table(ctx->Exec); #endif ctx->CurrentDispatch = ctx->Exec; #if FEATURE_dlist - _mesa_init_save_table(ctx->Save); + ctx->Save = _mesa_create_save_table(); + if (!ctx->Save) { + _mesa_release_shared_state(ctx, ctx->Shared); + free(ctx->Exec); + return GL_FALSE; + } + _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); #endif diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index f869a585d6..168c424ea1 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -8747,9 +8747,15 @@ exec_MultiModeDrawElementsIBM(const GLenum * mode, * initialized from _mesa_init_api_defaults and from the active vtxfmt * struct. */ -void -_mesa_init_save_table(struct _glapi_table *table) +struct _glapi_table * +_mesa_create_save_table(void) { + struct _glapi_table *table; + + table = _mesa_alloc_dispatch_table(sizeof *table); + if (table == NULL) + return NULL; + _mesa_loopback_init_api_table(table); /* GL 1.0 */ @@ -9349,6 +9355,8 @@ _mesa_init_save_table(struct _glapi_table *table) (void) save_ClearBufferfv; (void) save_ClearBufferfi; #endif + + return table; } diff --git a/src/mesa/main/dlist.h b/src/mesa/main/dlist.h index f37a93a7f4..f8255facc5 100644 --- a/src/mesa/main/dlist.h +++ b/src/mesa/main/dlist.h @@ -72,7 +72,7 @@ extern void _mesa_delete_list(GLcontext *ctx, struct gl_display_list *dlist); extern void _mesa_save_vtxfmt_init( GLvertexformat *vfmt ); -extern void _mesa_init_save_table( struct _glapi_table *table ); +extern struct _glapi_table *_mesa_create_save_table(void); extern void _mesa_install_dlist_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt); -- cgit v1.2.3 From ea0c7e71638a4a72a4eae962e6cc471bd33a5605 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Apr 2010 20:26:51 -0400 Subject: mesa: Move api_exec_es*.c into mesa/main This requires renaming a few functions to have unique names so that they can all live within the same driver. --- src/mesa/Makefile | 6 + src/mesa/es/Makefile | 8 - src/mesa/es/main/APIspec.dtd | 52 - src/mesa/es/main/APIspec.py | 617 ------ src/mesa/es/main/APIspec.xml | 4336 -------------------------------------- src/mesa/es/main/APIspecutil.py | 265 --- src/mesa/es/main/es_generator.py | 719 ------- src/mesa/es/sources.mak | 2 - src/mesa/main/APIspec.dtd | 52 + src/mesa/main/APIspec.py | 617 ++++++ src/mesa/main/APIspec.xml | 4336 ++++++++++++++++++++++++++++++++++++++ src/mesa/main/APIspecutil.py | 265 +++ src/mesa/main/api_exec.h | 6 + src/mesa/main/context.c | 48 +- src/mesa/main/es_generator.py | 726 +++++++ src/mesa/main/remap.h | 33 + src/mesa/sources.mak | 2 + 17 files changed, 6086 insertions(+), 6004 deletions(-) delete mode 100644 src/mesa/es/main/APIspec.dtd delete mode 100644 src/mesa/es/main/APIspec.py delete mode 100644 src/mesa/es/main/APIspec.xml delete mode 100644 src/mesa/es/main/APIspecutil.py delete mode 100644 src/mesa/es/main/es_generator.py create mode 100644 src/mesa/main/APIspec.dtd create mode 100644 src/mesa/main/APIspec.py create mode 100644 src/mesa/main/APIspec.xml create mode 100644 src/mesa/main/APIspecutil.py create mode 100644 src/mesa/main/es_generator.py (limited to 'src/mesa/main/context.c') diff --git a/src/mesa/Makefile b/src/mesa/Makefile index 8c0ebf84c4..7dcde5275e 100644 --- a/src/mesa/Makefile +++ b/src/mesa/Makefile @@ -24,6 +24,12 @@ default: depend asm_subdirs glsl_builtin libmesa.a libmesagallium.a \ libglapi.a driver_subdirs +main/api_exec_es1.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py + $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES1.1 > $@ + +main/api_exec_es2.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py + $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES2.0 > $@ + ###################################################################### # Helper libraries used by many drivers: diff --git a/src/mesa/es/Makefile b/src/mesa/es/Makefile index 8b484853af..b095620c9d 100644 --- a/src/mesa/es/Makefile +++ b/src/mesa/es/Makefile @@ -83,17 +83,9 @@ libes2api.a: $(ES2_API_OBJECTS) @$(MKLIB) -o es2api -static $(ES2_API_OBJECTS) GENERATED_SOURCES := \ - main/api_exec_es1.c \ - main/api_exec_es2.c \ main/get_es1.c \ main/get_es2.c -main/api_exec_es1.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py - $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES1.1 > $@ - -main/api_exec_es2.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py - $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES2.0 > $@ - main/get_es1.c: main/get_gen.py $(PYTHON2) $(PYTHON_FLAGS) $< 1 > $@ diff --git a/src/mesa/es/main/APIspec.dtd b/src/mesa/es/main/APIspec.dtd deleted file mode 100644 index efcfa31f10..0000000000 --- a/src/mesa/es/main/APIspec.dtd +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/es/main/APIspec.py b/src/mesa/es/main/APIspec.py deleted file mode 100644 index 6947f7301c..0000000000 --- a/src/mesa/es/main/APIspec.py +++ /dev/null @@ -1,617 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2009 Chia-I Wu -# -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# on the rights to use, copy, modify, merge, publish, distribute, sub -# license, and/or sell copies of the Software, and to permit persons to whom -# the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice (including the next -# paragraph) shall be included in all copies or substantial portions of the -# Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL -# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -""" -A parser for APIspec. -""" - -class SpecError(Exception): - """Error in the spec file.""" - - -class Spec(object): - """A Spec is an abstraction of the API spec.""" - - def __init__(self, doc): - self.doc = doc - - self.spec_node = doc.getRootElement() - self.tmpl_nodes = {} - self.api_nodes = {} - self.impl_node = None - - # parse - node = self.spec_node.children - while node: - if node.type == "element": - if node.name == "template": - self.tmpl_nodes[node.prop("name")] = node - elif node.name == "api": - self.api_nodes[node.prop("name")] = node - else: - raise SpecError("unexpected node %s in apispec" % - node.name) - node = node.next - - # find an implementation - for name, node in self.api_nodes.iteritems(): - if node.prop("implementation") == "true": - self.impl_node = node - break - if not self.impl_node: - raise SpecError("unable to find an implementation") - - def get_impl(self): - """Return the implementation.""" - return API(self, self.impl_node) - - def get_api(self, name): - """Return an API.""" - return API(self, self.api_nodes[name]) - - -class API(object): - """An API consists of categories and functions.""" - - def __init__(self, spec, api_node): - self.name = api_node.prop("name") - self.is_impl = (api_node.prop("implementation") == "true") - - self.categories = [] - self.functions = [] - - # parse - func_nodes = [] - node = api_node.children - while node: - if node.type == "element": - if node.name == "category": - cat = node.prop("name") - self.categories.append(cat) - elif node.name == "function": - func_nodes.append(node) - else: - raise SpecError("unexpected node %s in api" % node.name) - node = node.next - - # realize functions - for func_node in func_nodes: - tmpl_node = spec.tmpl_nodes[func_node.prop("template")] - try: - func = Function(tmpl_node, func_node, self.is_impl, - self.categories) - except SpecError, e: - func_name = func_node.prop("name") - raise SpecError("failed to parse %s: %s" % (func_name, e)) - self.functions.append(func) - - def match(self, func, conversions={}): - """Find a matching function in the API.""" - match = None - need_conv = False - for f in self.functions: - matched, conv = f.match(func, conversions) - if matched: - match = f - need_conv = conv - # exact match - if not need_conv: - break - return (match, need_conv) - - -class Function(object): - """Parse and realize a