Skip to content

Commit

Permalink
Added framework for GLSL 1.20 support.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Jun 29, 2008
1 parent 8e3ae31 commit 24a66bf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
19 changes: 19 additions & 0 deletions mojoshader.c
Expand Up @@ -421,6 +421,7 @@ struct Context
int determined_constants_arrays:1;
int predicated:1;
int support_nv2:1;
int support_glsl120:1;
int glsl_generated_lit_opcode:1;
};

Expand Down Expand Up @@ -2225,6 +2226,23 @@ static void emit_GLSL_start(Context *ctx, const char *profilestr)
return;
} // if

ctx->output = &ctx->globals;

if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL) == 0)
/* no-op. */ ;

else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL120) == 0)
{
ctx->support_glsl120 = 1;
output_line(ctx, "#version 120");
} // else if

else
{
failf(ctx, "Profile '%s' unsupported or unknown.", profilestr);
return;
} // else

ctx->output = &ctx->mainline_intro;
output_line(ctx, "void main()");
output_line(ctx, "{");
Expand Down Expand Up @@ -4928,6 +4946,7 @@ static const Profile profiles[] =
// This is for profiles that extend other profiles...
static const struct { const char *from; const char *to; } profileMap[] =
{
{ MOJOSHADER_PROFILE_GLSL120, MOJOSHADER_PROFILE_GLSL },
{ MOJOSHADER_PROFILE_NV2, MOJOSHADER_PROFILE_ARB1 },
};

Expand Down
5 changes: 5 additions & 0 deletions mojoshader.h
Expand Up @@ -337,6 +337,11 @@ typedef struct
*/
#define MOJOSHADER_PROFILE_GLSL "glsl"

/*
* Profile string for GLSL 1.20: minor improvements to base GLSL spec.
*/
#define MOJOSHADER_PROFILE_GLSL120 "glsl120"

/*
* Profile string for OpenGL ARB 1.0 shaders: GL_ARB_(vertex|fragment)_program.
*/
Expand Down
41 changes: 37 additions & 4 deletions mojoshader_opengl.c
Expand Up @@ -383,15 +383,35 @@ static int verify_extension(const char *ext, int have, const char *extlist,
} // verify_extension


static void parse_opengl_version(const char *verstr)
static void parse_opengl_version_str(const char *verstr, int *maj, int *min)
{
if (verstr == NULL)
ctx->opengl_major = ctx->opengl_minor = 0;
*maj = *min = 0;
else
sscanf(verstr, "%d.%d", &ctx->opengl_major, &ctx->opengl_minor);
sscanf(verstr, "%d.%d", maj, min);
} // parse_opengl_version_str


static inline void parse_opengl_version(const char *verstr)
{
parse_opengl_version_str(verstr, &ctx->opengl_major, &ctx->opengl_minor);
} // parse_opengl_version


static int glsl_version_atleast(int maj, int min)
{
int glslmin = 0;
int glslmaj = 0;
ctx->glGetError(); // flush any existing error state.
const GLenum enumval = GL_SHADING_LANGUAGE_VERSION_ARB;
const char *str = (const char *) ctx->glGetString(enumval);
if (ctx->glGetError() == GL_INVALID_ENUM)
return 0; // this is a basic, 1.0-compliant implementation.
parse_opengl_version_str(str, &glslmaj, &glslmin);
return ( (glslmaj > maj) || ((glslmaj == maj) && (glslmin >= min)) );
} // glsl_version_atleast


static void load_extensions(void *(*lookup)(const char *fnname))
{
const char *extlist = NULL;
Expand Down Expand Up @@ -468,6 +488,17 @@ static int valid_profile(const char *profile)
#endif

#if SUPPORT_PROFILE_GLSL
else if (strcmp(profile, MOJOSHADER_PROFILE_GLSL120) == 0)
{
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects);
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_vertex_shader);
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_fragment_shader);
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shading_language_100);
// if you got here, you have all the extensions.
if (!glsl_version_atleast(1, 2))
return 0;
} // else if

else if (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0)
{
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects);
Expand Down Expand Up @@ -502,6 +533,7 @@ 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_NV2,
MOJOSHADER_PROFILE_ARB1,
Expand Down Expand Up @@ -585,7 +617,8 @@ MOJOSHADER_glContext *MOJOSHADER_glCreateContext(const char *profile,
if (profile == NULL) {}

#if SUPPORT_PROFILE_GLSL
else if (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0)
else if ( (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0) ||
(strcmp(profile, MOJOSHADER_PROFILE_GLSL120) == 0) )
{
ctx->profileMaxUniforms = impl_GLSL_MaxUniforms;
ctx->profileCompileShader = impl_GLSL_CompileShader;
Expand Down

0 comments on commit 24a66bf

Please sign in to comment.