[Mesa-dev] [PATCH 1/2] mesa: Refactor handling of extension strings
Chad Versace
chad at chad-versace.us
Mon Jan 10 10:42:00 PST 2011
On 01/10/2011 07:18 AM, Brian Paul wrote:
> Why not just defined the GL, ES1 and ES2 bits to be 1 << gl_api like this:
>
> GL = 1 << API_OPENGL
> ES1 = 1 << API_OPENGLES
> ES2 = 1 << API_OPENGLES2
>
> That'd make api_bit() trivial.
Ah, I've never seen that trick before: bit-shifing on enum values. I've
accordingly modified patch 1/2 by amending the following:
[Beware of Thunderbird line wraps...]
@@ -37,22 +37,9 @@
#include "mfeatures.h"
#include "mtypes.h"
-static const uint8_t GL = 1 << 0;
-static const uint8_t ES1 = 1 << 1;
-static const uint8_t ES2 = 1 << 2;
-
-static unsigned
-api_bit(struct gl_context* ctx)
-{
- switch(ctx->API) {
- case API_OPENGL: return GL;
- case API_OPENGLES: return ES1;
- case API_OPENGLES2: return ES2;
- default:
- assert(0);
- return 0;
- }
-}
+static const uint8_t GL = 1 << API_OPENGL;
+static const uint8_t ES1 = 1 << API_OPENGLES;
+static const uint8_t ES2 = 1 << API_OPENGLES2;
/**
* \brief An element of the \c extension_table.
@@ -841,7 +828,7 @@ _mesa_make_extension_string(struct gl_context *ctx)
/* Compute length of the extension string. */
for (const struct extension *i = extension_table; i->name != 0; ++i) {
- if (base[i->offset] && (i->api_set & api_bit(ctx))) {
+ if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
length += strlen(i->name) + 1; /* +1 for space */
}
}
@@ -857,7 +844,7 @@ _mesa_make_extension_string(struct gl_context *ctx)
/* Build the extension string.*/
for (const struct extension *i = extension_table; i->name != 0; ++i) {
- if (base[i->offset] && (i->api_set & api_bit(ctx))) {
+ if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
strcat(exts, i->name);
strcat(exts, " ");
}
--------------------------------------------------------------------------
>> + { 0, 0, 0, },
>
> Some compilers will complain about the trailing comma after the 0 there.
Trailing comma has been removed.
--
Chad Versace
chad.versace at intel.com
chad at chad-versace.us
More information about the mesa-dev
mailing list