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

Commit df48b571 authored by Jason Sams's avatar Jason Sams
Browse files

Cleanup seperation of Legacy and user attribs. All user programs now use the...

Cleanup seperation of Legacy and user attribs.  All user programs now use the new names.  Legacy vertex attribs are given default names.
parent 882652bf
Loading
Loading
Loading
Loading
+13 −19
Original line number Diff line number Diff line
@@ -168,27 +168,27 @@ void ProgramVertex::createShader()
        }
        mShader.append(mUserShader);
    } else {
        mShader.append("attribute vec4 ATTRIB_LegacyPosition;\n");
        mShader.append("attribute vec4 ATTRIB_LegacyColor;\n");
        mShader.append("attribute vec3 ATTRIB_LegacyNormal;\n");
        mShader.append("attribute float ATTRIB_LegacyPointSize;\n");
        mShader.append("attribute vec4 ATTRIB_LegacyTexture;\n");

        for (uint32_t ct=0; ct < mUniformCount; ct++) {
            mShader.append("uniform mat4 ");
            mShader.append(mUniformNames[ct]);
            mShader.append(";\n");
        }

        for (uint32_t ct=VertexArray::POSITION; ct < mAttribCount; ct++) {
            mShader.append("attribute vec4 ");
            mShader.append(mAttribNames[ct]);
            mShader.append(";\n");
        }

        mShader.append("void main() {\n");
        mShader.append("  gl_Position = UNI_MVP * ATTRIB_Position;\n");
        mShader.append("  gl_PointSize = ATTRIB_PointSize.x;\n");
        mShader.append("  gl_Position = UNI_MVP * ATTRIB_LegacyPosition;\n");
        mShader.append("  gl_PointSize = ATTRIB_LegacyPointSize;\n");

        mShader.append("  varColor = ATTRIB_Color;\n");
        mShader.append("  varColor = ATTRIB_LegacyColor;\n");
        if (mTextureMatrixEnable) {
            mShader.append("  varTex0 = UNI_TexMatrix * ATTRIB_Texture;\n");
            mShader.append("  varTex0 = UNI_TexMatrix * ATTRIB_LegacyTexture;\n");
        } else {
            mShader.append("  varTex0 = ATTRIB_Texture;\n");
            mShader.append("  varTex0 = ATTRIB_LegacyTexture;\n");
        }
        //mShader.append("  pos.x = pos.x / 480.0;\n");
        //mShader.append("  pos.y = pos.y / 800.0;\n");
@@ -326,10 +326,11 @@ void ProgramVertex::initAddUserElement(const Element *e, String8 *names, uint32_
    }
}


void ProgramVertex::init(Context *rsc)
{
    if (mUserShader.size() > 0) {
    mAttribCount = 0;
    if (mUserShader.size() > 0) {
        for (uint32_t ct=0; ct < mInputCount; ct++) {
            initAddUserElement(mInputElements[ct].get(), mAttribNames, &mAttribCount, "ATTRIB_");
        }
@@ -340,13 +341,6 @@ void ProgramVertex::init(Context *rsc)
            initAddUserElement(mConstantTypes[ct]->getElement(), mUniformNames, &mUniformCount, "UNI_");
        }
    } else {
        mAttribCount = 5;
        mAttribNames[0].setTo("ATTRIB_Position");
        mAttribNames[1].setTo("ATTRIB_Color");
        mAttribNames[2].setTo("ATTRIB_Normal");
        mAttribNames[3].setTo("ATTRIB_PointSize");
        mAttribNames[4].setTo("ATTRIB_Texture");

        mUniformCount = 2;
        mUniformNames[0].setTo("UNI_MVP");
        mUniformNames[1].setTo("UNI_TexMatrix");
+4 −4
Original line number Diff line number Diff line
@@ -687,7 +687,7 @@ static void SC_drawLine(float x1, float y1, float z1,

    float vtx[] = { x1, y1, z1, x2, y2, z2 };
    VertexArray va;
    va.setPosition(2, GL_FLOAT, 12, (uint32_t)&vtx);
    va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
    if (rsc->checkVersion2_0()) {
        va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
    } else {
@@ -705,7 +705,7 @@ static void SC_drawPoint(float x, float y, float z)
    float vtx[] = { x, y, z };

    VertexArray va;
    va.setPosition(1, GL_FLOAT, 12, (uint32_t)&vtx);
    va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
    if (rsc->checkVersion2_0()) {
        va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
    } else {
@@ -737,8 +737,8 @@ static void SC_drawQuadTexCoords(float x1, float y1, float z1,
    const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};

    VertexArray va;
    va.setPosition(3, GL_FLOAT, 12, (uint32_t)&vtx);
    va.setTexture(2, GL_FLOAT, 8, (uint32_t)&tex);
    va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
    va.addLegacy(GL_FLOAT, 2, 8, RS_KIND_TEXTURE, false, (uint32_t)tex);
    if (rsc->checkVersion2_0()) {
        va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
    } else {
+17 −11
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag
    e->vtx = vtx->getShaderID();
    e->frag = frag->getShaderID();
    e->program = glCreateProgram();
    e->mUserVertexProgram = vtx->isUserProgram();
    if (mEntries[mEntryCount].program) {
        GLuint pgm = e->program;
        glAttachShader(pgm, vtx->getShaderID());
@@ -93,13 +94,16 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag
        glAttachShader(pgm, frag->getShaderID());

        if (!vtx->isUserProgram()) {
            glBindAttribLocation(pgm, VertexArray::POSITION, "ATTRIB_Position");
            glBindAttribLocation(pgm, VertexArray::COLOR, "ATTRIB_Color");
            glBindAttribLocation(pgm, VertexArray::NORMAL, "ATTRIB_Normal");
            glBindAttribLocation(pgm, VertexArray::POINT_SIZE, "ATTRIB_PointSize");
            glBindAttribLocation(pgm, VertexArray::TEXTURE, "ATTRIB_T0");
        } else {

            glBindAttribLocation(pgm, 0, "ATTRIB_LegacyPosition");
            glBindAttribLocation(pgm, 1, "ATTRIB_LegacyColor");
            glBindAttribLocation(pgm, 2, "ATTRIB_LegacyNormal");
            glBindAttribLocation(pgm, 3, "ATTRIB_LegacyPointSize");
            glBindAttribLocation(pgm, 4, "ATTRIB_LegacyTexture");
            e->mVtxAttribSlots[RS_KIND_POSITION] = 0;
            e->mVtxAttribSlots[RS_KIND_COLOR] = 1;
            e->mVtxAttribSlots[RS_KIND_NORMAL] = 2;
            e->mVtxAttribSlots[RS_KIND_POINT_SIZE] = 3;
            e->mVtxAttribSlots[RS_KIND_TEXTURE] = 4;
        }

        //LOGE("e2 %x", glGetError());
@@ -120,12 +124,14 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag
            }
            glDeleteProgram(pgm);
        }
        if (vtx->isUserProgram()) {
            for (uint32_t ct=0; ct < vtx->getAttribCount(); ct++) {
                e->mVtxAttribSlots[ct] = glGetAttribLocation(pgm, vtx->getAttribName(ct));
                if (rsc->props.mLogShaders) {
                    LOGV("vtx A %i, %s = %d\n", ct, vtx->getAttribName(ct).string(), e->mVtxAttribSlots[ct]);
                }
            }
        }
        for (uint32_t ct=0; ct < vtx->getUniformCount(); ct++) {
            e->mVtxUniformSlots[ct] = glGetUniformLocation(pgm, vtx->getUniformName(ct));
            if (rsc->props.mLogShaders) {
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public:
    int32_t vtxUniformSlot(uint32_t a) const {return mCurrent->mVtxUniformSlots[a];}
    int32_t fragAttribSlot(uint32_t a) const {return mCurrent->mFragAttribSlots[a];}
    int32_t fragUniformSlot(uint32_t a) const {return mCurrent->mFragUniformSlots[a];}
    bool isUserVertexProgram() const {return mCurrent->mUserVertexProgram;}

protected:
    typedef struct {
@@ -54,6 +55,7 @@ protected:
        int32_t mVtxUniformSlots[Program::MAX_UNIFORMS];
        int32_t mFragAttribSlots[Program::MAX_ATTRIBS];
        int32_t mFragUniformSlots[Program::MAX_UNIFORMS];
        bool mUserVertexProgram;
    } entry_t;
    entry_t *mEntries;
    entry_t *mCurrent;
+29 −17
Original line number Diff line number Diff line
@@ -207,35 +207,47 @@ void Type::enableGLVertexBuffer(VertexArray *va) const

    uint32_t stride = mElement->getSizeBytes();
    if (mGL.mVtx.size) {
        va->setPosition(mGL.mVtx.size,
                        mGL.mVtx.type,
        va->addLegacy(mGL.mVtx.type,
                      mGL.mVtx.size,
                      stride,
                      RS_KIND_POSITION,
                      false,
                      mGL.mVtx.offset);
    }

    if (mGL.mNorm.size) {
        va->setNormal(mGL.mNorm.type,
        va->addLegacy(mGL.mNorm.type,
                     3,
                     stride,
                     RS_KIND_NORMAL,
                     false,
                     mGL.mNorm.offset);
    }

    if (mGL.mColor.size) {
        va->setColor(mGL.mColor.size,
                     mGL.mColor.type,
        va->addLegacy(mGL.mColor.type,
                     mGL.mColor.size,
                     stride,
                     RS_KIND_COLOR,
                     true,
                     mGL.mColor.offset);
    }

    if (mGL.mTex.size) {
        va->setTexture(mGL.mTex.size,
                       mGL.mTex.type,
        va->addLegacy(mGL.mTex.type,
                     mGL.mTex.size,
                     stride,
                     RS_KIND_TEXTURE,
                     false,
                     mGL.mTex.offset);
    }

    if (mGL.mPointSize.size) {
        va->setPointSize(mGL.mPointSize.type,
        va->addLegacy(mGL.mPointSize.type,
                     1,
                     stride,
                     RS_KIND_POINT_SIZE,
                     false,
                     mGL.mPointSize.offset);
    }

@@ -249,7 +261,7 @@ void Type::enableGLVertexBuffer2(VertexArray *va) const
    uint32_t stride = mElement->getSizeBytes();
    for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
        if (mGL.mUser[ct].size) {
            va->setUser(mGL.mUser[ct], stride);
            va->addUser(mGL.mUser[ct], stride);
        }
    }
}
Loading