From 61895240b8de422cbd3ddd2022a78cd5aa0b6433 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 28 Jan 2010 21:05:31 +0000 Subject: [PATCH] Started API simplification of GLTexture --- .../src/processing/android/core/GLFont.java | 6 - .../src/processing/android/core/GLModel.java | 18 +- .../processing/android/core/GLTexture.java | 258 +++++++----------- 3 files changed, 115 insertions(+), 167 deletions(-) diff --git a/android/core/src/processing/android/core/GLFont.java b/android/core/src/processing/android/core/GLFont.java index fc7078ce3..00f290813 100644 --- a/android/core/src/processing/android/core/GLFont.java +++ b/android/core/src/processing/android/core/GLFont.java @@ -24,14 +24,8 @@ package processing.android.core; -//import java.awt.*; -//import java.awt.image.BufferedImage; -//import java.awt.image.Raster; import java.io.*; -//import java.lang.reflect.*; import java.util.Arrays; -import java.util.HashMap; - import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; diff --git a/android/core/src/processing/android/core/GLModel.java b/android/core/src/processing/android/core/GLModel.java index 7d88a060d..101f5afa0 100644 --- a/android/core/src/processing/android/core/GLModel.java +++ b/android/core/src/processing/android/core/GLModel.java @@ -59,11 +59,11 @@ public class GLModel implements GLConstants, PConstants { public GLModel(PApplet parent, int numVert, int numTex) { - this(parent, numVert, numTex, new GLModelParameters()); + this(parent, numVert, numTex, new Parameters()); } - public GLModel(PApplet parent, int numVert, int numTex, GLModelParameters params) { + public GLModel(PApplet parent, int numVert, int numTex, Parameters params) { this.parent = parent; a3d = (PGraphicsAndroid3D)parent.g; if (a3d.gl instanceof GL11) { @@ -877,8 +877,8 @@ public class GLModel implements GLConstants, PConstants { } - public GLModelParameters getParameters() { - GLModelParameters res = new GLModelParameters(); + public Parameters getParameters() { + Parameters res = new Parameters(); if (glMode == GL11.GL_POINTS) { if (pointSprites) res.drawMode = POINT_SPRITES; @@ -898,7 +898,7 @@ public class GLModel implements GLConstants, PConstants { } - protected void readParameters(GLModelParameters params) { + protected void readParameters(Parameters params) { pointSprites = false; if (params.drawMode == POINTS) glMode = GL11.GL_POINTS; else if (params.drawMode == POINT_SPRITES) { @@ -1157,9 +1157,13 @@ public class GLModel implements GLConstants, PConstants { } static public Parameters newParameters(int drawMode) { - return new Parameters(); + return new Parameters(drawMode); } - + + static public Parameters newParameters(int drawMode, int updateMode) { + return new Parameters(drawMode, updateMode); + } + static public class Parameters { public Parameters() { updateMode = STATIC; diff --git a/android/core/src/processing/android/core/GLTexture.java b/android/core/src/processing/android/core/GLTexture.java index 3c03228bc..79b2b6a35 100644 --- a/android/core/src/processing/android/core/GLTexture.java +++ b/android/core/src/processing/android/core/GLTexture.java @@ -25,86 +25,97 @@ import java.nio.*; * only at the end if the texture is needed as a regular image. */ @SuppressWarnings("unused") -public class GLTexture extends PImage implements PConstants, GLConstants -{ +public class GLTexture extends PImage implements PConstants, GLConstants { + protected PGraphicsAndroid3D pgl; + protected GL10 gl; + + protected int[] tex = { 0 }; + protected int texTarget; + protected int texInternalFormat; + protected int minFilter; + protected int magFilter; + protected boolean usingMipmaps; + protected float maxTexCoordS; + protected float maxTexCoordT; - /** - * Creates an instance of GLTexture with size width x height. The texture is initialized (empty) to that size. - * @param parent PApplet - * @param width int - * @param height int - */ - public GLTexture(PApplet parent, int width, int height) - { - super(width, height, ARGB); - this.parent = parent; + protected boolean flippedX; + protected boolean flippedY; + + //////////////////////////////////////////////////////////// + + // Constructors. + + /** + * Creates an instance of GLTexture with size width x height. The texture is initialized (empty) to that size. + * @param parent PApplet + * @param width int + * @param height int + */ + public GLTexture(PApplet parent, int width, int height) { + super(width, height, ARGB); + this.parent = parent; - pgl = (PGraphicsAndroid3D)parent.g; - gl = pgl.gl; - //glstate = new GLState(gl); - setTextureParams(new Parameters()); + pgl = (PGraphicsAndroid3D)parent.g; + gl = pgl.gl; + setTextureParams(new Parameters()); - initTexture(width, height); - } + initTexture(width, height); + } - /** - * Creates an instance of GLTexture with size width x height and with the specified parameters. - * The texture is initialized (empty) to that size. - * @param parent PApplet - * @param width int - * @param height int - * @param params GLTextureParameters - */ - public GLTexture(PApplet parent, int width, int height, Parameters params) - { - super(width, height, params.format); - this.parent = parent; + + /** + * Creates an instance of GLTexture with size width x height and with the specified parameters. + * The texture is initialized (empty) to that size. + * @param parent PApplet + * @param width int + * @param height int + * @param params Parameters + */ + public GLTexture(PApplet parent, int width, int height, Parameters params) { + super(width, height, params.format); + this.parent = parent; - pgl = (PGraphicsAndroid3D)parent.g; - gl = pgl.gl; - //glstate = new GLState(gl); - setTextureParams(params); + pgl = (PGraphicsAndroid3D)parent.g; + gl = pgl.gl; + setTextureParams(params); - initTexture(width, height); - } + initTexture(width, height); + } - /** - * Creates an instance of GLTexture using image file filename as source. - * @param parent PApplet - * @param filename String - */ - public GLTexture(PApplet parent, String filename) - { - super(1, 1, ARGB); - this.parent = parent; + /** + * Creates an instance of GLTexture using image file filename as source. + * @param parent PApplet + * @param filename String + */ + public GLTexture(PApplet parent, String filename) { + super(1, 1, ARGB); + this.parent = parent; - pgl = (PGraphicsAndroid3D)parent.g; - gl = pgl.gl; - //glstate = new GLState(gl); + pgl = (PGraphicsAndroid3D)parent.g; + gl = pgl.gl; - loadTexture(filename); - } - - /** - * Creates an instance of GLTexture using image file filename as source and the specified texture parameters. - * @param parent PApplet - * @param filename String - * @param params GLTextureParameters - */ - public GLTexture(PApplet parent, String filename, Parameters params) - { - super(1, 1, params.format); - this.parent = parent; + loadTexture(filename); + } + + + /** + * Creates an instance of GLTexture using image file filename as source and the specified texture parameters. + * @param parent PApplet + * @param filename String + * @param params Parameters + */ + public GLTexture(PApplet parent, String filename, Parameters params) { + super(1, 1, params.format); + this.parent = parent; - pgl = (PGraphicsAndroid3D)parent.g; - gl = pgl.gl; - //glstate = new GLState(gl); + pgl = (PGraphicsAndroid3D)parent.g; + gl = pgl.gl; - loadTexture(filename, params); - } + loadTexture(filename, params); + } protected void finalize() { @@ -114,7 +125,9 @@ public class GLTexture extends PImage implements PConstants, GLConstants } - + //////////////////////////////////////////////////////////// + + // Set methods public void set(PImage img) { @@ -128,39 +141,34 @@ public class GLTexture extends PImage implements PConstants, GLConstants } - - /** - * Copy texture to pixels. - */ - public void updatePixels() - { - int size = width * height; - IntBuffer buffer = BufferUtil.newIntBuffer(size); + /** + * Copy texture to pixels. + */ + public void updatePixels() { + int size = width * height; + IntBuffer buffer = BufferUtil.newIntBuffer(size); - gl.glBindTexture(texTarget, tex[0]); - //gl.glGetTexImage(texTarget, 0, GL10.GL.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buffer); - gl.glBindTexture(texTarget, 0); + gl.glBindTexture(texTarget, tex[0]); + //gl.glGetTexImage(texTarget, 0, GL10.GL.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buffer); + gl.glBindTexture(texTarget, 0); - buffer.get(pixels); - int[] pixelsARGB = convertToARGB(pixels); - PApplet.arrayCopy(pixelsARGB, pixels); - if (flippedX) flipArrayOnX(pixels, 1); - if (flippedY) flipArrayOnY(pixels, 1); + buffer.get(pixels); + int[] pixelsARGB = convertToARGB(pixels); + PApplet.arrayCopy(pixelsARGB, pixels); + if (flippedX) flipArrayOnX(pixels, 1); + if (flippedY) flipArrayOnY(pixels, 1); - super.updatePixels(); - } + super.updatePixels(); + } + - - - - /** - * Puts img into texture, pixels and image. - * @param img PImage - */ - public void putImage(PImage img) - { - putImage(img, new Parameters()); - } + /** + * Puts img into texture, pixels and image. + * @param img PImage + */ + public void putImage(PImage img) { + putImage(img, new Parameters()); + } /** * Puts img into texture, pixels and image. @@ -1672,65 +1680,7 @@ public class GLTexture extends PImage implements PConstants, GLConstants height = h; } - /** - * @invisible - */ - protected GL10 gl; - - /** - * @invisible - */ - protected PGraphicsAndroid3D pgl; - - /** - * @invisible - */ - protected int[] tex = { 0 }; - - /** - * @invisible - */ - protected int texTarget; - - /** - * @invisible - */ - protected int texInternalFormat; - /** - * @invisible - */ - protected int minFilter; - - /** - * @invisible - */ - protected int magFilter; - - /** - * @invisible - */ - protected boolean usingMipmaps; - - /** - * @invisible - */ - protected float maxTexCoordS; - - /** - * @invisible - */ - protected float maxTexCoordT; - - /** - * @invisible - */ - protected boolean flippedX; - - /** - * @invisible - */ - protected boolean flippedY; ///////////////////////////////////////////////////////////////////////////