[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx demo/irregu3.py libpaper/texcache.py
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx demo/irregu3.py libpaper/texcache.py |
Date: |
Fri, 25 Oct 2002 04:28:05 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/10/25 04:28:05
Modified files:
gfx/demo : irregu3.py
gfx/libpaper : texcache.py
Log message:
Cache shade_all_levels textures and make irregu3 modes run-time
selectable
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregu3.py.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/texcache.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: gzz/gfx/demo/irregu3.py
diff -u gzz/gfx/demo/irregu3.py:1.17 gzz/gfx/demo/irregu3.py:1.18
--- gzz/gfx/demo/irregu3.py:1.17 Thu Oct 24 11:08:29 2002
+++ gzz/gfx/demo/irregu3.py Fri Oct 25 04:28:05 2002
@@ -1,97 +1,143 @@
from math import sin,cos,sqrt,pi,atan2
+from gfx.libpaper.texcache import getCachedTexture
+
ripple_scale = .25
-size = 128
+size = 256
+lodbias = 0
+
+profiles = []
if (GL.hasExtension("GL_NV_register_combiners") and
GL.hasExtension("GL_EXT_secondary_color")):
+ profiles.append("NV")
+
+if GL.hasExtension("GL_EXT_texture_env_dot3"):
+ profiles.append("DOT3")
+
+profiles.append("STD")
- print "Using full displacement resolution textures with
GL_NV_register_combiners"
+def init(profile):
+ global tex, texinv
+ global texenv_inner, texenv_outer, alphalevel, w0, w1
+ global colmap0, colmap1
- from gfx.libutil.nvcode import combinercode
- texenv_outer = combinercode("""
- SecondaryColorEXT %(dotvec)s
+ if profile == "NV":
- Enable REGISTER_COMBINERS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
+ print "Using full displacement resolution textures with
GL_NV_register_combiners"
+
+ from gfx.libutil.nvcode import combinercode
+ texenv_outer = combinercode("""
+ SecondaryColorEXT %(dotvec)s
+
+ Enable REGISTER_COMBINERS_NV
+ CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
+
+ # Compute TEXTURE . SECONDARY_COLOR dot product
+ CI0 RGB A TEXTURE0 UNSIGNED_IDENTITY_NV RGB
+ CI0 RGB B SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
+ CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV NONE NONE TRUE FALSE FALSE
+
+ # Add PRIMARY_COLOR
+ CI1 RGB A SPARE0_NV UNSIGNED_IDENTITY_NV RGB
+ CI1 RGB B ZERO UNSIGNED_INVERT_NV RGB
+ CI1 RGB C PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
+ CI1 RGB D ZERO UNSIGNED_INVERT_NV RGB
+ CO1 RGB DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE FALSE FALSE
+
+ # Use as alpha
+ FCI G SPARE0_NV UNSIGNED_IDENTITY_NV BLUE
+ """)
+
+ texenv_inner = combinercode("""
+ SecondaryColorEXT 0 0 0
+
+ Enable REGISTER_COMBINERS_NV
+ CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
+
+ 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 SPARE0_NV NONE NONE FALSE FALSE FALSE
+
+ FCI G SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
+ """)
+
+ alphalevel = 1
+ w0,w1 = 1,1
+ def colmap0(dotvec): return "1 1 1"
+ def colmap1(dotvec): return "0 0 0"
+
+ tex_scale = 1
+ tex_bias = 0
+ tex_format = "RGBA"
+
+ elif profile == "DOT3":
+ print "Using 1/4 displacement resolution textures with
GL_EXT_texture_env_dot3"
- # Compute TEXTURE . SECONDARY_COLOR dot product
- CI0 RGB A TEXTURE0 UNSIGNED_IDENTITY_NV RGB
- CI0 RGB B SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
- CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV NONE NONE TRUE FALSE FALSE
-
- # Add PRIMARY_COLOR
- CI1 RGB A SPARE0_NV UNSIGNED_IDENTITY_NV RGB
- CI1 RGB B ZERO UNSIGNED_INVERT_NV RGB
- CI1 RGB C PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
- CI1 RGB D ZERO UNSIGNED_INVERT_NV RGB
- CO1 RGB DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE FALSE FALSE
-
- # Use as alpha
- FCI G SPARE0_NV UNSIGNED_IDENTITY_NV BLUE
- """)
-
- texenv_inner = combinercode("""
- SecondaryColorEXT 0 0 0
-
- Enable REGISTER_COMBINERS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
-
- 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 SPARE0_NV NONE NONE FALSE FALSE FALSE
-
- FCI G SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
- """)
-
- tex_scale = 1
- tex_bias = 0
- alphalevel = 1
- w0,w1 = 1,1
+ texenv = """
+ Hint PERSPECTIVE_CORRECTION_HINT NICEST
+ TexEnv TEXTURE_ENV TEXTURE_ENV_MODE COMBINE_EXT
+ TexEnv TEXTURE_ENV COMBINE_RGB_EXT DOT3_RGBA_EXT
+ TexEnv TEXTURE_ENV SOURCE0_RGB_EXT TEXTURE
+ TexEnv TEXTURE_ENV OPERAND0_RGB_EXT %s
+ TexEnv TEXTURE_ENV SOURCE1_RGB_EXT PREVIOUS_EXT
+ TexEnv TEXTURE_ENV OPERAND1_RGB_EXT SRC_COLOR
+ """
+ texenv_inner = texenv % "SRC_ALPHA"
+ texenv_outer = texenv % "SRC_COLOR"
+
+ alphalevel = .5
+ w0,w1 = 1,.5
+ def colmap0(dotvec): return js([.5 + .5 * c for c in dotvec])
+ def colmap1(dotvec): return js([.5 + .25 * c for c in dotvec])
+
+ tex_scale = .25
+ tex_bias = .75
+ tex_format = "RGBA"
+
+ elif profile == "STD":
+ print "Using full displacement resolution texture with standard GL"
+
+ texenv = """
+ TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD
+ """
+ texenv_inner = texenv
+ texenv_outer = texenv
+
+ alphalevel = 1
+ w0,w1 = 1,1
+ def colmap0(dotvec): return "1 1 1 1"
+ def colmap1(dotvec): return "0 0 0 0"
+
+ tex_scale = 1
+ tex_bias = 0
+ tex_format = "INTENSITY"
+ else:
+ assert(0)
- def colmap0(dotvec): return "1 1 1"
- def colmap1(dotvec): return "0 0 0"
-elif GL.hasExtension("GL_EXT_texture_env_dot3"):
+ args = ["radius", "2", "ripple_scale", str(ripple_scale),
+ "scale", str(tex_scale), "bias", str(tex_bias), "eps", ".125"]
- print "Using 1/4 displacement resolution textures with
GL_EXT_texture_env_dot3"
-
- texenv = """
- Hint PERSPECTIVE_CORRECTION_HINT NICEST
- TexEnv TEXTURE_ENV TEXTURE_ENV_MODE COMBINE_EXT
- TexEnv TEXTURE_ENV COMBINE_RGB_EXT DOT3_RGBA_EXT
- TexEnv TEXTURE_ENV SOURCE0_RGB_EXT TEXTURE
- TexEnv TEXTURE_ENV OPERAND0_RGB_EXT %s
- TexEnv TEXTURE_ENV SOURCE1_RGB_EXT PREVIOUS_EXT
- TexEnv TEXTURE_ENV OPERAND1_RGB_EXT SRC_COLOR
- """
- texenv_inner = texenv % "SRC_ALPHA"
- texenv_outer = texenv % "SRC_COLOR"
-
- tex_scale = .25
- tex_bias = .75
- alphalevel = .5
- w0,w1 = 1,.5
-
- def colmap0(dotvec): return js([.5 + .5 * c for c in dotvec])
- def colmap1(dotvec): return js([.5 + .25 * c for c in dotvec])
-else:
- assert(0)
-
-
-args = ["radius", "2", "ripple_scale", str(ripple_scale),
- "scale", str(tex_scale), "bias", str(tex_bias), "eps", ".125"]
-
-tex = GL.createTexture()
-texinv = GL.createTexture()
-tex.shade_all_levels(size, size, 0, 4, "RGBA", "RGBA", "irregu", args)
-texinv.shade_all_levels(size, size, 0, 4, "RGBA", "RGBA", "irregu", args +
- ["invert", "1"])
+ tex = getCachedTexture([size, size, 0, 4, tex_format, "RGBA", "irregu",
+ args], shade_all_levels = 1)
+ texinv = getCachedTexture([size, size, 0, 4, tex_format, "RGBA", "irregu",
+ args + ["invert", "1"]],
+ shade_all_levels = 1)
+
+
+
+init(profiles[0])
+
+def globalkey(k):
+ if "F1" <= k <= "F4":
+ global profiles
+ init(profiles[int(k[1]) - 1])
+
-lodbias = 0
# alpha(y) = e / y * f >= e
# y <= f
@@ -104,16 +150,22 @@
def vecadd(u, v): return [ u[i] + v[i] for i in range(0, len(u)) ]
def vecsub(u, v): return [ u[i] - v[i] for i in range(0, len(u)) ]
-def getIrregu(texid, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0):
+def getIrregu(invert, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0):
+
+ if invert:
+ texid = texinv.getTexId()
+ else:
+ texid = tex.getTexId()
+
len = sqrt((x1 - x0)**2 + (y1 - y0)**2)
m = 0.5 * ripple_scale * texscale / len
- vec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90
+ nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90
- vert0 = js(vecmul(vecsub((x0,y0,0,1),vec), w0))
- vert1 = js(vecmul(vecadd((x0,y0,0,1),vec), w1))
- vert2 = js(vecmul(vecsub((x1,y1,0,1),vec), w0))
- vert3 = js(vecmul(vecadd((x1,y1,0,1),vec), w1))
+ vert0 = js(vecmul(vecsub((x0,y0,0,1),nvec), w0))
+ vert1 = js(vecmul(vecadd((x0,y0,0,1),nvec), w1))
+ vert2 = js(vecmul(vecsub((x1,y1,0,1),nvec), w0))
+ vert3 = js(vecmul(vecadd((x1,y1,0,1),nvec), w1))
tex0 = js(vecmul((x0,y0,0,texscale), w0))
tex1 = js(vecmul((x0,y0,0,texscale), w1))
@@ -162,6 +214,12 @@
else:
code += texenv_inner % locals()
+ if outer and texenv_inner == texenv_outer:
+ code += """
+ PushMatrix
+ Translate %s
+ """ % js(vecmul(nvec[:3], 24. / scale))
+
alpha = alphalevel
code += """
# Create edge stencil
@@ -201,6 +259,11 @@
""" % locals()
+ if outer and texenv_inner == texenv_outer:
+ code += """
+ PopMatrix
+ """
+
return code
class IrreguScene:
@@ -212,6 +275,9 @@
def scene(self, vs):
putnoc(vs, background((0.7,0.7,1.0)))
+ global scale
+ scale = self.scale
+
cs3 = vs.coords.affineCoordsys(0, 0, 512, 384, self.scale, 0, 0,
self.scale)
vs.matcher.add(cs3, "3")
@@ -249,25 +315,22 @@
PopAttrib
""" % locals()
- i0 = tex.getTexId()
- i1 = texinv.getTexId()
-
vs.map.put(getDListNocoords("""
PushMatrix
MultMatrix 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
"""))
- vs.map.put(getDList(getIrregu(i0,x0,-1,x1,-1,1, texscale, self.angle) +
- getIrregu(i0,+1,y0,+1,y1,1, texscale, self.angle) +
- getIrregu(i1,x1,+1,x0,+1,1, texscale, self.angle) +
- getIrregu(i1,-1,y1,-1,y0,1, texscale, self.angle) +
+ 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(i0,x0,-1,x1,-1,0, texscale, self.angle) +
- getIrregu(i0,+1,y0,+1,y1,0, texscale, self.angle) +
- getIrregu(i1,x1,+1,x0,+1,0, texscale, self.angle) +
- getIrregu(i1,-1,y1,-1,y0,0, texscale, self.angle) +
+ vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,0, texscale, self.angle) +
+ getIrregu(0,+1,y0,+1,y1,0, texscale, self.angle) +
+ getIrregu(1,x1,+1,x0,+1,0, texscale, self.angle) +
+ getIrregu(1,-1,y1,-1,y0,0, texscale, self.angle) +
"Color 1 1 1" + paint), cs3)
vs.map.put(getDListNocoords("""
Index: gzz/gfx/libpaper/texcache.py
diff -u gzz/gfx/libpaper/texcache.py:1.2 gzz/gfx/libpaper/texcache.py:1.3
--- gzz/gfx/libpaper/texcache.py:1.2 Fri Oct 11 07:08:42 2002
+++ gzz/gfx/libpaper/texcache.py Fri Oct 25 04:28:05 2002
@@ -13,7 +13,7 @@
if not globals().has_key("texcache"):
texcache = {}
-def getCachedTexture(args):
+def getCachedTexture(args, shade_all_levels = 0):
global texcache
name = args[6]
@@ -27,13 +27,17 @@
if srctime > bintime:
os.system("make -C gfx/libtexture " + name + ".bin")
- key = str(args)
+ key = str((args,shade_all_levels))
if texcache.has_key(key) and texcache[(key,"ctime")] == srctime:
#print "Returning cached texture"
return texcache[key]
tex = GL.createTexture()
- res = tex.shade(*args)
+ if shade_all_levels:
+ res = tex.shade_all_levels(*args)
+ else:
+ res = tex.shade(*args)
+
texcache[key] = tex
texcache[(key,"ctime")] = srctime
print "SHADER: ", res, tex.getTexId()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gfx demo/irregu3.py libpaper/texcache.py,
Janne V. Kujala <=