Merge change 23890 into eclair

* changes:
  Improve structure support using symbol lookup of named structures in scripts to allow them to appear as just pointers to structs.
This commit is contained in:
Android (Google) Code Review
2009-09-03 15:47:39 -07:00
13 changed files with 194 additions and 88 deletions

View File

@@ -110,9 +110,12 @@ public class Allocation extends BaseObj {
} }
public void data(Object o) { public void data(Object o) {
mRS.nAllocationDataFromObject(mID, mType, o); mRS.nAllocationSubDataFromObject(mID, mType, 0, o);
} }
public void subData(int offset, Object o) {
mRS.nAllocationSubDataFromObject(mID, mType, offset, o);
}
public class Adapter1D extends BaseObj { public class Adapter1D extends BaseObj {
Adapter1D(int id, RenderScript rs) { Adapter1D(int id, RenderScript rs) {

View File

@@ -244,8 +244,8 @@ public class Element extends BaseObj {
} }
public Builder addFloatXY(String prefix) { public Builder addFloatXY(String prefix) {
add(DataType.FLOAT, DataKind.X, false, 32, prefix + "X"); add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "Y"); add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
return this; return this;
} }
@@ -257,9 +257,9 @@ public class Element extends BaseObj {
} }
public Builder addFloatXYZ(String prefix) { public Builder addFloatXYZ(String prefix) {
add(DataType.FLOAT, DataKind.X, false, 32, prefix + "X"); add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "Y"); add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "Z"); add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z");
return this; return this;
} }
@@ -270,8 +270,8 @@ public class Element extends BaseObj {
} }
public Builder addFloatST(String prefix) { public Builder addFloatST(String prefix) {
add(DataType.FLOAT, DataKind.S, false, 32, prefix + "S"); add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s");
add(DataType.FLOAT, DataKind.T, false, 32, prefix + "T"); add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t");
return this; return this;
} }
@@ -283,9 +283,9 @@ public class Element extends BaseObj {
} }
public Builder addFloatNorm(String prefix) { public Builder addFloatNorm(String prefix) {
add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "NX"); add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx");
add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "NY"); add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny");
add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "NZ"); add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz");
return this; return this;
} }
@@ -294,8 +294,8 @@ public class Element extends BaseObj {
return this; return this;
} }
public Builder addFloatPointSize(String name) { public Builder addFloatPointSize(String prefix) {
add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, name); add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize");
return this; return this;
} }
@@ -307,9 +307,9 @@ public class Element extends BaseObj {
} }
public Builder addFloatRGB(String prefix) { public Builder addFloatRGB(String prefix) {
add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "R"); add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "G"); add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "B"); add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
return this; return this;
} }
@@ -322,10 +322,10 @@ public class Element extends BaseObj {
} }
public Builder addFloatRGBA(String prefix) { public Builder addFloatRGBA(String prefix) {
add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "R"); add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "G"); add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "B"); add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "A"); add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a");
return this; return this;
} }
@@ -338,10 +338,10 @@ public class Element extends BaseObj {
} }
public Builder addUNorm8RGBA(String prefix) { public Builder addUNorm8RGBA(String prefix) {
add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "R"); add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r");
add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "G"); add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g");
add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "B"); add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b");
add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "A"); add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a");
return this; return this;
} }

View File

@@ -106,7 +106,7 @@ public class RenderScript {
native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes); native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes);
native void nAllocationRead(int id, int[] d); native void nAllocationRead(int id, int[] d);
native void nAllocationRead(int id, float[] d); native void nAllocationRead(int id, float[] d);
native void nAllocationDataFromObject(int id, Type t, Object o); native void nAllocationSubDataFromObject(int id, Type t, int offset, Object o);
native void nTriangleMeshBegin(int vertex, int index); native void nTriangleMeshBegin(int vertex, int index);
native void nTriangleMeshAddVertex_XY (float x, float y); native void nTriangleMeshAddVertex_XY (float x, float y);

View File

@@ -50,6 +50,13 @@ public class SimpleMesh extends BaseObj {
return Allocation.createTyped(mRS, mIndexType); return Allocation.createTyped(mRS, mIndexType);
} }
public Type getVertexType(int slot) {
return mVertexTypes[slot];
}
public Type getIndexType() {
return mIndexType;
}
public static class Builder { public static class Builder {
RenderScript mRS; RenderScript mRS;

View File

@@ -543,7 +543,7 @@ nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data)
//{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject }, //{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject },
static void static void
nAllocationDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jobject _o) nAllocationSubDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o)
{ {
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc);
@@ -556,7 +556,7 @@ nAllocationDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type
const TypeFieldCache *tfc = &tc->fields[ct]; const TypeFieldCache *tfc = &tc->fields[ct];
buf = tfc->ptr(_env, _o, tfc->field, buf); buf = tfc->ptr(_env, _o, tfc->field, buf);
} }
rsAllocationData(con, (RsAllocation)alloc, bufAlloc, tc->size); rsAllocation1DSubData(con, (RsAllocation)alloc, offset, 1, bufAlloc, tc->size);
const uint32_t * tmp = (const uint32_t *)bufAlloc; const uint32_t * tmp = (const uint32_t *)bufAlloc;
free(bufAlloc); free(bufAlloc);
} }
@@ -1282,7 +1282,7 @@ static JNINativeMethod methods[] = {
{"nAllocationSubData2D", "(IIIII[FI)V", (void*)nAllocationSubData2D_f }, {"nAllocationSubData2D", "(IIIII[FI)V", (void*)nAllocationSubData2D_f },
{"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i }, {"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i },
{"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f }, {"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f },
{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject }, {"nAllocationSubDataFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject },
{"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin }, {"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin },
{"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY }, {"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY },

View File

@@ -52,8 +52,8 @@ int offset(int x, int y, int width) {
} }
void dropWithStrength(int x, int y, int r, int s) { void dropWithStrength(int x, int y, int r, int s) {
int width = State_meshWidth; int width = State->meshWidth;
int height = State_meshHeight; int height = State->meshHeight;
if (x < r) x = r; if (x < r) x = r;
if (y < r) y = r; if (y < r) y = r;
@@ -62,8 +62,8 @@ void dropWithStrength(int x, int y, int r, int s) {
x = width - x; x = width - x;
int rippleMapSize = State_rippleMapSize; int rippleMapSize = State->rippleMapSize;
int index = State_rippleIndex; int index = State->rippleIndex;
int origin = offset(0, 0, width); int origin = offset(0, 0, width);
int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin); int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin);
@@ -94,10 +94,10 @@ void drop(int x, int y, int r) {
} }
void updateRipples() { void updateRipples() {
int rippleMapSize = State_rippleMapSize; int rippleMapSize = State->rippleMapSize;
int width = State_meshWidth; int width = State->meshWidth;
int height = State_meshHeight; int height = State->meshHeight;
int index = State_rippleIndex; int index = State->rippleIndex;
int origin = offset(0, 0, width); int origin = offset(0, 0, width);
int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin); int* current = loadArrayI32(RSID_RIPPLE_MAP, index * rippleMapSize + origin);
@@ -139,9 +139,9 @@ int refraction(int d, int wave, int *map) {
void generateRipples() { void generateRipples() {
int rippleMapSize = loadI32(RSID_STATE, OFFSETOF_WorldState_rippleMapSize); int rippleMapSize = loadI32(RSID_STATE, OFFSETOF_WorldState_rippleMapSize);
int width = State_meshWidth; int width = State->meshWidth;
int height = State_meshHeight; int height = State->meshHeight;
int index = State_rippleIndex; int index = State->rippleIndex;
int origin = offset(0, 0, width); int origin = offset(0, 0, width);
int b = width + 2; int b = width + 2;
@@ -180,7 +180,7 @@ void generateRipples() {
// Update Z coordinate of the vertex // Update Z coordinate of the vertex
vertices[index + 7] = dy * fy; vertices[index + 7] = dy * fy;
w -= 1; w -= 1;
current += 1; current += 1;
wave = nextWave; wave = nextWave;
@@ -210,7 +210,7 @@ void generateRipples() {
float v2x = vertices[o1 + 5]; float v2x = vertices[o1 + 5];
float v2y = vertices[o1 + 6]; float v2y = vertices[o1 + 6];
float v2z = vertices[o1 + 7]; float v2z = vertices[o1 + 7];
// V3 // V3
float v3x = vertices[ow + 5]; float v3x = vertices[ow + 5];
float v3y = vertices[ow + 6]; float v3y = vertices[ow + 6];
@@ -236,7 +236,7 @@ void generateRipples() {
n3x *= len; n3x *= len;
n3y *= len; n3y *= len;
n3z *= len; n3z *= len;
// V2 // V2
v2x = vertices[ow1 + 5]; v2x = vertices[ow1 + 5];
v2y = vertices[ow1 + 6]; v2y = vertices[ow1 + 6];
@@ -266,7 +266,7 @@ void generateRipples() {
vertices[o + 0] = n3x; vertices[o + 0] = n3x;
vertices[o + 1] = n3y; vertices[o + 1] = n3y;
vertices[o + 2] = -n3z; vertices[o + 2] = -n3z;
// reset Z // reset Z
//vertices[(yOffset + x) << 3 + 7] = 0.0f; //vertices[(yOffset + x) << 3 + 7] = 0.0f;
} }
@@ -322,7 +322,7 @@ void drawLeaf(int index, float* vertices, int meshWidth, int meshHeight,
float z2 = 0.0f; float z2 = 0.0f;
float z3 = 0.0f; float z3 = 0.0f;
float z4 = 0.0f; float z4 = 0.0f;
float a = leafStruct[LEAF_STRUCT_ALTITUDE]; float a = leafStruct[LEAF_STRUCT_ALTITUDE];
float s = leafStruct[LEAF_STRUCT_SCALE]; float s = leafStruct[LEAF_STRUCT_SCALE];
float r = leafStruct[LEAF_STRUCT_ANGLE]; float r = leafStruct[LEAF_STRUCT_ANGLE];
@@ -384,7 +384,7 @@ void drawLeaf(int index, float* vertices, int meshWidth, int meshHeight,
LEAF_SIZE * s + y < -glHeight / 2.0f) { LEAF_SIZE * s + y < -glHeight / 2.0f) {
int sprite = randf(LEAVES_TEXTURES_COUNT); int sprite = randf(LEAVES_TEXTURES_COUNT);
leafStruct[LEAF_STRUCT_X] = randf2(-1.0f, 1.0f); leafStruct[LEAF_STRUCT_X] = randf2(-1.0f, 1.0f);
leafStruct[LEAF_STRUCT_Y] = glHeight / 2.0f + LEAF_SIZE * 2 * randf(1.0f); leafStruct[LEAF_STRUCT_Y] = glHeight / 2.0f + LEAF_SIZE * 2 * randf(1.0f);
leafStruct[LEAF_STRUCT_SCALE] = randf2(0.4f, 0.5f); leafStruct[LEAF_STRUCT_SCALE] = randf2(0.4f, 0.5f);
leafStruct[LEAF_STRUCT_SPIN] = degf(randf2(-0.02f, 0.02f)) / 4.0f; leafStruct[LEAF_STRUCT_SPIN] = degf(randf2(-0.02f, 0.02f)) / 4.0f;
@@ -401,20 +401,20 @@ void drawLeaves() {
bindProgramVertex(NAMED_PVSky); bindProgramVertex(NAMED_PVSky);
bindTexture(NAMED_PFBackground, 0, NAMED_TLeaves); bindTexture(NAMED_PFBackground, 0, NAMED_TLeaves);
int leavesCount = State_leavesCount; int leavesCount = State->leavesCount;
int count = leavesCount * LEAF_STRUCT_FIELDS_COUNT; int count = leavesCount * LEAF_STRUCT_FIELDS_COUNT;
int width = State_meshWidth; int width = State->meshWidth;
int height = State_meshHeight; int height = State->meshHeight;
float glWidth = State_glWidth; float glWidth = State->glWidth;
float glHeight = State_glHeight; float glHeight = State->glHeight;
float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh); float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
int i = 0; int i = 0;
for ( ; i < count; i += LEAF_STRUCT_FIELDS_COUNT) { for ( ; i < count; i += LEAF_STRUCT_FIELDS_COUNT) {
drawLeaf(i, vertices, width, height, glWidth, glHeight); drawLeaf(i, vertices, width, height, glWidth, glHeight);
} }
float matrix[16]; float matrix[16];
matrixLoadIdentity(matrix); matrixLoadIdentity(matrix);
vpLoadModelMatrix(matrix); vpLoadModelMatrix(matrix);
@@ -433,8 +433,8 @@ void drawSky() {
bindProgramFragmentStore(NAMED_PFSLeaf); bindProgramFragmentStore(NAMED_PFSLeaf);
bindTexture(NAMED_PFSky, 0, NAMED_TSky); bindTexture(NAMED_PFSky, 0, NAMED_TSky);
float x = State_skyOffsetX + State_skySpeedX; float x = State->skyOffsetX + State->skySpeedX;
float y = State_skyOffsetY + State_skySpeedY; float y = State->skyOffsetY + State->skySpeedY;
if (x > 1.0f) x = 0.0f; if (x > 1.0f) x = 0.0f;
if (x < -1.0f) x = 0.0f; if (x < -1.0f) x = 0.0f;
@@ -467,8 +467,8 @@ void drawLighting() {
} }
void drawNormals() { void drawNormals() {
int width = State_meshWidth; int width = State->meshWidth;
int height = State_meshHeight; int height = State->meshHeight;
float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh); float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
@@ -496,12 +496,10 @@ void drawNormals() {
} }
int main(int index) { int main(int index) {
int dropX = Drop_dropX; if (Drop->dropX != -1) {
if (dropX != -1) { drop(Drop->dropX, Drop->dropY, DROP_RADIUS);
int dropY = Drop_dropY; Drop->dropX = -1;
drop(dropX, dropY, DROP_RADIUS); Drop->dropY = -1;
storeI32(RSID_DROP, OFFSETOF_DropState_dropX, -1);
storeI32(RSID_DROP, OFFSETOF_DropState_dropY, -1);
} }
updateRipples(); updateRipples();

View File

@@ -5,10 +5,6 @@
#pragma stateFragment(PFBackground) #pragma stateFragment(PFBackground)
#pragma stateFragmentStore(PSBackground) #pragma stateFragmentStore(PSBackground)
#define POS_TRANSLATE 0
#define POS_ROTATE 1
#define POS_FOCUS 2
#define STATE_TRIANGLE_OFFSET_COUNT 0 #define STATE_TRIANGLE_OFFSET_COUNT 0
#define STATE_LAST_FOCUS 1 #define STATE_LAST_FOCUS 1
@@ -18,12 +14,14 @@
// bank1: (r) The position information // bank1: (r) The position information
// bank2: (rw) The temporary texture state // bank2: (rw) The temporary texture state
int lastFocus;
int main(int index) int main(int index)
{ {
float mat1[16]; float mat1[16];
float trans = Pos_translate; float trans = Pos->translate;
float rot = Pos_rotate; float rot = Pos->rotate;
matrixLoadScale(mat1, 2.f, 2.f, 2.f); matrixLoadScale(mat1, 2.f, 2.f, 2.f);
matrixTranslate(mat1, 0.f, 0.f, trans); matrixTranslate(mat1, 0.f, 0.f, trans);
@@ -39,7 +37,7 @@ int main(int index)
bindProgramFragment(NAMED_PFImages); bindProgramFragment(NAMED_PFImages);
bindProgramVertex(NAMED_PVImages); bindProgramVertex(NAMED_PVImages);
float focusPos = Pos_focus; float focusPos = Pos->focus;
int focusID = 0; int focusID = 0;
int lastFocusID = loadI32(2, STATE_LAST_FOCUS); int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
int imgCount = 13; int imgCount = 13;
@@ -63,9 +61,9 @@ int main(int index)
} }
} }
*/ */
storeI32(2, STATE_LAST_FOCUS, focusID); lastFocus = focusID;
int triangleOffsetsCount = Pos_triangleOffsetCount; int triangleOffsetsCount = Pos->triangleOffsetCount;
int imgId = 0; int imgId = 0;
for (imgId=1; imgId <= imgCount; imgId++) { for (imgId=1; imgId <= imgCount; imgId++) {

View File

@@ -4,27 +4,32 @@
#pragma stateFragment(default) #pragma stateFragment(default)
#pragma stateFragmentStore(default) #pragma stateFragmentStore(default)
struct PartStruct {float dx; float dy; float x; float y; int c;};
int newPart = 0; int newPart = 0;
int main(int launchID) { int main(int launchID) {
int ct; int ct;
int count = Control_count - 1; int count = Control->count;
int rate = Control_rate; int rate = Control->rate;
float height = getHeight(); float height = getHeight();
struct PartStruct * p = (struct PartStruct *)loadArrayF(1, 0); struct point_s * p = (struct point_s *)point;
if (rate) { if (rate) {
float rMax = ((float)rate) * 0.005f; float rMax = ((float)rate) * 0.005f;
int x = Control_x; int x = Control->x;
int y = Control_y; int y = Control->y;
int c = colorFloatRGBAtoUNorm8(Control_r, Control_g, Control_b, 0.99f); char r = Control->r * 255.f;
char g = Control->g * 255.f;
char b = Control->b * 255.f;
char a = 0xf0;
while (rate--) { while (rate--) {
vec2Rand((float *)(p + newPart), rMax); vec2Rand((float *)(p + newPart), rMax);
p[newPart].x = x; p[newPart].x = x;
p[newPart].y = y; p[newPart].y = y;
p[newPart].c = c; p[newPart].r = r;
p[newPart].g = g;
p[newPart].b = b;
p[newPart].a = a;
newPart++; newPart++;
if (newPart >= count) { if (newPart >= count) {
newPart = 0; newPart = 0;
@@ -45,6 +50,6 @@ int main(int launchID) {
} }
uploadToBufferObject(NAMED_PartBuffer); uploadToBufferObject(NAMED_PartBuffer);
drawSimpleMeshRange(NAMED_PartMesh, 0, count); drawSimpleMesh(NAMED_PartMesh);
return 1; return 1;
} }

View File

@@ -79,10 +79,10 @@ public class FountainRS {
mIntAlloc.data(mSD); mIntAlloc.data(mSD);
Element.Builder eb = new Element.Builder(mRS); Element.Builder eb = new Element.Builder(mRS);
eb.addFloat(Element.DataKind.USER); //dx eb.addFloat(Element.DataKind.USER, "dx");
eb.addFloat(Element.DataKind.USER); //dy eb.addFloat(Element.DataKind.USER, "dy");
eb.addFloatXY(); eb.addFloatXY("");
eb.addUNorm8RGBA(); eb.addUNorm8RGBA("");
Element primElement = eb.create(); Element primElement = eb.create();
@@ -102,6 +102,7 @@ public class FountainRS {
sb.setScript(mRes, R.raw.fountain); sb.setScript(mRes, R.raw.fountain);
sb.setRoot(true); sb.setRoot(true);
sb.setType(mSDType, "Control", 0); sb.setType(mSDType, "Control", 0);
sb.setType(mSM.getVertexType(0), "point", 1);
Script script = sb.create(); Script script = sb.create();
script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);

View File

@@ -116,6 +116,7 @@ bool Context::runRootScript()
//glEnable(GL_LIGHT0); //glEnable(GL_LIGHT0);
glViewport(0, 0, mEGL.mWidth, mEGL.mHeight); glViewport(0, 0, mEGL.mWidth, mEGL.mHeight);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glEnable(GL_POINT_SMOOTH);
glClearColor(mRootScript->mEnviroment.mClearColor[0], glClearColor(mRootScript->mEnviroment.mClearColor[0],
mRootScript->mEnviroment.mClearColor[1], mRootScript->mEnviroment.mClearColor[1],
@@ -153,10 +154,18 @@ void Context::timerReset()
void Context::timerInit() void Context::timerInit()
{ {
mTimeLast = getTime(); mTimeLast = getTime();
mTimeFrame = mTimeLast;
mTimeLastFrame = mTimeLast;
mTimerActive = RS_TIMER_INTERNAL; mTimerActive = RS_TIMER_INTERNAL;
timerReset(); timerReset();
} }
void Context::timerFrame()
{
mTimeLastFrame = mTimeFrame;
mTimeFrame = getTime();
}
void Context::timerSet(Timers tm) void Context::timerSet(Timers tm)
{ {
uint64_t last = mTimeLast; uint64_t last = mTimeLast;
@@ -171,8 +180,10 @@ void Context::timerPrint()
for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) {
total += mTimers[ct]; total += mTimers[ct];
} }
uint64_t frame = mTimeFrame - mTimeLastFrame;
LOGV("RS Time Data: Idle %2.1f (%lli), Internal %2.1f (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli)", LOGV("RS: Frame (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli), Idle %2.1f (%lli), Internal %2.1f (%lli)",
frame / 1000000,
100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000, 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000,
100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000, 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000,
@@ -232,6 +243,7 @@ void * Context::threadProc(void *vrsc)
#endif #endif
eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
#if RS_LOG_TIMES #if RS_LOG_TIMES
rsc->timerFrame();
rsc->timerSet(RS_TIMER_INTERNAL); rsc->timerSet(RS_TIMER_INTERNAL);
rsc->timerPrint(); rsc->timerPrint();
rsc->timerReset(); rsc->timerReset();

View File

@@ -131,6 +131,7 @@ public:
void timerReset(); void timerReset();
void timerSet(Timers); void timerSet(Timers);
void timerPrint(); void timerPrint();
void timerFrame();
bool checkVersion1_1() const {return (mGL.mMajorVersion > 1) || (mGL.mMinorVersion >= 1); } bool checkVersion1_1() const {return (mGL.mMajorVersion > 1) || (mGL.mMinorVersion >= 1); }
bool checkVersion2_0() const {return mGL.mMajorVersion >= 2; } bool checkVersion2_0() const {return mGL.mMajorVersion >= 2; }
@@ -202,6 +203,8 @@ private:
uint64_t mTimers[_RS_TIMER_TOTAL]; uint64_t mTimers[_RS_TIMER_TOTAL];
Timers mTimerActive; Timers mTimerActive;
uint64_t mTimeLast; uint64_t mTimeLast;
uint64_t mTimeFrame;
uint64_t mTimeLastFrame;
}; };

View File

@@ -67,6 +67,12 @@ bool ScriptC::run(Context *rsc, uint32_t launchIndex)
= nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
} }
for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
if (mProgram.mSlotPointers[ct]) {
*mProgram.mSlotPointers[ct] = mSlots[ct]->getPtr();
}
}
bool ret = false; bool ret = false;
tls->mScript = this; tls->mScript = this;
ret = mProgram.mScript(launchIndex) != 0; ret = mProgram.mScript(launchIndex) != 0;
@@ -139,6 +145,7 @@ void ScriptCState::runCompiler(Context *rsc)
accRegisterSymbolCallback(mAccScript, symbolLookup, NULL); accRegisterSymbolCallback(mAccScript, symbolLookup, NULL);
accCompileScript(mAccScript); accCompileScript(mAccScript);
accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript);
accGetScriptLabel(mAccScript, "init", (ACCvoid**) &mProgram.mInit);
rsAssert(mProgram.mScript); rsAssert(mProgram.mScript);
if (!mProgram.mScript) { if (!mProgram.mScript) {
@@ -148,6 +155,19 @@ void ScriptCState::runCompiler(Context *rsc)
LOGE(buf); LOGE(buf);
} }
if (mProgram.mInit) {
mProgram.mInit();
}
for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
if (mSlotNames[ct].length() > 0) {
accGetScriptLabel(mAccScript,
mSlotNames[ct].string(),
(ACCvoid**) &mProgram.mSlotPointers[ct]);
LOGE("var %s %p", mSlotNames[ct].string(), mProgram.mSlotPointers[ct]);
}
}
mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore());
@@ -224,6 +244,19 @@ void ScriptCState::runCompiler(Context *rsc)
} }
} }
static void appendElementBody(String8 *s, const Element *e)
{
s->append(" {\n");
for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
const Component *c = e->getComponent(ct2);
s->append(" ");
s->append(c->getCType());
s->append(" ");
s->append(c->getComponentName());
s->append(";\n");
}
s->append("}");
}
void ScriptCState::appendVarDefines(String8 *str) void ScriptCState::appendVarDefines(String8 *str)
{ {
@@ -246,6 +279,8 @@ void ScriptCState::appendVarDefines(String8 *str)
} }
} }
void ScriptCState::appendTypes(String8 *str) void ScriptCState::appendTypes(String8 *str)
{ {
char buf[256]; char buf[256];
@@ -257,6 +292,19 @@ void ScriptCState::appendTypes(String8 *str)
continue; continue;
} }
const Element *e = t->getElement(); const Element *e = t->getElement();
if (e->getName() && (e->getComponentCount() > 1)) {
String8 s("struct struct_");
s.append(e->getName());
appendElementBody(&s, e);
s.append(";\n");
s.append("#define ");
s.append(e->getName());
s.append("_t struct struct_");
s.append(e->getName());
s.append("\n\n");
LOGD(s);
str->append(s);
}
if (t->getName()) { if (t->getName()) {
for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) { for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
@@ -267,12 +315,39 @@ void ScriptCState::appendTypes(String8 *str)
tmp.append(c->getComponentName()); tmp.append(c->getComponentName());
sprintf(buf, " %i\n", ct2); sprintf(buf, " %i\n", ct2);
tmp.append(buf); tmp.append(buf);
//LOGD(tmp); LOGD(tmp);
str->append(tmp); str->append(tmp);
} }
} }
if (mSlotNames[ct].length() > 0) { if (mSlotNames[ct].length() > 0) {
String8 s;
if (e->getComponentCount() > 1) {
if (e->getName()) {
// Use the named struct
s.setTo(e->getName());
s.append("_t *");
} else {
// create an struct named from the slot.
s.setTo("struct ");
s.append(mSlotNames[ct]);
s.append("_s");
appendElementBody(&s, e);
s.append(";\n");
s.append("struct ");
s.append(mSlotNames[ct]);
s.append("_s * ");
}
} else {
// Just make an array
s.setTo(e->getComponent(0)->getCType());
s.append("_t *");
}
s.append(mSlotNames[ct]);
s.append(";\n");
LOGD(s);
str->append(s);
#if 0
for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) { for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
const Component *c = e->getComponent(ct2); const Component *c = e->getComponent(ct2);
tmp.setTo("#define "); tmp.setTo("#define ");
@@ -295,12 +370,12 @@ void ScriptCState::appendTypes(String8 *str)
sprintf(buf, "%i, %i)\n", ct, ct2); sprintf(buf, "%i, %i)\n", ct, ct2);
tmp.append(buf); tmp.append(buf);
//LOGD(tmp); LOGD(tmp);
str->append(tmp); str->append(tmp);
} }
#endif
} }
} }
} }

View File

@@ -35,6 +35,7 @@ class ScriptC : public Script
{ {
public: public:
typedef int (*RunScript_t)(uint32_t launchIndex); typedef int (*RunScript_t)(uint32_t launchIndex);
typedef void (*VoidFunc_t)();
ScriptC(); ScriptC();
virtual ~ScriptC(); virtual ~ScriptC();
@@ -48,6 +49,9 @@ public:
int mVersionMinor; int mVersionMinor;
RunScript_t mScript; RunScript_t mScript;
VoidFunc_t mInit;
void ** mSlotPointers[MAX_SCRIPT_BANKS];
}; };
Program_t mProgram; Program_t mProgram;