OSDN Git Service

[fixed] texture loading in angle backend. we really need to unify all the texture...
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 15 Dec 2010 15:57:59 +0000 (15:57 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 15 Dec 2010 15:57:59 +0000 (15:57 +0000)
[added] Pixmap.drawPixel(), cause we like things to be slow...

backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidPixmap.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglPixmap.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglPixmap.java
backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AnglePixmap.java
backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleTexture.java
gdx/src/com/badlogic/gdx/graphics/Pixmap.java
tests/gdx-tests-angle/src/com/badlogic/gdx/tests/angle/AngleDebugStarter.java
tests/gdx-tests/src/com/badlogic/gdx/tests/MeshShaderTest.java

index 10916aa..0bba07d 100644 (file)
@@ -196,4 +196,9 @@ final class AndroidPixmap implements Pixmap {
                pixmap.getPixels(pixels, 0, pixmap.getWidth(), 0, y, pixmap.getWidth(), 1);\r
        }\r
 \r
+       @Override\r
+       public void drawPixel(int x, int y, int color) {\r
+               pixmap.setPixel(x, y, color);\r
+       }\r
+\r
 }\r
index f24591c..c0ef31d 100644 (file)
@@ -217,4 +217,11 @@ final class JoglPixmap implements Pixmap {
 \r
        }\r
 \r
+       @Override\r
+       public void drawPixel(int x, int y, int color) {\r
+               Graphics2D g = pixmap.createGraphics();\r
+               g.setColor(new Color(color, true));\r
+               g.drawRect(x, y, 1, 1);\r
+               g.dispose();\r
+       }\r
 }\r
index 6308fff..6bd6f0d 100644 (file)
@@ -172,5 +172,12 @@ final class LwjglPixmap implements Pixmap {
                }\r
 \r
        }\r
-\r
+       \r
+       @Override\r
+       public void drawPixel(int x, int y, int color) {\r
+               Graphics2D g = pixmap.createGraphics();\r
+               g.setColor(new Color(color, true));\r
+               g.drawRect(x, y, 1, 1);\r
+               g.dispose();\r
+       }\r
 }\r
index f4697cb..8cc99f7 100644 (file)
@@ -173,4 +173,12 @@ final class AnglePixmap implements Pixmap {
 \r
        }\r
 \r
+       @Override\r
+       public void drawPixel(int x, int y, int color) {\r
+               Graphics2D g = pixmap.createGraphics();\r
+               g.setColor(new Color(color, true));\r
+               g.drawRect(x, y, 1, 1);\r
+               g.dispose();\r
+       }\r
+\r
 }\r
index 71b45c4..2ffb4ed 100644 (file)
@@ -61,13 +61,9 @@ final class AngleTexture implements Texture {
                this.isManaged = managed;\r
                this.isMipMapped = TextureFilter.isMipMap(minFilter);\r
 \r
-               if (!isMipMapped && file.path().endsWith(".png")) {\r
-                       // Fast path.\r
-                       loadPNG(file);\r
-               } else {\r
-                       BufferedImage image = (BufferedImage)Gdx.graphics.newPixmap(file).getNativePixmap();\r
-                       loadMipMap(image);\r
-               }\r
+               BufferedImage image = (BufferedImage)Gdx.graphics.newPixmap(file).getNativePixmap();\r
+               loadMipMap(image);\r
+\r
                bind();\r
                GL20 gl = Gdx.graphics.getGL20();\r
                gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
@@ -140,7 +136,7 @@ final class AngleTexture implements Texture {
                        int stride = texWidth * 4;\r
                        ensureBufferSize(stride * texHeight);\r
 \r
-                       Format pngFormat = pngDecoder.decideTextureFormat(PNGDecoder.Format.RGBA);\r
+                       Format pngFormat = pngDecoder.decideTextureFormat(PNGDecoder.Format.BGRA);\r
                        int glFormat, glInternalFormat;\r
                        switch (pngFormat) {\r
                        case ALPHA:\r
@@ -190,15 +186,28 @@ final class AngleTexture implements Texture {
                ensureBufferSize(width * height * 4);\r
 \r
                Raster raster = image.getRaster();\r
-               if (image.getType() == BufferedImage.TYPE_INT_ARGB)\r
-                       intBuffer.put(((DataBufferInt)raster.getDataBuffer()).getData(), 0, width * height);\r
+               if (image.getType() == BufferedImage.TYPE_INT_ARGB ||\r
+                       image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {\r
+                       int[] pixels = ((DataBufferInt)raster.getDataBuffer()).getData();\r
+                       for(int i = 0; i < pixels.length; i++) {\r
+                               int col = pixels[i];\r
+                               col = ((col & 0xffffff) << 8) |\r
+                                     ((col & 0xff000000) >>> 24);\r
+                               pixels[i] = col;\r
+                       }\r
+                       intBuffer.put(pixels, 0, width * height);\r
+               }\r
                else {\r
                        // Same as image.getRGB() without allocating a large int[].\r
                        ColorModel colorModel = image.getColorModel();\r
                        Object data = raster.getDataElements(0, 0, null);\r
                        for (int y = 0; y < height; y++)\r
-                               for (int x = 0; x < width; x++)\r
-                                       intBuffer.put(colorModel.getRGB(raster.getDataElements(x, y, data)));\r
+                               for (int x = 0; x < width; x++) {\r
+                                       int col = colorModel.getRGB(raster.getDataElements(x, y, data));\r
+                                       col = ((col & 0xffffff) << 8) |\r
+                                         ((col & 0xff000000) >>> 24);\r
+                                       intBuffer.put(col);\r
+                               }\r
                }\r
 \r
                buffer.limit(intBuffer.position() * 4);\r
@@ -209,7 +218,7 @@ final class AngleTexture implements Texture {
                if (buffer == null || buffer.capacity() < size) {\r
                        buffer = BufferUtils.newByteBuffer(size);\r
                        ByteBuffer temp = buffer.slice();\r
-                       temp.order(ByteOrder.LITTLE_ENDIAN);\r
+                       temp.order(ByteOrder.BIG_ENDIAN);\r
                        intBuffer = temp.asIntBuffer();\r
                } else {\r
                        buffer.clear();\r
@@ -226,7 +235,7 @@ final class AngleTexture implements Texture {
                return scaled;\r
        }\r
 \r
-       private void loadMipMap (BufferedImage image) {\r
+       private void loadMipMap (BufferedImage image) {         \r
                int level = 0;\r
                int height = image.getHeight();\r
                int width = image.getWidth();\r
index 788312a..1131ebd 100644 (file)
@@ -155,4 +155,13 @@ public interface Pixmap {
         * Releases all resources associated with this Pixmap.\r
         */\r
        public void dispose ();\r
+\r
+       /**\r
+        * Draws a pixel at the given location\r
+        * \r
+        * @param x the x-coordinate\r
+        * @param y the y-coordinate\r
+        * @param color the color, ARGB8888\r
+        */\r
+       public void drawPixel(int x, int y, int color);\r
 }\r
index 78c26e2..bbde349 100644 (file)
@@ -17,6 +17,6 @@ import com.badlogic.gdx.backends.angle.AngleApplication;
 \r
 public class AngleDebugStarter {\r
        public static void main (String[] argv) {\r
-               new AngleApplication(new com.badlogic.gdx.tests.VertexBufferObjectShaderTest(), "Angle Test", 480, 320, false);\r
+               new AngleApplication(new com.badlogic.gdx.tests.MeshShaderTest(), "Angle Test", 480, 320, false);\r
        }\r
 }\r
index 0342d78..4654ceb 100644 (file)
 \r
 package com.badlogic.gdx.tests;\r
 \r
-import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.graphics.GL10;\r
 import com.badlogic.gdx.graphics.GL20;\r
 import com.badlogic.gdx.graphics.Mesh;\r
+import com.badlogic.gdx.graphics.Pixmap;\r
+import com.badlogic.gdx.graphics.Pixmap.Format;\r
 import com.badlogic.gdx.graphics.SpriteBatch;\r
 import com.badlogic.gdx.graphics.Texture;\r
-import com.badlogic.gdx.graphics.VertexAttribute;\r
 import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
 import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.VertexAttribute;\r
 import com.badlogic.gdx.graphics.VertexAttributes.Usage;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.Matrix4;\r
@@ -45,7 +47,7 @@ public class MeshShaderTest extends GdxTest {
                                + "varying vec2 v_texCoords;"\r
                                + "void main()                  \n"\r
                                + "{                            \n"\r
-                               + "   v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n"\r
+                               + "   v_color = vec4(1, 1, 1, 1); \n"\r
                                + "   v_texCoords = a_texCoords; \n"\r
                                + "   gl_Position =  u_worldView * a_position;  \n"\r
                                + "}                            \n";\r
@@ -64,16 +66,26 @@ public class MeshShaderTest extends GdxTest {
                        System.exit(0);\r
                }\r
 \r
-               mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3,\r
+               mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3,\r
                                "a_position"), new VertexAttribute(Usage.Color, 4, "a_color"),\r
                                new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));\r
 \r
-               mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 1, 0, 0, 1, 0, 0, 0.5f,\r
-                               -0.5f, 0, 0, 1, 0, 1, 1, 0, 0, 0.5f, 0, 0, 0, 1, 1, 0.5f, 1 });\r
-               mesh.setIndices(new short[] { 0, 1, 2 });\r
+               mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 1, 1, 1, 1, 0, 1,\r
+                                                                               0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1,\r
+                                                                               0.5f,  0.5f, 0, 1, 1, 1, 1, 1, 0,\r
+                                                                          -0.5f,  0.5f, 0, 1, 1, 1, 1, 0, 0});\r
+               mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });\r
+\r
 \r
+               Pixmap pixmap = Gdx.graphics.newPixmap(2, 1, Format.RGBA8888);\r
+//             pixmap.drawPixel(0, 0, 0xffff0000);\r
+//             pixmap.drawPixel(1, 0, 0xff00ff00);\r
+//             pixmap.drawPixel(0, 1, 0xff0000ff);\r
+//             pixmap.drawPixel(0, 0, 0xffff00ff);\r
+//             pixmap.drawPixel(1, 0, 0xffffff00);\r
+//             texture = Gdx.graphics.newUnmanagedTexture(pixmap, TextureFilter.Nearest, TextureFilter.Nearest, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
                texture = Gdx.graphics.newTexture(Gdx.files.getFileHandle(\r
-                               "data/badlogic.jpg", FileType.Internal), TextureFilter.MipMap,\r
+                               "data/bobrgb888-32x32.png", FileType.Internal), TextureFilter.MipMap,\r
                                TextureFilter.Linear, TextureWrap.ClampToEdge,\r
                                TextureWrap.ClampToEdge);\r
 \r
@@ -94,6 +106,8 @@ public class MeshShaderTest extends GdxTest {
                Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1);\r
                Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);\r
                Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);\r
+               Gdx.graphics.getGL20().glEnable(GL10.GL_BLEND);\r
+               Gdx.graphics.getGL20().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);\r
                texture.bind();\r
                shader.begin();\r
                shader.setUniformMatrix("u_worldView", matrix);\r