gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gfx demo/fontfilter.py libutil/nvcode.py


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx demo/fontfilter.py libutil/nvcode.py
Date: Thu, 30 Jan 2003 14:18:57 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        03/01/30 14:18:57

Modified files:
        gfx/demo       : fontfilter.py 
        gfx/libutil    : nvcode.py 

Log message:
        fpCombiner works

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/fontfilter.py.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/nvcode.py.diff?tr1=1.15&tr2=1.16&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/fontfilter.py
diff -u gzz/gfx/demo/fontfilter.py:1.12 gzz/gfx/demo/fontfilter.py:1.13
--- gzz/gfx/demo/fontfilter.py:1.12     Wed Jan 29 08:41:22 2003
+++ gzz/gfx/demo/fontfilter.py  Thu Jan 30 14:18:56 2003
@@ -3,7 +3,7 @@
 from gfx.libpaper.texcache import getCachedTexture
 import gzz.media.impl
 from gfx.util.fparb import dump
-from gfx.libutil.nvcode import parseCombiner
+from gfx.libutil.nvcode import parseCombiner,convCombiner
 from gfx.demo.paper.util import getpaper
 
 pis = gzz.media.impl.PageImageScroll(None, gzz.mediaserver.Mediaserver.Id(
@@ -183,6 +183,9 @@
        Enable BLEND
        BlendFunc ONE SRC_ALPHA
         """ % locals())
+
+        if GL.hasExtension("GL_ARB_fragment_program"):
+            code = convCombiner(code, GL)
 
         code += """
        
Index: gzz/gfx/libutil/nvcode.py
diff -u gzz/gfx/libutil/nvcode.py:1.15 gzz/gfx/libutil/nvcode.py:1.16
--- gzz/gfx/libutil/nvcode.py:1.15      Mon Jan 27 14:06:11 2003
+++ gzz/gfx/libutil/nvcode.py   Thu Jan 30 14:18:56 2003
@@ -650,7 +650,7 @@
             "FOG": "TEMP FOG; MOV FOG, state.fog.color;",
             "SPARE0_NV": "TEMP SPARE0_NV; MOV SPARE0_NV.w, TEXTURE0;",
             "SPARE1_NV": "TEMP SPARE1_NV;",
-            "ZERO": "ALIAS ZERO = 0;",
+            "ZERO": "PARAM ZERO = 0;",
             "E_TIMES_F_NV": "TEMP E_TIMES_F_NV; MUL E_TIMES_F_NV, E, F;",
             "SPARE0_PLUS_SECONDARY_COLOR_NV": "TEMP 
SPARE0_PLUS_SECONDARY_COLOR_NV; ADD SPARE0_PLUS_SECONDARY_COLOR_NV, SPARE0, 
SECONDARY_COLOR_NV;"
             }
@@ -676,7 +676,9 @@
             return "program.env[%s]" % num
             
         if not self.initializedRegs.has_key(reg):
-            if output:
+            if output and 0:
+                # XXX: should track the need for initialization
+                # for rgb and alpha components separately
                 self.code += "TEMP %s;\n";
             else:
                 if reg == "SPARE0_NV": self.initreg("TEXTURE0")
@@ -706,9 +708,12 @@
 
         self.code += inmap[mapping].replace("TMP", var) % reg;
 
-    def genOutputMapping(self, reg, tmp, scale, bias):
+    def genOutputMapping(self, reg, comp, tmp, scale, bias):
         self.initreg(reg, output = 1)
-            
+
+        if comp == "RGB": reg += ".xyz"
+        if comp == "ALPHA": reg += ".w"
+
         outmap = {
             ("SCALE_BY_ONE_HALF_NV","NONE"): "MUL %s, .5, %s;\n",
             ("NONE","NONE"): "MOV %s, %s;\n",
@@ -717,38 +722,36 @@
             ("SCALE_BY_TWO_NV","BIAS_BY_NEGATIVE_ONE_HALF_NV"): "MAD %s, %s, 
2, -1",
             ("SCALE_BY_FOUR_NV","NONE"): "MUL %s, %s, 4;\n",
             }
-        return outmap[(scale,bias)] % (reg, tmp);
+        self.code += outmap[(scale,bias)] % (reg, tmp);
 
 
-    def genGeneralCombiner(self, abOut, cdOut, sumOut, scale, bias, abDot, 
cdDot, muxSum, comp = "RGB"):
-        suff = ""
-        if comp == "ALPHA": suff = ".w"
-        
+    def genGeneralCombiner(self, comp, abOut, cdOut, sumOut, scale, bias, 
abDot, cdDot, muxSum):
         if abOut != "DISCARD_NV" or sumOut != "DISCARD_NV":
-            if abDot:
+            if abDot not in ("FALSE", "0"):
                 self.code += "DP3 AB, VARIABLE_A_NV, VARIABLE_B_NV;\n"
             else:
                 self.code += "MUL AB, VARIABLE_A_NV, VARIABLE_B_NV;\n"
                 
             if abOut != "DISCARD_NV":
-                self.genOutputMapping(abOut + suff, "AB", scale, bias);
+                self.genOutputMapping(abOut, comp, "AB", scale, bias);
                     
         if cdOut != "DISCARD_NV" or sumOut != "DISCARD_NV":
-            if cdDot:                
+            if cdDot not in ("FALSE", "0"):
                 self.code += "DP3 CD, VARIABLE_C_NV, VARIABLE_D_NV;\n"
             else:
                 self.code += "MUL CD, VARIABLE_C_NV, VARIABLE_D_NV;\n"
 
             if cdOut != "DISCARD_NV":
-                self.genOutputMapping(cdOut + suff, "CD", scale, bias);
+                self.genOutputMapping(cdOut, comp, "CD", scale, bias);
 
         if sumOut != "DISCARD_NV":
-            if muxSum:
+            if muxSum not in ("FALSE", "0"):
                 # FIXME:
                 print "ERROR: mux not supported yet!\n"
             else:
                 self.code += "ADD SUM, AB, CD;\n"
-                self.genOutputMapping(sumOut + suff, "SUM", scale, bias);
+                self.genOutputMapping(sumOut, comp, "SUM", scale, bias);
+        self.code += "\n"
 
 
     def genFinalCombiner(self):
@@ -781,6 +784,9 @@
                 vec = fields[3:]
                 out.append("ProgramEnvParameter FRAGMENT_PROGRAM_ARB " +
                            var + " " + " ".join(vec))
+            elif (fields[0] in ("Enable","Disable") and
+                     fields[1] == "REGISTER_COMBINERS_NV"):
+                out.append(fields[0] + " FRAGMENT_PROGRAM_ARB")
             # Interpret and remove combiner specification:
             elif fields[0] in ("FinalCombinerInputNV",
                                "CombinerParameterNV"):
@@ -812,8 +818,7 @@
         
         TEMP VARIABLE_A_NV, VARIABLE_B_NV, VARIABLE_C_NV, VARIABLE_D_NV;
         TEMP VARIABLE_E_NV, VARIABLE_F_NV, VARIABLE_G_NV;
-        TEMP AB, CD, SUM;
-        """
+        TEMP AB, CD, SUM;\n\n"""
 
         self.initParams()
 
@@ -829,7 +834,8 @@
                                 "VARIABLE_D_NV",):
                         if vars.has_key(var):
                             self.genInputMapping(var, *vars[var])
-                    self.genGeneralCombiner(*self.generalOutput[num][comp])
+
+                    self.genGeneralCombiner(comp, 
*self.generalOutput[num][comp])
 
         self.stage = -1
 
@@ -850,3 +856,32 @@
         self.code += "END"
         return self.code
         
+
+fpcodes = {}
+def convCombiner(code, GL):
+    """Convert register combiners into fragment programs in CallGL code.
+    The generated fragment programs are cached in a table.
+    """
+
+    #print "Code: ", code
+
+    foo = fpCombiner()
+    code = foo.parseCode(code)
+
+    #print "Converted code: ", code
+
+    fpcode = foo.getFragmentProgram()
+
+    #print "Fragment program: ", fpcode
+    
+
+    if fpcodes.has_key(fpcode):
+        fp = fpcodes[fpcode]
+    else:
+        fp = GL.createProgram(fpcode)
+        print "Creating fragment program %s" % fp.getProgId()
+        fpcodes[fpcode] = fp
+
+    return """
+    BindProgramARB FRAGMENT_PROGRAM_ARB %s
+    """ % fp.getProgId() + code




reply via email to

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