From 4531356817ec8383ac35932903773de67af92e37 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 10 Sep 2010 10:31:06 +0800 Subject: gallium: Add context profile support to st_api. Add struct st_context_attribs to describe context profiles and attributes. Modify st_api::create_context to take the new struct instead of an st_visual. st_context_attribs can be used to support GLX_ARB_create_context_profile and GLX_EXT_create_context_es2_profile in the future. But the motivation for doing it now is to be able to replace ST_API_OPENGL_ES1 and ST_API_OPENGL_ES2 by profiles. Having 3 st_api's to provide OpenGL, OpenGL ES 1.1, and OpenGL ES 2.0 is not a sane abstraction, since all of them share glapi for current context/dispatch management. --- src/mesa/main/version.c | 6 ++- src/mesa/state_tracker/st_manager.c | 75 +++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 21 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c index d833a160e9..9e1f5f2a4f 100644 --- a/src/mesa/main/version.c +++ b/src/mesa/main/version.c @@ -260,11 +260,15 @@ compute_version_es2(GLcontext *ctx) /** * Set the context's VersionMajor, VersionMinor, VersionString fields. - * This should only be called once as part of context initialization. + * This should only be called once as part of context initialization + * or to perform version check for GLX_ARB_create_context_profile. */ void _mesa_compute_version(GLcontext *ctx) { + if (ctx->VersionMajor) + return; + switch (ctx->API) { case API_OPENGL: compute_version(ctx); diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c index ccce574c36..8acd0938bb 100644 --- a/src/mesa/state_tracker/st_manager.c +++ b/src/mesa/state_tracker/st_manager.c @@ -44,6 +44,7 @@ #include "main/framebuffer.h" #include "main/fbobject.h" #include "main/renderbuffer.h" +#include "main/version.h" #include "st_texture.h" #include "st_context.h" @@ -303,10 +304,6 @@ st_visual_to_context_mode(const struct st_visual *visual, { memset(mode, 0, sizeof(*mode)); - /* FBO-only context */ - if (!visual) - return; - if (st_visual_have_buffers(visual, ST_ATTACHMENT_BACK_LEFT_MASK)) mode->doubleBufferMode = GL_TRUE; if (st_visual_have_buffers(visual, @@ -612,26 +609,57 @@ st_context_destroy(struct st_context_iface *stctxi) } static struct st_context_iface * -create_context(gl_api api, struct st_manager *smapi, - const struct st_visual *visual, - struct st_context_iface *shared_stctxi) +st_api_create_context(struct st_api *stapi, struct st_manager *smapi, + const struct st_context_attribs *attribs, + struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; __GLcontextModes mode; + gl_api api; + + if (!(stapi->profile_mask & (1 << attribs->profile))) + return NULL; + + switch (attribs->profile) { + case ST_PROFILE_DEFAULT: + api = API_OPENGL; + break; + case ST_PROFILE_OPENGL_ES1: + api = API_OPENGLES; + break; + case ST_PROFILE_OPENGL_ES2: + api = API_OPENGLES2; + break; + case ST_PROFILE_OPENGL_CORE: + default: + return NULL; + break; + } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) return NULL; - st_visual_to_context_mode(visual, &mode); + st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx); if (!st) { pipe->destroy(pipe); return NULL; } + /* need to perform version check */ + if (attribs->major > 1 || attribs->minor > 0) { + _mesa_compute_version(st->ctx); + + if (st->ctx->VersionMajor < attribs->major || + st->ctx->VersionMajor < attribs->minor) { + st_destroy_context(st); + return NULL; + } + } + st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); @@ -646,28 +674,20 @@ create_context(gl_api api, struct st_manager *smapi, return &st->iface; } -static struct st_context_iface * -st_api_create_context(struct st_api *stapi, struct st_manager *smapi, - const struct st_visual *visual, - struct st_context_iface *shared_stctxi) -{ - return create_context(API_OPENGL, smapi, visual, shared_stctxi); -} - static struct st_context_iface * st_api_create_context_es1(struct st_api *stapi, struct st_manager *smapi, - const struct st_visual *visual, + const struct st_context_attribs *attribs, struct st_context_iface *shared_stctxi) { - return create_context(API_OPENGLES, smapi, visual, shared_stctxi); + return st_api_create_context(stapi, smapi, attribs, shared_stctxi); } static struct st_context_iface * st_api_create_context_es2(struct st_api *stapi, struct st_manager *smapi, - const struct st_visual *visual, + const struct st_context_attribs *attribs, struct st_context_iface *shared_stctxi) { - return create_context(API_OPENGLES2, smapi, visual, shared_stctxi); + return st_api_create_context(stapi, smapi, attribs, shared_stctxi); } static boolean @@ -852,6 +872,17 @@ st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb, } static const struct st_api st_gl_api = { + ST_API_OPENGL, +#if FEATURE_GL + ST_PROFILE_DEFAULT_MASK | +#endif +#if FEATURE_ES1 + ST_PROFILE_OPENGL_ES1_MASK | +#endif +#if FEATURE_ES2 + ST_PROFILE_OPENGL_ES2_MASK | +#endif + 0, st_api_destroy, st_api_get_proc_address, st_api_create_context, @@ -860,6 +891,8 @@ static const struct st_api st_gl_api = { }; static const struct st_api st_gl_api_es1 = { + ST_API_OPENGL_ES1, + ST_PROFILE_OPENGL_ES1_MASK, st_api_destroy, st_api_get_proc_address, st_api_create_context_es1, @@ -868,6 +901,8 @@ static const struct st_api st_gl_api_es1 = { }; static const struct st_api st_gl_api_es2 = { + ST_API_OPENGL_ES2, + ST_PROFILE_OPENGL_ES2_MASK, st_api_destroy, st_api_get_proc_address, st_api_create_context_es2, -- cgit v1.2.3