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

Commit 4244afa8 authored by Jason Sams's avatar Jason Sams
Browse files

Add support for multitexture and fix allocation ref counting bug in RS. Add...

Add support for multitexture and fix allocation ref counting bug in RS.  Add plaque to rollo and leave it disabled due to ugly appearance.
parent aabd0096
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -25,13 +25,13 @@ int main(void* con, int ft, int launchID)
    int pressure;


    iconCount = 38;//loadI32(0, 1);
    rotStep = 20 * 0x10000;
    pressure = loadI32(0, 2);

    rowCount = 4;
    rot = (-20 + loadI32(0, 0)) * 0x10000;

    iconCount = loadI32(0, 1);
    rot = (-20 + loadI32(0, 0)) * 0x10000;
    while (iconCount) {
        tmpSin = sinx(rot);
        tmpCos = cosx(rot);
@@ -45,9 +45,7 @@ int main(void* con, int ft, int launchID)
        for (y = 0; (y < rowCount) && iconCount; y++) {
            ty1 = (y * 0x30000) - 0x48000;
            ty2 = ty1 + 0x20000;

            pfBindTexture(NAMED_PF, 0, loadI32(1, y));

            drawQuad(tx1, ty1, tz1,
                     tx2, ty1, tz2,
                     tx2, ty2, tz2,
@@ -57,8 +55,6 @@ int main(void* con, int ft, int launchID)
        rot = rot + rotStep;
    }

    //renderTriangleMesh(con, NAMED_MeshCard);
    //renderTriangleMesh(con, NAMED_MeshTab);
    return 1;
    return 0;
}
+35 −1
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class RolloRS {
    private RenderScript.ProgramVertex mPV;
    private ProgramVertexAlloc mPVAlloc;
    private RenderScript.Allocation[] mIcons;
    private RenderScript.Allocation mIconPlate;

    private int[] mAllocStateBuf;
    private RenderScript.Allocation mAllocState;
@@ -79,7 +80,9 @@ public class RolloRS {
    private void initNamed() {
        mRS.samplerBegin();
        mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN,
                       RenderScript.SamplerValue.LINEAR_MIP_LINEAR);
                       RenderScript.SamplerValue.LINEAR);//_MIP_LINEAR);
        mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG,
                       RenderScript.SamplerValue.LINEAR);
        mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_S,
                       RenderScript.SamplerValue.CLAMP);
        mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_T,
@@ -89,10 +92,13 @@ public class RolloRS {

        mRS.programFragmentBegin(null, null);
        mRS.programFragmentSetTexEnable(0, true);
        //mRS.programFragmentSetTexEnable(1, true);
        //mRS.programFragmentSetEnvMode(0, RS_TEX_ENV_MODE_REPLACE);
        //mRS.programFragmentSetEnvMode(1, RS_TEX_ENV_MODE_MODULATE);
        mPFImages = mRS.programFragmentCreate();
        mPFImages.setName("PF");
        mPFImages.bindSampler(mSampler, 0);
        mPFImages.bindSampler(mSampler, 1);

        mRS.programFragmentStoreBegin(null, null);
        mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
@@ -148,6 +154,34 @@ public class RolloRS {
                mAllocIconIDBuf[ct] = mIcons[ct].getID();
            }
            mAllocIconID.data(mAllocIconIDBuf);

            RenderScript.Element e = mRS.elementGetPredefined(RenderScript.ElementPredefined.RGB_565);
            mRS.typeBegin(e);
            mRS.typeAdd(RenderScript.Dimension.X, 64);
            mRS.typeAdd(RenderScript.Dimension.Y, 64);
            RenderScript.Type t = mRS.typeCreate();
            mIconPlate = mRS.allocationCreateTyped(t);
            //t.destroy();
            //e.destroy();

            int tmp[] = new int[64 * 32];
            for(int ct = 0; ct < (64*32); ct++) {
                tmp[ct] = 7 | (13 << 5) | (7 << 11);
                tmp[ct] = tmp[ct] | (tmp[ct] << 16);
            }
            for(int ct = 0; ct < 32; ct++) {
                tmp[ct] = 0;
                tmp[ct + (63*32)] = 0;
            }
            for(int ct = 0; ct < 64; ct++) {
                tmp[ct * 32] = 0;
                tmp[ct * 32 + 31] = 0;
            }
            mIconPlate.data(tmp);
            Log.e("xx", "plate");
            mIconPlate.uploadToTexture(0);
            mIconPlate.setName("Plate");
            mPFImages.bindTexture(mIconPlate, 0);
        }

    }
+1 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype)
    const Type * type = static_cast<const Type *>(vtype);

    Allocation * alloc = new Allocation(type);
    alloc->incRef();
    return alloc;
}

+26 −8
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ ProgramFragment::ProgramFragment(Element *in, Element *out) :
        mTextureDimensions[ct] = 2;
    }
    mTextureEnableMask = 0;
    mEnvModes[1] = RS_TEX_ENV_MODE_DECAL;
}

ProgramFragment::~ProgramFragment()
@@ -42,10 +43,7 @@ void ProgramFragment::setupGL()
{
    for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) {
        glActiveTexture(GL_TEXTURE0 + ct);
        if (!(mTextureEnableMask & (1 << ct)) ||
            //!mSamplers[ct].get() ||
            !mTextures[ct].get()) {

        if (!(mTextureEnableMask & (1 << ct)) || !mTextures[ct].get()) {
            glDisable(GL_TEXTURE_2D);
            continue;
        }
@@ -55,13 +53,13 @@ void ProgramFragment::setupGL()

        switch(mEnvModes[ct]) {
        case RS_TEX_ENV_MODE_REPLACE:
            glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            break;
        case RS_TEX_ENV_MODE_MODULATE:
            glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            break;
        case RS_TEX_ENV_MODE_DECAL:
            glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
            break;
        }

@@ -70,10 +68,29 @@ void ProgramFragment::setupGL()
        } else {
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        }

        // Gross hack.
        if (ct == 2) {
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

            glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
            glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
            glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

            glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
            glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
            glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
        }
    }


    glActiveTexture(GL_TEXTURE0);
}

@@ -85,6 +102,7 @@ void ProgramFragment::bindTexture(uint32_t slot, Allocation *a)
        return;
    }

    //LOGE("bindtex %i %p", slot, a);
    mTextures[slot].set(a);
}

+9 −2
Original line number Diff line number Diff line
@@ -334,12 +334,19 @@ extern "C" void drawQuad(int32_t x1, int32_t y1, int32_t z1,
    //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FIXED, 0, vtx);

    glClientActiveTexture(GL_TEXTURE0);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FIXED, 0, tex);
    glClientActiveTexture(GL_TEXTURE1);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FIXED, 0, tex);
    glClientActiveTexture(GL_TEXTURE0);

    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    glVertexPointer(3, GL_FIXED, 0, vtx);
    glTexCoordPointer(2, GL_FIXED, 0, tex);
    //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);