* Introduce Image.isNPOT() which is now used to check if the image is non-power-of-2 in renderer implementations.
This commit is contained in:
parent
d694229335
commit
81498d6f79
@ -429,14 +429,12 @@ public class TextureUtil {
|
|||||||
int width = img.getWidth();
|
int width = img.getWidth();
|
||||||
int height = img.getHeight();
|
int height = img.getHeight();
|
||||||
|
|
||||||
if (!NPOT) {
|
if (!NPOT && img.isNPOT()) {
|
||||||
// Check if texture is POT
|
// Check if texture is POT
|
||||||
if (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height)) {
|
|
||||||
throw new RendererException("Non-power-of-2 textures "
|
throw new RendererException("Non-power-of-2 textures "
|
||||||
+ "are not supported by the video hardware "
|
+ "are not supported by the video hardware "
|
||||||
+ "and no scaling path available for image: " + img);
|
+ "and no scaling path available for image: " + img);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
AndroidGLImageFormat imageFormat = getImageFormat(fmt);
|
AndroidGLImageFormat imageFormat = getImageFormat(fmt);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
@ -524,14 +522,12 @@ public class TextureUtil {
|
|||||||
int width = img.getWidth();
|
int width = img.getWidth();
|
||||||
int height = img.getHeight();
|
int height = img.getHeight();
|
||||||
|
|
||||||
if (!NPOT) {
|
if (!NPOT && img.isNPOT()) {
|
||||||
// Check if texture is POT
|
// Check if texture is POT
|
||||||
if (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height)) {
|
|
||||||
throw new RendererException("Non-power-of-2 textures "
|
throw new RendererException("Non-power-of-2 textures "
|
||||||
+ "are not supported by the video hardware "
|
+ "are not supported by the video hardware "
|
||||||
+ "and no scaling path available for image: " + img);
|
+ "and no scaling path available for image: " + img);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
AndroidGLImageFormat imageFormat = getImageFormat(fmt);
|
AndroidGLImageFormat imageFormat = getImageFormat(fmt);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
package com.jme3.texture;
|
package com.jme3.texture;
|
||||||
|
|
||||||
import com.jme3.export.*;
|
import com.jme3.export.*;
|
||||||
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.renderer.Caps;
|
import com.jme3.renderer.Caps;
|
||||||
import com.jme3.renderer.Renderer;
|
import com.jme3.renderer.Renderer;
|
||||||
import com.jme3.texture.image.ColorSpace;
|
import com.jme3.texture.image.ColorSpace;
|
||||||
@ -392,6 +393,17 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
|
|||||||
return needGeneratedMips;
|
return needGeneratedMips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the image is NPOT.
|
||||||
|
*
|
||||||
|
* @return if the image is a non-power-of-2 image, e.g. having dimensions
|
||||||
|
* that are not powers of 2.
|
||||||
|
*/
|
||||||
|
public boolean isNPOT() {
|
||||||
|
return width != 0 && height != 0
|
||||||
|
&& (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetObject() {
|
public void resetObject() {
|
||||||
this.id = -1;
|
this.id = -1;
|
||||||
|
@ -443,14 +443,12 @@ public class TextureUtil {
|
|||||||
int width = img.getWidth();
|
int width = img.getWidth();
|
||||||
int height = img.getHeight();
|
int height = img.getHeight();
|
||||||
|
|
||||||
if (!NPOT) {
|
if (!NPOT && img.isNPOT()) {
|
||||||
// Check if texture is POT
|
// Check if texture is POT
|
||||||
if (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height)) {
|
|
||||||
throw new RendererException("Non-power-of-2 textures "
|
throw new RendererException("Non-power-of-2 textures "
|
||||||
+ "are not supported by the video hardware "
|
+ "are not supported by the video hardware "
|
||||||
+ "and no scaling path available for image: " + img);
|
+ "and no scaling path available for image: " + img);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
IosGLImageFormat imageFormat = getImageFormat(fmt);
|
IosGLImageFormat imageFormat = getImageFormat(fmt);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
@ -543,14 +541,12 @@ public class TextureUtil {
|
|||||||
int width = img.getWidth();
|
int width = img.getWidth();
|
||||||
int height = img.getHeight();
|
int height = img.getHeight();
|
||||||
|
|
||||||
if (!NPOT) {
|
if (!NPOT && img.isNPOT()) {
|
||||||
// Check if texture is POT
|
// Check if texture is POT
|
||||||
if (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height)) {
|
|
||||||
throw new RendererException("Non-power-of-2 textures "
|
throw new RendererException("Non-power-of-2 textures "
|
||||||
+ "are not supported by the video hardware "
|
+ "are not supported by the video hardware "
|
||||||
+ "and no scaling path available for image: " + img);
|
+ "and no scaling path available for image: " + img);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
IosGLImageFormat imageFormat = getImageFormat(fmt);
|
IosGLImageFormat imageFormat = getImageFormat(fmt);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
@ -806,16 +806,10 @@ public class JoglGL1Renderer implements GL1Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check sizes if graphics card doesn't support NPOT
|
// Check sizes if graphics card doesn't support NPOT
|
||||||
if (!gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) {
|
if (!gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two") && img.isNPOT()) {
|
||||||
if (img.getWidth() != 0 && img.getHeight() != 0) {
|
|
||||||
if (!FastMath.isPowerOfTwo(img.getWidth())
|
|
||||||
|| !FastMath.isPowerOfTwo(img.getHeight())) {
|
|
||||||
|
|
||||||
// Resize texture to Power-of-2 size
|
// Resize texture to Power-of-2 size
|
||||||
MipMapGenerator.resizeToPowerOf2(img);
|
MipMapGenerator.resizeToPowerOf2(img);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
|
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
|
||||||
// No pregenerated mips available,
|
// No pregenerated mips available,
|
||||||
|
@ -1962,18 +1962,13 @@ public class JoglRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Yes, some OpenGL2 cards (GeForce 5) still dont support NPOT.
|
// Yes, some OpenGL2 cards (GeForce 5) still dont support NPOT.
|
||||||
if (!gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two")) {
|
if (!gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two") && img.isNPOT()) {
|
||||||
if (img.getWidth() != 0 && img.getHeight() != 0) {
|
|
||||||
if (!FastMath.isPowerOfTwo(img.getWidth())
|
|
||||||
|| !FastMath.isPowerOfTwo(img.getHeight())) {
|
|
||||||
if (img.getData(0) == null) {
|
if (img.getData(0) == null) {
|
||||||
throw new RendererException("non-power-of-2 framebuffer textures are not supported by the video hardware");
|
throw new RendererException("non-power-of-2 framebuffer textures are not supported by the video hardware");
|
||||||
} else {
|
} else {
|
||||||
MipMapGenerator.resizeToPowerOf2(img);
|
MipMapGenerator.resizeToPowerOf2(img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if graphics card doesn't support multisample textures
|
// Check if graphics card doesn't support multisample textures
|
||||||
if (!gl.isExtensionAvailable("GL_ARB_texture_multisample")) {
|
if (!gl.isExtensionAvailable("GL_ARB_texture_multisample")) {
|
||||||
|
@ -753,16 +753,10 @@ public class LwjglGL1Renderer implements GL1Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check sizes if graphics card doesn't support NPOT
|
// Check sizes if graphics card doesn't support NPOT
|
||||||
if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) {
|
if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two && img.isNPOT()) {
|
||||||
if (img.getWidth() != 0 && img.getHeight() != 0) {
|
|
||||||
if (!FastMath.isPowerOfTwo(img.getWidth())
|
|
||||||
|| !FastMath.isPowerOfTwo(img.getHeight())) {
|
|
||||||
|
|
||||||
// Resize texture to Power-of-2 size
|
// Resize texture to Power-of-2 size
|
||||||
MipMapGenerator.resizeToPowerOf2(img);
|
MipMapGenerator.resizeToPowerOf2(img);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
|
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
|
||||||
// No pregenerated mips available,
|
// No pregenerated mips available,
|
||||||
|
@ -1870,18 +1870,13 @@ public class LwjglRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Yes, some OpenGL2 cards (GeForce 5) still dont support NPOT.
|
// Yes, some OpenGL2 cards (GeForce 5) still dont support NPOT.
|
||||||
if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) {
|
if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two && img.isNPOT()) {
|
||||||
if (img.getWidth() != 0 && img.getHeight() != 0) {
|
|
||||||
if (!FastMath.isPowerOfTwo(img.getWidth())
|
|
||||||
|| !FastMath.isPowerOfTwo(img.getHeight())) {
|
|
||||||
if (img.getData(0) == null) {
|
if (img.getData(0) == null) {
|
||||||
throw new RendererException("non-power-of-2 framebuffer textures are not supported by the video hardware");
|
throw new RendererException("non-power-of-2 framebuffer textures are not supported by the video hardware");
|
||||||
} else {
|
} else {
|
||||||
MipMapGenerator.resizeToPowerOf2(img);
|
MipMapGenerator.resizeToPowerOf2(img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if graphics card doesn't support multisample textures
|
// Check if graphics card doesn't support multisample textures
|
||||||
if (!GLContext.getCapabilities().GL_ARB_texture_multisample) {
|
if (!GLContext.getCapabilities().GL_ARB_texture_multisample) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user