Updating cubemap loading code.
Change-Id: I93bb00e5fd1ccc622d17eba70a510664c2093723
This commit is contained in:
@ -166366,8 +166366,6 @@
|
|||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="mips" type="android.renderscript.Allocation.MipmapControl">
|
<parameter name="mips" type="android.renderscript.Allocation.MipmapControl">
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="layout" type="android.renderscript.Allocation.CubemapLayout">
|
|
||||||
</parameter>
|
|
||||||
<parameter name="usage" type="int">
|
<parameter name="usage" type="int">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
@ -166385,8 +166383,6 @@
|
|||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="b" type="android.graphics.Bitmap">
|
<parameter name="b" type="android.graphics.Bitmap">
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="layout" type="android.renderscript.Allocation.CubemapLayout">
|
|
||||||
</parameter>
|
|
||||||
</method>
|
</method>
|
||||||
<method name="createFromBitmap"
|
<method name="createFromBitmap"
|
||||||
return="android.renderscript.Allocation"
|
return="android.renderscript.Allocation"
|
||||||
@ -166646,39 +166642,6 @@
|
|||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
</class>
|
</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"
|
<class name="Allocation.MipmapControl"
|
||||||
extends="java.lang.Enum"
|
extends="java.lang.Enum"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
|
@ -53,19 +53,6 @@ public class Allocation extends BaseObj {
|
|||||||
public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;
|
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 {
|
public enum MipmapControl {
|
||||||
MIPMAP_NONE(0),
|
MIPMAP_NONE(0),
|
||||||
MIPMAP_FULL(1),
|
MIPMAP_FULL(1),
|
||||||
@ -416,33 +403,41 @@ public class Allocation extends BaseObj {
|
|||||||
USAGE_GRAPHICS_TEXTURE);
|
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,
|
static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
|
||||||
MipmapControl mips,
|
MipmapControl mips,
|
||||||
CubemapLayout layout,
|
|
||||||
int usage) {
|
int usage) {
|
||||||
rs.validate();
|
rs.validate();
|
||||||
|
|
||||||
int height = b.getHeight();
|
int height = b.getHeight();
|
||||||
int width = b.getWidth();
|
int width = b.getWidth();
|
||||||
|
|
||||||
if (layout != CubemapLayout.VERTICAL_FACE_LIST) {
|
if (width % 6 != 0) {
|
||||||
throw new RSIllegalArgumentException("Only vertical face list supported");
|
|
||||||
}
|
|
||||||
if (height % 6 != 0) {
|
|
||||||
throw new RSIllegalArgumentException("Cubemap height must be multiple of 6");
|
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");
|
throw new RSIllegalArgumentException("Only square cobe map faces supported");
|
||||||
}
|
}
|
||||||
boolean isPow2 = (width & (width - 1)) == 0;
|
boolean isPow2 = (height & (height - 1)) == 0;
|
||||||
if (!isPow2) {
|
if (!isPow2) {
|
||||||
throw new RSIllegalArgumentException("Only power of 2 cube faces supported");
|
throw new RSIllegalArgumentException("Only power of 2 cube faces supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
Element e = elementFromBitmap(rs, b);
|
Element e = elementFromBitmap(rs, b);
|
||||||
Type.Builder tb = new Type.Builder(rs, e);
|
Type.Builder tb = new Type.Builder(rs, e);
|
||||||
tb.setX(width);
|
tb.setX(height);
|
||||||
tb.setY(width);
|
tb.setY(height);
|
||||||
tb.setFaces(true);
|
tb.setFaces(true);
|
||||||
tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL);
|
tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL);
|
||||||
Type t = tb.create();
|
Type t = tb.create();
|
||||||
@ -454,10 +449,9 @@ public class Allocation extends BaseObj {
|
|||||||
return new Allocation(id, rs, t, usage);
|
return new Allocation(id, rs, t, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
|
static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b) {
|
||||||
CubemapLayout layout) {
|
|
||||||
return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
|
return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
|
||||||
layout, USAGE_GRAPHICS_TEXTURE);
|
USAGE_GRAPHICS_TEXTURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public Allocation createFromBitmapResource(RenderScript rs,
|
static public Allocation createFromBitmapResource(RenderScript rs,
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
@ -22,7 +22,6 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.renderscript.*;
|
import android.renderscript.*;
|
||||||
import android.renderscript.Allocation.CubemapLayout;
|
|
||||||
import android.renderscript.Allocation.MipmapControl;
|
import android.renderscript.Allocation.MipmapControl;
|
||||||
import android.renderscript.Program.TextureType;
|
import android.renderscript.Program.TextureType;
|
||||||
import android.renderscript.ProgramStore.DepthFunc;
|
import android.renderscript.ProgramStore.DepthFunc;
|
||||||
@ -318,8 +317,7 @@ public class RsBenchRS {
|
|||||||
mTexTransparent = loadTextureARGB(R.drawable.leaf);
|
mTexTransparent = loadTextureARGB(R.drawable.leaf);
|
||||||
mTexChecker = loadTextureRGB(R.drawable.checker);
|
mTexChecker = loadTextureRGB(R.drawable.checker);
|
||||||
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
|
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
|
||||||
mTexCube = Allocation.createCubemapFromBitmap(mRS, b,
|
mTexCube = Allocation.createCubemapFromBitmap(mRS, b);
|
||||||
Allocation.CubemapLayout.VERTICAL_FACE_LIST);
|
|
||||||
|
|
||||||
mScript.set_gTexTorus(mTexTorus);
|
mScript.set_gTexTorus(mTexTorus);
|
||||||
mScript.set_gTexOpaque(mTexOpaque);
|
mScript.set_gTexOpaque(mTexOpaque);
|
||||||
|
@ -22,7 +22,6 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.renderscript.*;
|
import android.renderscript.*;
|
||||||
import android.renderscript.Allocation.CubemapLayout;
|
|
||||||
import android.renderscript.Font.Style;
|
import android.renderscript.Font.Style;
|
||||||
import android.renderscript.Program.TextureType;
|
import android.renderscript.Program.TextureType;
|
||||||
import android.renderscript.ProgramStore.DepthFunc;
|
import android.renderscript.ProgramStore.DepthFunc;
|
||||||
@ -308,8 +307,7 @@ public class RsRenderStatesRS {
|
|||||||
mTexTransparent = loadTextureARGB(R.drawable.leaf);
|
mTexTransparent = loadTextureARGB(R.drawable.leaf);
|
||||||
mTexChecker = loadTextureRGB(R.drawable.checker);
|
mTexChecker = loadTextureRGB(R.drawable.checker);
|
||||||
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
|
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
|
||||||
mTexCube = Allocation.createCubemapFromBitmap(mRS, b,
|
mTexCube = Allocation.createCubemapFromBitmap(mRS, b);
|
||||||
Allocation.CubemapLayout.VERTICAL_FACE_LIST);
|
|
||||||
|
|
||||||
mScript.set_gTexTorus(mTexTorus);
|
mScript.set_gTexTorus(mTexTorus);
|
||||||
mScript.set_gTexOpaque(mTexOpaque);
|
mScript.set_gTexOpaque(mTexOpaque);
|
||||||
|
@ -831,16 +831,21 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
|
|||||||
return NULL;
|
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;
|
uint8_t *sourcePtr = (uint8_t*)data;
|
||||||
for (uint32_t face = 0; face < 6; face ++) {
|
for (uint32_t face = 0; face < 6; face ++) {
|
||||||
Adapter2D faceAdapter(rsc, texAlloc);
|
Adapter2D faceAdapter(rsc, texAlloc);
|
||||||
faceAdapter.setFace(face);
|
faceAdapter.setFace(face);
|
||||||
|
|
||||||
size_t cpySize = t->getDimX() * t->getDimX() * t->getElementSizeBytes();
|
for (uint32_t dI = 0; dI < faceSize; dI ++) {
|
||||||
memcpy(faceAdapter.getElement(0, 0), sourcePtr, cpySize);
|
memcpy(faceAdapter.getElement(0, dI), sourcePtr + strideBytes * dI, copySize);
|
||||||
|
}
|
||||||
|
|
||||||
// Move the data pointer to the next cube face
|
// Move the data pointer to the next cube face
|
||||||
sourcePtr += cpySize;
|
sourcePtr += copySize;
|
||||||
|
|
||||||
if (mips == RS_ALLOCATION_MIPMAP_FULL) {
|
if (mips == RS_ALLOCATION_MIPMAP_FULL) {
|
||||||
Adapter2D adapt(rsc, texAlloc);
|
Adapter2D adapt(rsc, texAlloc);
|
||||||
|
Reference in New Issue
Block a user