summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2011-01-11 14:47:44 -0800
committerAlex Sakhartchouk <alexst@google.com>2011-01-11 14:47:44 -0800
commitdcc231955d81c66309ce97cca05a25f79ee7d5ea (patch)
treeac72f6344468683aa146e431c3fc96c710f197b9 /graphics
parentd5208cf42c0f9b281505cb465b4de4e8179a6f9f (diff)
downloadframeworks_base-dcc231955d81c66309ce97cca05a25f79ee7d5ea.zip
frameworks_base-dcc231955d81c66309ce97cca05a25f79ee7d5ea.tar.gz
frameworks_base-dcc231955d81c66309ce97cca05a25f79ee7d5ea.tar.bz2
Adding ability to load cubemaps from individual faces.
Change-Id: Ic8b6693f625c181e031d4393ba8fac40049da88b
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/Allocation.java67
1 files changed, 64 insertions, 3 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 7a47c3b..7a76685 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;
@@ -427,7 +426,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) {
@@ -449,11 +448,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,