gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx/libcallgl callgl.cxx callgl.hxx


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx/libcallgl callgl.cxx callgl.hxx
Date: Fri, 01 Nov 2002 06:03:17 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/11/01 06:03:17

Modified files:
        gfx/libcallgl  : callgl.cxx callgl.hxx 

Log message:
        Cleanup and add a general CallGL::loadProgram method

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcallgl/callgl.cxx.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcallgl/callgl.hxx.diff?tr1=1.20&tr2=1.21&r1=text&r2=text

Patches:
Index: gzz/gfx/libcallgl/callgl.cxx
diff -u gzz/gfx/libcallgl/callgl.cxx:1.29 gzz/gfx/libcallgl/callgl.cxx:1.30
--- gzz/gfx/libcallgl/callgl.cxx:1.29   Thu Oct 31 09:59:18 2002
+++ gzz/gfx/libcallgl/callgl.cxx        Fri Nov  1 06:03:17 2002
@@ -23,8 +23,6 @@
 
     using std::cerr;
 
-    ExtCalls ext_calls;
-
     static bool Begin = false;
 
     int getToken(string tok);
@@ -470,48 +468,11 @@
 
 #endif
 
-
-#define FLOAT3(ADDRESS) ((void (*)(float, float, float))(ADDRESS))
-#define FLOAT4(ADDRESS) ((void (*)(float, float, float, float))(ADDRESS))
-
-// XXX
-//#define USE_GL_EXTENSION_CALLS
-#ifdef USE_GL_EXTENSION_CALLS
-           
-       } else {
-
-         void (* addr)() = ext_calls.getAddress(v[0]);
-         bool isOpenGLCall = true;
-         if (addr == NULL) isOpenGLCall = false;
-         
-         if (isOpenGLCall) {
-           if(checkfunc(v, "SecondaryColorEXT", 3)) {
-             void (* a)(float,float,float) = FLOAT3(addr);
-             (* a)( atof(v[1].c_str()), atof(v[2].c_str()),
-                    atof(v[3].c_str())); 
-           } else if(checkfunc(v, "BlendColorEXT", 4)) {
-             void (* a)(float,float,float,float) = FLOAT4(addr);
-             (* a)( atof(v[1].c_str()), atof(v[2].c_str()),
-                    atof(v[3].c_str()), atof(v[4].c_str()));
-           } else {
-             cerr << "Extension OpenGL call \'" << v[0] 
-                  <<"\' not supported.\n";
-           }
-         } else {
-           cerr << "Unknown function \"" << v[0] << "\" with " 
-                << v.size() - 1 << " arguments\n";
-           return false;
-         }
-       }
-
-#else /* with no extension calls.. */
        } else {
          cerr << "Unknown function \"" << v[0] << "\" with " 
               << v.size() - 1 << " arguments\n";
          return false;
        }
-#endif  /* USE_GL_EXTENSION_CALLS */
-
 
        if (!Begin) {
          int er = glGetError(); 
@@ -691,16 +652,40 @@
     }
 
 
-    void compileNVProg(GLuint TARGET, GLuint id, const string source) {
+    bool loadProgram(GLuint id, const string source) {
+#ifdef GL_VERTEX_PROGRAM_NV
+       if (source.compare(0, 4, "!!VP") == 0)
+           return loadNVProg(GL_VERTEX_PROGRAM_NV, id, source);
+       else if (source.compare(0, 5, "!!VSP") == 0) 
+           return loadNVProg(GL_VERTEX_STATE_PROGRAM_NV, id, source);
+#endif
+#ifdef GL_FRAGMENT_PROGRAM_NV
+       else if (source.compare(0, 5, "!!FP") == 0)
+           return loadNVProg(GL_FRAGMENT_PROGRAM_NV, id, source);
+#endif
+#ifdef GL_VERTEX_PROGRAM_ARB
+       else if (source.compare(0, 7, "!!ARBvp") == 0)
+           return loadARBProg(GL_VERTEX_PROGRAM_ARB, id, source);
+#endif
+#ifdef GL_FRAGMENT_PROGRAM_ARB
+       else if (source.compare(0, 7, "!!ARBfp") == 0)
+           return loadARBProg(GL_FRAGMENT_PROGRAM_ARB, id, source);
+#endif
+       cerr << "loadProgram: unknown program type: " << source << "\n";
+       return false;
+    }
 
+    bool loadNVProg(GLuint TARGET, GLuint id, const string source) {
        int er = glGetError(); 
        if (er != GL_NO_ERROR)
          cerr << "Warning: OPENGL ERROR " 
               << gluErrorString(er)
-              << " before loading vertex program\n"; 
+              << " before loading " 
+              << getTokenString(TARGET) 
+              << " program\n"; 
 
-#ifdef GL_VERTEX_PROGRAM_NV
-       glLoadProgramNV(TARGET, id, source.length(), (GLubyte*)source.data());
+#ifdef GL_NV_vertex_program // XXX: how to test support for any program type?
+       glLoadProgramNV(TARGET, id, source.length(), (GLubyte*)source.data());
        
        er = glGetError(); 
        if (er != GL_NO_ERROR) {
@@ -714,7 +699,42 @@
 
          glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errpos);
          std::cerr << "Program error position: " << errpos << "\n";
+         return false;
        }
 #endif
+       return true;
+    }
+
+    bool loadARBProg(GLuint TARGET, GLuint id, const string source) {
+       int er = glGetError(); 
+       if (er != GL_NO_ERROR)
+         cerr << "Warning: OPENGL ERROR " 
+              << gluErrorString(er)
+              << " before loading " 
+              << getTokenString(TARGET) 
+              << " program\n"; 
+
+#ifdef PROGRAM_ERROR_STRING_ARB // XXX: how to test support?
+       glBindProgramARB(TARGET, id);
+       glProgramStringARB(TARGET, PROGRAM_FORMAT_ASCII_ARB, 
+                          source.length(), (GLubyte*)source.data());
+       er = glGetError(); 
+       if (er != GL_NO_ERROR) {
+         GLint errpos;
+         
+         cerr << "OPENGL ERROR " 
+              << gluErrorString(er)
+              << " when loading " 
+              << getTokenString(TARGET) 
+              << " program\n"; 
+
+         glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errpos);
+         std::cerr << "PRGORAM ERROR: " 
+                   << glGetString(GL_PROGRAM_ERROR_STRING_ARB)
+                   << " at position " << errpos << "\n";
+         return false;
+       }
+#endif
+       return true;
     }
 }
Index: gzz/gfx/libcallgl/callgl.hxx
diff -u gzz/gfx/libcallgl/callgl.hxx:1.20 gzz/gfx/libcallgl/callgl.hxx:1.21
--- gzz/gfx/libcallgl/callgl.hxx:1.20   Thu Oct 31 10:22:47 2002
+++ gzz/gfx/libcallgl/callgl.hxx        Fri Nov  1 06:03:17 2002
@@ -165,8 +165,16 @@
 #endif
     };
 
+    /** Load an OpenGL program into the driver.
+     * Target type (GL_NV_VERTEX_PROGRAM, ...) and loading method 
+     * (LoadProgramNV, ProgramStringARB, ...) is determined from the 
+     * "!!..." program header.
+     */
+    bool loadProgram(GLuint id, const string source);
+
+    bool loadARBProg(GLuint TARGET, GLuint id, const string source);
 
-    void compileNVProg(GLuint TARGET, GLuint id, const string source);
+    bool loadNVProg(GLuint TARGET, GLuint id, const string source);
 
     /** An instance of an NVIDIA program loaded into the driver.
      * The NVProg objects are immutable with value semantics.
@@ -194,61 +202,21 @@
     protected:
        void compile() {
            progid = shared_ptr<NVProgID>(new NVProgID);
-           compileNVProg(TARGET, progid->name, source);
+           loadNVProg(TARGET, progid->name, source);
        }
        string source;
        shared_ptr<NVProgID> progid;
     };
 
 
-#ifdef GL_VERTEX_PROGRAM_NV
+#ifdef GL_NV_vertex_program
     typedef NVProg<GL_VERTEX_PROGRAM_NV> VertexProgram;
     typedef NVProg<GL_VERTEX_STATE_PROGRAM_NV> VertexStateProgram;
 #endif
-#ifdef GL_FRAGMENT_PROGRAM_NV
+#ifdef GL_NV_fragment_program
     typedef NVProg<GL_FRAGMENT_PROGRAM_NV> FragmentProgram;
 #endif
 
-
-  /* Just a simple container for Extender Calls
-   *   -SecondaryColorEXT
-   *   -GL_EXT_blend_color
-   */
-  class ExtCalls {
-  private:
-    // < function name, proc address>
-    map<string, void (*)()> list_address;
-
-    // <OpenGL call name, function name>
-    map<string, string> list_names;
-
-  private:
-    void add(string call_name, string func_name) { 
-      list_names[call_name] = func_name; 
-    }
-
-  public:
-    ExtCalls() {
-      // EXT_secondary_color
-      add("SecondaryColorEXT", "glSecondaryColor3dEXT");
-
-      // GL_EXT_blend_color
-      add("BlendColorEXT","glBlendColorEXT");
-    }
-
-    void (* getAddress(string call_name))() {
-
-      string func_name = list_names[call_name];
-      if (func_name == "") return NULL;
-
-      void (* addr)() = list_address[func_name];
-      if (addr == NULL) {
-        addr = Os::getExtendedProcAddress(func_name.c_str());
-       list_address[func_name] = addr;
-      }
-      return addr;
-    }      
-  };
 }
 
 #endif // GZZ CALLGL HXX




reply via email to

[Prev in Thread] Current Thread [Next in Thread]