From ec44e5dc2f961c4f728babdd17bc4f2b7742750f Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Wed, 9 Oct 2013 17:15:36 -0700 Subject: Utility API for creating types. Change-Id: I3263cb4440ef3a60cd418f0559b8c5638a9b8bf3 --- graphics/java/android/renderscript/Type.java | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'graphics') diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index e023739..db4b577 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -216,6 +216,81 @@ public class Type extends BaseObj { } /** + * Utility function for creating basic 1D types. The type is + * created without mipmaps enabled. + * + * @param rs The RenderScript context + * @param e The Element for the Type + * @param dimX The X dimension, must be > 0 + * + * @return Type + */ + static public Type createX(RenderScript rs, Element e, int dimX) { + if (dimX < 1) { + throw new RSInvalidStateException("Dimension must be >= 1."); + } + + int id = rs.nTypeCreate(e.getID(rs), dimX, 0, 0, false, false, 0); + Type t = new Type(id, rs); + t.mElement = e; + t.mDimX = dimX; + t.calcElementCount(); + return t; + } + + /** + * Utility function for creating basic 2D types. The type is + * created without mipmaps or cubemaps. + * + * @param rs The RenderScript context + * @param e The Element for the Type + * @param dimX The X dimension, must be > 0 + * @param dimY The Y dimension, must be > 0 + * + * @return Type + */ + static public Type createXY(RenderScript rs, Element e, int dimX, int dimY) { + if ((dimX < 1) || (dimY < 1)) { + throw new RSInvalidStateException("Dimension must be >= 1."); + } + + int id = rs.nTypeCreate(e.getID(rs), dimX, dimY, 0, false, false, 0); + Type t = new Type(id, rs); + t.mElement = e; + t.mDimX = dimX; + t.mDimY = dimY; + t.calcElementCount(); + return t; + } + + /** + * Utility function for creating basic 3D types. The type is + * created without mipmaps. + * + * @param rs The RenderScript context + * @param e The Element for the Type + * @param dimX The X dimension, must be > 0 + * @param dimY The Y dimension, must be > 0 + * @param dimZ The Z dimension, must be > 0 + * + * @return Type + */ + static public Type createXYZ(RenderScript rs, Element e, int dimX, int dimY, int dimZ) { + if ((dimX < 1) || (dimY < 1) || (dimZ < 1)) { + throw new RSInvalidStateException("Dimension must be >= 1."); + } + + int id = rs.nTypeCreate(e.getID(rs), dimX, dimY, dimZ, false, false, 0); + Type t = new Type(id, rs); + t.mElement = e; + t.mDimX = dimX; + t.mDimY = dimY; + t.mDimZ = dimZ; + t.calcElementCount(); + return t; + } + + /** * Builder class for Type. * */ -- cgit v1.1