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

Kenneth Graunke kenneth at whitecape.org
Thu Jul 26 23:52:56 PDT 2012


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))

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.

Also, I like Brian's idea of getting rid of VersionMajor and
VersionMinor.  In almost all cases, the combined Version field is nicer
to work with (as this series demonstrates), and if we need major/minor,
extracting those is trivial.  I almost always prefer to have one copy of
data, rather than two copies stored in different forms with code to
synchronize them.

This series is:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>


More information about the mesa-dev mailing list