gzz-commits
[Top][All Lists]
Advanced

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

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


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx libcallgl/callgl.hxx libpaper/Paper.cxx...
Date: Mon, 09 Sep 2002 07:19:14 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/09/09 07:19:14

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

Log message:
        Implement vertex entry point for paper passes using nvidia vertex 
programs; not tested

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcallgl/callgl.hxx.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/Paper.cxx.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/Paper.hxx.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: gzz/gfx/libcallgl/callgl.hxx
diff -c gzz/gfx/libcallgl/callgl.hxx:1.6 gzz/gfx/libcallgl/callgl.hxx:1.7
*** gzz/gfx/libcallgl/callgl.hxx:1.6    Mon Aug 26 04:17:21 2002
--- gzz/gfx/libcallgl/callgl.hxx        Mon Sep  9 07:19:14 2002
***************
*** 127,132 ****
--- 127,186 ----
        string source;
        shared_ptr<DisplayList> displist;
      };
+ 
+ 
+ 
+ 
+     /** A simple automatic Vertex Program id object.
+      * Allocates a new VP name when created
+      * and deletes the name when destroyed.
+      * No assignment or copying is allowed; 
+      * use shared_ptr<VPid> for proper value semantics.
+      */
+     class VPid {
+     public:
+       GLuint name;
+       VPid(GLuint name) : name(name) {}
+       VPid() { glGenProgramsNV(1, &name); }
+       ~VPid() { if (name) glDeleteProgramsNV(1, &name); }
+     };
+ 
+     /** An instance of Vertex Program code loaded into the driver.
+      * The VPCode objects are immutable with value semantics.
+      * Example:
+      *                VPCode code("MOV o[HPOS], v[OPOS]");
+      */
+     class VPCode {
+     public:
+       VPCode() { }
+       VPCode(const char *source) : source(source) { compile(); }
+       string getSource() const { return source; }
+       void operator () (void) const {
+ #ifdef GL_VERTEX_PROGRAM_NV
+       glBindProgramNV(GL_VERTEX_PROGRAM_NV, vpid->name);
+ #endif
+       }
+       void operator () (const float *params) const {
+ #ifdef GL_VERTEX_PROGRAM_NV
+       glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV, vpid->name, params);
+ #endif
+       }
+ 
+     protected:
+       void compile() { 
+       vpid = shared_ptr<VPid>(new VPid);
+ #ifdef GL_VERTEX_PROGRAM_NV
+       if (source.compare(0, 5, "!!VSP"))
+         glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV, vpid->name, 
+                         source.length(), (GLubyte*)source.data());
+       else
+         glLoadProgramNV(GL_VERTEX_PROGRAM_NV, vpid->name, source.length(), 
+                         (GLubyte*)source.data());
+ #endif
+       }
+       string source;
+       shared_ptr<VPid> vpid;
+     };
  }
  
  #endif
Index: gzz/gfx/libpaper/Paper.cxx
diff -c gzz/gfx/libpaper/Paper.cxx:1.3 gzz/gfx/libpaper/Paper.cxx:1.4
*** gzz/gfx/libpaper/Paper.cxx:1.3      Sat Aug 31 01:26:58 2002
--- gzz/gfx/libpaper/Paper.cxx  Mon Sep  9 07:19:14 2002
***************
*** 1,5 ****
--- 1,7 ----
  #include "Paper.hxx"
  
+ #include <sstream>
+ 
  namespace Paper {
      TexGen::TexGen(const float *tex_mat) {
        svec[0] = tex_mat[0];
***************
*** 16,22 ****
        rvec[1] = tex_mat[9];
        rvec[2] = tex_mat[10];
        rvec[3] = tex_mat[11];
!       }
  
        void TexGen::setUp(LightParam *param) {
        glMatrixMode(GL_MODELVIEW);
--- 18,52 ----
        rvec[1] = tex_mat[9];
        rvec[2] = tex_mat[10];
        rvec[3] = tex_mat[11];
!     }
! 
!     void TexGen::setUpVP(int unit) {
!       GLuint base = unit * 4 + 60;
! 
!       // XXX: This could also be implemented as CallGL code
! #ifdef GL_VERTEX_PROGRAM_NV
!       glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 0, svec);
!       glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 1, tvec);
!       glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 2, rvec);
! 
!       //float qvec[4] = { 0, 0, 0, 1 };
!       //glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 3, qvec);
! #endif
!     }
!   
!     string TexGen::getVPCode(int unit) {
!       GLuint base = unit * 4 + 60;
!       
!       std::ostringstream code;
! 
!       code << "DP4 o[TEX0].x, c[" << base + 0 << "], v[TEX0]\n" 
!          << "DP4 o[TEX0].y, c[" << base + 1 << "], v[TEX0]\n" 
!          << "DP4 o[TEX0].z, c[" << base + 2 << "], v[TEX0]\n"
!          << "MOV o[TEX0].w, v[TEX0].w\n";
!       //     << "DP4 o[TEX0].w, c[" << base + 3 << "], v[TEX0]\n";
! 
!       return code.str();
!     }
  
        void TexGen::setUp(LightParam *param) {
        glMatrixMode(GL_MODELVIEW);
***************
*** 146,150 ****
--- 176,229 ----
        }
        }
  
+   void PaperPass::loadVP() {
+     string code = 
+       "!!VP1.0\n"
+       "MOV o[HPOS], v[OPOS]\n"
+       "MOV o[COL0], v[COL0]\n"
+       "MOV o[COL1], v[COL1]\n";
+ 
+     int unit = 0;
+     for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != 
texgen.end(); ++it) {
+       if (it->get()) code += (*it)->getVPCode(unit);
+       else std::cerr << "Warning: ignoring null TexGen\n";
+       unit++;
+     }
+ 
+     std::cerr << "Creating VPCode with the source " << code << "\n";
+ 
+     texgenvp = VPCode(code.c_str());
+   }
+ 
+   void PaperPass::setUpVP(LightParam *param) {
+         if (texgenvp.getSource().length() == 0)
+         loadVP();
+ 
+       /* Set up VP TexGen parameters for each texture unit */
+         int unit = 0;
+       for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != 
texgen.end(); ++it) {
+         if (it->get()) (*it)->setUpVP(unit);
+         else std::cerr << "Warning: ignoring null TexGen\n";
+         unit++;
+       }
+ 
+       /* Do general parametric setup */
+       for (vector<shared_ptr<LightSetup> >::iterator it = setup.begin(); it 
!= setup.end(); ++it) {
+         if (it->get()) (*it)->setUp(param);
+         else std::cerr << "Warning: ignoring null LightSetup\n";
+       }
+ 
+       texgenvp(); // Bind vertex program
+ #ifdef GL_VERTEX_PROGRAM_NV
+       glEnable(GL_VERTEX_PROGRAM_NV);
+ #endif
+   }
+ 
+   void PaperPass::tearDownVP() {
+     teardowncode();
+ #ifdef GL_VERTEX_PROGRAM_NV
+     glDisable(GL_VERTEX_PROGRAM_NV);
+ #endif
+   }
  
  }
Index: gzz/gfx/libpaper/Paper.hxx
diff -c gzz/gfx/libpaper/Paper.hxx:1.5 gzz/gfx/libpaper/Paper.hxx:1.6
*** gzz/gfx/libpaper/Paper.hxx:1.5      Sat Aug 31 01:26:58 2002
--- gzz/gfx/libpaper/Paper.hxx  Mon Sep  9 07:19:14 2002
***************
*** 87,92 ****
--- 87,97 ----
         */
        TexGen(const float *tex_mat) ;
        virtual void setUp(LightParam *param) ;
+ 
+ 
+       virtual void TexGen::setUpVP(int unit);
+ 
+       virtual string TexGen::getVPCode(int unit);
      };
  
      /** TexGen for embossing.
***************
*** 171,176 ****
--- 176,205 ----
        void tearDown() {
        teardowncode();
        }
+ 
+ 
+       /** Vertex Program Version of the rendering interface 
+        * XXX: currently only plain TexGens are implemented
+        * Note: most fields of *param will be ignored
+        */
+       void setUpVP(LightParam *param);
+       void tearDownVP();
+ 
+       /** Paperpass vertex
+        * @param pos vertex position (vector of 4 floats)
+        * @param ppos position within paper (vector of 4 floats)
+        */
+       void vertex(float *pos, float *ppos) {
+       glTexCoord4fv(ppos);
+       glVertex4fv(pos);
+       }
+ 
+       /** Generate and load the texgen vertex program 
+        * Automatically called on first setUpVP unless already loaded */
+       void loadVP();
+ 
+     protected:
+       VPCode texgenvp;
      };
  
      /** A paper is simply a vector of passes.




reply via email to

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