14 |
# Discriminate between different renderers. |
# Discriminate between different renderers. |
15 |
# These are for debug output only. |
# These are for debug output only. |
16 |
if dbg: |
if dbg: |
17 |
vendor = GL.getGLString("VENDOR") |
vendor = GL.getGLString("VENDOR") |
18 |
renderer = GL.getGLString("RENDERER") |
renderer = GL.getGLString("RENDERER") |
19 |
version = GL.getGLString("VERSION") |
version = GL.getGLString("VERSION") |
20 |
print "GL strings: '%s' '%s' '%s'"%( |
print "GL strings: '%s' '%s' '%s'"%( |
21 |
vendor,renderer,version) |
vendor,renderer,version) |
22 |
# The backend files to load |
# The backend files to load |
23 |
files = [ |
files = [ |
24 |
"textures.py", |
"textures.py", |
25 |
"texcoords.py", |
"texcoords.py", |
26 |
#"colors.py", |
#"colors.py", |
27 |
"params.py" |
"params.py" |
28 |
] |
] |
29 |
|
|
30 |
# |
# |
31 |
# Now, go through some questions. |
# Now, go through some questions. |
33 |
|
|
34 |
# Check which texture operations to use. |
# Check which texture operations to use. |
35 |
if GL.hasExtension("GL_NV_texture_shader"): |
if GL.hasExtension("GL_NV_texture_shader"): |
36 |
# We can use the general texture shaders. |
# We can use the general texture shaders. |
37 |
# XXX Should check separately for texture_shader2, |
# XXX Should check separately for texture_shader2, |
38 |
# otherwise it'll be SLOW. |
# otherwise it'll be SLOW. |
39 |
if dbg: print "Using NV20 texture shaders" |
if dbg: print "Using NV20 texture shaders" |
40 |
files.append("texops_NV2X.py") |
files.append("texops_NV2X.py") |
41 |
#from gfx.libpaper.texops_NV2X import * |
#from gfx.libpaper.texops_NV2X import * |
42 |
else: |
else: |
43 |
if dbg: print "Using unextended OpenGL texture accesses" |
if dbg: print "Using unextended OpenGL texture accesses" |
44 |
files.append("texops_STD.py") |
files.append("texops_STD.py") |
45 |
#from gfx.libpaper.texops_STD import * |
#from gfx.libpaper.texops_STD import * |
46 |
|
|
47 |
|
|
48 |
# Check which combiners to use. |
# Check which combiners to use. |
49 |
if GL.hasExtension("GL_NV_register_combiners"): |
if GL.hasExtension("GL_NV_register_combiners"): |
50 |
# We have at least a NV10, possibly better. |
# We have at least a NV10, possibly better. |
51 |
# Check the number of general combiners to be sure. |
# Check the number of general combiners to be sure. |
52 |
maxcomb = GL.getGLFloat("MAX_GENERAL_COMBINERS_NV")[0] |
maxcomb = GL.getGLFloat("MAX_GENERAL_COMBINERS_NV")[0] |
53 |
if maxcomb < 4: |
if maxcomb < 4: |
54 |
# use NV10 version |
# use NV10 version |
55 |
if dbg: print "Using NV10 combiners ",maxcomb |
if dbg: print "Using NV10 combiners ",maxcomb |
56 |
files.append("texcomb_NV1X.py") |
files.append("texcomb_NV1X.py") |
57 |
else: |
else: |
58 |
# use NV20 version |
# use NV20 version |
59 |
if dbg: print "Using NV20 combiners ",maxcomb |
if dbg: print "Using NV20 combiners ",maxcomb |
60 |
files.append("texcomb_NV2X.py") |
files.append("texcomb_NV2X.py") |
61 |
else: |
else: |
62 |
assert 0, "Sorry, can't do without NVIDIA register combiners yet." |
assert 0, "Sorry, can't do without NVIDIA register combiners yet." |
63 |
|
|
64 |
for f in files: |
for f in files: |
65 |
print "Load file ",f |
print "Load file ",f |
66 |
execfile("gfx/libpaper/"+f, globals()) |
execfile("gfx/libpaper/"+f, globals()) |
67 |
|
|
68 |
def randvec(rnd): return [rnd.nextDouble() for i in range(0,3)] |
def randvec(rnd): return [rnd.nextDouble() for i in range(0,3)] |
69 |
|
|
83 |
|
|
84 |
def setSolidPass(pas, color): |
def setSolidPass(pas, color): |
85 |
pas.setSetupcode(""" |
pas.setSetupcode(""" |
86 |
PushAttrib ENABLE_BIT TEXTURE_BIT |
PushAttrib ENABLE_BIT TEXTURE_BIT |
87 |
Disable REGISTER_COMBINERS_NV |
Disable REGISTER_COMBINERS_NV |
88 |
Disable TEXTURE_2D |
Disable TEXTURE_2D |
89 |
Disable BLEND |
Disable BLEND |
90 |
Enable DEPTH_TEST |
Enable DEPTH_TEST |
91 |
DepthFunc LESS |
DepthFunc LESS |
92 |
Color %(color)s |
Color %(color)s |
93 |
""" % { |
""" % { |
94 |
"color" : js(color), |
"color" : js(color), |
95 |
}) |
}) |
96 |
pas.setTeardowncode(""" |
pas.setTeardowncode(""" |
97 |
PopAttrib |
PopAttrib |
98 |
""") |
""") |
99 |
|
|
100 |
def setDummyPass(pas): |
def setDummyPass(pas): |
111 |
def getPaper(self, seed, passmask=[1,1,1,1,1,1,1]): |
def getPaper(self, seed, passmask=[1,1,1,1,1,1,1]): |
112 |
reg = Registry() |
reg = Registry() |
113 |
|
|
114 |
pap = Paper() |
pap = Paper() |
115 |
|
|
116 |
passes = [ { "trans" : 0, "emboss" : 0 }, |
passes = [ { "trans" : 0, "emboss" : 0 }, |
117 |
{ "trans" : .5, "emboss" : 0 }, |
{ "trans" : .5, "emboss" : 0 }, |
118 |
{ "trans" : .9375, "emboss" : 0 }, |
{ "trans" : .9375, "emboss" : 0 }, |
119 |
#{ "trans" : 0, "emboss" : 1 }, |
#{ "trans" : 0, "emboss" : 1 }, |
120 |
] |
] |
121 |
|
|
122 |
rng = java.util.Random(reg.get(regseed, "seed", seed)) |
rng = java.util.Random(reg.get(regseed, "seed", seed)) |
123 |
for foo in range(0,20): # eat bad beginning (Java's bad PRNG) |
for foo in range(0,20): # eat bad beginning (Java's bad PRNG) |
124 |
rng.nextInt() |
rng.nextInt() |
125 |
seeds = [rng.nextInt(2000000000) for foo in passes] |
seeds = [rng.nextInt(2000000000) for foo in passes] |
126 |
|
|
127 |
colors = Colors(rng.nextInt()) |
colors = Colors(rng.nextInt()) |
128 |
|
|
129 |
pap.setNPasses(len(passes)) |
pap.setNPasses(len(passes)) |
130 |
#setSolidPass(pap.getPass(0), (0.1,0.1,0.2)) |
#setSolidPass(pap.getPass(0), (0.1,0.1,0.2)) |
131 |
|
|
132 |
for i in range(0, len(passes)): |
for i in range(0, len(passes)): |
133 |
if passmask[i]: |
if passmask[i]: |
134 |
passreg = reg.sub("pass"+str(i)) |
passreg = reg.sub("pass"+str(i)) |
135 |
passreg.get(regseed, "seed", seeds[i]) |
passreg.get(regseed, "seed", seeds[i]) |
136 |
self.makePaperPass(passreg, |
self.makePaperPass(passreg, |
137 |
pap.getPass(i), colors, |
pap.getPass(i), colors, |
138 |
passes[i]["trans"], |
passes[i]["trans"], |
139 |
emboss = passes[i]["emboss"]) |
emboss = passes[i]["emboss"]) |
140 |
else: |
else: |
141 |
if i == 0: |
if i == 0: |
142 |
setSolidPass(pap.getPass(i), (1,1,1)) |
setSolidPass(pap.getPass(i), (1,1,1)) |
143 |
else: |
else: |
144 |
setDummyPass(pap.getPass(i)) |
setDummyPass(pap.getPass(i)) |
145 |
|
|
146 |
if dbg: reg.dump() |
if dbg: reg.dump() |
147 |
return pap |
return pap |
148 |
|
|
149 |
def makePaperPass(self, reg, ppass, colors, trans = 0, type = None, emboss = 0): |
def makePaperPass(self, reg, ppass, colors, trans = 0, type = None, emboss = 0): |
150 |
seed = reg.get(regseed, "seed") |
seed = reg.get(regseed, "seed") |
151 |
rnd = java.util.Random(seed) |
rnd = java.util.Random(seed) |
152 |
#sh = ShaderPass(selectRandom(shaderTypes,rnd)) |
#sh = ShaderPass(selectRandom(shaderTypes,rnd)) |
153 |
if emboss: |
if emboss: |
154 |
sh = makeEmbossShaderPass() |
sh = makeEmbossShaderPass() |
155 |
else: |
else: |
156 |
sh = makeNormalShaderPass() |
sh = makeNormalShaderPass() |
157 |
|
|
158 |
types = sh.getTextureTypes() |
types = sh.getTextureTypes() |
159 |
for i in range(0, len(types)): |
for i in range(0, len(types)): |
160 |
if types[i] != None: |
if types[i] != None: |
161 |
t = getPaperTexture(types[i], rnd) |
t = getPaperTexture(types[i], rnd) |
162 |
|
|
163 |
if emboss: |
if emboss: |
164 |
if (i%2) == 0: |
if (i%2) == 0: |
176 |
# comb = DebugCombinerPass() |
# comb = DebugCombinerPass() |
177 |
comb = TransparentCombinerPass() |
comb = TransparentCombinerPass() |
178 |
|
|
179 |
code = """ |
code = """ |
180 |
PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT |
PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT |
181 |
Disable BLEND |
Disable BLEND |
182 |
""" |
""" |
183 |
|
|
184 |
# Performance optimization: |
# Performance optimization: |
185 |
# Set normal depth testing for the first (non-transparent) pass |
# Set normal depth testing for the first (non-transparent) pass |
186 |
# and "equal" depth testing for the latter (transparent) passes, |
# and "equal" depth testing for the latter (transparent) passes, |
187 |
# and don't write to the depth buffer. |
# and don't write to the depth buffer. |
188 |
|
|
189 |
if trans == 0 and emboss == 0: |
if trans == 0 and emboss == 0: |
190 |
code += """ |
code += """ |
191 |
Enable DEPTH_TEST |
Enable DEPTH_TEST |
192 |
DepthFunc LESS |
DepthFunc LESS |
193 |
""" |
""" |
194 |
else: |
else: |
195 |
code += """ |
code += """ |
196 |
Enable DEPTH_TEST |
Enable DEPTH_TEST |
197 |
DepthFunc EQUAL |
DepthFunc EQUAL |
198 |
DepthMask 0 |
DepthMask 0 |
199 |
""" |
""" |
200 |
|
|
201 |
code += ( |
code += ( |
202 |
sh.setupCode() + |
sh.setupCode() + |
203 |
comb.setupCode(sh.getRGBoutputs(), colors, rnd, trans) |
comb.setupCode(sh.getRGBoutputs(), colors, rnd, trans) |
204 |
) |
) |
205 |
|
|
206 |
ppass.setSetupcode(code) |
ppass.setSetupcode(code) |
207 |
if dbg: print "SETUP: ", code |
if dbg: print "SETUP: ", code |
208 |
ppass.setTeardowncode(""" |
ppass.setTeardowncode(""" |
209 |
PopAttrib |
PopAttrib |
210 |
ActiveTexture TEXTURE0 |
ActiveTexture TEXTURE0 |
211 |
""") |
""") |
212 |
|
|
213 |
eps = 1E-4 |
eps = 1E-4 |
214 |
|
|
215 |
ttyp = sh.getTexgenTypes() |
ttyp = sh.getTexgenTypes() |
216 |
ppass.setNTexGens(len(ttyp)) |
ppass.setNTexGens(len(ttyp)) |
217 |
|
|
218 |
rootrep = TexGenXYRepeatUnit(rnd) |
rootrep = TexGenXYRepeatUnit(rnd) |
219 |
|
|
220 |
for i in range(0, len(ttyp)): |
for i in range(0, len(ttyp)): |
221 |
if ttyp[i] != None: |
if ttyp[i] != None: |
222 |
sca2 = 0.8 |
sca2 = 0.8 |
223 |
|
|
224 |
if ttyp[i] in ("TexGen2D", "TexGen3D"): |
if ttyp[i] in ("TexGen2D", "TexGen3D"): |
225 |
data = rootrep.getRelated(rnd).texCoords2D(rnd).getVec() |
data = rootrep.getRelated(rnd).texCoords2D(rnd).getVec() |
226 |
elif ttyp[i] == "TexGen2D": |
elif ttyp[i] == "TexGen2D": |
227 |
data = TexCoords().texCoords2D(rnd).getVec() |
data = TexCoords().texCoords2D(rnd).getVec() |
228 |
elif ttyp[i] == "TexGen3D": |
elif ttyp[i] == "TexGen3D": |
229 |
data = TexCoords().texCoords3D(rnd).getVec() |
data = TexCoords().texCoords3D(rnd).getVec() |
230 |
|
|
231 |
elif ttyp[i] == "TexGenDotVector": |
elif ttyp[i] == "TexGenDotVector": |
232 |
data = [ 0, 0, 0, sca2*rnd.nextGaussian(), |
data = [ 0, 0, 0, sca2*rnd.nextGaussian(), |
233 |
0, 0, 0, sca2*rnd.nextGaussian(), |
0, 0, 0, sca2*rnd.nextGaussian(), |
234 |
0, 0, 0, sca2*rnd.nextGaussian() ] |
0, 0, 0, sca2*rnd.nextGaussian() ] |
235 |
else: |
else: |
236 |
assert 0 |
assert 0 |
237 |
if len(data) < 12: |
if len(data) < 12: |
238 |
for i in (0,0,0,1): data.append(i) |
for i in (0,0,0,1): data.append(i) |
239 |
if emboss : |
if emboss : |
240 |
if eps > 0: |
if eps > 0: |
241 |
prev = data |
prev = data |