Updating cubemap loading code.

Change-Id: I93bb00e5fd1ccc622d17eba70a510664c2093723
This commit is contained in:
Alex Sakhartchouk
2011-01-10 15:57:57 -08:00
parent 3045bbaf58
commit fe852e216f
6 changed files with 29 additions and 71 deletions

View File

@ -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"

View File

@ -53,19 +53,6 @@ public class Allocation extends BaseObj {
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 @@ public class Allocation extends BaseObj {
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 @@ public class Allocation extends BaseObj {
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,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -22,7 +22,6 @@ import android.content.res.Resources;
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 @@ public class RsBenchRS {
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);

View File

@ -22,7 +22,6 @@ import android.content.res.Resources;
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 @@ public class RsRenderStatesRS {
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);

View File

@ -831,16 +831,21 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
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);