OSDN Git Service

[fixed] issue 76, OpenGL ES 2.0 allows non-power of two textures. Got to figure out...
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 14 Dec 2010 15:47:10 +0000 (15:47 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 14 Dec 2010 15:47:10 +0000 (15:47 +0000)
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidTexture.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGraphics.java
backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGraphics.java

index 4418f94..3384f3b 100644 (file)
@@ -51,6 +51,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer;
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.WindowedMean;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
+import com.badlogic.gdx.utils.MathUtils;\r
 \r
 /**\r
  * An implementation of {@link Graphics} for Android.\r
@@ -491,9 +492,8 @@ public final class AndroidGraphics implements Graphics, Renderer {
        public Texture newUnmanagedTexture(int width, int height, Format format,\r
                        TextureFilter minFilter, TextureFilter magFilter,\r
                        TextureWrap uWrap, TextureWrap vWrap) {\r
-               if (!isPowerOfTwo(width) || !isPowerOfTwo(height))\r
-                       throw new GdxRuntimeException(\r
-                                       "Dimensions have to be a power of two");\r
+               if (gl!=gl20 && (!MathUtils.isPowerOfTwo(width) || !MathUtils.isPowerOfTwo(height)))\r
+                       throw new GdxRuntimeException("Dimensions have to be a power of two");\r
 \r
                Bitmap.Config config = AndroidPixmap.getInternalFormat(format);\r
                Bitmap bitmap = Bitmap.createBitmap(width, height, config);\r
@@ -508,10 +508,8 @@ public final class AndroidGraphics implements Graphics, Renderer {
        public Texture newUnmanagedTexture(Pixmap pixmap, TextureFilter minFilter,\r
                        TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
 \r
-               if (!isPowerOfTwo(pixmap.getWidth())\r
-                               || !isPowerOfTwo(pixmap.getHeight()))\r
-                       throw new GdxRuntimeException(\r
-                                       "Dimensions have to be a power of two");\r
+               if (gl!=gl20 && (!MathUtils.isPowerOfTwo(pixmap.getWidth()) || !MathUtils.isPowerOfTwo(pixmap.getHeight())))\r
+                       throw new GdxRuntimeException("Dimensions have to be a power of two");\r
 \r
                return new AndroidTexture(this, (Bitmap) pixmap.getNativePixmap(),\r
                                minFilter, magFilter, uWrap, vWrap, false, null);\r
index 520d817..86d9611 100644 (file)
@@ -83,6 +83,9 @@ final class AndroidTexture implements Texture {
                if (image != null) {\r
                        this.texWidth = image.getWidth();\r
                        this.texHeight = image.getHeight();\r
+                       \r
+                       if (Gdx.gl!=Gdx.gl20 && (!MathUtils.isPowerOfTwo(image.getWidth()) || !MathUtils.isPowerOfTwo(image.getHeight())))\r
+                               throw new GdxRuntimeException("texture must have power of two size");\r
                }\r
 \r
                createTexture();\r
index 3c48111..7bb951c 100644 (file)
@@ -232,7 +232,7 @@ public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
        public Texture newUnmanagedTexture(int width, int height,\r
                        Pixmap.Format format, TextureFilter minFilter,\r
                        TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
-               if (!isPowerOfTwo(width) || !isPowerOfTwo(height))\r
+               if (gl!=gl20 && (!isPowerOfTwo(width) || !isPowerOfTwo(height)))\r
                        throw new GdxRuntimeException(\r
                                        "Texture dimensions must be a power of two");\r
 \r
@@ -248,8 +248,7 @@ public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
        @Override\r
        public Texture newUnmanagedTexture(Pixmap pixmap, TextureFilter minFilter,\r
                        TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
-               if (!isPowerOfTwo(pixmap.getHeight())\r
-                               || !isPowerOfTwo(pixmap.getWidth()))\r
+               if (gl!=gl20 && (!isPowerOfTwo(pixmap.getWidth()) || !isPowerOfTwo(pixmap.getHeight())))\r
                        throw new GdxRuntimeException(\r
                                        "Texture dimensions must be a power of two");\r
 \r
@@ -261,8 +260,7 @@ public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
        public Texture newTexture(FileHandle file, TextureFilter minFilter,\r
                        TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
                Pixmap pixmap = newPixmap(file);\r
-               if (!isPowerOfTwo(pixmap.getHeight())\r
-                               || !isPowerOfTwo(pixmap.getWidth()))\r
+               if (gl!=gl20 && (!isPowerOfTwo(pixmap.getWidth()) || !isPowerOfTwo(pixmap.getHeight())))\r
                        throw new GdxRuntimeException(\r
                                        "Texture dimensions must be a power of two");\r
 \r
index 810c682..6716c3c 100644 (file)
@@ -135,7 +135,7 @@ public final class LwjglGraphics implements Graphics {
 \r
        public Texture newUnmanagedTexture (int width, int height, Pixmap.Format format, TextureFilter minFilter,\r
                TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
-               if (!MathUtils.isPowerOfTwo(width) || !MathUtils.isPowerOfTwo(height))\r
+               if (gl!=gl20 && (!MathUtils.isPowerOfTwo(height) || !MathUtils.isPowerOfTwo(height)))\r
                        throw new GdxRuntimeException("Texture dimensions must be a power of two: " + width + "x" + height);\r
 \r
                if (format == Format.Alpha)\r
@@ -146,7 +146,7 @@ public final class LwjglGraphics implements Graphics {
 \r
        public Texture newUnmanagedTexture (Pixmap pixmap, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
                TextureWrap vWrap) {\r
-               if (!MathUtils.isPowerOfTwo(pixmap.getHeight()) || !MathUtils.isPowerOfTwo(pixmap.getWidth()))\r
+               if (gl!=gl20 && (!MathUtils.isPowerOfTwo(pixmap.getWidth()) || !MathUtils.isPowerOfTwo(pixmap.getHeight())))\r
                        throw new GdxRuntimeException("Texture dimensions must be a power of two: " + width + "x" + height);\r
 \r
                return new LwjglTexture((BufferedImage)pixmap.getNativePixmap(), minFilter, magFilter, uWrap, vWrap, false);\r
@@ -156,7 +156,7 @@ public final class LwjglGraphics implements Graphics {
                TextureWrap vWrap) {\r
                if (enforcePotImages) {\r
                        Pixmap pixmap = newPixmap(file);\r
-                       if (!MathUtils.isPowerOfTwo(pixmap.getHeight()) || !MathUtils.isPowerOfTwo(pixmap.getWidth()))\r
+                       if (gl!=gl20 && (!MathUtils.isPowerOfTwo(pixmap.getWidth()) || !MathUtils.isPowerOfTwo(pixmap.getHeight())))\r
                                throw new GdxRuntimeException("Texture dimensions must be a power of two: " + file + " (" + pixmap.getWidth() + "x"\r
                                        + pixmap.getHeight() + ")");\r
                }\r
index d19011c..d77fc20 100644 (file)
@@ -127,10 +127,6 @@ public class AngleGraphics implements Graphics {
        public Texture newUnmanagedTexture(int width, int height, Format format,\r
                        TextureFilter minFilter, TextureFilter magFilter,\r
                        TextureWrap uWrap, TextureWrap vWrap) {\r
-               if (!MathUtils.isPowerOfTwo(width) || !MathUtils.isPowerOfTwo(height))\r
-                       throw new GdxRuntimeException(\r
-                                       "Texture dimensions must be a power of two: " + width + "x"\r
-                                                       + height);\r
 \r
                if (format == Format.Alpha)\r
                        return new AngleTexture(width, height,\r
@@ -144,12 +140,7 @@ public class AngleGraphics implements Graphics {
 \r
        @Override\r
        public Texture newUnmanagedTexture(Pixmap pixmap, TextureFilter minFilter,\r
-                       TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
-               if (!MathUtils.isPowerOfTwo(pixmap.getHeight())\r
-                               || !MathUtils.isPowerOfTwo(pixmap.getWidth()))\r
-                       throw new GdxRuntimeException(\r
-                                       "Texture dimensions must be a power of two: " + width + "x"\r
-                                                       + height);\r
+                       TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {        \r
 \r
                return new AngleTexture((BufferedImage) pixmap.getNativePixmap(),\r
                                minFilter, magFilter, uWrap, vWrap, false);\r
@@ -158,11 +149,7 @@ public class AngleGraphics implements Graphics {
        @Override\r
        public Texture newTexture(FileHandle file, TextureFilter minFilter,\r
                        TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {                \r
-               Pixmap pixmap = newPixmap(file);\r
-               if (!MathUtils.isPowerOfTwo(pixmap.getHeight()) || !MathUtils.isPowerOfTwo(pixmap.getWidth()))\r
-                       throw new GdxRuntimeException("Texture dimensions must be a power of two: " + file + " (" + pixmap.getWidth() + "x"\r
-                               + pixmap.getHeight() + ")");            \r
-\r
+               \r
                return new AngleTexture(file, minFilter, magFilter, uWrap, vWrap, false);\r
        }\r
 \r