gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gfx demo/gldemo.py demo/irregu3.py libcallg...


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx demo/gldemo.py demo/irregu3.py libcallg...
Date: Sat, 26 Oct 2002 10:09:54 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/10/26 10:09:53

Modified files:
        gfx/demo       : gldemo.py irregu3.py 
        gfx/libcallgl  : callgl.cxx 
        gfx/libtexture : irregu.texture 
Added files:
        gfx/libtexture : irreguedge.texture 

Log message:
        Start shader version of irregu3; __GL_NV20_EMULATE does not seem to 
mipmap the dot-product addressed texture

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/gldemo.py.diff?tr1=1.43&tr2=1.44&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregu3.py.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcallgl/callgl.cxx.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libtexture/irreguedge.texture?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libtexture/irregu.texture.diff?tr1=1.10&tr2=1.11&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/gldemo.py
diff -u gzz/gfx/demo/gldemo.py:1.43 gzz/gfx/demo/gldemo.py:1.44
--- gzz/gfx/demo/gldemo.py:1.43 Tue Oct 15 11:12:34 2002
+++ gzz/gfx/demo/gldemo.py      Sat Oct 26 10:09:53 2002
@@ -243,7 +243,10 @@
             mod = sys.modules[modname]
             if hasattr(mod, "__do_not_delete__"):
                 print "Reloading", modname
-                reload(mod)
+                try:
+                    reload(mod)
+                except:
+                    print "Warning: reload failed"
                 
         for modname in mods:
             mod = sys.modules[modname]
Index: gzz/gfx/demo/irregu3.py
diff -u gzz/gfx/demo/irregu3.py:1.22 gzz/gfx/demo/irregu3.py:1.23
--- gzz/gfx/demo/irregu3.py:1.22        Fri Oct 25 08:53:38 2002
+++ gzz/gfx/demo/irregu3.py     Sat Oct 26 10:09:53 2002
@@ -7,6 +7,7 @@
 lodbias = 0
 texscale = 1
 use_texture = 0
+use_stencil = 1
 
 matrices = [ "1 0 0 0  0 1 0 0  0 0 1 0  0 0 0 1",
              "4 0 0 0.005  0 1 0 0  0 0 1 0  0 0 0 1" ]
@@ -15,8 +16,7 @@
 
 
 if (GL.hasExtension("GL_NV_texture_shader")):
-    #profiles.append("NV_SHAD")
-    pass
+    profiles.append("NV_SHAD")
 
 if (GL.hasExtension("GL_NV_register_combiners") and
     GL.hasExtension("GL_EXT_secondary_color")):
@@ -31,24 +31,56 @@
     global tex, texinv
     global texenv_inner, texenv_outer, alphalevel, w0, w1
     global colmap0, colmap1
+    global using_shader
 
+    using_shader = 0
+    
     if profile == "NV_SHAD":
         print "Using 2-vector HILO displacement texture with 
GL_NV_texture_shader"
+
+        using_shader = 1
+        global use_stencil
+        use_stencil = 0
+        edgetex = getCachedTexture([1, 1024, 0, 4, "RGBA", "RGBA",
+                                    "irreguedge", ["line_width", "100"]], 
shade_all_levels = 1)
+        
         texenv_inner = """
+        Enable TEXTURE_SHADER_NV
+        
+        TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV TEXTURE_2D
+        
+        ActiveTexture TEXTURE1
+        TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV DOT_PRODUCT_NV
         TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0
-        """
         
-        alphalevel = 1
+        ActiveTexture TEXTURE2
+        TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV DOT_PRODUCT_TEXTURE_2D_NV
+        TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0
+
+        BindTexture TEXTURE_2D %s
+        Enable TEXTURE_2D
+        TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
+        TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
+        TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT
+        TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP
+
+        ActiveTexture TEXTURE0
+
+        Disable ALPHA_TEST
+        """ % edgetex.getTexId()
+
+        texenv_outer = texenv_inner
+
+        alphalevel = None
         w0,w1 = 1,1
         def colmap0(dotvec): return (1,1,1)
-        def colmap1(dotvec): return (0,0,0)
+        def colmap1(dotvec): return (1,1,1)
 
         tex_scale = 1
         tex_bias = 0
-        tex_format = [ 2, "HILO", "HILO" ]
-        
+        tex_format = [ 2, "HILO_NV", "HILO_NV" ]
 
-    if profile == "NV_COMB":
+    elif profile == "NV_COMB":
         print "Using full displacement resolution textures with 
GL_NV_register_combiners"
     
         from gfx.libutil.nvcode import combinercode
@@ -127,6 +159,8 @@
 
         texenv = """
         TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD
+        Enable ALPHA_TEST
+        AlphaFunc LESS 1
         """
         texenv_inner = texenv
         texenv_outer = texenv
@@ -167,6 +201,9 @@
     elif k == "t":
         global use_texture
         use_texture = not use_texture
+    elif k == "i":
+        global use_stencil
+        use_stencil = not use_stencil
     global lodbias
     if k == "b": lodbias += .25; print "lodbias", lodbias
     elif k == "B": lodbias -= .25; print "lodbias", lodbias
@@ -188,40 +225,46 @@
 
 def getIrregu(invert, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0):
 
-    if invert:
+    if invert and not using_shader:
         texid = texinv.getTexId()
     else:
         texid = tex.getTexId()
 
-    len =  sqrt((x1 - x0)**2 + (y1 - y0)**2)
+    striplen = sqrt((x1 - x0)**2 + (y1 - y0)**2)
 
-    m = 0.5 * ripple_scale * texscale / len
+    m = 0.5 * ripple_scale * texscale / striplen
     nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90
 
-    vertices = [
-        vecmul(vecsub((x0,y0,0,1),nvec), w0),
-        vecmul(vecadd((x0,y0,0,1),nvec), w1),
-        vecmul(vecsub((x1,y1,0,1),nvec), w0),
-        vecmul(vecadd((x1,y1,0,1),nvec), w1)
-        ]
-
-    texcoords = [
-        vecmul((x0,y0,0,texscale), w0),
-        vecmul((x0,y0,0,texscale), w1),
-        vecmul((x1,y1,0,texscale), w0),
-        vecmul((x1,y1,0,texscale), w1)
-        ]
-
-    #print "Vertices:"
-    #print vert0, tex0
-    #print vert1, tex1
-    #print vert2, tex2
-    #print vert3, tex3
+    vertices = [ vecmul(vecsub((x0,y0,0,1),nvec), w0),
+                 vecmul(vecadd((x0,y0,0,1),nvec), w1),
+                 vecmul(vecsub((x1,y1,0,1),nvec), w0),
+                 vecmul(vecadd((x1,y1,0,1),nvec), w1)
+                 ]
+
+    texcoords = [ [ vecmul((x0,y0,0,texscale), w0),
+                    vecmul((x0,y0,0,texscale), w1),
+                    vecmul((x1,y1,0,texscale), w0),
+                    vecmul((x1,y1,0,texscale), w1)
+                    ]
+                  ]
 
     angle = atan2(y1 - y0, x1 - x0) - texangle
 
-    dx = str(cos(angle))
-    dy = str(sin(angle))
+    dx = cos(angle)
+    dy = sin(angle)
+
+    if using_shader:
+        texcoords += [ [ (0, 0, 0),
+                         (0, 0, 0),
+                         (0, 0, striplen / texscale*1024),
+                         (0, 0, striplen / texscale*1024),
+                         ],
+                       [ (dx,dy,0-.5*(dx+dy)),
+                         (dx,dy,1-.5*(dx+dy)),
+                         (dx,dy,0-.5*(dx+dy)),
+                         (dx,dy,1-.5*(dx+dy)),
+                         ]
+                       ]
 
     if outer:
         a = angle * 6 / (2 * pi)
@@ -236,12 +279,11 @@
 
     dotvec = js(vec)
 
-    cols = [
-        colmap0(vec),
-        colmap1(vec),
-        colmap0(vec),
-        colmap1(vec)
-    ]
+    cols = [ colmap0(vec),
+             colmap1(vec),
+             colmap0(vec),
+             colmap1(vec)
+             ]
     
     code = """
     PushAttrib ENABLE_BIT TEXTURE_BIT
@@ -257,6 +299,22 @@
         TexEnv TEXTURE_FILTER_CONTROL_EXT TEXTURE_LOD_BIAS_EXT %s
         """ % lodbias
 
+    if use_stencil:
+        code += """
+        # Create edge stencil
+        ColorMask 0 0 0 0
+        StencilMask 255
+        Enable STENCIL_TEST
+        StencilFunc ALWAYS 0 255
+        StencilOp INCR INCR INCR
+        """
+
+    if alphalevel:
+        code += """
+        Enable ALPHA_TEST
+        AlphaFunc LESS %s
+        """ % alphalevel
+
     if outer:
         code += texenv_outer % locals()
     else:
@@ -268,19 +326,8 @@
         Translate %s
         """ % js(vecmul(nvec[:3], 24. / scale))
 
-    alpha = alphalevel
-    code += """
-    # Create edge stencil
 
-    Enable ALPHA_TEST
-    AlphaFunc LESS %(alpha)s
-    ColorMask 0 0 0 0
-
-    StencilMask 255
-    Enable STENCIL_TEST
-    StencilFunc ALWAYS 0 255
-    StencilOp INCR INCR INCR
-    
+    code += """
     Begin QUAD_STRIP
     """ % locals()
 
@@ -288,14 +335,21 @@
         code += """
         Color %s
         TexCoord %s
+        """ % (js(cols[i]), js(texcoords[0][i]))
+
+        for u in range(1,len(texcoords)):
+            code += """
+            MultiTexCoord TEXTURE%s %s
+            """ % (u, js(texcoords[u][i]))
+        
+        code += """
         Vertex %s
-        """ % (js(cols[i]), js(texcoords[i]), js(vertices[i]))
+        """ % js(vertices[i])
 
     code += """
     End
 
     ColorMask 1 1 1 1
-    Disable STENCIL_TEST
     PopAttrib
     """ 
 
@@ -304,6 +358,8 @@
         PopMatrix
         """
 
+    #print code
+
     return code
 
 class IrreguScene:
@@ -346,8 +402,9 @@
             tex2d = "Enable"
         else:
             tex2d = "Disable"
-        
-        paint = """
+
+        if use_stencil:
+            paint = """
             PushAttrib ENABLE_BIT
             Enable STENCIL_TEST
             Disable ALPHA_TEST
@@ -369,7 +426,10 @@
             Vertex %(x1)s %(y1)s
             End 
             PopAttrib
-        """ % locals()
+            """ % locals()
+        else:
+            paint = """
+            """
 
         vs.map.put(getDListNocoords("""
             PushMatrix
@@ -377,11 +437,12 @@
             MultMatrix  %s
         """ % matrices[0]))
 
-        vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,1, texscale, self.angle) +
-                            getIrregu(0,+1,y0,+1,y1,1, texscale, self.angle) +
-                            getIrregu(1,x1,+1,x0,+1,1, texscale, self.angle) +
-                            getIrregu(1,-1,y1,-1,y0,1, texscale, self.angle) +
-                            "Color 0 0 0" + paint), cs3)
+        if not using_shader:
+            vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,1, texscale, 
self.angle) +
+                                getIrregu(0,+1,y0,+1,y1,1, texscale, 
self.angle) +
+                                getIrregu(1,x1,+1,x0,+1,1, texscale, 
self.angle) +
+                                getIrregu(1,-1,y1,-1,y0,1, texscale, 
self.angle) +
+                                "Color 0 0 0" + paint), cs3)
 
         vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,0, texscale, self.angle) +
                             getIrregu(0,+1,y0,+1,y1,0, texscale, self.angle) +
Index: gzz/gfx/libcallgl/callgl.cxx
diff -u gzz/gfx/libcallgl/callgl.cxx:1.26 gzz/gfx/libcallgl/callgl.cxx:1.27
--- gzz/gfx/libcallgl/callgl.cxx:1.26   Sun Oct 20 11:20:29 2002
+++ gzz/gfx/libcallgl/callgl.cxx        Sat Oct 26 10:09:53 2002
@@ -308,19 +308,39 @@
                             atof(v[3].c_str()), 
                             atof(v[4].c_str())); break;
          }
-       } else if (checkfunc(v, "TexCoord", 2, true)) {
+       } else if (checkfunc(v, "TexCoord", 1, true)) {
          switch (v.size()) {
+         case 2: glTexCoord1d(atof(v[1].c_str())); break;
          case 3: glTexCoord2d(atof(v[1].c_str()), 
-                            atof(v[2].c_str())); break;
+                              atof(v[2].c_str())); break;
          case 4: glTexCoord3d(atof(v[1].c_str()), 
-                            atof(v[2].c_str()), 
-                            atof(v[3].c_str())); break;
+                              atof(v[2].c_str()), 
+                              atof(v[3].c_str())); break;
          default:
            cerr << "Ignoring extra arguments to TexCoord\n";
          case 5: glTexCoord4d(atof(v[1].c_str()), 
-                            atof(v[2].c_str()), 
-                            atof(v[3].c_str()), 
-                            atof(v[4].c_str())); break;
+                              atof(v[2].c_str()), 
+                              atof(v[3].c_str()), 
+                              atof(v[4].c_str())); break;
+         }
+       } else if (checkfunc(v, "MultiTexCoord", 2, true)) {
+         GLenum tex = getToken(v[1]);
+         switch (v.size()) {
+         case 3: glMultiTexCoord1d(tex, atof(v[2].c_str())); break;
+         case 4: glMultiTexCoord2d(tex, 
+                                   atof(v[2].c_str()), 
+                                   atof(v[3].c_str())); break;
+         case 5: glMultiTexCoord3d(tex, 
+                                   atof(v[2].c_str()), 
+                                   atof(v[3].c_str()), 
+                                   atof(v[4].c_str())); break;
+         default:
+           cerr << "Ignoring extra arguments to MultiTexCoord\n";
+         case 6: glMultiTexCoord4d(tex, 
+                                   atof(v[2].c_str()), 
+                                   atof(v[3].c_str()), 
+                                   atof(v[4].c_str()), 
+                                   atof(v[5].c_str())); break;
          }
        } else if (checkfunc(v, "Color", 3, true)) {
          switch (v.size()) {
Index: gzz/gfx/libtexture/irregu.texture
diff -u gzz/gfx/libtexture/irregu.texture:1.10 
gzz/gfx/libtexture/irregu.texture:1.11
--- gzz/gfx/libtexture/irregu.texture:1.10      Fri Oct 25 08:53:38 2002
+++ gzz/gfx/libtexture/irregu.texture   Sat Oct 26 10:09:53 2002
@@ -75,9 +75,11 @@
        if (f > 1) f = 1;
        if (f < 0) f = 0;
 
-       // Scale down to make space for the border
-       f *= (1 - radius / (width * ripple_scale));
-       if (f < 0) f = 0;
+       if (components != 2) {
+           // Scale down to make space for the border
+           f *= (1 - radius / (width * ripple_scale));
+           if (f < 0) f = 0;
+       }
 
        data[i] = f * scale + bias;
 




reply via email to

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