gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz ./TODO gfx/libpaper/Paper.cxx gfx/libpaper/...


From: Asko Soukka
Subject: [Gzz-commits] gzz ./TODO gfx/libpaper/Paper.cxx gfx/libpaper/...
Date: Sat, 28 Sep 2002 15:34:38 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Asko Soukka <address@hidden>    02/09/28 15:34:38

Modified files:
        .              : TODO 
        gfx/libpaper   : Paper.cxx Paper.hxx 

Log message:
        Mainly PaperPass::vertex() routine to work without vertex program, but 
only with paper position.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/TODO.diff?tr1=1.178&tr2=1.179&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/Paper.cxx.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/Paper.hxx.diff?tr1=1.11&tr2=1.12&r1=text&r2=text

Patches:
Index: gzz/TODO
diff -c gzz/TODO:1.178 gzz/TODO:1.179
*** gzz/TODO:1.178      Sat Sep 28 13:57:28 2002
--- gzz/TODO    Sat Sep 28 15:34:38 2002
***************
*** 42,54 ****
        + ZZ vanishingview cell size for pagespans and linebroken
          paragraphs, as well as libpaper backgrounds
      humppake:
-       - clean up Paper VP interface [jvk will explain]
-         [this is for making things work on G400, and if you
-          get the GeForce2, this moves to alpha4!]:
-           - new vertex() routine, which works without
-             vertex program, both with and without paper
-             position.
-           - javadoc Paper.hxx: how to use Vertex Program interface.
        - make paperquad check whether vertex programs are available
          and use them if possible, otherwise use the above calls.
          Vertex programs and packed vertices can be MUCH more efficient,
--- 42,47 ----
***************
*** 61,66 ****
--- 54,65 ----
          which allows papers to work without register combiners.
          [this is for making things work on G400, and if you
           get the GeForce2, this moves to alpha4!]:
+       - clean up Paper VP interface [jvk will explain]
+         [this is for making things work on G400, and if you
+          get the GeForce2, this moves to alpha4!]:
+             - implement TexGenEmboss::setUp_explicit
+           - vertex_explicit() routine to work also without
+             paper position.
      tjl:
        - implement DistortCoords::createInverse(). This is not easy, and
          it IS allowable to use numeric approximation for root-finding.
Index: gzz/gfx/libpaper/Paper.cxx
diff -c gzz/gfx/libpaper/Paper.cxx:1.12 gzz/gfx/libpaper/Paper.cxx:1.13
*** gzz/gfx/libpaper/Paper.cxx:1.12     Sat Sep 28 11:03:00 2002
--- gzz/gfx/libpaper/Paper.cxx  Sat Sep 28 15:34:38 2002
***************
*** 2,12 ****
  
  #include <sstream>
  
! /* the matrix that maps v[TEX0] into o[TEXi] is stored 
!  * starting at c[tex_addr_base + 4*i] */
  #define tex_addr_base 60
  
  namespace Paper {
      TexGen::TexGen(const float *tex_mat) {
        this->tex_mat[0] = tex_mat[0];
        this->tex_mat[1] = tex_mat[1];
--- 2,14 ----
  
  #include <sstream>
  
! /** The matrix that maps v[TEX0] into o[TEXi] is stored 
!  * starting at c[tex_addr_base + 4*i].
!  */
  #define tex_addr_base 60
  
  namespace Paper {
+ 
      TexGen::TexGen(const float *tex_mat) {
        this->tex_mat[0] = tex_mat[0];
        this->tex_mat[1] = tex_mat[1];
***************
*** 39,45 ****
        glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 3, tex_mat + 12);
  #endif
      }
!   
      string TexGen::getVPCode(int unit) {
        std::ostringstream code;
  
--- 41,47 ----
        glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 3, tex_mat + 12);
  #endif
      }
! 
      string TexGen::getVPCode(int unit) {
        std::ostringstream code;
  
***************
*** 52,58 ****
        return code.str();
      }
  
!       void TexGen::setUp(LightParam *param) {
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        
--- 54,64 ----
        return code.str();
      }
  
!     void TexGen::setUp_explicit(LightParam * param) {
!       explicit_mat = tex_mat;
!     }
! 
!       void TexGen::setUp_texgen(LightParam *param) {
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        
***************
*** 76,99 ****
        }
  
        void TexGenEmboss::setUp_VP(int unit, LightParam *param) {
!       // Suppose 
!         //   x = vertex position
!       //   p = paper coordinates
!       //   s = texture coordinates
!       //   A = paper-to-vertex mapping
!       //   E = embossing mapping (translates x towards light)
!       //   M = modelview matrix
!       //   T = texture matrix
!       //
!       // The usual eye-linear embossing texgen computes
!       //   s' = Tp' = T((MEA)^-1 M x) = T(A^-1 E^-1 x)
!       // The usual simple texgen computes
!       //   s = Tp = T((MA)^-1 M x) = T(A^-1 x)  ==>  x = Ap
!       // Thus, the mapping from p to s' is
!       //   s' = Tp' = T(A^-1 E^-1 x) = T A^-1 E^-1 A p
!       // 
!       // The following code computes T A^-1 E^-1 A and stores it
!       // in place of T in the constant registers
  
  #ifdef GL_VERTEX_PROGRAM_NV
          GLuint base = unit * 4 + tex_addr_base;
--- 82,106 ----
        }
  
        void TexGenEmboss::setUp_VP(int unit, LightParam *param) {
!       /** Suppose 
!          *   x = vertex position
!        *   p = paper coordinates
!        *   s = texture coordinates
!        *   A = paper-to-vertex mapping
!        *   E = embossing mapping (translates x towards light)
!        *   M = modelview matrix
!        *   T = texture matrix
!        *
!        * The usual eye-linear embossing texgen computes
!        *   s' = Tp' = T((MEA)^-1 M x) = T(A^-1 E^-1 x)
!        * The usual simple texgen computes
!        *   s = Tp = T((MA)^-1 M x) = T(A^-1 x)  ==>  x = Ap
!        * Thus, the mapping from p to s' is
!        *   s' = Tp' = T(A^-1 E^-1 x) = T A^-1 E^-1 A p
!        * 
!        * The following code computes T A^-1 E^-1 A and stores it
!        * in place of T in the constant registers.
!        */
  
  #ifdef GL_VERTEX_PROGRAM_NV
          GLuint base = unit * 4 + tex_addr_base;
***************
*** 139,146 ****
  #endif
        }
    
! 
!       void TexGenEmboss::setUp(LightParam *param) {
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
  
--- 146,152 ----
  #endif
        }
    
!       void TexGenEmboss::setUp_texgen(LightParam *param) {
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
  
***************
*** 167,172 ****
--- 173,183 ----
        glPopMatrix();
        }
  
+       void TexGenEmboss::setUp_explicit(LightParam * param) {
+       std::cerr << "Warning: setUp_explicit for TexGenEmboss not implemented 
yet";
+       explicit_mat = tex_mat;
+       }
+ 
        TexGenLightmap::TexGenLightmap(const float *tex_mat, 
                     const float *inv_mat) 
        : TexGen(tex_mat) {
***************
*** 208,221 ****
        glEnable(GL_TEXTURE_GEN_T);
        glPopMatrix();
        }
!       
!       
        LightDirSetup::LightDirSetup(const float *tex_mat) {
        mat[0] = tex_mat[0];
        mat[1] = tex_mat[1];
        mat[2] = tex_mat[4];
        mat[3] = tex_mat[5];
        }
        void LightDirSetup::setUp(LightParam *param) {
        //ZVec Li = inverse_map(e0, e1, e2, Light).normalize();
        ZVec Li = ZVec(param->e0.dot(param->Light), 
param->e1.dot(param->Light), param->e2.dot(param->Light)).normalize();
--- 219,232 ----
        glEnable(GL_TEXTURE_GEN_T);
        glPopMatrix();
        }
!             
        LightDirSetup::LightDirSetup(const float *tex_mat) {
        mat[0] = tex_mat[0];
        mat[1] = tex_mat[1];
        mat[2] = tex_mat[4];
        mat[3] = tex_mat[5];
        }
+ 
        void LightDirSetup::setUp(LightParam *param) {
        //ZVec Li = inverse_map(e0, e1, e2, Light).normalize();
        ZVec Li = ZVec(param->e0.dot(param->Light), 
param->e1.dot(param->Light), param->e2.dot(param->Light)).normalize();
***************
*** 224,230 ****
               mat[2] * Li.x + mat[3] * Li.y, Li.z);
        glColor3f(.5 * L.x + .5, .5 * L.y + .5, .5 * L.z + .5);
        }
- 
    
    void PaperPass::setUp_texgen(LightParam *param) {
      setupcode();
--- 235,240 ----
***************
*** 233,239 ****
      GLenum unit = GL_TEXTURE0_ARB;
      for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != 
texgen.end(); ++it) {
        glActiveTextureARB(unit++);
!       if (it->get()) (*it)->setUp(param);
        else std::cerr << "Warning: ignoring null TexGen\n";
      }
        
--- 243,249 ----
      GLenum unit = GL_TEXTURE0_ARB;
      for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != 
texgen.end(); ++it) {
        glActiveTextureARB(unit++);
!       if (it->get()) (*it)->setUp_texgen(param);
        else std::cerr << "Warning: ignoring null TexGen\n";
      }
        
***************
*** 296,299 ****
--- 306,354 ----
      glDisable(GL_VERTEX_PROGRAM_NV);
  #endif
    }
+ 
+   void PaperPass::setUp_explicit(LightParam *param) {
+     setupcode();
+     
+     /* Set up explicit TexGen parameters for each texture unit */
+     for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != 
texgen.end(); ++it) {
+       if (it->get()) (*it)->setUp_explicit(param);
+       else std::cerr << "Warning: ignoring null TexGen\n";
+     }
+ 
+     /* 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";
+     }
+   }
+ 
+   void PaperPass::vertex_explicit(float *ppos) {
+     const float *mat;
+     float texCoords[4];
+ 
+     GLenum unit = GL_TEXTURE0_ARB;
+ 
+     /* Multiplicates TexGen's explicit_mat with ppos for proper texCoords */
+     for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != 
texgen.end(); ++it) {
+       if (it->get()) {
+       mat = (*it)->explicit_mat;
+       texCoords[0] = mat[0] * ppos[0] + mat[1] * ppos[1] + mat[2] * ppos[2] + 
mat[3] * ppos[3];
+       texCoords[1] = mat[4] * ppos[0] + mat[5] * ppos[1] + mat[6] * ppos[2] + 
mat[7] * ppos[3];
+       texCoords[2] = mat[8] * ppos[0] + mat[9] * ppos[1] + mat[10] * ppos[2] 
+ mat[11] * ppos[3];
+       texCoords[3] = mat[12] * ppos[0] + mat[13] * ppos[1] + mat[14] * 
ppos[2] + mat[15] * ppos[3];
+ 
+       glMultiTexCoord4fvARB(unit, texCoords);
+       }
+       else std::cerr << "Warning: ignoring null TexGen\n";
+       unit++;
+     }
+   }
  }
+ 
+ 
+ 
+ 
+ 
+ 
+ 
Index: gzz/gfx/libpaper/Paper.hxx
diff -c gzz/gfx/libpaper/Paper.hxx:1.11 gzz/gfx/libpaper/Paper.hxx:1.12
*** gzz/gfx/libpaper/Paper.hxx:1.11     Sat Sep 28 11:03:00 2002
--- gzz/gfx/libpaper/Paper.hxx  Sat Sep 28 15:34:38 2002
***************
*** 28,34 ****
       */
      class LightParam {
      public:
!       /** Paper coordinate system basis vectors and origin in object 
coordinates
         * Paper coordinates x, y, (and z) are mapped to 
         * object position (orig + x e0 + y e1 + z e2).
         * For the eye-linear TexGens, the basis and origin vectors are 
transformed
--- 28,34 ----
       */
      class LightParam {
      public:
!       /** Paper coordinate system basis vectors and origin in object 
coordinates.
         * Paper coordinates x, y, (and z) are mapped to 
         * object position (orig + x e0 + y e1 + z e2).
         * For the eye-linear TexGens, the basis and origin vectors are 
transformed
***************
*** 39,49 ****
         * e0, e1, and e2 should be orthogonal and the same length. */
        ZVec e0, e1, e2, orig;
  
!       /** Light position in object coordinates
         * Light position should be given in the same coordinate system as 
         * the basis vectors above. */
        ZVec Light;
!       /** Light position w component 
         * Basically, Light_w should be 1.0 for finite light and
         * 0.0 for infinite light */
        float Light_w;
--- 39,50 ----
         * e0, e1, and e2 should be orthogonal and the same length. */
        ZVec e0, e1, e2, orig;
  
!       /** Light position in object coordinates.
         * Light position should be given in the same coordinate system as 
         * the basis vectors above. */
        ZVec Light;
! 
!       /** Light position w component. 
         * Basically, Light_w should be 1.0 for finite light and
         * 0.0 for infinite light */
        float Light_w;
***************
*** 70,115 ****
        }
      };
  
!     /** Simple, non-lighting-dependent TexGen.
!      * Transforms paper coordinates into texture coordinates using
!      * the given matrix.
       */
!     class TexGen : public LightSetup {
      protected:
!       // XXX: Currently the last four values are always initialized to 0,0,0,1
!       float tex_mat[16];
  
      public:
!       /** Create a new texgen.
!        * @param tex_mat A float vector of 12 elements, components of
!        * s, t and r vectors, respectively.
!        */
!       TexGen(const float *tex_mat) ;
!       virtual void setUp(LightParam *param) ;
  
!       virtual void setUp_VP(int unit, LightParam * param);
!       virtual string getVPCode(int unit);
      };
  
!     /** TexGen for embossing.
!      * Shifts the texture towards the light by an amount proportional to eps.
!      * Take the difference of the filtered values generated by two emboss 
!      * texgens using the same texture with +eps and -eps parameters
!      * to obtain an approximation of the diffuse dot product.
       */
!     class TexGenEmboss : public TexGen {
!     protected:
!       float eps;
! 
!     public:
!       TexGenEmboss(const float *tex_mat, float eps) 
!       : TexGen(tex_mat), eps(eps) {}
  
! 
!       virtual void setUp(LightParam *param) ;
! 
!       virtual void setUp_VP(int unit, LightParam * param);
!     };
  
      /** TexGen for transforming light intensity or direction map 
       * into paper texture coordinates for a light at a finite distance.
--- 71,153 ----
        }
      };
  
!     /** Computes light direction in paper texture coordinates
!      * into the primary color.
!      * Used for DOT3 bump mapping with infinite light.
!      * The tex_mat parameter is the TexGen matrix of the paper texture
       */
!     class LightDirSetup : public LightSetup {
      protected:
!       float mat[4];
  
      public:
!       LightDirSetup(const float *tex_mat) ;
  
!       virtual void setUp(LightParam *param) ;
      };
  
!   /** Simple, non-lighting-dependent TexGen.
!    * Transforms paper coordinates into texture coordinates using
!    * the given matrix.
!    */
!   class TexGen {
!   protected:
!     /** Matrix used to convert paper coordinates into texture coordinates. */
!     // XXX: Currently the last four values are always initialized to 0,0,0,1
!     float tex_mat[16];
!     
!   public:
!     /** Pointer to current texture matrix used in setUp_explicit */
!     const float *explicit_mat;
!       
!     /** Creates a new TexGen.
!      * @param tex_mat A float vector of 12 elements, 
!      * components of s, t and r vectors, respectively.
!      */
!     TexGen(const float *tex_mat);
! 
!     /*** TexGen version of the TexGen setUp. */
!     virtual void setUp_texgen(LightParam *param);
!     /*** Vertex program version of the TexGen setUp. */
!     virtual void setUp_VP(int unit, LightParam * param);
!     /*** Explicit version of the TexGen setUp. */
!     virtual void setUp_explicit(LightParam *param);
! 
!     /*** Generates a vertex program for requested unit */
!     virtual string getVPCode(int unit);
!   };
! 
!   /** TexGen for embossing.
!    * Shifts the texture towards the light by an amount proportional to eps.
!    * Take the difference of the filtered values generated by two emboss 
!    * texgens using the same texture with +eps and -eps parameters
!    * to obtain an approximation of the diffuse dot product.
!    */
!   class TexGenEmboss : public TexGen {
!   protected:
!     /** ??? */
!     float eps;
!     /** Inverted tex_mat is needed by vertex_explicit() when
!      * handling TexGenEmbosses.
       */
!     float inv_tex_mat[16];
  
!   public:
!     /** Creates a new TexGen for embossing.
!      * @param tex_mat A float vector of 12 elements, 
!      * components of s, t and r vectors, respectively.
!      * @param eps ???
!      */
!     TexGenEmboss(const float *tex_mat, float eps) 
!       : TexGen(tex_mat), eps(eps) {}
! 
!     /*** TexGen version of the TexGenEmboss setUp. */
!     virtual void setUp_texgen(LightParam *param) ;
!     /*** Vertex program  version of the TexGenEmboss setUp. */
!     virtual void setUp_VP(int unit, LightParam * param);
!     /*** Explicit version of the TexGenEmboss setUp. */
!     virtual void setUp_explicit(LightParam * param);
!   };
  
      /** TexGen for transforming light intensity or direction map 
       * into paper texture coordinates for a light at a finite distance.
***************
*** 128,149 ****
        virtual void setUp(LightParam *param) ;
      };
    
!     /** Compute light direction in paper texture coordinates 
!      * into the primary color.
!      * Used for DOT3 bump mapping with infinite light.
!      * The tex_mat parameter is the TexGen matrix of the paper texture
!      */
!     class LightDirSetup : public LightSetup {
!     protected:
!       float mat[4];
! 
!     public:
!       LightDirSetup(const float *tex_mat) ;
! 
!       virtual void setUp(LightParam *param) ;
!     };
! 
!   /** A single rendering pass.
       * The data members are public to allow modification,
       * but when using a ready-made PaperPass, _choose one_
       * (and only one) of the following ways to use it:
--- 166,172 ----
        virtual void setUp(LightParam *param) ;
      };
    
!     /** A single rendering pass.
       * The data members are public to allow modification,
       * but when using a ready-made PaperPass, _choose one_
       * (and only one) of the following ways to use it:
***************
*** 156,169 ****
       *   2) using a vertex program
       *      - call setUp_VP with LightParam to use
       *      - call glTexCoord*() and glVertex*() directly from 
!      *        the context, use vertex arrays _or_ call vector_VP()
!      *        with vertex and texture coordinates in arrays 
!      *        of 4 floats.
       *      - call teardown_VP()
       *
       *   3) using explicit coordinates
       *     - call setUp_explicit with LightParam to use
!      *     - ???? without? with texcoords? with texcoord and vertex?
       *     - call teardown_explicit()
       */
    class PaperPass {
--- 179,193 ----
       *   2) using a vertex program
       *      - call setUp_VP with LightParam to use
       *      - call glTexCoord*() and glVertex*() directly from 
!      *        the context _or_ call vertex_VP() with position
!      *        within the paper in array of 4 floats
       *      - call teardown_VP()
       *
       *   3) using explicit coordinates
       *     - call setUp_explicit with LightParam to use
!      *     - call vertex_explicit() with paper coordinates in
!      *       arrays of 4 floats and call glVertex*() directly
!      *       from the context.
       *     - call teardown_explicit()
       */
    class PaperPass {
***************
*** 173,191 ****
       * unless it's  already loaded.
       */
      void loadVP();
! 
    public:
      /** The code to call before beginning to render the pass. */
      CallGLCode setupcode;
      /** The code to call after rendering the pass. */
      CallGLCode teardowncode;
! 
      /** The TexGen objects for the different texture units. */
      vector<shared_ptr<TexGen> > texgen;
      /** The non-texgen light setup routines. */
      vector<shared_ptr<LightSetup> > setup;
          
!     /*** Texgen version of the renderinf interface. */
      /** Calls setupcode, texgen and setup for the texture.
       *
       * @param param light parameters (LightParam object)
--- 197,215 ----
       * unless it's  already loaded.
       */
      void loadVP();
!     
    public:
      /** The code to call before beginning to render the pass. */
      CallGLCode setupcode;
      /** The code to call after rendering the pass. */
      CallGLCode teardowncode;
!     
      /** The TexGen objects for the different texture units. */
      vector<shared_ptr<TexGen> > texgen;
      /** The non-texgen light setup routines. */
      vector<shared_ptr<LightSetup> > setup;
          
!     /*** TexGen version of the renderinf interface. */
      /** Calls setupcode, texgen and setup for the texture.
       *
       * @param param light parameters (LightParam object)
***************
*** 196,202 ****
       */
      void tearDown_texgen () { teardowncode(); }
  
!     /*** Vertex program version of the rendering interface */
      /** Calls setupcode, texgen and setup for the texture.
       *          
       * @param param light parameters (LightParam object)
--- 220,226 ----
       */
      void tearDown_texgen () { teardowncode(); }
  
!     /*** Vertex program version of the rendering interface. */
      /** Calls setupcode, texgen and setup for the texture.
       *          
       * @param param light parameters (LightParam object)
***************
*** 207,216 ****
       */
      void tearDown_VP();
  
!     /** Vertex program version of the paperpass vertex
       * Calling vertex_VP() is optional. It's possible to call
       * glTexCoord*() and glVertex*() directly from the context
!      * and choose the best function variant or use vertex arrays
       * (vertex_VP() forces to pass coordinates in arrays of 4 floats).
       *
       * @param pos vertex position (array of 4 floats)
--- 231,240 ----
       */
      void tearDown_VP();
  
!     /** Vertex program version of the paperpass vertex.
       * Calling vertex_VP() is optional. It's possible to call
       * glTexCoord*() and glVertex*() directly from the context
!      * and choose the best function variant - ie. use vertex arrays
       * (vertex_VP() forces to pass coordinates in arrays of 4 floats).
       *
       * @param pos vertex position (array of 4 floats)
***************
*** 221,245 ****
        glVertex4fv(pos);
      }
          
!     /*** Explicit version of the rendering interface */
      /** Calls setupcode, texgen and setup for the texture.
       *          
       * @param param light parameters (LightParam object)
       */
!     void setUp_explicit(LightParam *param) {}
  
!     /** Calls teardowncode. 
       */
!     void tearDown_explicit() {}
  
!     /** Explicit version of the paperpass vertex
       */
!     void vertex_explicit() {}
!     void vertex_explicit(float *ppos) {}
!     void vertex_explicit(float *pos, float *ppos) {}
          
    protected:
!     /* Vertex program code */
      VPCode texgenvp;
    };
    
--- 245,267 ----
        glVertex4fv(pos);
      }
          
!     /*** Explicit version of the rendering interface. */
      /** Calls setupcode, texgen and setup for the texture.
       *          
       * @param param light parameters (LightParam object)
       */
!     void setUp_explicit(LightParam *param);
  
!     /** Calls teardowncode.
       */
!     void tearDown_explicit () { teardowncode(); }
  
!     /** Explicit version of the PaperPass vertex.
       */
!     void vertex_explicit(float *ppos);
          
    protected:
!     /* Vertex program code. */
      VPCode texgenvp;
    };
    




reply via email to

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