Updating cubemap loading code.
Change-Id: I93bb00e5fd1ccc622d17eba70a510664c2093723
diff --git a/api/current.xml b/api/current.xml
index 7302fd6..01a401b 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -166366,8 +166366,6 @@
</parameter>
<parameter name="mips" type="android.renderscript.Allocation.MipmapControl">
</parameter>
-<parameter name="layout" type="android.renderscript.Allocation.CubemapLayout">
-</parameter>
<parameter name="usage" type="int">
</parameter>
</method>
@@ -166385,8 +166383,6 @@
</parameter>
<parameter name="b" type="android.graphics.Bitmap">
</parameter>
-<parameter name="layout" type="android.renderscript.Allocation.CubemapLayout">
-</parameter>
</method>
<method name="createFromBitmap"
return="android.renderscript.Allocation"
@@ -166646,39 +166642,6 @@
>
</field>
</class>
-<class name="Allocation.CubemapLayout"
- extends="java.lang.Enum"
- abstract="false"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-<method name="valueOf"
- return="android.renderscript.Allocation.CubemapLayout"
- abstract="false"
- native="false"
- synchronized="false"
- static="true"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="name" type="java.lang.String">
-</parameter>
-</method>
-<method name="values"
- return="android.renderscript.Allocation.CubemapLayout[]"
- abstract="false"
- native="false"
- synchronized="false"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-</class>
<class name="Allocation.MipmapControl"
extends="java.lang.Enum"
abstract="false"
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 53962e1..7a47c3b 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -53,19 +53,6 @@
public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;
- public enum CubemapLayout {
- VERTICAL_FACE_LIST (0),
- HORIZONTAL_FACE_LIST (1),
- VERTICAL_CROSS (2),
- HORIZONTAL_CROSS (3);
-
- int mID;
- CubemapLayout(int id) {
- mID = id;
- }
- }
-
-
public enum MipmapControl {
MIPMAP_NONE(0),
MIPMAP_FULL(1),
@@ -416,33 +403,41 @@
USAGE_GRAPHICS_TEXTURE);
}
+ /**
+ * Creates a cubemap allocation from a bitmap containing the
+ * horizontal list of cube faces. Each individual face must be
+ * the same size and power of 2
+ *
+ * @param rs
+ * @param b bitmap with cubemap faces layed out in the following
+ * format: right, left, top, bottom, front, back
+ * @param mips specifies desired mipmap behaviour for the cubemap
+ * @param usage bitfield specifying how the cubemap is utilized
+ *
+ **/
static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
MipmapControl mips,
- CubemapLayout layout,
int usage) {
rs.validate();
int height = b.getHeight();
int width = b.getWidth();
- if (layout != CubemapLayout.VERTICAL_FACE_LIST) {
- throw new RSIllegalArgumentException("Only vertical face list supported");
- }
- if (height % 6 != 0) {
+ if (width % 6 != 0) {
throw new RSIllegalArgumentException("Cubemap height must be multiple of 6");
}
- if (height / 6 != width) {
+ if (width / 6 != height) {
throw new RSIllegalArgumentException("Only square cobe map faces supported");
}
- boolean isPow2 = (width & (width - 1)) == 0;
+ boolean isPow2 = (height & (height - 1)) == 0;
if (!isPow2) {
throw new RSIllegalArgumentException("Only power of 2 cube faces supported");
}
Element e = elementFromBitmap(rs, b);
Type.Builder tb = new Type.Builder(rs, e);
- tb.setX(width);
- tb.setY(width);
+ tb.setX(height);
+ tb.setY(height);
tb.setFaces(true);
tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL);
Type t = tb.create();
@@ -454,10 +449,9 @@
return new Allocation(id, rs, t, usage);
}
- static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
- CubemapLayout layout) {
+ static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b) {
return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
- layout, USAGE_GRAPHICS_TEXTURE);
+ USAGE_GRAPHICS_TEXTURE);
}
static public Allocation createFromBitmapResource(RenderScript rs,
diff --git a/libs/rs/java/Samples/res/drawable/cubemap_test.png b/libs/rs/java/Samples/res/drawable/cubemap_test.png
index 75ad0a4..baf35d0 100644
--- a/libs/rs/java/Samples/res/drawable/cubemap_test.png
+++ b/libs/rs/java/Samples/res/drawable/cubemap_test.png
Binary files differ
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java
index 5430a13..1afcee3 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java
@@ -22,7 +22,6 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.renderscript.*;
-import android.renderscript.Allocation.CubemapLayout;
import android.renderscript.Allocation.MipmapControl;
import android.renderscript.Program.TextureType;
import android.renderscript.ProgramStore.DepthFunc;
@@ -318,8 +317,7 @@
mTexTransparent = loadTextureARGB(R.drawable.leaf);
mTexChecker = loadTextureRGB(R.drawable.checker);
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
- mTexCube = Allocation.createCubemapFromBitmap(mRS, b,
- Allocation.CubemapLayout.VERTICAL_FACE_LIST);
+ mTexCube = Allocation.createCubemapFromBitmap(mRS, b);
mScript.set_gTexTorus(mTexTorus);
mScript.set_gTexOpaque(mTexOpaque);
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
index cac105a..87840a7 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
@@ -22,7 +22,6 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.renderscript.*;
-import android.renderscript.Allocation.CubemapLayout;
import android.renderscript.Font.Style;
import android.renderscript.Program.TextureType;
import android.renderscript.ProgramStore.DepthFunc;
@@ -308,8 +307,7 @@
mTexTransparent = loadTextureARGB(R.drawable.leaf);
mTexChecker = loadTextureRGB(R.drawable.checker);
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
- mTexCube = Allocation.createCubemapFromBitmap(mRS, b,
- Allocation.CubemapLayout.VERTICAL_FACE_LIST);
+ mTexCube = Allocation.createCubemapFromBitmap(mRS, b);
mScript.set_gTexTorus(mTexTorus);
mScript.set_gTexOpaque(mTexOpaque);
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 3608e43..673ade2 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -831,16 +831,21 @@
return NULL;
}
+ uint32_t faceSize = t->getDimX();
+ uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
+ uint32_t copySize = faceSize * t->getElementSizeBytes();
+
uint8_t *sourcePtr = (uint8_t*)data;
for (uint32_t face = 0; face < 6; face ++) {
Adapter2D faceAdapter(rsc, texAlloc);
faceAdapter.setFace(face);
- size_t cpySize = t->getDimX() * t->getDimX() * t->getElementSizeBytes();
- memcpy(faceAdapter.getElement(0, 0), sourcePtr, cpySize);
+ for (uint32_t dI = 0; dI < faceSize; dI ++) {
+ memcpy(faceAdapter.getElement(0, dI), sourcePtr + strideBytes * dI, copySize);
+ }
// Move the data pointer to the next cube face
- sourcePtr += cpySize;
+ sourcePtr += copySize;
if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Adapter2D adapt(rsc, texAlloc);