Merge change 21570 into eclair
* changes: Update fountain and add writable flag to script slots.
This commit is contained in:
@@ -223,6 +223,52 @@ public class Element extends BaseObj {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder addFloat(Element.DataKind dk) {
|
||||||
|
add(DataType.FLOAT, dk, false, 32, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addFloat(Element.DataKind dk, String name) {
|
||||||
|
add(DataType.FLOAT, dk, false, 32, name);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addFloatXY() {
|
||||||
|
add(DataType.FLOAT, DataKind.X, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.Y, false, 32, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addFloatXYZ() {
|
||||||
|
add(DataType.FLOAT, DataKind.X, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.Y, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.Z, false, 32, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addFloatRGB() {
|
||||||
|
add(DataType.FLOAT, DataKind.RED, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addFloatRGBA() {
|
||||||
|
add(DataType.FLOAT, DataKind.RED, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
|
||||||
|
add(DataType.FLOAT, DataKind.ALPHA, false, 32, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addUNorm8RGBA() {
|
||||||
|
add(DataType.UNSIGNED, DataKind.RED, true, 8, null);
|
||||||
|
add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null);
|
||||||
|
add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null);
|
||||||
|
add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
static synchronized Element internalCreate(RenderScript rs, Builder b) {
|
static synchronized Element internalCreate(RenderScript rs, Builder b) {
|
||||||
rs.nElementBegin();
|
rs.nElementBegin();
|
||||||
for (int ct=0; ct < b.mEntryCount; ct++) {
|
for (int ct=0; ct < b.mEntryCount; ct++) {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class RenderScript {
|
|||||||
native void nScriptSetClearDepth(int script, float depth);
|
native void nScriptSetClearDepth(int script, float depth);
|
||||||
native void nScriptSetClearStencil(int script, int stencil);
|
native void nScriptSetClearStencil(int script, int stencil);
|
||||||
native void nScriptSetTimeZone(int script, byte[] timeZone);
|
native void nScriptSetTimeZone(int script, byte[] timeZone);
|
||||||
native void nScriptSetType(int type, String name, int slot);
|
native void nScriptSetType(int type, boolean writable, String name, int slot);
|
||||||
native void nScriptSetRoot(boolean isRoot);
|
native void nScriptSetRoot(boolean isRoot);
|
||||||
|
|
||||||
native void nScriptCBegin();
|
native void nScriptCBegin();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class Script extends BaseObj {
|
|||||||
|
|
||||||
boolean mIsRoot;
|
boolean mIsRoot;
|
||||||
Type[] mTypes;
|
Type[] mTypes;
|
||||||
|
boolean[] mWritable;
|
||||||
|
|
||||||
Script(int id, RenderScript rs) {
|
Script(int id, RenderScript rs) {
|
||||||
super(rs);
|
super(rs);
|
||||||
@@ -67,11 +68,13 @@ public class Script extends BaseObj {
|
|||||||
boolean mIsRoot = false;
|
boolean mIsRoot = false;
|
||||||
Type[] mTypes;
|
Type[] mTypes;
|
||||||
String[] mNames;
|
String[] mNames;
|
||||||
|
boolean[] mWritable;
|
||||||
|
|
||||||
Builder(RenderScript rs) {
|
Builder(RenderScript rs) {
|
||||||
mRS = rs;
|
mRS = rs;
|
||||||
mTypes = new Type[MAX_SLOT];
|
mTypes = new Type[MAX_SLOT];
|
||||||
mNames = new String[MAX_SLOT];
|
mNames = new String[MAX_SLOT];
|
||||||
|
mWritable = new boolean[MAX_SLOT];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(Type t, int slot) {
|
public void setType(Type t, int slot) {
|
||||||
@@ -84,11 +87,15 @@ public class Script extends BaseObj {
|
|||||||
mNames[slot] = name;
|
mNames[slot] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(boolean writable, int slot) {
|
||||||
|
mWritable[slot] = writable;
|
||||||
|
}
|
||||||
|
|
||||||
void transferCreate() {
|
void transferCreate() {
|
||||||
mRS.nScriptSetRoot(mIsRoot);
|
mRS.nScriptSetRoot(mIsRoot);
|
||||||
for(int ct=0; ct < mTypes.length; ct++) {
|
for(int ct=0; ct < mTypes.length; ct++) {
|
||||||
if(mTypes[ct] != null) {
|
if(mTypes[ct] != null) {
|
||||||
mRS.nScriptSetType(mTypes[ct].mID, mNames[ct], ct);
|
mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -825,15 +825,15 @@ nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nScriptSetType(JNIEnv *_env, jobject _this, jint type, jstring _str, jint slot)
|
nScriptSetType(JNIEnv *_env, jobject _this, jint type, jboolean writable, jstring _str, jint slot)
|
||||||
{
|
{
|
||||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||||
LOG_API("nScriptCAddType, con(%p), type(%p), slot(%i)", con, (RsType)type, slot);
|
LOG_API("nScriptCAddType, con(%p), type(%p), writable(%i), slot(%i)", con, (RsType)type, writable, slot);
|
||||||
const char* n = NULL;
|
const char* n = NULL;
|
||||||
if (_str) {
|
if (_str) {
|
||||||
n = _env->GetStringUTFChars(_str, NULL);
|
n = _env->GetStringUTFChars(_str, NULL);
|
||||||
}
|
}
|
||||||
rsScriptSetType((RsType)type, slot, n);
|
rsScriptSetType((RsType)type, slot, writable, n);
|
||||||
if (n) {
|
if (n) {
|
||||||
_env->ReleaseStringUTFChars(_str, n);
|
_env->ReleaseStringUTFChars(_str, n);
|
||||||
}
|
}
|
||||||
@@ -1381,7 +1381,7 @@ static JNINativeMethod methods[] = {
|
|||||||
{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth },
|
{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth },
|
||||||
{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil },
|
{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil },
|
||||||
{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone },
|
{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone },
|
||||||
{"nScriptSetType", "(ILjava/lang/String;I)V", (void*)nScriptSetType },
|
{"nScriptSetType", "(IZLjava/lang/String;I)V", (void*)nScriptSetType },
|
||||||
{"nScriptSetRoot", "(Z)V", (void*)nScriptSetRoot },
|
{"nScriptSetRoot", "(Z)V", (void*)nScriptSetRoot },
|
||||||
|
|
||||||
{"nScriptCBegin", "()V", (void*)nScriptCBegin },
|
{"nScriptCBegin", "()V", (void*)nScriptCBegin },
|
||||||
|
|||||||
@@ -1,86 +1,52 @@
|
|||||||
// Fountain test script
|
// Fountain test script
|
||||||
|
|
||||||
#pragma version(1)
|
#pragma version(1)
|
||||||
#pragma stateVertex(default)
|
#pragma stateVertex(default)
|
||||||
#pragma stateFragment(PgmFragParts)
|
#pragma stateFragment(default)
|
||||||
#pragma stateFragmentStore(PFSBlend)
|
#pragma stateFragmentStore(default)
|
||||||
|
|
||||||
|
|
||||||
int main(int launchID) {
|
int main(int launchID) {
|
||||||
int ct;
|
int ct;
|
||||||
int count = loadI32(0, OFFSETOF_SomeData_count);
|
int count = Control_count - 1;
|
||||||
int touch = loadI32(0, OFFSETOF_SomeData_touch);
|
int rate = Control_rate;
|
||||||
int rate = 4;
|
float *dataF = loadArrayF(1, 0);
|
||||||
int maxLife = (count / rate) - 1;
|
float height = getHeight();
|
||||||
|
|
||||||
if (touch) {
|
if (rate) {
|
||||||
int x = loadI32(0, OFFSETOF_SomeData_x);
|
debugI32("rate", rate);
|
||||||
int y = loadI32(0, OFFSETOF_SomeData_y);
|
int *dataI = loadArrayI32(1, 0);
|
||||||
int newPart = loadI32(2, 0);
|
float rMax = ((float)rate) * 0.005f;
|
||||||
for (ct=0; ct<rate; ct++) {
|
int x = Control_x;
|
||||||
int idx = newPart * 5 + 1;
|
int y = Control_y;
|
||||||
storeF(2, idx, randf(1.f) - 0.5f);
|
int newPart = loadI32(1, count * 5);
|
||||||
storeF(2, idx + 1, randf(1.f) - 0.5f);
|
int c = colorFloatRGBAtoUNorm8(Control_r, Control_g, Control_b, 0.99f);
|
||||||
storeI32(2, idx + 2, maxLife);
|
|
||||||
storeF(2, idx + 3, x);
|
while (rate--) {
|
||||||
storeF(2, idx + 4, y);
|
int idx = newPart * 5;
|
||||||
|
vec2Rand(dataF + idx, rMax);
|
||||||
|
dataF[idx + 2] = x;
|
||||||
|
dataF[idx + 3] = y;
|
||||||
|
dataI[idx + 4] = c;
|
||||||
newPart++;
|
newPart++;
|
||||||
if (newPart >= count) {
|
if (newPart >= count) {
|
||||||
newPart = 0;
|
newPart = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
storeI32(2, 0, newPart);
|
storeI32(1, count * 5, newPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
int drawCount = 0;
|
|
||||||
float height = getHeight();
|
|
||||||
for (ct=0; ct < count; ct++) {
|
for (ct=0; ct < count; ct++) {
|
||||||
int srcIdx = ct * 5 + 1;
|
float dy = dataF[1] + 0.15f;
|
||||||
|
float posy = dataF[3] + dy;
|
||||||
int life = loadI32(2, srcIdx + 2);
|
if ((posy > height) && (dy > 0)) {
|
||||||
|
dy *= -0.3f;
|
||||||
if (life) {
|
|
||||||
float posx = loadF(2, srcIdx + 3);
|
|
||||||
float posy = loadF(2, srcIdx + 4);
|
|
||||||
float dx = loadF(2, srcIdx);
|
|
||||||
float dy = loadF(2, srcIdx + 1);
|
|
||||||
if (posy < height) {
|
|
||||||
int dstIdx = drawCount * 9;
|
|
||||||
int c = 0xcfcfcfcf;
|
|
||||||
|
|
||||||
storeI32(1, dstIdx, c);
|
|
||||||
storeF(1, dstIdx + 1, posx);
|
|
||||||
storeF(1, dstIdx + 2, posy);
|
|
||||||
|
|
||||||
storeI32(1, dstIdx + 3, c);
|
|
||||||
storeF(1, dstIdx + 4, posx + 1.f);
|
|
||||||
storeF(1, dstIdx + 5, posy + dy);
|
|
||||||
|
|
||||||
storeI32(1, dstIdx + 6, c);
|
|
||||||
storeF(1, dstIdx + 7, posx - 1.f);
|
|
||||||
storeF(1, dstIdx + 8, posy + dy);
|
|
||||||
drawCount ++;
|
|
||||||
} else {
|
|
||||||
if (dy > 0) {
|
|
||||||
dy *= -0.5f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
posx = posx + dx;
|
|
||||||
posy = posy + dy;
|
|
||||||
dy = dy + 0.05f;
|
|
||||||
life --;
|
|
||||||
|
|
||||||
//storeI32(2, srcIdx, dx);
|
|
||||||
storeF(2, srcIdx + 1, dy);
|
|
||||||
storeI32(2, srcIdx + 2, life);
|
|
||||||
storeF(2, srcIdx + 3, posx);
|
|
||||||
storeF(2, srcIdx + 4, posy);
|
|
||||||
}
|
}
|
||||||
|
dataF[1] = dy;
|
||||||
|
dataF[2] += dataF[0];
|
||||||
|
dataF[3] = posy;
|
||||||
|
dataF += 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
//drawTriangleArray(NAMED_PartBuffer, drawCount);
|
|
||||||
uploadToBufferObject(NAMED_PartBuffer);
|
uploadToBufferObject(NAMED_PartBuffer);
|
||||||
drawSimpleMeshRange(NAMED_PartMesh, 0, drawCount * 3);
|
drawSimpleMeshRange(NAMED_PartMesh, 0, count);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,26 +16,22 @@
|
|||||||
|
|
||||||
package com.android.fountain;
|
package com.android.fountain;
|
||||||
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.renderscript.*;
|
import android.renderscript.*;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
public class FountainRS {
|
public class FountainRS {
|
||||||
public static final int PART_COUNT = 4000;
|
public static final int PART_COUNT = 20000;
|
||||||
|
|
||||||
static class SomeData {
|
static class SomeData {
|
||||||
public int x;
|
public int x;
|
||||||
public int y;
|
public int y;
|
||||||
public int touch;
|
|
||||||
public int rate;
|
public int rate;
|
||||||
public int count;
|
public int count;
|
||||||
|
public float r;
|
||||||
|
public float g;
|
||||||
|
public float b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FountainRS() {
|
public FountainRS() {
|
||||||
@@ -47,8 +43,18 @@ public class FountainRS {
|
|||||||
initRS();
|
initRS();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void newTouchPosition(int x, int y) {
|
public void newTouchPosition(int x, int y, int rate) {
|
||||||
mSD.touch = 1;
|
if (mSD.rate == 0) {
|
||||||
|
mSD.r = ((x & 0x1) != 0) ? 0.f : 1.f;
|
||||||
|
mSD.g = ((x & 0x2) != 0) ? 0.f : 1.f;
|
||||||
|
mSD.b = ((x & 0x4) != 0) ? 0.f : 1.f;
|
||||||
|
if ((mSD.r + mSD.g + mSD.b) < 0.9f) {
|
||||||
|
mSD.r = 0.8f;
|
||||||
|
mSD.g = 0.5f;
|
||||||
|
mSD.b = 1.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSD.rate = rate;
|
||||||
mSD.x = x;
|
mSD.x = x;
|
||||||
mSD.y = y;
|
mSD.y = y;
|
||||||
mIntAlloc.data(mSD);
|
mIntAlloc.data(mSD);
|
||||||
@@ -62,50 +68,29 @@ public class FountainRS {
|
|||||||
private RenderScript mRS;
|
private RenderScript mRS;
|
||||||
private Allocation mIntAlloc;
|
private Allocation mIntAlloc;
|
||||||
private Allocation mPartAlloc;
|
private Allocation mPartAlloc;
|
||||||
private Allocation mVertAlloc;
|
|
||||||
private Script mScript;
|
private Script mScript;
|
||||||
private ProgramStore mPFS;
|
|
||||||
private ProgramFragment mPF;
|
|
||||||
private SimpleMesh mSM;
|
private SimpleMesh mSM;
|
||||||
|
private SomeData mSD;
|
||||||
private Bitmap mBackground;
|
|
||||||
|
|
||||||
SomeData mSD = new SomeData();
|
|
||||||
private Type mSDType;
|
private Type mSDType;
|
||||||
|
|
||||||
private void initRS() {
|
private void initRS() {
|
||||||
mSD = new SomeData();
|
mSD = new SomeData();
|
||||||
mSDType = Type.createFromClass(mRS, SomeData.class, 1, "SomeData");
|
mSDType = Type.createFromClass(mRS, SomeData.class, 1, "SomeData");
|
||||||
mIntAlloc = Allocation.createTyped(mRS, mSDType);
|
mIntAlloc = Allocation.createTyped(mRS, mSDType);
|
||||||
mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, PART_COUNT * 5 + 1);
|
|
||||||
|
|
||||||
ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
|
|
||||||
bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE);
|
|
||||||
bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
|
|
||||||
bs.setDepthMask(false);
|
|
||||||
bs.setDitherEnable(false);
|
|
||||||
mPFS = bs.create();
|
|
||||||
mPFS.setName("PFSBlend");
|
|
||||||
|
|
||||||
ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
|
|
||||||
mPF = bf.create();
|
|
||||||
mPF.setName("PgmFragParts");
|
|
||||||
|
|
||||||
mSD.count = PART_COUNT;
|
mSD.count = PART_COUNT;
|
||||||
mIntAlloc.data(mSD);
|
mIntAlloc.data(mSD);
|
||||||
|
|
||||||
Element.Builder eb = new Element.Builder(mRS);
|
Element.Builder eb = new Element.Builder(mRS);
|
||||||
eb.add(Element.DataType.UNSIGNED, Element.DataKind.RED, true, 8);
|
eb.addFloat(Element.DataKind.USER); //dx
|
||||||
eb.add(Element.DataType.UNSIGNED, Element.DataKind.GREEN, true, 8);
|
eb.addFloat(Element.DataKind.USER); //dy
|
||||||
eb.add(Element.DataType.UNSIGNED, Element.DataKind.BLUE, true, 8);
|
eb.addFloatXY();
|
||||||
eb.add(Element.DataType.UNSIGNED, Element.DataKind.ALPHA, true, 8);
|
eb.addUNorm8RGBA();
|
||||||
eb.add(Element.DataType.FLOAT, Element.DataKind.X, false, 32);
|
|
||||||
eb.add(Element.DataType.FLOAT, Element.DataKind.Y, false, 32);
|
|
||||||
Element primElement = eb.create();
|
Element primElement = eb.create();
|
||||||
|
|
||||||
|
|
||||||
SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
|
SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
|
||||||
int vtxSlot = smb.addVertexType(primElement, PART_COUNT * 3);
|
int vtxSlot = smb.addVertexType(primElement, PART_COUNT);
|
||||||
smb.setPrimitive(Primitive.TRIANGLE);
|
smb.setPrimitive(Primitive.POINT);
|
||||||
mSM = smb.create();
|
mSM = smb.create();
|
||||||
mSM.setName("PartMesh");
|
mSM.setName("PartMesh");
|
||||||
|
|
||||||
@@ -118,13 +103,12 @@ public class FountainRS {
|
|||||||
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
||||||
sb.setScript(mRes, R.raw.fountain);
|
sb.setScript(mRes, R.raw.fountain);
|
||||||
sb.setRoot(true);
|
sb.setRoot(true);
|
||||||
sb.setType(mSDType, 0);
|
sb.setType(mSDType, "Control", 0);
|
||||||
mScript = sb.create();
|
mScript = sb.create();
|
||||||
mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
mScript.bindAllocation(mIntAlloc, 0);
|
mScript.bindAllocation(mIntAlloc, 0);
|
||||||
mScript.bindAllocation(mPartAlloc, 1);
|
mScript.bindAllocation(mPartAlloc, 1);
|
||||||
mScript.bindAllocation(mVertAlloc, 2);
|
|
||||||
mRS.contextBindRootScript(mScript);
|
mRS.contextBindRootScript(mScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,18 @@ public class FountainView extends RSSurfaceView {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent ev)
|
public boolean onTouchEvent(MotionEvent ev)
|
||||||
{
|
{
|
||||||
boolean ret = true;
|
|
||||||
int act = ev.getAction();
|
int act = ev.getAction();
|
||||||
if (act == ev.ACTION_UP) {
|
if (act == ev.ACTION_UP) {
|
||||||
ret = false;
|
mRender.newTouchPosition(0, 0, 0);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
mRender.newTouchPosition((int)ev.getX(), (int)ev.getY());
|
float rate = (ev.getPressure() * 50.f);
|
||||||
return ret;
|
rate *= rate;
|
||||||
|
if(rate > 2000.f) {
|
||||||
|
rate = 2000.f;
|
||||||
|
}
|
||||||
|
mRender.newTouchPosition((int)ev.getX(), (int)ev.getY(), (int)rate);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -315,6 +315,7 @@ ScriptSetClearStencil {
|
|||||||
ScriptSetType {
|
ScriptSetType {
|
||||||
param RsType type
|
param RsType type
|
||||||
param uint32_t slot
|
param uint32_t slot
|
||||||
|
param bool isWritable
|
||||||
param const char * name
|
param const char * name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,11 +76,12 @@ void rsi_ScriptSetClearStencil(Context * rsc, RsScript vs, uint32_t v)
|
|||||||
s->mEnviroment.mClearStencil = v;
|
s->mEnviroment.mClearStencil = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, const char *name)
|
void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name)
|
||||||
{
|
{
|
||||||
ScriptCState *ss = &rsc->mScriptC;
|
ScriptCState *ss = &rsc->mScriptC;
|
||||||
const Type *t = static_cast<const Type *>(vt);
|
const Type *t = static_cast<const Type *>(vt);
|
||||||
ss->mConstantBufferTypes[slot].set(t);
|
ss->mConstantBufferTypes[slot].set(t);
|
||||||
|
ss->mSlotWritable[slot] = writable;
|
||||||
if (name) {
|
if (name) {
|
||||||
ss->mSlotNames[slot].setTo(name);
|
ss->mSlotNames[slot].setTo(name);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public:
|
|||||||
ObjectBaseRef<Allocation> mSlots[MAX_SCRIPT_BANKS];
|
ObjectBaseRef<Allocation> mSlots[MAX_SCRIPT_BANKS];
|
||||||
ObjectBaseRef<const Type> mTypes[MAX_SCRIPT_BANKS];
|
ObjectBaseRef<const Type> mTypes[MAX_SCRIPT_BANKS];
|
||||||
String8 mSlotNames[MAX_SCRIPT_BANKS];
|
String8 mSlotNames[MAX_SCRIPT_BANKS];
|
||||||
|
bool mSlotWritable[MAX_SCRIPT_BANKS];
|
||||||
|
|
||||||
virtual bool run(Context *, uint32_t launchID) = 0;
|
virtual bool run(Context *, uint32_t launchID) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ void ScriptCState::clear()
|
|||||||
for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
||||||
mConstantBufferTypes[ct].clear();
|
mConstantBufferTypes[ct].clear();
|
||||||
mSlotNames[ct].setTo("");
|
mSlotNames[ct].setTo("");
|
||||||
|
mSlotWritable[ct] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&mEnviroment, 0, sizeof(mEnviroment));
|
memset(&mEnviroment, 0, sizeof(mEnviroment));
|
||||||
@@ -341,6 +342,7 @@ RsScript rsi_ScriptCCreate(Context * rsc)
|
|||||||
for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
||||||
s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
|
s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
|
||||||
s->mSlotNames[ct] = ss->mSlotNames[ct];
|
s->mSlotNames[ct] = ss->mSlotNames[ct];
|
||||||
|
s->mSlotWritable[ct] = ss->mSlotWritable[ct];
|
||||||
}
|
}
|
||||||
|
|
||||||
ss->clear();
|
ss->clear();
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
|
|
||||||
ObjectBaseRef<const Type> mConstantBufferTypes[MAX_SCRIPT_BANKS];
|
ObjectBaseRef<const Type> mConstantBufferTypes[MAX_SCRIPT_BANKS];
|
||||||
String8 mSlotNames[MAX_SCRIPT_BANKS];
|
String8 mSlotNames[MAX_SCRIPT_BANKS];
|
||||||
|
bool mSlotWritable[MAX_SCRIPT_BANKS];
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void runCompiler(Context *rsc);
|
void runCompiler(Context *rsc);
|
||||||
|
|||||||
@@ -465,6 +465,14 @@ static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void SC_vec2Rand(float *vec, float maxLen)
|
||||||
|
{
|
||||||
|
float angle = SC_randf(PI * 2);
|
||||||
|
float len = SC_randf(maxLen);
|
||||||
|
vec[0] = len * sinf(angle);
|
||||||
|
vec[1] = len * cosf(angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -780,6 +788,24 @@ static uint32_t SC_getHeight()
|
|||||||
return rsc->getHeight();
|
return rsc->getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
|
||||||
|
{
|
||||||
|
uint32_t c = 0;
|
||||||
|
c |= (uint32_t)(r * 255.f + 0.5f);
|
||||||
|
c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
|
||||||
|
c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
|
||||||
|
c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
|
||||||
|
{
|
||||||
|
uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
|
||||||
|
uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
|
||||||
|
uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
|
||||||
|
return rs888to565(ir, ig, ib);
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// Class implementation
|
// Class implementation
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -937,6 +963,10 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
|
|||||||
{ "matrixTranslate", (void *)&SC_matrixTranslate,
|
{ "matrixTranslate", (void *)&SC_matrixTranslate,
|
||||||
"void", "(float *mat, float x, float y, float z)" },
|
"void", "(float *mat, float x, float y, float z)" },
|
||||||
|
|
||||||
|
// vector
|
||||||
|
{ "vec2Rand", (void *)&SC_vec2Rand,
|
||||||
|
"void", "(float *vec, float maxLen)" },
|
||||||
|
|
||||||
// context
|
// context
|
||||||
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
|
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
|
||||||
"void", "(int)" },
|
"void", "(int)" },
|
||||||
@@ -999,6 +1029,12 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
|
|||||||
{ "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
|
{ "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
|
||||||
"void", "(int)" },
|
"void", "(int)" },
|
||||||
|
|
||||||
|
{ "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
|
||||||
|
"int", "(float, float, float, float)" },
|
||||||
|
{ "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
|
||||||
|
"int", "(float, float, float)" },
|
||||||
|
|
||||||
|
|
||||||
{ "getWidth", (void *)&SC_getWidth,
|
{ "getWidth", (void *)&SC_getWidth,
|
||||||
"int", "()" },
|
"int", "()" },
|
||||||
{ "getHeight", (void *)&SC_getHeight,
|
{ "getHeight", (void *)&SC_getHeight,
|
||||||
|
|||||||
Reference in New Issue
Block a user