101 |
* thread. |
* thread. |
102 |
*/ |
*/ |
103 |
synchronized void loadData() throws IOException { |
synchronized void loadData() throws IOException { |
104 |
|
if(dbg) |
105 |
|
pa("LoadData "+MipzipLoader.this+" "+level+ |
106 |
|
" "+state); |
107 |
if(state != STATE_NONE) return; |
if(state != STATE_NONE) return; |
108 |
// Not sure if required, but safer |
// Not sure if required, but safer |
109 |
loadedData = readEntry(""+level); |
loadedData = readEntry(""+level); |
116 |
* Must be called in GL thread. |
* Must be called in GL thread. |
117 |
*/ |
*/ |
118 |
synchronized void texImage() { |
synchronized void texImage() { |
119 |
|
if(dbg) |
120 |
|
pa("TexImage "+MipzipLoader.this+" "+level+ |
121 |
|
" "+state); |
122 |
if(state != STATE_DATALOADED) return; |
if(state != STATE_DATALOADED) return; |
123 |
tex.compressedTexImage(level, texFormat, |
tex.compressedTexImage(level, texFormat, |
124 |
size.width, size.height, 0, |
size.width, size.height, 0, |
133 |
* Hope this really works. |
* Hope this really works. |
134 |
*/ |
*/ |
135 |
synchronized void discard() { |
synchronized void discard() { |
136 |
|
if(dbg) |
137 |
|
pa("Discard "+MipzipLoader.this+" "+level+ |
138 |
|
" "+state); |
139 |
switch(state) { |
switch(state) { |
140 |
case STATE_INTEXTURE: |
case STATE_INTEXTURE: |
141 |
tex.loadNull2D(level, texFormat, |
tex.loadNull2D(level, texFormat, |
194 |
*/ |
*/ |
195 |
synchronized public void setGoalBaseLevel(int level, |
synchronized public void setGoalBaseLevel(int level, |
196 |
Background bg, float priority) { |
Background bg, float priority) { |
197 |
|
if(dbg) pa("MipzipLoader "+this+" goal "+level); |
198 |
this.goalBaseLevel = level; |
this.goalBaseLevel = level; |
199 |
this.bg = bg; |
this.bg = bg; |
200 |
this.priority = priority; |
this.priority = priority; |
213 |
}; |
}; |
214 |
|
|
215 |
synchronized private void runBg() { |
synchronized private void runBg() { |
216 |
|
if(dbg) pa("MipzipLoader "+this+" runBg!!"); |
217 |
// See what data is missing and load it |
// See what data is missing and load it |
218 |
for(int i=levels.length-1; i >= goalBaseLevel && i >= 0; |
for(int i=levels.length-1; i >= goalBaseLevel && i >= 0; |
219 |
i--) { |
i--) { |
240 |
// If yes, discard and reschedule. |
// If yes, discard and reschedule. |
241 |
// Then, set base level and return. |
// Then, set base level and return. |
242 |
synchronized private void runGL() { |
synchronized private void runGL() { |
243 |
|
if(dbg) pa("MipzipLoader "+this+" runGL!!"); |
244 |
for(int i=0; i<goalBaseLevel && i < levels.length-1; |
for(int i=0; i<goalBaseLevel && i < levels.length-1; |
245 |
i++) { |
i++) { |
246 |
if(levels[i].state != STATE_NONE) { |
if(levels[i].state != STATE_NONE) { |
296 |
/** Get the level that uses at most given amount of memory. |
/** Get the level that uses at most given amount of memory. |
297 |
* @return The level index. |
* @return The level index. |
298 |
*/ |
*/ |
299 |
public int getLevelBytes(int memory) { |
public int getLevelForBytes(int memory) { |
300 |
for(int i = 0; i<levels.length; i++) { |
for(int i = 0; i<levels.length; i++) { |
301 |
if(getMemory(i) <= memory) return i; |
if(getMemory(i) <= memory) return i; |
302 |
} |
} |
315 |
int maxdim = Math.max(levels[0].size.height, levels[0].size.width); |
int maxdim = Math.max(levels[0].size.height, levels[0].size.width); |
316 |
float ratio = maxdim / quality; |
float ratio = maxdim / quality; |
317 |
int l = (int)(Math.log(ratio) / LG2); |
int l = (int)(Math.log(ratio) / LG2); |
318 |
l = Math.max(0, l); |
int lc = Math.max(0, l); |
319 |
l = Math.min(levels.length-1, l); |
lc = Math.min(levels.length-1, lc); |
320 |
|
if(false) pa("Mipzip level4qual: "+this+" "+ |
321 |
|
quality+" "+maxdim+" "+ratio+" "+ |
322 |
|
l+" "+levels.length+" "+lc); |
323 |
return l; |
return l; |
324 |
} |
} |
325 |
|
|