Merge "Begin using reflected files."

This commit is contained in:
Jason Sams
2010-06-08 15:43:57 -07:00
committed by Android (Google) Code Review
12 changed files with 163 additions and 170 deletions

View File

@ -72,12 +72,6 @@ public class Element extends BaseObj {
public enum DataKind { public enum DataKind {
USER (0), USER (0),
COLOR (1),
POSITION (2),
TEXTURE (3),
NORMAL (4),
INDEX (5),
POINT_SIZE(6),
PIXEL_L (7), PIXEL_L (7),
PIXEL_A (8), PIXEL_A (8),
@ -105,6 +99,20 @@ public class Element extends BaseObj {
return rs.mElement_I8; return rs.mElement_I8;
} }
public static Element U16(RenderScript rs) {
if(rs.mElement_U16 == null) {
rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16);
}
return rs.mElement_U16;
}
public static Element I16(RenderScript rs) {
if(rs.mElement_I16 == null) {
rs.mElement_I16 = createUser(rs, DataType.SIGNED_16);
}
return rs.mElement_I16;
}
public static Element U32(RenderScript rs) { public static Element U32(RenderScript rs) {
if(rs.mElement_U32 == null) { if(rs.mElement_U32 == null) {
rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32); rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32);
@ -239,13 +247,6 @@ public class Element extends BaseObj {
return rs.mElement_RGBA_8888; return rs.mElement_RGBA_8888;
} }
public static Element INDEX_16(RenderScript rs) {
if(rs.mElement_INDEX_16 == null) {
rs.mElement_INDEX_16 = createIndex(rs);
}
return rs.mElement_INDEX_16;
}
public static Element F32_2(RenderScript rs) { public static Element F32_2(RenderScript rs) {
if(rs.mElement_FLOAT_2 == null) { if(rs.mElement_FLOAT_2 == null) {
rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2); rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2);
@ -314,10 +315,6 @@ public class Element extends BaseObj {
return new Element(rs, dt, DataKind.USER, false, size); return new Element(rs, dt, DataKind.USER, false, size);
} }
public static Element createIndex(RenderScript rs) {
return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
}
public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) { public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
if (!(dk == DataKind.PIXEL_L || if (!(dk == DataKind.PIXEL_L ||
dk == DataKind.PIXEL_A || dk == DataKind.PIXEL_A ||

View File

@ -223,7 +223,6 @@ public class RenderScript {
Element mElement_RGBA_4444; Element mElement_RGBA_4444;
Element mElement_RGBA_8888; Element mElement_RGBA_8888;
Element mElement_INDEX_16;
Element mElement_FLOAT_2; Element mElement_FLOAT_2;
Element mElement_FLOAT_3; Element mElement_FLOAT_3;
Element mElement_FLOAT_4; Element mElement_FLOAT_4;

View File

@ -332,7 +332,7 @@ public class SimpleMesh extends BaseObj {
Builder smb = new Builder(mRS); Builder smb = new Builder(mRS);
smb.addVertexType(mElement, mVtxCount / floatCount); smb.addVertexType(mElement, mVtxCount / floatCount);
smb.setIndexType(Element.createIndex(mRS), mIndexCount); smb.setIndexType(Element.U16(mRS), mIndexCount);
smb.setPrimitive(Primitive.TRIANGLE); smb.setPrimitive(Primitive.TRIANGLE);
SimpleMesh sm = smb.create(); SimpleMesh sm = smb.create();

View File

@ -103,19 +103,12 @@ enum RsDataType {
enum RsDataKind { enum RsDataKind {
RS_KIND_USER, RS_KIND_USER,
RS_KIND_COLOR,
RS_KIND_POSITION,
RS_KIND_TEXTURE,
RS_KIND_NORMAL,
RS_KIND_INDEX,
RS_KIND_POINT_SIZE,
RS_KIND_PIXEL_L, RS_KIND_PIXEL_L = 7,
RS_KIND_PIXEL_A, RS_KIND_PIXEL_A,
RS_KIND_PIXEL_LA, RS_KIND_PIXEL_LA,
RS_KIND_PIXEL_RGB, RS_KIND_PIXEL_RGB,
RS_KIND_PIXEL_RGBA, RS_KIND_PIXEL_RGBA,
}; };
enum RsSamplerParam { enum RsSamplerParam {

View File

@ -40,17 +40,7 @@ int root() {
return 1; return 1;
} }
// Putting the overloadable attribute on this function breaks rendering #pragma rs export_func(addParticles)
// appears to be a bug.
static uchar4 /*__attribute__((overloadable))*/ pack(float r, float g, float b)
{
uchar4 c;
c.x = (uchar)(r * 255.f);
c.y = (uchar)(g * 255.f);
c.z = (uchar)(b * 255.f);
c.w = 255;
return c;
}
void addParticles(int rate, int x, int y) void addParticles(int rate, int x, int y)
{ {
@ -63,10 +53,7 @@ void addParticles(int rate, int x, int y)
float rMax = ((float)rate) * 0.005f; float rMax = ((float)rate) * 0.005f;
int size = rsAllocationGetDimX(rsGetAllocation(point)); int size = rsAllocationGetDimX(rsGetAllocation(point));
//uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z); uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z);
uchar4 c = pack(partColor.x, partColor.y, partColor.z);
c.x = 255;
c.w = 255;
//rsDebug("color ", ((int *)&c)[0]); //rsDebug("color ", ((int *)&c)[0]);
Point_t * np = &point[newPart]; Point_t * np = &point[newPart];

View File

@ -34,7 +34,7 @@ public class FountainRS {
mRS = rs; mRS = rs;
mRes = res; mRes = res;
ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT); ScriptField_Point_s points = new ScriptField_Point_s(mRS, PART_COUNT);
SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS); SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
int vtxSlot = smb.addVertexType(points.getType()); int vtxSlot = smb.addVertexType(points.getType());
@ -59,7 +59,7 @@ public class FountainRS {
tmpColor.z = mRand.nextFloat(); tmpColor.z = mRand.nextFloat();
mScript.set_partColor(tmpColor); mScript.set_partColor(tmpColor);
} }
mScript.invokable_addParticles(rate, x, y); mScript.invoke_addParticles(rate, x, y);
holdingColor = true; holdingColor = true;
} else { } else {
holdingColor = false; holdingColor = false;

View File

@ -1,46 +1,77 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.fountain; package com.android.fountain;
import android.content.res.Resources;
import android.renderscript.*; import android.renderscript.*;
import android.content.res.Resources;
import android.util.Log; import android.util.Log;
public class ScriptC_Fountain public class ScriptC_Fountain extends ScriptC {
extends android.renderscript.ScriptC // Constructor
{ public ScriptC_Fountain(RenderScript rs, Resources resources, boolean isRoot) {
public ScriptC_Fountain(RenderScript rs, Resources resources, boolean isRoot) {
super(rs, resources, R.raw.fountain_bc, isRoot); super(rs, resources, R.raw.fountain_bc, isRoot);
} }
private final static int mExportVarIdx_partColor = 0;
private Float4 mExportVar_partColor;
public void set_partColor(Float4 v) { public void set_partColor(Float4 v) {
mExportVar_partColor = v;
FieldPacker fp = new FieldPacker(16); FieldPacker fp = new FieldPacker(16);
fp.addF32(v); fp.addF32(v);
setVar(0, fp); setVar(mExportVarIdx_partColor, fp);
} }
public Float4 get_partColor() {
return mExportVar_partColor;
}
private final static int mExportVarIdx_partMesh = 1;
private SimpleMesh mExportVar_partMesh;
public void set_partMesh(SimpleMesh v) { public void set_partMesh(SimpleMesh v) {
setVar(1, v.getID()); mExportVar_partMesh = v;
int id = 0;
if (v != null) id = v.getID();
setVar(mExportVarIdx_partMesh, id);
} }
private ScriptField_Point mField_point; public SimpleMesh get_partMesh() {
public void bind_point(ScriptField_Point f) { return mExportVar_partMesh;
mField_point = f;
if (f == null) {
bindAllocation(null, 2);
} else {
bindAllocation(f.getAllocation(), 2);
}
}
public ScriptField_Point get_point() {
return mField_point;
} }
private final static int mExportVarIdx_point = 2;
public void invokable_addParticles(int count, int x, int y) { private ScriptField_Point_s mExportVar_point;
FieldPacker fp = new FieldPacker(12); public void bind_point(ScriptField_Point_s v) {
fp.addI32(count); mExportVar_point = v;
fp.addI32(x); if(v == null) bindAllocation(null, mExportVarIdx_point);
fp.addI32(y); else bindAllocation(v.getAllocation(), mExportVarIdx_point);
invokeV(0, fp);
} }
public ScriptField_Point_s get_point() {
return mExportVar_point;
}
private final static int mExportFuncIdx_addParticles = 0;
public void invoke_addParticles(int rate, int x, int y) {
FieldPacker addParticles_fp = new FieldPacker(12);
addParticles_fp.addI32(rate);
addParticles_fp.addI32(x);
addParticles_fp.addI32(y);
invokeV(mExportFuncIdx_addParticles, addParticles_fp);
}
} }

View File

@ -1,67 +0,0 @@
package com.android.fountain;
import android.content.res.Resources;
import android.renderscript.*;
import android.util.Log;
public class ScriptField_Point
extends android.renderscript.Script.FieldBase
{
static public class Item {
Item() {
delta = new Float2();
pos = new Float2();
color = new Short4();
}
public static final int sizeof = (5*4);
Float2 delta;
Float2 pos;
Short4 color;
}
private Item mItemArray[];
public ScriptField_Point(RenderScript rs, int count) {
// Allocate a pack/unpack buffer
mIOBuffer = new FieldPacker(Item.sizeof * count);
mItemArray = new Item[count];
Element.Builder eb = new Element.Builder(rs);
eb.add(Element.F32_2(rs), "delta");
eb.add(Element.F32_2(rs), "position");
eb.add(Element.U8_4(rs), "color");
mElement = eb.create();
init(rs, count);
}
private void copyToArray(Item i, int index) {
mIOBuffer.reset(index * Item.sizeof);
mIOBuffer.addF32(i.delta);
mIOBuffer.addF32(i.pos);
mIOBuffer.addU8(i.color);
}
public void set(Item i, int index, boolean copyNow) {
mItemArray[index] = i;
if (copyNow) {
copyToArray(i, index);
mAllocation.subData1D(index * Item.sizeof, Item.sizeof, mIOBuffer.getData());
}
}
public void copyAll() {
for (int ct=0; ct < mItemArray.length; ct++) {
copyToArray(mItemArray[ct], ct);
}
mAllocation.data(mIOBuffer.getData());
}
private FieldPacker mIOBuffer;
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.fountain;
import android.renderscript.*;
import android.content.res.Resources;
import android.util.Log;
public class ScriptField_Point_s extends android.renderscript.Script.FieldBase {
static public class Item {
public static final int sizeof = 20;
Float2 delta;
Float2 position;
Short4 color;
Item() {
delta = new Float2();
position = new Float2();
color = new Short4();
}
}
private Item mItemArray[];
private FieldPacker mIOBuffer;
public ScriptField_Point_s(RenderScript rs, int count) {
mItemArray = null;
mIOBuffer = null;
{
Element.Builder eb = new Element.Builder(rs);
eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta");
eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "position");
eb.add(Element.createVector(rs, Element.DataType.UNSIGNED_8, 4), "color");
mElement = eb.create();
}
init(rs, count);
}
private void copyToArray(Item i, int index) {
if (mIOBuffer == null) mIOBuffer = new FieldPacker(Item.sizeof * mType.getX() /* count */);
mIOBuffer.reset(index * Item.sizeof);
mIOBuffer.addF32(i.delta);
mIOBuffer.addF32(i.position);
mIOBuffer.addU8(i.color);
}
public void set(Item i, int index, boolean copyNow) {
if (mItemArray == null) mItemArray = new Item[mType.getX() /* count */];
mItemArray[index] = i;
if (copyNow) {
copyToArray(i, index);
mAllocation.subData1D(index * Item.sizeof, Item.sizeof, mIOBuffer.getData());
}
}
public void copyAll() {
for (int ct=0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct);
mAllocation.data(mIOBuffer.getData());
}
}

View File

@ -196,32 +196,9 @@ void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len
setupScript(rsc); setupScript(rsc);
Script * oldTLS = setTLS(this); Script * oldTLS = setTLS(this);
const uint32_t * dPtr = (const uint32_t *)data; ((void (*)(const void *, uint32_t))
switch(len) { mEnviroment.mInvokeFunctions[slot])(data, len);
case 0:
mEnviroment.mInvokeFunctions[slot]();
break;
case 4:
((void (*)(uint32_t))
mEnviroment.mInvokeFunctions[slot])(dPtr[0]);
break;
case 8:
((void (*)(uint32_t, uint32_t))
mEnviroment.mInvokeFunctions[slot])(dPtr[0], dPtr[1]);
break;
case 12:
((void (*)(uint32_t, uint32_t, uint32_t))
mEnviroment.mInvokeFunctions[slot])(dPtr[0], dPtr[1], dPtr[2]);
break;
case 16:
((void (*)(uint32_t, uint32_t, uint32_t, uint32_t))
mEnviroment.mInvokeFunctions[slot])(dPtr[0], dPtr[1], dPtr[2], dPtr[3]);
break;
case 20:
((void (*)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t))
mEnviroment.mInvokeFunctions[slot])(dPtr[0], dPtr[1], dPtr[2], dPtr[3], dPtr[4]);
break;
}
setTLS(oldTLS); setTLS(oldTLS);
} }

View File

@ -1,8 +1,6 @@
#ifndef __RS_CORE_RSH__ #ifndef __RS_CORE_RSH__
#define __RS_CORE_RSH__ #define __RS_CORE_RSH__
//uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b);
//uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a);
static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b) static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b)
{ {
@ -24,8 +22,6 @@ static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g,
return c; return c;
} }
/*
static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color) static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color)
{ {
color *= 255.f; color *= 255.f;
@ -51,10 +47,11 @@ static float4 rsUnpackColor8888(uchar4 c)
return ret; return ret;
} }
extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b); //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3); //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
extern float4 rsUnpackColor565(uchar4); //extern float4 rsUnpackColor565(uchar4);
*/
#endif #endif