Added MOJOSHADER_glMaxUniforms(). trunk
authorRyan C. Gordon <icculus@icculus.org>
Sat, 03 May 2008 13:42:47 -0400
branchtrunk
changeset 276 1d7437469c94
parent 275 cd25ba040c5e
child 277 49a6571cac6d
Added MOJOSHADER_glMaxUniforms().
mojoshader.h
mojoshader_opengl.c
--- a/mojoshader.h	Sat May 03 13:40:55 2008 -0400
+++ b/mojoshader.h	Sat May 03 13:42:47 2008 -0400
@@ -463,6 +463,23 @@
 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.
  *
--- a/mojoshader_opengl.c	Sat May 03 13:40:55 2008 -0400
+++ b/mojoshader_opengl.c	Sat May 03 13:42:47 2008 -0400
@@ -78,7 +78,8 @@
 };
 
 // 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 @@
 
     // Entry points...
     PFNGLGETSTRINGPROC glGetString;
+    PFNGLGETINTEGERVPROC glGetIntegerv;
     PFNGLDELETEOBJECTARBPROC glDeleteObject;
     PFNGLATTACHOBJECTARBPROC glAttachObject;
     PFNGLCOMPILESHADERARBPROC glCompileShader;
@@ -199,6 +201,7 @@
 {
     #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 @@
 } // 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)
 {