[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx demo/irregu4.py libutil/Irregu.hxx libu...
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx demo/irregu4.py libutil/Irregu.hxx libu... |
Date: |
Sun, 24 Nov 2002 05:01:40 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/11/24 05:01:40
Modified files:
gfx/demo : irregu4.py
gfx/libutil : Irregu.hxx nvcode.py
Log message:
Cleanup combiner parser and use it to enahance irregu4 multitex profile
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregu4.py.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/Irregu.hxx.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/nvcode.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gzz/gfx/demo/irregu4.py
diff -u gzz/gfx/demo/irregu4.py:1.21 gzz/gfx/demo/irregu4.py:1.22
--- gzz/gfx/demo/irregu4.py:1.21 Thu Nov 21 07:07:09 2002
+++ gzz/gfx/demo/irregu4.py Sun Nov 24 05:01:40 2002
@@ -1,4 +1,4 @@
-from gfx.libutil.nvcode import combinercode
+from gfx.libutil.nvcode import combinercode, parseCombiner
from gfx.libpaper.texcache import getCachedTexture
from math import sin,cos
@@ -136,78 +136,29 @@
Color 0 0 0 1
""")
- code2 = combinercode("""
+ code2 = parseCombiner("""
PushAttrib ENABLE_BIT TEXTURE_BIT
- CombinerParameterNV CONSTANT_COLOR0_NV %(color)s
-
- # compute alpha = max( SEC_COL.b + TEX0 + COL.alpha + COL.b,
- # SEC_COL.b + TEX1 + COL.alpha,
- # SEC_COL.b + TEX2 + COL.alpha )
-
Enable REGISTER_COMBINERS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 4
- # TEX2 -= TEX1
- CI0 RGB A TEXTURE2 UNSIGNED_IDENTITY_NV RGB
- CI0 RGB B ZERO UNSIGNED_INVERT_NV RGB
- CI0 RGB C TEXTURE1 SIGNED_NEGATE_NV RGB
- CI0 RGB D ZERO UNSIGNED_INVERT_NV RGB
- CO0 RGB DISCARD_NV DISCARD_NV TEXTURE2 NONE NONE FALSE FALSE FALSE
-
- # TEX0 += COL.b
- CI0 ALPHA A TEXTURE0 UNSIGNED_IDENTITY_NV ALPHA
- CI0 ALPHA B ZERO UNSIGNED_INVERT_NV ALPHA
- CI0 ALPHA C PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE
- CI0 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
- CO0 ALPHA DISCARD_NV DISCARD_NV TEXTURE0 NONE NONE FALSE FALSE
FALSE
+ CONST0 = %(color)s
+
+ # compute alpha = max( COL1.b + TEX0 + COL0.b,
+ # COL1.b + TEX1 + COL0.alpha,
+ # COL1.b + TEX2 + COL0.alpha )
+ TEX2 = TEX2.alpha - TEX1.alpha
+ TEX1.alpha = TEX1.alpha + COL0.alpha
+
+ TEX1 = TEX1.alpha + TEX2
+ TEX0.alpha = TEX0.alpha + COL0.blue
+ TEX1 = TEX1 - TEX0.alpha
+ TEX0.alpha = TEX0.alpha + COL1.blue
- # TEX1 -= TEX0
- CI1 RGB A TEXTURE1 UNSIGNED_IDENTITY_NV RGB
- CI1 RGB B ZERO UNSIGNED_INVERT_NV RGB
- CI1 RGB C TEXTURE0 SIGNED_NEGATE_NV ALPHA
- CI1 RGB D ZERO UNSIGNED_INVERT_NV RGB
- CO1 RGB DISCARD_NV DISCARD_NV TEXTURE1 NONE NONE FALSE FALSE FALSE
-
- # TEX0 += COL.alpha
- CI1 ALPHA A TEXTURE0 UNSIGNED_IDENTITY_NV ALPHA
- CI1 ALPHA B ZERO UNSIGNED_INVERT_NV ALPHA
- CI1 ALPHA C PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV ALPHA
- CI1 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
- CO1 ALPHA DISCARD_NV DISCARD_NV TEXTURE0 NONE NONE FALSE FALSE
FALSE
-
-
- # TEX1 += unsigned(TEX2)
- CI2 RGB A TEXTURE1 SIGNED_IDENTITY_NV RGB
- CI2 RGB B ZERO UNSIGNED_INVERT_NV RGB
- CI2 RGB C TEXTURE2 UNSIGNED_IDENTITY_NV RGB
- CI2 RGB D ZERO UNSIGNED_INVERT_NV RGB
- CO2 RGB DISCARD_NV DISCARD_NV TEXTURE1 NONE NONE FALSE FALSE FALSE
-
- # TEX0 += SEC_COL.b
- CI2 ALPHA A TEXTURE0 UNSIGNED_IDENTITY_NV ALPHA
- CI2 ALPHA B ZERO UNSIGNED_INVERT_NV ALPHA
- CI2 ALPHA C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE
- CI2 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
- CO2 ALPHA DISCARD_NV DISCARD_NV TEXTURE0 NONE NONE FALSE FALSE
FALSE
-
-
- # TEX0 += unsigned(TEX1)
- CI3 RGB A TEXTURE0 SIGNED_IDENTITY_NV ALPHA
- CI3 RGB B ZERO UNSIGNED_INVERT_NV RGB
- CI3 RGB C TEXTURE1 UNSIGNED_IDENTITY_NV RGB
- CI3 RGB D ZERO UNSIGNED_INVERT_NV RGB
- CO3 RGB DISCARD_NV DISCARD_NV TEXTURE0 NONE NONE FALSE FALSE FALSE
-
- # alpha <- TEXTURE0
- FCI G TEXTURE0 UNSIGNED_IDENTITY_NV BLUE
+ TEX0.alpha = TEX0.alpha + TEX1.blue
- # color <- CONTANT_COLOR0
- FCI A ZERO UNSIGNED_IDENTITY_NV RGB
- FCI B ZERO UNSIGNED_IDENTITY_NV RGB
- FCI C ZERO UNSIGNED_IDENTITY_NV RGB
- FCI D CONSTANT_COLOR0_NV UNSIGNED_IDENTITY_NV RGB
+ alpha = TEX0.alpha
+ color = CONST0
ActiveTexture TEXTURE1
BindTexture TEXTURE_2D %(tex)s
@@ -249,7 +200,7 @@
texscale = 1.0
linewidth = 2
refsize = 128
- scale_pow = 0
+ scale_pow = 1
border0 = -.5 * ripple_scale * texscale
border1 = .5 * ripple_scale * texscale
texslicing = self.texslicing
Index: gzz/gfx/libutil/Irregu.hxx
diff -u gzz/gfx/libutil/Irregu.hxx:1.13 gzz/gfx/libutil/Irregu.hxx:1.14
--- gzz/gfx/libutil/Irregu.hxx:1.13 Fri Nov 15 04:14:53 2002
+++ gzz/gfx/libutil/Irregu.hxx Sun Nov 24 05:01:40 2002
@@ -204,10 +204,10 @@
scale1 = linewidth * pow(scale1, scale_pow);
if (multi > 0) {
- // XXX: 1.5 hardcoded
+ // XXX: .75 hardcoded
ZVec dt = pt[j] - pt[i];
- d0 = scale0 * dt * (1.5 / dv0t.length());
- d1 = scale1 * dt * (1.5 / dv1t.length());
+ d0 = scale0 * dt * (.75 / dv0t.length());
+ d1 = scale1 * dt * (.75 / dv1t.length());
float dy = 1.0 /
dv0t.cw90().normalize().dot(vert2[i][1] - vert2[i][0]);
@@ -261,7 +261,7 @@
GLenum u;
- if (multi > 0) glColor4f(0,0,dy1,dy1);
+ if (multi > 0) glColor4f(0,0,dy1,.5*dy1);
colorfv(c0 + 4);
colorfv2(c1 + 4);
texCoord(a1q, texscale * q1);
@@ -273,7 +273,7 @@
}
vertex(vert2[i][1] + shift1);
- if (multi > 0) glColor4f(0,0,dy0,dy0);
+ if (multi > 0) glColor4f(0,0,dy0,.5*dy0);
colorfv(c0);
colorfv2(c1);
texCoord(vert1[i][0], texscale);
@@ -303,7 +303,7 @@
}
vertex(vert2[j][0] + shift0);
- if (multi > 0) glColor4f(0,0,dy1,dy1);
+ if (multi > 0) glColor4f(0,0,dy1,.5*dy1);
colorfv(c0 + 4);
colorfv2(c1 + 4);
texCoord(b1q, texscale * q1);
Index: gzz/gfx/libutil/nvcode.py
diff -u gzz/gfx/libutil/nvcode.py:1.6 gzz/gfx/libutil/nvcode.py:1.7
--- gzz/gfx/libutil/nvcode.py:1.6 Sat Nov 23 12:43:37 2002
+++ gzz/gfx/libutil/nvcode.py Sun Nov 24 05:01:40 2002
@@ -38,7 +38,7 @@
def matchop(str,i):
def opchar(str, i):
- return i < len(str) and str[i] in [ "*", "/", "+", "-", ".", "|" ]
+ return i < len(str) and str[i] in [ "*", "/", "+", "-", ".", "|", "%" ]
if opchar(str, i): return i + 1
return 0
@@ -144,16 +144,9 @@
tree[i:i+1] = [("reg", regmap[node[1]], "RGB")]
i += 1
-def removeparen(tree):
- # Remove extra parentheses
- if len(tree) == 1 and tree[0][0] == "sub":
- tree[:] = tree[0][1]
- return tree
-
def parsekey(tree):
# Return list of node types
- return map(lambda x: x[0], tree)
-
+ return tuple(map(lambda x: x[0], tree))
def findregs(tree, type = "reg"):
def func(x, type=type): return x[0] == type
@@ -189,25 +182,19 @@
("-", .5): "HALF_BIAS_NORMAL_NV",
}
- key = tuple(parsekey(tree))
-
- if inputmap.has_key(key):
- reg = (findregs(tree) + [("reg", "ZERO", "ALPHA")])[0]
- tree[:] = [("in", reg[1], inputmap[key], reg[2])]
- else:
- for i in range(0,len(tree)):
- if tree[i][0] == "sub":
- parseinput(tree[i][1], final)
- if len(tree[i][1]) == 1:
- tree[i] = tree[i][1][0]
+ for i in range(0,len(tree)):
+ if tree[i][0] == "sub":
+ key = parsekey(tree[i][1])
+ if inputmap.has_key(key):
+ reg = (findregs(tree[i][1]) + [("reg", "ZERO", "ALPHA")])[0]
+ tree[i] = ("in", reg[1], inputmap[key], reg[2])
else:
- # Search for substring matches, too, for single-node keys
- key = (tree[i][0],)
- if inputmap.has_key(key):
- reg = ("reg", "ZERO", "ALPHA")
- if key == ("reg",): reg = tree[i]
- tree[i] = ("in", reg[1], inputmap[key], reg[2])
+ parseinput(tree[i][1], final)
+ elif tree[i][0] == "reg":
+ # Convert identity-mapped regs
+ tree[i] = ("in", tree[i][1], inputmap["reg",], tree[i][2])
+ return tree
def parseGeneralCombiner(outreg, tree):
out = {
@@ -227,39 +214,44 @@
("-", 0): "NONE",
}
- key = tuple(parsekey(tree))
+ key = parsekey(tree)
if outputscale.has_key(key):
out["scale"] = outputscale[key]
- tree[:] = tree[:-2]
- removeparen(tree)
+ tree = tree[0][1]
- key = tuple(parsekey(tree)[-2:])
+ key = parsekey(tree[-2:])
if outputbias.has_key(key):
out["bias"] = outputbias[key]
- tree[:] = tree[:-2]
+ tree = tree[:-2]
- removeparen(tree)
parseinput(tree)
funcmap = {
("in", ".", "in"): ("AB", "TRUE"),
- ("in",): ("A", "FALSE"),
("in", "*", "in"): ("AB", "FALSE"),
+ ("in",): ("A", "FALSE"),
+ ("-", "in"): ("A", "FALSE", 1),
("in", "+", "in"): ("AC", "FALSE"),
("in", "+", "in", "*", "in"): ("ACD", "FALSE"),
("in", "*", "in", "+", "in"): ("ABC", "FALSE"),
("in", "*", "in", "+", "in", "*", "in"): ("ABCD", "FALSE"),
+ ("-", "in", "+", "in"): ("AC", "FALSE", 1),
+ ("-", "in", "+", "in", "*", "in"): ("ACD", "FALSE", 1),
+ ("in", "-", "in"): ("AC", "FALSE", 2),
+ ("in", "*", "in", "-", "in"): ("ABC", "FALSE", 1),
+ ("-", "in", "-", "in"): ("AC", "FALSE", 3),
("in", "|", "in"): ("AC", "TRUE"),
("in", "|", "in", "*", "in"): ("ACD", "TRUE"),
("in", "*", "in", "|", "in"): ("ABC", "TRUE"),
("in", "*", "in", "|", "in", "*", "in"): ("ABCD", "TRUE"),
}
- key = tuple(parsekey(tree))
+ key = parsekey(tree)
if funcmap.has_key(key):
func = funcmap[key]
regs = findregs(tree, "in")
+ neg = len(func) > 2 and func[2]
if "C" in func[0]:
regset = "ABCD"
@@ -275,8 +267,9 @@
for reg in regset:
if reg not in func[0]:
- out[reg] = "ZERO UNSIGNED_IDENTITY_NV ALPHA"
-
+ if neg & 1: out[reg] = "ZERO EXPAND_NORMAL_NV ALPHA"
+ else: out[reg] = "ZERO UNSIGNED_INVERT_NV ALPHA"
+ neg >>= 1
else:
print "ERROR: General combiner function", key, "not recognized"
return None
@@ -346,23 +339,24 @@
def parseFinalCombiner(outreg, tree):
- parseinput(tree, final = 1)
+ tree = parseinput([("sub",tree)], final = 1)
+ if tree[0][0] == "sub": tree = tree[0][1]
- key = tuple(parsekey(tree))
+ key = parsekey(tree)
if outreg == "EF":
if key != ("in", "*", "in"):
print "ERROR: EF must be a product, got", key
return ""
- return ("FinalCombinerInput VARIABLE_E_NV " +
+ return ("FinalCombinerInputNV VARIABLE_E_NV " +
" ".join(tree[0][1:]) + "\n" +
- "FinalCombinerInput VARIABLE_F_NV " +
+ "FinalCombinerInputNV VARIABLE_F_NV " +
" ".join(tree[2][1:]) + "\n")
elif outreg == "ALPHA":
if key != ("in",):
print "ERROR: alpha must be an input mapped register, got", key
return ""
- return ("FinalCombinerInput VARIABLE_G_NV " +
+ return ("FinalCombinerInputNV VARIABLE_G_NV " +
" ".join(tree[0][1:]) + "\n")
else:
funcmap = {
@@ -387,12 +381,12 @@
regs[0], regs[i])
return ""
else:
- code += ("FinalCombinerInput VARIABLE_%s_NV %s\n"
+ code += ("FinalCombinerInputNV VARIABLE_%s_NV %s\n"
% (func[i], " ".join(regs[i][1:])))
for reg in "ABCD":
if reg not in func:
- code += ("FinalCombinerInput VARIABLE_%s_NV "
+ code += ("FinalCombinerInputNV VARIABLE_%s_NV "
"ZERO UNSIGNED_IDENTITY_NV ALPHA\n" % reg)
return code
@@ -419,6 +413,7 @@
| REGNAME . RGB_COMP
IN = REG
+ | (REG)
| (1 - REG)
| (+REG)
| (-REG)
@@ -426,8 +421,7 @@
| (1 - 2 * REG)
| (REG - .5)
| (.5 - REG)
- | 0 | .5 | 1 | (-1) | (-.5) | (-0) | (+0) | (+.5) | (+1)
- | (IN)
+ | (0) | (.5) | (1) | (-1) | (-.5) | (-0) | (+0) | (+.5) | (+1)
EXP = IN . IN
| IN
@@ -441,12 +435,9 @@
| IN * IN '|' IN
| IN * IN '|' IN * IN
-PAREN_EXP = EXP
- | (EXP)
-
-BIASED_EXP = PAREN_EXP
- | PAREN_EXP - .5
- | PAREN_EXP - 0
+BIASED_EXP = EXP
+ | EXP - .5
+ | EXP - 0
OUT = BIASED_EXP
| (BIASED_EXP) / 2
@@ -455,22 +446,24 @@
| (BIASED_EXP) * 2
| (BIASED_EXP) * 4
-
FINAL_IN = REG
- | (1 - REG)
- | 0 | 1
- | (FINAL_IN)
+ | (1 - REG)
+ | (0) | (1)
+
+FINAL_IN1 = FINAL_IN
+ | 1 - REG
+ | 0 | 1
FINAL_OUT = FINAL_IN * FINAL_IN + FINAL_IN * FINAL_IN + FINAL_IN
| FINAL_IN * FINAL_IN + FINAL_IN * FINAL_IN
| FINAL_IN * FINAL_IN + FINAL_IN
| FINAL_IN + FINAL_IN
| FINAL_IN * FINAL_IN
- | FINAL_IN
+ | FINAL_IN1
FUNC = REG '=' OUT
| RGB_COMP '=' FINAL_OUT
- | ALPHA_COMP '=' FINAL_IN
+ | ALPHA_COMP '=' FINAL_IN1
| EF '=' FINAL_IN * FINAL_IN
| CONST0 '=' vector
| CONST1 '=' vector
@@ -479,13 +472,13 @@
# The syntax is given by FUNC above.
# Code from lines not containing a '=' is passed through.
#
-# str The code lines separated by '\n' or ';'. '#'-comments are removed.
+# str The code lines separated by '\n' or ';'. '#'-comments are ignored
# returns The generated code
#
# NUM_GENERAL_COMBINERS_NV and PER_STAGE_CONSTANTS_NV are automatically set.
#
# Semantics:
-# - A new combiner stage is started for all combiner code lines except for
+# - A new combiner stage is started (unless empty) for all lines except for
# those adjacent "REG = OUT" assignments that can fit in the current stage.
# - Per stage constants are enabled unless all constant assignments are
# either before or after all general combiner register assignments
@@ -502,14 +495,16 @@
# color = EF * FOG + (1-EF) * SPARE1
#
def parseCombiner(str):
- def removeComment(line):
+ def splitLine(line):
pos = line.find("#")
- if pos >= 0: return line[:pos]
- return line
-
- lines = ";".join(map(removeComment,str.splitlines())).split(";")
-
-
+ if pos >= 0:
+ if line[:pos].strip():
+ return line[:pos].split(";") + [ line[pos:] ]
+ return [ line ]
+ return line.split(";")
+
+ lines = reduce(lambda x,y: x+y, map(splitLine, str.splitlines()))
+
code = ""
stage = {
@@ -519,11 +514,13 @@
}
for line in lines:
- line = line.strip()
- if not line: continue
-
+ if line.lstrip().startswith("#"):
+ code += line + "\n"
+ continue
+
pos = line.find("=")
if pos == -1:
+ code += outputGeneralCombiner(stage)
code += line + "\n"
continue
@@ -561,6 +558,10 @@
else:
out = parseGeneralCombiner(outreg, right)
if not out: return ""
+
+ if outcomp == "BLUE":
+ print "ERROR: cannot write only BLUE in", line
+ return ""
if not addStageComp(stage[outcomp], out):
code += outputGeneralCombiner(stage)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gfx demo/irregu4.py libutil/Irregu.hxx libu...,
Janne V. Kujala <=