summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2011-05-12 10:38:03 -0700
committerAlex Sakhartchouk <alexst@google.com>2011-05-12 10:49:39 -0700
commit25999a08a6652ff5d7d0973f279f1e92e04b3506 (patch)
treefd3a2678fee9bcf1217e03c17d9cb8a080ffacb7
parent415c842aa6dd3cc797ed2ef1ae42351f594a6c74 (diff)
downloadframeworks_base-25999a08a6652ff5d7d0973f279f1e92e04b3506.zip
frameworks_base-25999a08a6652ff5d7d0973f279f1e92e04b3506.tar.gz
frameworks_base-25999a08a6652ff5d7d0973f279f1e92e04b3506.tar.bz2
Cleanup mesh creation.
Change-Id: Iaf5e060711dcb6341ac0f337dfb274528cb68d3e
-rw-r--r--graphics/java/android/renderscript/Mesh.java126
-rw-r--r--graphics/java/android/renderscript/RenderScript.java21
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp44
-rw-r--r--libs/rs/rs.spec23
-rw-r--r--libs/rs/rsMesh.cpp31
-rw-r--r--libs/rs/rsMesh.h7
6 files changed, 102 insertions, 150 deletions
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index 2774809..7b3b73f 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -320,53 +320,55 @@ public class Mesh extends BaseObj {
return tb.create();
}
- static synchronized Mesh internalCreate(RenderScript rs, Builder b) {
+ /**
+ * Create a Mesh object from the current state of the builder
+ *
+ **/
+ public Mesh create() {
+ mRS.validate();
+ int[] vtx = new int[mVertexTypeCount];
+ int[] idx = new int[mIndexTypes.size()];
+ int[] prim = new int[mIndexTypes.size()];
- int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
- Mesh newMesh = new Mesh(id, rs);
- newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
- newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
- newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
+ Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
+ Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
+ Primitive[] primitives = new Primitive[mIndexTypes.size()];
- for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
+ for(int ct = 0; ct < mVertexTypeCount; ct ++) {
Allocation alloc = null;
- Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
+ Entry entry = mVertexTypes[ct];
if (entry.t != null) {
- alloc = Allocation.createTyped(rs, entry.t, b.mUsage);
- }
- else if(entry.e != null) {
- alloc = Allocation.createSized(rs, entry.e, entry.size, b.mUsage);
+ alloc = Allocation.createTyped(mRS, entry.t, mUsage);
+ } else if(entry.e != null) {
+ alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
}
- int allocID = (alloc == null) ? 0 : alloc.getID();
- rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
- newMesh.mIndexBuffers[ct] = alloc;
- newMesh.mPrimitives[ct] = entry.prim;
+ vertexBuffers[ct] = alloc;
+ vtx[ct] = alloc.getID();
}
- for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
+ for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
Allocation alloc = null;
- Entry entry = b.mVertexTypes[ct];
+ Entry entry = (Entry)mIndexTypes.elementAt(ct);
if (entry.t != null) {
- alloc = Allocation.createTyped(rs, entry.t, b.mUsage);
+ alloc = Allocation.createTyped(mRS, entry.t, mUsage);
} else if(entry.e != null) {
- alloc = Allocation.createSized(rs, entry.e, entry.size, b.mUsage);
+ alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
}
- rs.nMeshBindVertex(id, alloc.getID(), ct);
- newMesh.mVertexBuffers[ct] = alloc;
+ int allocID = (alloc == null) ? 0 : alloc.getID();
+ indexBuffers[ct] = alloc;
+ primitives[ct] = entry.prim;
+
+ idx[ct] = allocID;
+ prim[ct] = entry.prim.mID;
}
- rs.nMeshInitVertexAttribs(id);
- return newMesh;
- }
+ int id = mRS.nMeshCreate(vtx, idx, prim);
+ Mesh newMesh = new Mesh(id, mRS);
+ newMesh.mVertexBuffers = vertexBuffers;
+ newMesh.mIndexBuffers = indexBuffers;
+ newMesh.mPrimitives = primitives;
- /**
- * Create a Mesh object from the current state of the builder
- *
- **/
- public Mesh create() {
- mRS.validate();
- Mesh sm = internalCreate(mRS, this);
- return sm;
+ return newMesh;
}
}
@@ -463,40 +465,44 @@ public class Mesh extends BaseObj {
return this;
}
- static synchronized Mesh internalCreate(RenderScript rs, AllocationBuilder b) {
+ /**
+ * Create a Mesh object from the current state of the builder
+ *
+ **/
+ public Mesh create() {
+ mRS.validate();
- int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
- Mesh newMesh = new Mesh(id, rs);
- newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
- newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
- newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
+ int[] vtx = new int[mVertexTypeCount];
+ int[] idx = new int[mIndexTypes.size()];
+ int[] prim = new int[mIndexTypes.size()];
- for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
- Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
- int allocID = (entry.a == null) ? 0 : entry.a.getID();
- rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
- newMesh.mIndexBuffers[ct] = entry.a;
- newMesh.mPrimitives[ct] = entry.prim;
+ Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
+ Primitive[] primitives = new Primitive[mIndexTypes.size()];
+ Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
+
+ for(int ct = 0; ct < mVertexTypeCount; ct ++) {
+ Entry entry = mVertexTypes[ct];
+ vertexBuffers[ct] = entry.a;
+ vtx[ct] = entry.a.getID();
}
- for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
- Entry entry = b.mVertexTypes[ct];
- rs.nMeshBindVertex(id, entry.a.getID(), ct);
- newMesh.mVertexBuffers[ct] = entry.a;
+ for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
+ Entry entry = (Entry)mIndexTypes.elementAt(ct);
+ int allocID = (entry.a == null) ? 0 : entry.a.getID();
+ indexBuffers[ct] = entry.a;
+ primitives[ct] = entry.prim;
+
+ idx[ct] = allocID;
+ prim[ct] = entry.prim.mID;
}
- rs.nMeshInitVertexAttribs(id);
- return newMesh;
- }
+ int id = mRS.nMeshCreate(vtx, idx, prim);
+ Mesh newMesh = new Mesh(id, mRS);
+ newMesh.mVertexBuffers = vertexBuffers;
+ newMesh.mIndexBuffers = indexBuffers;
+ newMesh.mPrimitives = primitives;
- /**
- * Create a Mesh object from the current state of the builder
- *
- **/
- public Mesh create() {
- mRS.validate();
- Mesh sm = internalCreate(mRS, this);
- return sm;
+ return newMesh;
}
}
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index feb74b8..41a29e6 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -527,25 +527,10 @@ public class RenderScript {
return rsnProgramVertexCreate(mContext, shader, params);
}
- native int rsnMeshCreate(int con, int vtxCount, int indexCount);
- synchronized int nMeshCreate(int vtxCount, int indexCount) {
+ native int rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim);
+ synchronized int nMeshCreate(int[] vtx, int[] idx, int[] prim) {
validate();
- return rsnMeshCreate(mContext, vtxCount, indexCount);
- }
- native void rsnMeshBindVertex(int con, int id, int alloc, int slot);
- synchronized void nMeshBindVertex(int id, int alloc, int slot) {
- validate();
- rsnMeshBindVertex(mContext, id, alloc, slot);
- }
- native void rsnMeshBindIndex(int con, int id, int alloc, int prim, int slot);
- synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) {
- validate();
- rsnMeshBindIndex(mContext, id, alloc, prim, slot);
- }
- native void rsnMeshInitVertexAttribs(int con, int id);
- synchronized void nMeshInitVertexAttribs(int id) {
- validate();
- rsnMeshInitVertexAttribs(mContext, id);
+ return rsnMeshCreate(mContext, vtx, idx, prim);
}
native int rsnMeshGetVertexBufferCount(int con, int id);
synchronized int nMeshGetVertexBufferCount(int id) {
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 2eaedaa..26a6287 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -1075,35 +1075,28 @@ nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint
// ---------------------------------------------------------------------------
static jint
-nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jint vtxCount, jint idxCount)
+nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
{
- LOG_API("nMeshCreate, con(%p), vtxCount(%i), idxCount(%i)", con, vtxCount, idxCount);
- int id = (int)rsMeshCreate(con, vtxCount, idxCount);
- return id;
-}
+ LOG_API("nMeshCreate, con(%p)", con);
-static void
-nMeshBindVertex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint slot)
-{
- LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot);
- rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot);
-}
+ jint vtxLen = _env->GetArrayLength(_vtx);
+ jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
+ jint idxLen = _env->GetArrayLength(_idx);
+ jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
+ jint primLen = _env->GetArrayLength(_prim);
+ jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
-static void
-nMeshBindIndex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint primID, jint slot)
-{
- LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc);
- rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot);
-}
+ int id = (int)rsMeshCreate(con,
+ (RsAllocation *)vtxPtr, vtxLen,
+ (RsAllocation *)idxPtr, idxLen,
+ (uint32_t *)primPtr, primLen);
-static void
-nMeshInitVertexAttribs(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
-{
- LOG_API("nMeshInitVertexAttribs, con(%p), Mesh(%p)", con, (RsMesh)mesh);
- rsMeshInitVertexAttribs(con, (RsMesh)mesh);
+ _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
+ _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
+ _env->ReleaseIntArrayElements(_prim, primPtr, 0);
+ return id;
}
-
static jint
nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
{
@@ -1267,10 +1260,7 @@ static JNINativeMethod methods[] = {
{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
-{"rsnMeshCreate", "(III)I", (void*)nMeshCreate },
-{"rsnMeshBindVertex", "(IIII)V", (void*)nMeshBindVertex },
-{"rsnMeshBindIndex", "(IIIII)V", (void*)nMeshBindIndex },
-{"rsnMeshInitVertexAttribs", "(II)V", (void*)nMeshInitVertexAttribs },
+{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 00e3a0a..1da00a5 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -403,25 +403,8 @@ FontCreateFromMemory {
}
MeshCreate {
+ param RsAllocation *vtx
+ param RsAllocation *idx
+ param uint32_t *primType
ret RsMesh
- param uint32_t vtxCount
- param uint32_t idxCount
}
-
-MeshBindIndex {
- param RsMesh mesh
- param RsAllocation idx
- param uint32_t primType
- param uint32_t slot
- }
-
-MeshBindVertex {
- param RsMesh mesh
- param RsAllocation vtx
- param uint32_t slot
- }
-
-MeshInitVertexAttribs {
- param RsMesh mesh
- }
-
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index 35184c1..3d0342d 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -263,30 +263,25 @@ void Mesh::computeBBox() {
namespace android {
namespace renderscript {
-RsMesh rsi_MeshCreate(Context *rsc, uint32_t vtxCount, uint32_t idxCount) {
+RsMesh rsi_MeshCreate(Context *rsc,
+ RsAllocation *vtx, uint32_t vtxCount,
+ RsAllocation *idx, uint32_t idxCount,
+ uint32_t *primType, uint32_t primTypeCount) {
+ rsAssert(idxCount == primTypeCount);
Mesh *sm = new Mesh(rsc, vtxCount, idxCount);
sm->incUserRef();
- return sm;
-}
-
-void rsi_MeshBindVertex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t slot) {
- Mesh *sm = static_cast<Mesh *>(mv);
- rsAssert(slot < sm->mHal.state.vertexBuffersCount);
-
- sm->setVertexBuffer((Allocation *)va, slot);
-}
-
-void rsi_MeshBindIndex(Context *rsc, RsMesh mv, RsAllocation va, uint32_t primType, uint32_t slot) {
- Mesh *sm = static_cast<Mesh *>(mv);
- rsAssert(slot < sm->mHal.state.primitivesCount);
+ for (uint32_t i = 0; i < vtxCount; i ++) {
+ sm->setVertexBuffer((Allocation*)vtx[i], i);
+ }
- sm->setPrimitive((Allocation *)va, (RsPrimitive)primType, slot);
-}
+ for (uint32_t i = 0; i < idxCount; i ++) {
+ sm->setPrimitive((Allocation*)idx[i], (RsPrimitive)primType[i], i);
+ }
-void rsi_MeshInitVertexAttribs(Context *rsc, RsMesh mv) {
- Mesh *sm = static_cast<Mesh *>(mv);
sm->init();
+
+ return sm;
}
}}
diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h
index 1e279f4..ed1e93d 100644
--- a/libs/rs/rsMesh.h
+++ b/libs/rs/rsMesh.h
@@ -39,13 +39,6 @@ public:
RsPrimitive mPrimitive;
};
- // compatibility to not break the build
- ObjectBaseRef<Allocation> *mVertexBuffers;
- uint32_t mVertexBufferCount;
- Primitive_t ** mPrimitives;
- uint32_t mPrimitivesCount;
- // end compatibility
-
virtual void serialize(OStream *stream) const;
virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
static Mesh *createFromStream(Context *rsc, IStream *stream);