[Mesa-dev] [PATCH 1/4] mesa: Add a Version field to the context with VersionMajor*10+VersionMinor.

Brian Paul brianp at vmware.com
Fri Jul 27 06:47:01 PDT 2012


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<kenneth at whitecape.org>  wrote:
>>> On 07/26/2012 05:54 PM, Jordan Justen wrote:
>>>> On Thu, Jul 26, 2012 at 5:27 PM, Eric Anholt<eric at 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;
}

-Brian


More information about the mesa-dev mailing list