On Fri, Jul 27, 2012 at 6:47 AM, Brian Paul <bri...@vmware.com> wrote: > On 07/27/2012 01:51 AM, Kenneth Graunke wrote: >> >> On 07/27/2012 12:19 AM, Jordan Justen wrote: >>> >>> On Thu, Jul 26, 2012 at 11:52 PM, Kenneth Graunke<kenn...@whitecape.org> >>> wrote: >>>> >>>> On 07/26/2012 05:54 PM, Jordan Justen wrote: >>>>> >>>>> On Thu, Jul 26, 2012 at 5:27 PM, Eric Anholt<e...@anholt.net> wrote: >>>>>> >>>>>> As we get into supporting GL 3.x core, we come across more and more >>>>>> features >>>>>> of the API that depend on the version number as opposed to just the >>>>>> extension >>>>>> list. This will let us more sanely do version checks than >>>>>> "(VersionMajor == 3 >>>>>> && VersionMinor>= 2) || VersionMajor>= 4". >>>>>> --- >>>>>> src/mesa/main/mtypes.h | 2 ++ >>>>>> src/mesa/main/version.c | 6 ++++++ >>>>>> 2 files changed, 8 insertions(+) >>>>>> >>>>>> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h >>>>>> index 3d59dc6..23d32a6 100644 >>>>>> --- a/src/mesa/main/mtypes.h >>>>>> +++ b/src/mesa/main/mtypes.h >>>>>> @@ -3427,6 +3427,8 @@ struct gl_context >>>>>> >>>>>> /** Version info */ >>>>>> GLuint VersionMajor, VersionMinor; >>>>>> + /** VersionMajor * 10 + VersionMinor, so 31 for GL 3.1. */ >>>>>> + GLuint Version; >>>>>> char *VersionString; >>>>>> >>>>>> /** \name State attribute stack (for glPush/PopAttrib) */ >>>>>> diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c >>>>>> index efaaf58..697758e 100644 >>>>>> --- a/src/mesa/main/version.c >>>>>> +++ b/src/mesa/main/version.c >>>>>> @@ -223,6 +223,8 @@ compute_version(struct gl_context *ctx) >>>>>> >>>>>> override_version(ctx,&ctx->VersionMajor,&ctx->VersionMinor); >>>>>> >>>>>> >>>>>> + ctx->Version = ctx->VersionMajor * 10 + ctx->VersionMinor; >>>>> >>>>> >>>>> How about a macro rather than coding the *10 everywhere? >>>>> #define UINT_VERSION(major, minor) ((10*(major)) + (minor)) >>> >>> >>> I'm not too happy with UINT_VERSION, so maybe GLVER could be a less >>> verbose option. >>> >>>> Personally I like the major * 10 + minor version, as its clear what it >>>> does. But I wouldn't object too strongly to a macro or inline function >>>> either. >>> >>> >>> I guess history would seem to indicate that a minor> 9 is unlikely, >>> but is this guaranteed? >> >> >> It does seem very unlikely, given the speed at which major change comes, >> but I guess I couldn't say it's impossible. >> >>> Personally, I would prefer: >>> if (ctx->Version< GLVER(major, minor)) >>> over >>> if (ctx->Version< major * 10 + minor) >>> >>> And, I would prefer: >>> if (ctx->Version< GLVER(3, 1)) >>> over >>> if (ctx->Version< 31) >> >> >> Yeah, that is definitely more future-proof than relying on 2-digit math. >> I'd be fine with either approach. > > > How about a simple inline helper function like this: > > /** > * Check if the OpenGL version is greater than or equal to "major.minor" > */ > static inline GLboolean > _mesa_have_version(const struct gl_context *ctx, int major, int minor) > { > return ctx->Version >= major * 10 + minor; > }
Yeah, that seems good: if (!_mesa_have_version(ctx, major, minor)) if (!_mesa_have_version(ctx, 3, 1)) /* ver < 3.1 */ And, can we add this nearby so both are easily changed: static inline void _mesa_set_version(struct gl_context *ctx, int major, int minor) { ctx->Version = major * 10 + minor; } -Jordan _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev