25 |
maxsize >> i, maxsize >> i, 0, |
maxsize >> i, maxsize >> i, 0, |
26 |
"RGBA", "UNSIGNED_BYTE", ebytes) |
"RGBA", "UNSIGNED_BYTE", ebytes) |
27 |
|
|
|
tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAG_FILTER", "LINEAR") |
|
|
tex.setTexParameter("TEXTURE_2D", "TEXTURE_MIN_FILTER", "LINEAR_MIPMAP_LINEAR") |
|
|
tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_ANISOTROPY_EXT", "20") |
|
28 |
|
|
29 |
|
quadlist = vob.gl.GL.createDisplayList(""" |
30 |
|
Begin QUADS |
31 |
|
TexCoord 0 0 |
32 |
|
Vertex 0 0 |
33 |
|
TexCoord 0 1 |
34 |
|
Vertex 0 1 |
35 |
|
TexCoord 1 1 |
36 |
|
Vertex 1 1 |
37 |
|
TexCoord 1 0 |
38 |
|
Vertex 1 0 |
39 |
|
End |
40 |
|
""") |
41 |
|
quadlistId = quadlist.getDisplayListID() |
42 |
|
|
43 |
|
if 1: |
44 |
|
# Use the simple distorted surrounding-square mode |
45 |
|
def getSqSize(level): |
46 |
|
"""Get the size of the square to use in the unified visualization. |
47 |
|
|
48 |
|
level -- mipmap level |
49 |
|
""" |
50 |
|
if level == 0: return 2 |
51 |
|
else: return getSqSize(level-1) * 2 + 2 |
52 |
|
|
53 |
|
def getSqCoord(level, x): |
54 |
|
"""Get the relative coordinate of the square in the unified visualization. |
55 |
|
|
56 |
|
level -- mipmap level |
57 |
|
x -- the coordinate in the texture |
58 |
|
""" |
59 |
|
# print "GetSqCoord",level,x |
60 |
|
if level >= nlevels: return 0 |
61 |
|
ret = 1 + (x & 1) * getSqSize(level) + getSqCoord(level+1, x>>1) |
62 |
|
# print "Ret: ",ret |
63 |
|
return ret |
64 |
|
|
65 |
|
squareLists = [] |
66 |
|
for level in range(0, nlevels + 1): |
67 |
|
sqSize = getSqSize(level) |
68 |
|
sql = [] |
69 |
|
for i in range(0, sqSize): |
70 |
|
sqM = sqSize - 1 |
71 |
|
sql.append(""" |
72 |
|
PushMatrix |
73 |
|
Translate %(i)s 0 0 |
74 |
|
CallList %(quadlistId)s |
75 |
|
Translate 0 %(sqM)s 0 |
76 |
|
CallList %(quadlistId)s |
77 |
|
PopMatrix |
78 |
|
PushMatrix |
79 |
|
Translate 0 %(i)s 0 |
80 |
|
CallList %(quadlistId)s |
81 |
|
Translate %(sqM)s 0 0 |
82 |
|
CallList %(quadlistId)s |
83 |
|
PopMatrix |
84 |
|
""" % locals()) |
85 |
|
squareLists.append(GL.createDisplayList("".join(sql))) |
86 |
|
else: |
87 |
|
# XXX unfinished use real square |
88 |
|
def getSqCoord(level, x): |
89 |
|
return nlevels - level + (nlevels+1)*0 |
90 |
|
|
91 |
xoffs = 0 |
xoffs = 0 |
92 |
list = [""" |
list = [""" |
93 |
BindTexture TEXTURE_2D %s |
BindTexture TEXTURE_2D %s |
94 |
""" % tex.getTexId()] |
""" % tex.getTexId()] |
95 |
|
|
96 |
|
sqx = 10 |
97 |
|
sqy = 100 |
98 |
|
|
99 |
|
|
100 |
for i in range(0, nlevels + 1): |
for i in range(0, nlevels + 1): |
101 |
|
listId = squareLists[i].getDisplayListID() |
102 |
for x in range(0, maxsize >> i): |
for x in range(0, maxsize >> i): |
103 |
|
xsq = sqx + getSqCoord(i, x) |
104 |
for y in range(0, maxsize >> i): |
for y in range(0, maxsize >> i): |
105 |
xt = x * (1. / (maxsize >> i)) |
ysq = sqy + getSqCoord(i, y) |
|
yt = y * (1. / (maxsize >> i)) |
|
106 |
xm = x + xoffs |
xm = x + xoffs |
107 |
ym = y |
ym = y |
|
xp = xm+1 |
|
|
yp = ym+1 |
|
108 |
list.append(""" |
list.append(""" |
109 |
TexSubImage2D TEXTURE_2D %(i)s %(x)s %(y)s 1 1 RGBA 1 1 1 1 |
TexSubImage2D TEXTURE_2D %(i)s %(x)s %(y)s 1 1 RGBA 1 1 1 1 |
110 |
Begin QUADS |
PushMatrix |
111 |
TexCoord 0 0 |
Translate %(xm)s %(ym)s 0 |
112 |
Vertex %(xm)s %(ym)s |
CallList %(quadlistId)s |
113 |
TexCoord 0 1 |
PopMatrix |
114 |
Vertex %(xm)s %(yp)s |
""" % locals()) |
115 |
TexCoord 1 1 |
|
116 |
Vertex %(xp)s %(yp)s |
list.append(""" |
117 |
TexCoord 1 0 |
PushMatrix |
118 |
Vertex %(xp)s %(ym)s |
Translate %(xsq)s %(ysq)s 0 |
119 |
End |
CallList %(listId)s |
120 |
|
PopMatrix |
121 |
|
""" % locals()) |
122 |
|
|
123 |
|
list.append(""" |
124 |
TexSubImage2D TEXTURE_2D %(i)s %(x)s %(y)s 1 1 RGBA 0.5 0.5 0.5 0.5 |
TexSubImage2D TEXTURE_2D %(i)s %(x)s %(y)s 1 1 RGBA 0.5 0.5 0.5 0.5 |
125 |
"""% locals()) |
"""% locals()) |
126 |
xoffs += maxsize >> i |
xoffs += maxsize >> i |
129 |
# print "".join(list) |
# print "".join(list) |
130 |
|
|
131 |
list = getDListNocoords("".join(list)) |
list = getDListNocoords("".join(list)) |
132 |
|
# XXX SHould adddepend to dlist but not vital |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
class Scene: |
class Scene: |
137 |
def __init__(self): |
def __init__(self): |
138 |
|
self.minfilters = [ |
139 |
|
"LINEAR_MIPMAP_LINEAR", |
140 |
|
"LINEAR_MIPMAP_NEAREST", |
141 |
|
"NEAREST_MIPMAP_LINEAR", |
142 |
|
"NEAREST_MIPMAP_NEAREST", |
143 |
|
] |
144 |
self.key = KeyPresses( |
self.key = KeyPresses( |
145 |
self, |
self, |
146 |
SlideLin("ctrx", .5, .01, "x coord", "Left", "Right"), |
SlideLin("ctrx", .5, .01, "x coord", "Left", "Right"), |
148 |
SlideLin("rot", 0, 1, "angle", ">", "<"), |
SlideLin("rot", 0, 1, "angle", ">", "<"), |
149 |
SlideLog("sx", .09, "x scale", "j", "k"), |
SlideLog("sx", .09, "x scale", "j", "k"), |
150 |
SlideLog("sy", .09, "y scale", "h", "l"), |
SlideLog("sy", .09, "y scale", "h", "l"), |
151 |
|
ListIndex("minfilter", "minfilters", 0, "Filter type", "F", "f"), |
152 |
) |
) |
153 |
def scene(self, vs): |
def scene(self, vs): |
154 |
self.vs = vs |
self.vs = vs |
158 |
texturerot = vs.rotateCS(texturetrans, "B", self.rot) |
texturerot = vs.rotateCS(texturetrans, "B", self.rot) |
159 |
texturemat = vs.scaleCS(texturerot, "C", self.sx, self.sy) |
texturemat = vs.scaleCS(texturerot, "C", self.sx, self.sy) |
160 |
|
|
161 |
|
tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAG_FILTER", "LINEAR") |
162 |
|
tex.setTexParameter("TEXTURE_2D", "TEXTURE_MIN_FILTER", self.minfilters[self.minfilter]) |
163 |
|
tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_ANISOTROPY_EXT", "20") |
164 |
|
|
165 |
|
# invtexturemat = vs.invertCS(texturemat, "D") |
166 |
|
print "Min: ",self.minfilters[self.minfilter] |
167 |
|
|
168 |
vs.put(getDListNocoords(vob.putil.nvcode.parseCombiner(""" |
vs.put(getDListNocoords(vob.putil.nvcode.parseCombiner(""" |
169 |
|
PushAttrib ENABLE_BIT TEXTURE_BIT |
170 |
Enable TEXTURE_2D |
Enable TEXTURE_2D |
171 |
Disable BLEND |
Disable BLEND |
172 |
Disable ALPHA_TEST |
Disable ALPHA_TEST |
174 |
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE |
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
# Strengthen by multiplying by 4 |
# Strengthen by multiplying by 4 |
179 |
|
|
180 |
Enable REGISTER_COMBINERS_NV |
Enable REGISTER_COMBINERS_NV |
199 |
texturemat) |
texturemat) |
200 |
vs.put(list) |
vs.put(list) |
201 |
|
|
202 |
|
footprintFrame = vs.orthoCS(0, "F", 0, 500, 100, 256, 256) |
203 |
|
footprintCS = vs.coords.concat(footprintFrame, texturemat) |
204 |
|
vs.matcher.add(footprintCS, "FP") |
205 |
|
footprintCS = vs.translateCS(footprintCS, "TRA", 0, 0, -10) |
206 |
|
|
207 |
|
vs.put(getDListNocoords(""" |
208 |
|
PopAttrib |
209 |
|
Disable TEXTURE_2D |
210 |
|
PolygonMode FRONT_AND_BACK LINE |
211 |
|
""")) |
212 |
|
|
213 |
|
vs.put(coloredQuad((0,0,0)), footprintFrame) |
214 |
|
vs.put(coloredQuad((1,0,0)), footprintCS) |
215 |
|
|
216 |
|
vs.put(getDListNocoords(""" |
217 |
|
PolygonMode FRONT_AND_BACK FILL |
218 |
|
""")) |
219 |
|
|
220 |
|
print vs.coords.transformPoints3(footprintCS, [0,0,0, 0,1,0, 1,0,0, 1,1,0], None) |
221 |
|
|
222 |
|
|