From ba2f76694ec483e65435ac1e6f863e264c59cd69 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 3 May 2008 13:42:47 -0400 Subject: [PATCH] Added MOJOSHADER_glMaxUniforms(). --HG-- branch : trunk --- mojoshader.h | 17 +++++++++++++++++ mojoshader_opengl.c | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/mojoshader.h b/mojoshader.h index d3db7f47..4cb2ab6d 100644 --- a/mojoshader.h +++ b/mojoshader.h @@ -462,6 +462,23 @@ void MOJOSHADER_glMakeContextCurrent(MOJOSHADER_glContext *ctx); */ const char *MOJOSHADER_glGetError(void); +/* + * Get the maximum uniforms a shader can support for the current GL context, + * MojoShader profile, and shader type. You can use this to make decisions + * about what shaders you want to use (for example, a less complicated + * shader may be swapped in for lower-end systems). + * + * Returns the number, or -1 on error. + * + * 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. + * + * This call requires a valid MOJOSHADER_glContext to have been made current, + * or it will crash your program. See MOJOSHADER_glMakeContextCurrent(). + */ +int MOJOSHADER_glMaxUniforms(MOJOSHADER_shaderType shader_type); + /* * Compile a buffer of Direct3D shader bytecode into an OpenGL shader. * You still need to link the shader before you may render with it. diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 0cce0f3e..4d66e5ad 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -78,7 +78,8 @@ struct MOJOSHADER_glProgram }; // Entry points in base OpenGL that lack function pointer prototypes... -typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); +typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); +typedef WINGDIAPI const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); struct MOJOSHADER_glContext { @@ -112,6 +113,7 @@ struct MOJOSHADER_glContext // Entry points... PFNGLGETSTRINGPROC glGetString; + PFNGLGETINTEGERVPROC glGetIntegerv; PFNGLDELETEOBJECTARBPROC glDeleteObject; PFNGLATTACHOBJECTARBPROC glAttachObject; PFNGLCOMPILESHADERARBPROC glCompileShader; @@ -199,6 +201,7 @@ static void lookup_entry_points(void *(*lookup)(const char *fnname)) { #define DO_LOOKUP(ext, typ, fn) ctx->fn = (typ) loadsym(lookup, #fn, &ctx->have_##ext) DO_LOOKUP(base_opengl, PFNGLGETSTRINGPROC, glGetString); + DO_LOOKUP(base_opengl, PFNGLGETINTEGERVPROC, glGetIntegerv); DO_LOOKUP(GL_ARB_shader_objects, PFNGLDELETEOBJECTARBPROC, glDeleteObject); DO_LOOKUP(GL_ARB_shader_objects, PFNGLATTACHOBJECTARBPROC, glAttachObject); DO_LOOKUP(GL_ARB_shader_objects, PFNGLCOMPILESHADERARBPROC, glCompileShader); @@ -413,6 +416,22 @@ void MOJOSHADER_glMakeContextCurrent(MOJOSHADER_glContext *_ctx) } // MOJOSHADER_glMakeContextCurrent +int MOJOSHADER_glMaxUniforms(MOJOSHADER_shaderType shader_type) +{ + GLenum pname = GL_NONE; + GLint val = 0; + if (shader_type == MOJOSHADER_TYPE_VERTEX) + pname = GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB; + else if (shader_type == MOJOSHADER_TYPE_PIXEL) + pname = GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB; + else + return -1; + + ctx->glGetIntegerv(pname, &val); + return (int) val; +} // MOJOSHADER_glMaxUniforms + + MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf, const unsigned int bufsize) {