aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes
diff options
context:
space:
mode:
authorChien Yang <[email protected]>2007-03-06 04:59:57 +0000
committerChien Yang <[email protected]>2007-03-06 04:59:57 +0000
commitce4454ea2fba291eedd5f1623c48faaec5d34e1a (patch)
treea16e4ecef5731e68fcfd57b577a56815c0aaa590 /src/classes
parentf558afb8ef2797ff0cfe3e9918ffcee29892d6d1 (diff)
1) Fixed Issue 414 : D3D: NPOT textures not properly disabled on card that lacks support
2) Redo NPOT support by pushing all control logic to Java side. git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@784 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/jogl/javax/media/j3d/JoglContext.java3
-rw-r--r--src/classes/jogl/javax/media/j3d/JoglPipeline.java55
-rw-r--r--src/classes/share/javax/media/j3d/TextureRetained.java40
3 files changed, 28 insertions, 70 deletions
diff --git a/src/classes/jogl/javax/media/j3d/JoglContext.java b/src/classes/jogl/javax/media/j3d/JoglContext.java
index 211507b..90923f6 100644
--- a/src/classes/jogl/javax/media/j3d/JoglContext.java
+++ b/src/classes/jogl/javax/media/j3d/JoglContext.java
@@ -28,7 +28,6 @@ class JoglContext implements Context {
private int currentTextureUnit;
private int currentCombinerUnit;
private boolean hasMultisample;
- private boolean hasTextureNonPowerOfTwo;
// Needed for vertex attribute implementation
private JoglShaderObject shaderProgram;
@@ -169,8 +168,6 @@ class JoglContext implements Context {
void setCurrentCombinerUnit(int val) { currentCombinerUnit = val; }
boolean getHasMultisample() { return hasMultisample; }
void setHasMultisample(boolean val){ hasMultisample = val; }
- boolean getHasTextureNonPowerOfTwo() { return hasTextureNonPowerOfTwo; }
- void setHasTextureNonPowerOfTwo(boolean val){ hasTextureNonPowerOfTwo = val; }
// Helpers for vertex attribute methods
void initCgVertexAttributeImpl() {
diff --git a/src/classes/jogl/javax/media/j3d/JoglPipeline.java b/src/classes/jogl/javax/media/j3d/JoglPipeline.java
index 7b6b6b7..8e2c842 100644
--- a/src/classes/jogl/javax/media/j3d/JoglPipeline.java
+++ b/src/classes/jogl/javax/media/j3d/JoglPipeline.java
@@ -5781,13 +5781,6 @@ class JoglPipeline extends Pipeline {
int type = GL.GL_UNSIGNED_INT_8_8_8_8;
boolean forceAlphaToOne = false;
- // check if we are trying to draw NPOT on a system that doesn't support it
- if (!(((JoglContext) ctx).getHasTextureNonPowerOfTwo()) &&
- (!isPowerOfTwo(width) || !isPowerOfTwo(height) || !isPowerOfTwo(depth))) {
- // disable texture by setting width, height and depth to 0
- width = height = depth = 0;
- }
-
switch (textureFormat) {
case Texture.INTENSITY:
internalFormat = GL.GL_INTENSITY;
@@ -5950,24 +5943,6 @@ class JoglPipeline extends Pipeline {
pixelStore = true;
gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, tilew);
}
-
- // if NPOT textures are not supported, check if h=w=0, if so we have been
- // disabled due to a NPOT texture being sent to a context that doesn't
- // support it: disable the glTexSubImage as well
- if (!(((JoglContext) ctx).getHasTextureNonPowerOfTwo())) {
- int[] tmp = new int[1];
- int texWidth, texHeight, texDepth;
- gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_WIDTH, tmp, 0);
- texWidth = tmp[0];
- gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_HEIGHT, tmp, 0);
- texHeight = tmp[0];
- gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_DEPTH, tmp, 0);
- texDepth = tmp[0];
- if ((texWidth == 0) && (texHeight == 0) && (texDepth == 0)) {
- // disable the sub-image by setting it's width, height and depth to 0
- width = height = depth = 0;
- }
- }
switch (textureFormat) {
case Texture.INTENSITY:
@@ -6333,13 +6308,6 @@ class JoglPipeline extends Pipeline {
int type = GL.GL_UNSIGNED_INT_8_8_8_8;
boolean forceAlphaToOne = false;
- // check if we are trying to draw NPOT on a system that doesn't support it
- if (!(((JoglContext) ctx).getHasTextureNonPowerOfTwo()) &&
- (!isPowerOfTwo(width) || !isPowerOfTwo(height))) {
- // disable texture by setting width and height to 0
- width = height = 0;
- }
-
switch (textureFormat) {
case Texture.INTENSITY:
internalFormat = GL.GL_INTENSITY;
@@ -6494,22 +6462,6 @@ class JoglPipeline extends Pipeline {
gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, tilew);
}
- // if NPOT textures are not supported, check if h=w=0, if so we have been
- // disabled due to a NPOT texture being sent to a context that doesn't
- // support it: disable the glTexSubImage as well
- if (!(((JoglContext) ctx).getHasTextureNonPowerOfTwo())) {
- int[] tmp = new int[1];
- int texWidth, texHeight;
- gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_WIDTH, tmp, 0);
- texWidth = tmp[0];
- gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_HEIGHT, tmp, 0);
- texHeight = tmp[0];
- if ((texWidth == 0) && (texHeight == 0)) {
- // disable the sub-image by setting it's width and height to 0
- width = height = 0;
- }
- }
-
switch (textureFormat) {
case Texture.INTENSITY:
internalFormat = GL.GL_INTENSITY;
@@ -6659,11 +6611,6 @@ class JoglPipeline extends Pipeline {
}
-
- private static boolean isPowerOfTwo(int val) {
- return ((val & (val - 1)) == 0);
- }
-
void updateTextureFilterModes(Context ctx,
int target,
int minFilter,
@@ -8296,7 +8243,6 @@ class JoglPipeline extends Pipeline {
if (!VirtualUniverse.mc.enforcePowerOfTwo &&
gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) {
cv.textureExtendedFeatures |= Canvas3D.TEXTURE_NON_POWER_OF_TWO;
- ctx.setHasTextureNonPowerOfTwo(true);
}
}
@@ -8489,7 +8435,6 @@ class JoglPipeline extends Pipeline {
if (gl20) {
if(!VirtualUniverse.mc.enforcePowerOfTwo) {
cv.textureExtendedFeatures |= Canvas3D.TEXTURE_NON_POWER_OF_TWO;
- ctx.setHasTextureNonPowerOfTwo(true);
}
}
diff --git a/src/classes/share/javax/media/j3d/TextureRetained.java b/src/classes/share/javax/media/j3d/TextureRetained.java
index 6ed41eb..7fa241e 100644
--- a/src/classes/share/javax/media/j3d/TextureRetained.java
+++ b/src/classes/share/javax/media/j3d/TextureRetained.java
@@ -68,7 +68,7 @@ abstract class TextureRetained extends NodeComponentRetained {
int format = Texture.RGB; // Texture format
int width = 1; // Width in pixels (2**n)
int height = 1; // Height in pixels (2**m)
-
+ private boolean widthOrHeightIsNPOT = false; // true if width or height is non power of two
ImageComponentRetained images[][]; // Array of images (one for each mipmap level)
boolean imagesLoaded = false; // TRUE if all mipmap levels are loaded
int mipmapLevels; // Number of MIPMAP levels needed
@@ -166,17 +166,24 @@ abstract class TextureRetained extends NodeComponentRetained {
// need to synchronize access from multiple rendering threads
Object resourceLock = new Object();
-
+ private static boolean isPowerOfTwo(int val) {
+ return ((val & (val - 1)) == 0);
+ }
+
void initialize(int format, int width, int widLevels,
int height, int heiLevels, int mipmapMode,
int boundaryWidth) {
-
+
this.mipmapMode = mipmapMode;
this.format = format;
this.width = width;
this.height = height;
this.boundaryWidth = boundaryWidth;
+ if(!isPowerOfTwo(width) || !isPowerOfTwo(height)) {
+ this.widthOrHeightIsNPOT = true;
+ }
+
// determine the maximum number of mipmap levels that can be
// defined from the specified dimension
@@ -1094,17 +1101,26 @@ abstract class TextureRetained extends NodeComponentRetained {
}
}
-
+ private boolean isEnabled(Canvas3D cv) {
+ if(widthOrHeightIsNPOT &&
+ (((cv.textureExtendedFeatures & Canvas3D.TEXTURE_NON_POWER_OF_TWO ) == 0) ||
+ VirtualUniverse.mc.enforcePowerOfTwo)) {
+ return false;
+ }
+ return enable;
+ }
+
+
// bind a named texture to a texturing target
-
void bindTexture(Canvas3D cv) {
+
synchronized(resourceLock) {
if (objectId == -1) {
objectId = getTextureId();
}
cv.addTextureResource(objectId, this);
}
- bindTexture(cv.ctx, objectId, enable);
+ bindTexture(cv.ctx, objectId, isEnabled(cv));
}
@@ -1362,7 +1378,7 @@ abstract class TextureRetained extends NodeComponentRetained {
y = info.y,
width = info.width,
height = info.height;
-
+
//The x and y here specifies the subregion of the imageData of
//the associated RenderedImage.
@@ -1375,7 +1391,7 @@ abstract class TextureRetained extends NodeComponentRetained {
int xoffset = x;
int yoffset = y;
- // TODO Check this logic : If !yUp adjust yoffset --- Chien
+ // TODO Check this logic : If !yUp adjust yoffset
if (!image.yUp) {
yoffset = image.height - yoffset - height;
}
@@ -1646,12 +1662,12 @@ abstract class TextureRetained extends NodeComponentRetained {
// if texture is not enabled, don't bother downloading the
// the texture state
- if (enable == false) {
+ if (!isEnabled(cv)) {
return;
}
bindTexture(cv);
-
+
// reload all levels of texture image
// update texture parameters such as boundary modes, filtering
@@ -1689,11 +1705,11 @@ abstract class TextureRetained extends NodeComponentRetained {
//System.out.println("Texture/updateNative: " + this + "object= " + objectId + " enable= " + enable);
bindTexture(cv);
-
+
// if texture is not enabled, don't bother downloading the
// the texture state
- if (enable == false) {
+ if (!isEnabled(cv)) {
return;
}