[Mesa-dev] [PATCH 1/4] mesa: Add a Version field to the context with VersionMajor*10+VersionMinor.
Jordan Justen
jljusten at gmail.com
Fri Jul 27 00:19:43 PDT 2012
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?
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)
> 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.
Agreed.
> This series is:
> Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Same here,
Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
More information about the mesa-dev
mailing list