aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChien Yang <[email protected]>2006-10-27 20:00:45 +0000
committerChien Yang <[email protected]>2006-10-27 20:00:45 +0000
commit43daeb67bce1132b0d6479ddd3ef735038bd33a3 (patch)
treeb703410a5a4e4f10b5e9642f7097a59e1531e6ee /src
parenta667c6f38ae0916ef492c4d1bdbb9479db91c260 (diff)
Fix to issue 371 : Poor raster quality for systems that don't support NPOT textures
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@730 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src')
-rw-r--r--src/classes/share/javax/media/j3d/ImageComponentRetained.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/classes/share/javax/media/j3d/ImageComponentRetained.java b/src/classes/share/javax/media/j3d/ImageComponentRetained.java
index 2279b89..c0e6e8a 100644
--- a/src/classes/share/javax/media/j3d/ImageComponentRetained.java
+++ b/src/classes/share/javax/media/j3d/ImageComponentRetained.java
@@ -1762,18 +1762,35 @@ abstract class ImageComponentRetained extends NodeComponentRetained {
}
}
+ private int getCeilPowerOf2(int value) {
+
+ if (value < 1)
+ return value;
+
+ int powerValue = 1;
+ for (;;) {
+ powerValue *= 2;
+ if (value <= powerValue) {
+ // Found max bound of power
+ return powerValue;
+ }
+ }
+ }
+
void evaluateExtNonPowerOfTwo(int ext) {
+ int npotWidth;
+ int npotHeight;
// If npotSupported is false, a copy power of two image has been created
// so we don't have to check again.
if(!npotSupported) {
return;
}
-
+
if (imageData == null && !isByReference()) {
return;
}
-
+
if((ext & Canvas3D.TEXTURE_NON_POWER_OF_TWO) != 0) {
return;
}
@@ -1781,12 +1798,17 @@ abstract class ImageComponentRetained extends NodeComponentRetained {
// NPOT is unsupported, set flag to false.
npotSupported = false;
- // scale to power of 2 for texture mapping
- //xmax and ymax are in BackgroundRetained.
- /* xmax = width;
- ymax = height; */
- int npotWidth = getClosestPowerOf2(width);
- int npotHeight = getClosestPowerOf2(height);
+ // Always scale up if image size is smaller 512*512.
+ if((width * height) < 262144) {
+ npotWidth = getCeilPowerOf2(width);
+ npotHeight = getCeilPowerOf2(height);
+ } else {
+ npotWidth = getClosestPowerOf2(width);
+ npotHeight = getClosestPowerOf2(height);
+ }
+
+// System.err.println("width " + width + " height " + height + " npotWidth " + npotWidth + " npotHeight " + npotHeight);
+
float xScale = (float)npotWidth/(float)width;
float yScale = (float)npotHeight/(float)height;