diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-01-12 11:53:42 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-01-12 11:53:42 -0800 |
commit | 27d116085ebbb112ec1fd959763a027ec08f7179 (patch) | |
tree | 84ed2039d69959fe571a5ce4744542bb0144275e /graphics/java/android | |
parent | 7a8f01abf98b6212358ea0e0401879093d2c0f93 (diff) | |
parent | dcc231955d81c66309ce97cca05a25f79ee7d5ea (diff) | |
download | frameworks_base-27d116085ebbb112ec1fd959763a027ec08f7179.zip frameworks_base-27d116085ebbb112ec1fd959763a027ec08f7179.tar.gz frameworks_base-27d116085ebbb112ec1fd959763a027ec08f7179.tar.bz2 |
Merge "Adding ability to load cubemaps from individual faces." into honeycomb
Diffstat (limited to 'graphics/java/android')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 40c9a96..abe66726 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -18,7 +18,6 @@ package android.renderscript; import java.io.IOException; import java.io.InputStream; - import android.content.res.Resources; import android.content.res.AssetManager; import android.graphics.Bitmap; @@ -470,7 +469,7 @@ public class Allocation extends BaseObj { throw new RSIllegalArgumentException("Cubemap height must be multiple of 6"); } if (width / 6 != height) { - throw new RSIllegalArgumentException("Only square cobe map faces supported"); + throw new RSIllegalArgumentException("Only square cube map faces supported"); } boolean isPow2 = (height & (height - 1)) == 0; if (!isPow2) { @@ -492,11 +491,73 @@ public class Allocation extends BaseObj { return new Allocation(id, rs, t, usage); } - static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b) { + static public Allocation createCubemapFromBitmap(RenderScript rs, + Bitmap b) { return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, USAGE_GRAPHICS_TEXTURE); } + static public Allocation createCubemapFromCubeFaces(RenderScript rs, + Bitmap xpos, + Bitmap xneg, + Bitmap ypos, + Bitmap yneg, + Bitmap zpos, + Bitmap zneg, + MipmapControl mips, + int usage) { + int height = xpos.getHeight(); + if (xpos.getWidth() != height || + xneg.getWidth() != height || xneg.getHeight() != height || + ypos.getWidth() != height || ypos.getHeight() != height || + yneg.getWidth() != height || yneg.getHeight() != height || + zpos.getWidth() != height || zpos.getHeight() != height || + zneg.getWidth() != height || zneg.getHeight() != height) { + throw new RSIllegalArgumentException("Only square cube map faces supported"); + } + boolean isPow2 = (height & (height - 1)) == 0; + if (!isPow2) { + throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); + } + + Element e = elementFromBitmap(rs, xpos); + Type.Builder tb = new Type.Builder(rs, e); + tb.setX(height); + tb.setY(height); + tb.setFaces(true); + tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); + Type t = tb.create(); + Allocation cubemap = Allocation.createTyped(rs, t, mips, usage); + + AllocationAdapter adapter = AllocationAdapter.create2D(rs, cubemap); + adapter.setFace(Type.CubemapFace.POSITVE_X); + adapter.copyFrom(xpos); + adapter.setFace(Type.CubemapFace.NEGATIVE_X); + adapter.copyFrom(xneg); + adapter.setFace(Type.CubemapFace.POSITVE_Y); + adapter.copyFrom(ypos); + adapter.setFace(Type.CubemapFace.NEGATIVE_Y); + adapter.copyFrom(yneg); + adapter.setFace(Type.CubemapFace.POSITVE_Z); + adapter.copyFrom(zpos); + adapter.setFace(Type.CubemapFace.NEGATIVE_Z); + adapter.copyFrom(zneg); + + return cubemap; + } + + static public Allocation createCubemapFromCubeFaces(RenderScript rs, + Bitmap xpos, + Bitmap xneg, + Bitmap ypos, + Bitmap yneg, + Bitmap zpos, + Bitmap zneg) { + return createCubemapFromCubeFaces(rs, xpos, xneg, ypos, yneg, + zpos, zneg, MipmapControl.MIPMAP_NONE, + USAGE_GRAPHICS_TEXTURE); + } + static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, |