Navigation Menu

Skip to content

Commit

Permalink
Added MOJOSHADER_glMaxUniforms().
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed May 3, 2008
1 parent a6318d8 commit ba2f766
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions mojoshader.h
Expand Up @@ -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.
Expand Down
21 changes: 20 additions & 1 deletion mojoshader_opengl.c
Expand Up @@ -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
{
Expand Down Expand Up @@ -112,6 +113,7 @@ struct MOJOSHADER_glContext

// Entry points...
PFNGLGETSTRINGPROC glGetString;
PFNGLGETINTEGERVPROC glGetIntegerv;
PFNGLDELETEOBJECTARBPROC glDeleteObject;
PFNGLATTACHOBJECTARBPROC glAttachObject;
PFNGLCOMPILESHADERARBPROC glCompileShader;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit ba2f766

Please sign in to comment.