Skip to content

Commit

Permalink
Added MOJOSHADER_glAvailableProfiles().
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Jul 3, 2008
1 parent 097a5d0 commit 918f621
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 19 deletions.
31 changes: 29 additions & 2 deletions mojoshader.h
Expand Up @@ -434,9 +434,36 @@ typedef struct MOJOSHADER_glProgram MOJOSHADER_glProgram;


/*
* Determine the best profile to use for the current system.
* Get a list of available profiles. This will fill in the array (profs)
* with up to (size) pointers of profiles that the current system can handle;
* that is, the profiles are built into MojoShader and the OpenGL extensions
* required for them exist at runtime. This function returns the number of
* available profiles, which may be more, less, or equal to (size).
*
* You do not need to call this if all you want is MOJOSHADER_parse().
* If there are more than (size) profiles, the (profs) buffer will not
* overflow. You can check the return value for the total number of
* available profiles, allocate more space, and try again if necessary.
* Calling this function with (size) == 0 is legal.
*
* You can only call this AFTER you have successfully built your GL context
* and made it current. This function will lookup the GL functions it needs
* through the callback you supply. The lookup function is neither stored nor
* used by MojoShader after this function returns, nor are the functions it
* might look up.
*
* You should not free any strings returned from this function; they are
* pointers to internal, probably static, memory.
*
* This call is NOT thread safe! As most OpenGL implementations are not thread
* safe, you should probably only call this from the same thread that created
* the GL context.
*/
int MOJOSHADER_glAvailableProfiles(void *(*lookup)(const char *fnname),
const char **profs, const int size);


/*
* Determine the best profile to use for the current system.
*
* You can only call this AFTER you have successfully built your GL context
* and made it current. This function will lookup the GL functions it needs
Expand Down
51 changes: 34 additions & 17 deletions mojoshader_opengl.c
Expand Up @@ -804,9 +804,22 @@ static int valid_profile(const char *profile)
} // valid_profile


const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname))
static const char *profile_priorities[] = {
#if SUPPORT_PROFILE_GLSL
MOJOSHADER_PROFILE_GLSL120,
MOJOSHADER_PROFILE_GLSL,
#endif
#if SUPPORT_PROFILE_ARB1
MOJOSHADER_PROFILE_NV3,
MOJOSHADER_PROFILE_NV2,
MOJOSHADER_PROFILE_ARB1,
#endif
};

int MOJOSHADER_glAvailableProfiles(void *(*lookup)(const char *fnname),
const char **profs, const int size)
{
const char *retval = NULL;
int retval = 0;
MOJOSHADER_glContext _ctx;
MOJOSHADER_glContext *current_ctx = ctx;

Expand All @@ -816,32 +829,36 @@ const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname))

if (ctx->have_base_opengl)
{
static const char *priority[] = {
MOJOSHADER_PROFILE_GLSL120,
MOJOSHADER_PROFILE_GLSL,
MOJOSHADER_PROFILE_NV3,
MOJOSHADER_PROFILE_NV2,
MOJOSHADER_PROFILE_ARB1,
};

int i;
for (i = 0; i < STATICARRAYLEN(priority); i++)
for (i = 0; i < STATICARRAYLEN(profile_priorities); i++)
{
// !!! FIXME: if Mac OS X <= 10.4, don't ever pick GLSL, even if
// !!! FIXME: the system claims it is available.
if (valid_profile(priority[i]))
const char *profile = profile_priorities[i];
if (valid_profile(profile))
{
retval = priority[i];
break;
if (retval < size)
profs[retval] = profile;
retval++;
} // if
} // for

if (retval == NULL)
set_error("no profiles available");
} // if

ctx = current_ctx;
return retval;
} // MOJOSHADER_glAvailableProfiles


const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname))
{
const char *prof[STATICARRAYLEN(profile_priorities)];
if (MOJOSHADER_glAvailableProfiles(lookup, prof, STATICARRAYLEN(prof)) <= 0)
{
set_error("no profiles available");
return NULL;
} // if

return prof[0]; // profiles are sorted "best" to "worst."
} // MOJOSHADER_glBestProfile


Expand Down

0 comments on commit 918f621

Please sign in to comment.