Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4a010d5 authored by Alex Sakhartchouk's avatar Alex Sakhartchouk Committed by Android (Google) Code Review
Browse files

Merge "Cleanup mesh creation."

parents 90eb1053 25999a08
Loading
Loading
Loading
Loading
+66 −60
Original line number Diff line number Diff line
@@ -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;
            }
            rs.nMeshInitVertexAttribs(id);
                int allocID = (alloc == null) ? 0 : alloc.getID();
                indexBuffers[ct] = alloc;
                primitives[ct] = entry.prim;

            return newMesh;
                idx[ct] = allocID;
                prim[ct] = entry.prim.mID;
            }

        /**
        * Create a Mesh object from the current state of the builder
        *
        **/
        public Mesh create() {
            mRS.validate();
            Mesh sm = internalCreate(mRS, this);
            return sm;
            int id = mRS.nMeshCreate(vtx, idx, prim);
            Mesh newMesh = new Mesh(id, mRS);
            newMesh.mVertexBuffers = vertexBuffers;
            newMesh.mIndexBuffers = indexBuffers;
            newMesh.mPrimitives = primitives;

            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 < 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 < mVertexTypeCount; ct ++) {
                Entry entry = mVertexTypes[ct];
                vertexBuffers[ct] = entry.a;
                vtx[ct] = entry.a.getID();
            }
            rs.nMeshInitVertexAttribs(id);

            return newMesh;
            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;
            }

        /**
        * Create a Mesh object from the current state of the builder
        *
        **/
        public Mesh create() {
            mRS.validate();
            Mesh sm = internalCreate(mRS, this);
            return sm;
            int id = mRS.nMeshCreate(vtx, idx, prim);
            Mesh newMesh = new Mesh(id, mRS);
            newMesh.mVertexBuffers = vertexBuffers;
            newMesh.mIndexBuffers = indexBuffers;
            newMesh.mPrimitives = primitives;

            return newMesh;
        }
    }

+3 −18
Original line number Diff line number Diff line
@@ -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) {
+17 −27
Original line number Diff line number Diff line
@@ -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 },
+3 −20
Original line number Diff line number Diff line
@@ -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
	}
+13 −18
Original line number Diff line number Diff line
@@ -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);
    for (uint32_t i = 0; i < vtxCount; i ++) {
        sm->setVertexBuffer((Allocation*)vtx[i], i);
    }

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);

    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;
}

}}
Loading