mojoshader_opengl.c
branchtrunk
changeset 358 f63e18cf642f
parent 355 f42ca594e366
child 359 969805f41dba
--- a/mojoshader_opengl.c	Tue Jun 03 14:37:10 2008 -0400
+++ b/mojoshader_opengl.c	Sat Jun 14 22:15:40 2008 -0400
@@ -103,6 +103,8 @@
 typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
 typedef WINGDIAPI const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
 typedef WINGDIAPI GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
+typedef WINGDIAPI void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
+typedef WINGDIAPI void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
 
 struct MOJOSHADER_glContext
 {
@@ -141,6 +143,8 @@
     PFNGLGETSTRINGPROC glGetString;
     PFNGLGETERRORPROC glGetError;
     PFNGLGETINTEGERVPROC glGetIntegerv;
+    PFNGLENABLEPROC glEnable;
+    PFNGLDISABLEPROC glDisable;
     PFNGLDELETEOBJECTARBPROC glDeleteObject;
     PFNGLATTACHOBJECTARBPROC glAttachObject;
     PFNGLCOMPILESHADERARBPROC glCompileShader;
@@ -255,6 +259,15 @@
 } // MOJOSHADER_glGetError
 
 
+static inline void toggle_gl_state(GLenum state, int val)
+{
+    if (val)
+        ctx->glEnable(state);
+    else
+        ctx->glDisable(state);
+} // toggle_gl_state
+
+
 static void *loadsym(void *(*lookup)(const char *fn), const char *fn, int *ext)
 {
     void *retval = NULL;
@@ -281,6 +294,8 @@
     DO_LOOKUP(base_opengl, PFNGLGETSTRINGPROC, glGetString);
     DO_LOOKUP(base_opengl, PFNGLGETERRORPROC, glGetError);
     DO_LOOKUP(base_opengl, PFNGLGETINTEGERVPROC, glGetIntegerv);
+    DO_LOOKUP(base_opengl, PFNGLENABLEPROC, glEnable);
+    DO_LOOKUP(base_opengl, PFNGLDISABLEPROC, glDisable);
     DO_LOOKUP(GL_ARB_shader_objects, PFNGLDELETEOBJECTARBPROC, glDeleteObject);
     DO_LOOKUP(GL_ARB_shader_objects, PFNGLATTACHOBJECTARBPROC, glAttachObject);
     DO_LOOKUP(GL_ARB_shader_objects, PFNGLCOMPILESHADERARBPROC, glCompileShader);
@@ -552,9 +567,6 @@
     assert(ctx->profileDeleteShader != NULL);
     assert(ctx->profileDeleteProgram != NULL);
     assert(ctx->profileMaxUniforms != NULL);
-    assert(ctx->profileCompileShader != NULL);
-    assert(ctx->profileDeleteShader != NULL);
-    assert(ctx->profileDeleteProgram != NULL);
     assert(ctx->profileGetAttribLocation != NULL);
     assert(ctx->profileGetUniformLocation != NULL);
     assert(ctx->profileGetSamplerLocation != NULL);
@@ -611,7 +623,7 @@
         return -1;
 
     ctx->glGetProgramivARB(program_type, GL_MAX_PROGRAM_PARAMETERS_ARB, &retval);
-    return (int) retval;
+    return (int) retval;  // !!! FIXME: times four?
 } // impl_ARB1_MaxUniforms
 
 
@@ -655,8 +667,23 @@
 
     ctx->glGetError();  // flush any existing error state.
     ctx->glBindProgramARB(shader_type, shader);
-    ctx->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
-                            shaderlen, pd->output);
+
+#if 0
+    if (shader_type == GL_FRAGMENT_PROGRAM_ARB) {
+        const char *prog =
+            "!!ARBfp1.0\n"
+            "OUTPUT oC0 = result.color;\n"
+            "MOV oC0, { 1.0, 0.0, 0.0, 1.0 };\n"
+            "END\n";
+        ctx->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
+                                strlen(prog), prog);
+    } else
+#endif
+
+    {
+        ctx->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
+                                shaderlen, pd->output);
+    }
 
     if (ctx->glGetError() == GL_INVALID_OPERATION)
     { 
@@ -1053,6 +1080,9 @@
             phandle = program->fragment->handle;
     } // if
 
+    toggle_gl_state(GL_VERTEX_PROGRAM_ARB, vhandle != 0);
+    toggle_gl_state(GL_FRAGMENT_PROGRAM_ARB, phandle != 0);
+
     ctx->glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vhandle);
     ctx->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, phandle);
 } // impl_GLSL_UseProgramObject