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

Commit 80a4c2cd authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Work on synchronizing a3d created files and java layer.

Adding culling to ProgramRaster

Change-Id: I58ccc82d37edc9539289d5eba44ea0e720874af5
parent cefd8d95
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@ public class Allocation extends BaseObj {
        mType = t;
    }

    Allocation(int id, RenderScript rs) {
        super(rs);
        mID = id;
    }

    public Type getType() {
        return mType;
    }
+5 −0
Original line number Diff line number Diff line
@@ -81,5 +81,10 @@ class BaseObj {
        mRS.nObjDestroy(mID);
    }

    // If an object came from an a3d file, java fields need to be
    // created with objects from the native layer
    void updateFromNative() {
    }

}
+32 −0
Original line number Diff line number Diff line
@@ -59,6 +59,38 @@ public class Mesh extends BaseObj {
        return mPrimitives[slot];
    }

    @Override
    void updateFromNative() {
        int vtxCount = mRS.nMeshGetVertexBufferCount(mID);
        int idxCount = mRS.nMeshGetIndexCount(mID);

        int[] vtxIDs = new int[vtxCount];
        int[] idxIDs = new int[idxCount];
        int[] primitives = new int[idxCount];

        mRS.nMeshGetVertices(mID, vtxIDs, vtxCount);
        mRS.nMeshGetIndices(mID, idxIDs, primitives, vtxCount);

        mVertexBuffers = new Allocation[vtxCount];
        mIndexBuffers = new Allocation[idxCount];
        mPrimitives = new Primitive[idxCount];

        for(int i = 0; i < vtxCount; i ++) {
            if(vtxIDs[i] != 0) {
                mVertexBuffers[i] = new Allocation(vtxIDs[i], mRS);
                mVertexBuffers[i].updateFromNative();
            }
        }

        for(int i = 0; i < idxCount; i ++) {
            if(idxIDs[i] != 0) {
                mIndexBuffers[i] = new Allocation(idxIDs[i], mRS);
                mIndexBuffers[i].updateFromNative();
            }
            mPrimitives[i] = Primitive.values()[primitives[i]];
        }
    }

    public static class Builder {
        RenderScript mRS;

+39 −22
Original line number Diff line number Diff line
@@ -26,12 +26,23 @@ import android.util.Log;
 *
 **/
public class ProgramRaster extends BaseObj {

    public enum CullMode {
        BACK (0),
        FRONT (1),
        NONE (2);

        int mID;
        CullMode(int id) {
            mID = id;
        }
    }

    boolean mPointSmooth;
    boolean mLineSmooth;
    boolean mPointSprite;
    float mLineWidth;
    Element mIn;
    Element mOut;
    CullMode mCullMode;

    ProgramRaster(int id, RenderScript rs) {
        super(rs);
@@ -41,6 +52,8 @@ public class ProgramRaster extends BaseObj {
        mPointSmooth = false;
        mLineSmooth = false;
        mPointSprite = false;

        mCullMode = CullMode.BACK;
    }

    public void setLineWidth(float w) {
@@ -49,45 +62,48 @@ public class ProgramRaster extends BaseObj {
        mRS.nProgramRasterSetLineWidth(mID, w);
    }

    void internalInit() {
        int inID = 0;
        int outID = 0;
        if (mIn != null) {
            inID = mIn.mID;
        }
        if (mOut != null) {
            outID = mOut.mID;
        }
        mID = mRS.nProgramRasterCreate(inID, outID, mPointSmooth, mLineSmooth, mPointSprite);
    public void setCullMode(CullMode m) {
        mRS.validate();
        mCullMode = m;
        mRS.nProgramRasterSetCullMode(mID, m.mID);
    }


    public static class Builder {
        RenderScript mRS;
        ProgramRaster mPR;
        boolean mPointSprite;
        boolean mPointSmooth;
        boolean mLineSmooth;

        // Legacy to not break app in other projects, will be removed in cleanup pass
        public Builder(RenderScript rs, Element in, Element out) {
            mRS = rs;
            mPR = new ProgramRaster(0, rs);
            mPointSmooth = false;
            mLineSmooth = false;
            mPointSprite = false;
        }

        public Builder(RenderScript rs) {
            mRS = rs;
            mPointSmooth = false;
            mLineSmooth = false;
            mPointSprite = false;
        }

        public void setPointSpriteEnable(boolean enable) {
            mPR.mPointSprite = enable;
            mPointSprite = enable;
        }

        public void setPointSmoothEnable(boolean enable) {
            mPR.mPointSmooth = enable;
            mPointSmooth = enable;
        }

        public void setLineSmoothEnable(boolean enable) {
            mPR.mLineSmooth = enable;
            mLineSmooth = enable;
        }


        static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
            b.mPR.internalInit();
            ProgramRaster pr = b.mPR;
            b.mPR = new ProgramRaster(0, b.mRS);
            int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite);
            ProgramRaster pr = new ProgramRaster(id, rs);
            return pr;
        }

@@ -103,3 +119,4 @@ public class ProgramRaster extends BaseObj {



+7 −1
Original line number Diff line number Diff line
@@ -165,8 +165,9 @@ public class RenderScript {
    native void nProgramStoreDither(boolean enable);
    native int  nProgramStoreCreate();

    native int  nProgramRasterCreate(int in, int out, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
    native int  nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
    native void nProgramRasterSetLineWidth(int pr, float v);
    native void nProgramRasterSetCullMode(int pr, int mode);

    native void nProgramBindConstants(int pv, int slot, int mID);
    native void nProgramBindTexture(int vpf, int slot, int a);
@@ -188,6 +189,10 @@ public class RenderScript {
    native int  nMeshCreate(int vtxCount, int indexCount);
    native void nMeshBindVertex(int id, int alloc, int slot);
    native void nMeshBindIndex(int id, int alloc, int prim, int slot);
    native int  nMeshGetVertexBufferCount(int id);
    native int  nMeshGetIndexCount(int id);
    native void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount);
    native void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount);

    native void nAnimationBegin(int attribCount, int keyframeCount);
    native void nAnimationAdd(float time, float[] attribs);
@@ -357,3 +362,4 @@ public class RenderScript {
}


Loading