package com.seewo.factoryaging.opengl3d.h;

import android.opengl.GLES20;
import android.opengl.Matrix;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseArray;
import com.cvte.vman.instance.InvokeCmd;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/* JADX INFO: compiled from: DrawerImpl.java */
/* JADX INFO: loaded from: classes.dex */
class g implements com.seewo.factoryaging.opengl3d.j.a {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private static final float[] f342h = {1.0f, 1.0f, 1.0f, 1.0f};

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private static final float[] f343i = {1.0f, 1.0f, 1.0f, 1.0f};
    private final Set<String> a;
    private final int b;
    private final float[] c = new float[16];
    private final float[] d = new float[16];
    private final float[] e = new float[16];
    private double f = -1.0d;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private boolean f344g = true;

    private g(String str, String str2, String str3, Set<String> set) {
        new SparseArray();
        this.a = set;
        Log.i("Object3DImpl2", "Compiling 3D Drawer... " + str);
        this.b = com.seewo.factoryaging.opengl3d.k.b.b(com.seewo.factoryaging.opengl3d.k.b.c(35633, str2), com.seewo.factoryaging.opengl3d.k.b.c(35632, str3), (String[]) set.toArray(new String[set.size()]));
        Log.i("Object3DImpl2", "Compiled 3D Drawer (" + str + ") with id " + this.b);
    }

    private void d(com.seewo.factoryaging.opengl3d.j.c cVar, int i2, int i3) {
        FloatBuffer floatBufferF = cVar.F() != null ? cVar.F() : cVar.G();
        int i4 = 0;
        floatBufferF.position(0);
        List<int[]> listF = cVar.f();
        Buffer bufferG = cVar.g();
        int i5 = InvokeCmd.CMD_AUDIO_GET_FORCE_OUTPUT_DEVICE;
        if (!this.f344g) {
            bufferG = cVar.h();
            i5 = InvokeCmd.CMD_AUDIO_GET_EQ_MODE;
        }
        if (cVar.L()) {
            bufferG = null;
        }
        if (listF != null) {
            if (bufferG != null) {
                for (int i6 = 0; i6 < listF.size(); i6++) {
                    int[] iArr = listF.get(i6);
                    int i7 = iArr[0];
                    int i8 = iArr[1];
                    int i9 = iArr[2];
                    bufferG.position(i8);
                    GLES20.glDrawElements(i7, i9, i5, bufferG);
                    if (this.f344g && com.seewo.factoryaging.opengl3d.k.b.a("glDrawElements")) {
                        this.f344g = false;
                    }
                }
                return;
            }
            for (int i10 = 0; i10 < listF.size(); i10++) {
                int[] iArr2 = listF.get(i10);
                int i11 = iArr2[0];
                int i12 = iArr2[1];
                int i13 = iArr2[2];
                if (i2 != 2 || iArr2[2] <= 3) {
                    GLES20.glDrawArrays(i2, iArr2[1], iArr2[2]);
                } else {
                    for (int i14 = 0; i14 < iArr2[2] - 2; i14++) {
                        GLES20.glDrawArrays(i2, iArr2[1] + i14, 3);
                    }
                }
            }
            return;
        }
        if (bufferG == null) {
            if (i3 > 0) {
                while (i4 < floatBufferF.capacity() / 3) {
                    GLES20.glDrawArrays(i2, i4, i3);
                    i4 += i3;
                }
                return;
            }
            int iCapacity = floatBufferF.capacity() / 3;
            if (this.f >= 0.0d) {
                double dUptimeMillis = ((double) ((SystemClock.uptimeMillis() % 10000) / 10000.0f)) * 6.283185307179586d;
                if (this.f == 0.0d) {
                    this.f = dUptimeMillis;
                }
                iCapacity = (int) (((Math.sin((dUptimeMillis - this.f) + 4.71238898038469d) + 1.0d) / 2.0d) * ((double) iCapacity));
            }
            GLES20.glDrawArrays(i2, 0, iCapacity);
            return;
        }
        if (i3 <= 0) {
            bufferG.position(0);
            GLES20.glDrawElements(i2, bufferG.capacity(), i5, bufferG);
            if (this.f344g && com.seewo.factoryaging.opengl3d.k.b.a("glDrawElements")) {
                this.f344g = false;
                return;
            }
            return;
        }
        int i15 = 0;
        while (i15 < bufferG.capacity()) {
            bufferG.position(i15);
            GLES20.glDrawElements(i2, i3, i5, bufferG);
            i15 += i3;
        }
        if (this.f344g && com.seewo.factoryaging.opengl3d.k.b.a("glDrawElements")) {
            this.f344g = false;
        }
    }

    public static g e(String str, String str2, String str3) {
        HashSet hashSet = new HashSet();
        w(hashSet, str2, "a_Position");
        w(hashSet, str2, "u_MVMatrix");
        w(hashSet, str2, "a_Normal");
        w(hashSet, str2, "a_Color");
        w(hashSet, str2, "a_TexCoordinate");
        w(hashSet, str2, "u_LightPos");
        w(hashSet, str2, "u_MVMatrix");
        w(hashSet, str2, "in_jointIndices");
        w(hashSet, str2, "in_weights");
        return new g(str, str2, str3, hashSet);
    }

    private float[] f(com.seewo.factoryaging.opengl3d.j.c cVar) {
        Matrix.setIdentityM(this.c, 0);
        if (cVar.v() != null) {
            Matrix.rotateM(this.c, 0, cVar.v()[0], 1.0f, 0.0f, 0.0f);
            Matrix.rotateM(this.c, 0, cVar.v()[1], 0.0f, 1.0f, 0.0f);
            Matrix.rotateM(this.c, 0, cVar.w(), 0.0f, 0.0f, 1.0f);
        }
        if (cVar.x() != null) {
            Matrix.scaleM(this.c, 0, cVar.y(), cVar.z(), cVar.A());
        }
        if (cVar.r() != null) {
            Matrix.translateM(this.c, 0, cVar.s(), cVar.t(), cVar.u());
        }
        return this.c;
    }

    private float[] g(float[] fArr, float[] fArr2) {
        Matrix.multiplyMM(this.d, 0, fArr2, 0, fArr, 0);
        return this.d;
    }

    private float[] h(float[] fArr, float[] fArr2) {
        Matrix.multiplyMM(this.e, 0, fArr2, 0, fArr, 0);
        return this.e;
    }

    private void i(com.seewo.factoryaging.opengl3d.j.c cVar) {
        int iGlGetUniformLocation = GLES20.glGetUniformLocation(this.b, "vColor");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetUniformLocation");
        GLES20.glUniform4fv(iGlGetUniformLocation, 1, cVar.d() != null ? cVar.d() : f342h, 0);
        com.seewo.factoryaging.opengl3d.k.b.a("glUniform4fv");
    }

    private void j(float[] fArr) {
        int iGlGetUniformLocation = GLES20.glGetUniformLocation(this.b, "vColorMask");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetUniformLocation");
        if (fArr == null) {
            fArr = f343i;
        }
        GLES20.glUniform4fv(iGlGetUniformLocation, 1, fArr, 0);
        com.seewo.factoryaging.opengl3d.k.b.a("glUniform4fv");
    }

    private int k(com.seewo.factoryaging.opengl3d.j.c cVar) {
        int iGlGetAttribLocation = GLES20.glGetAttribLocation(this.b, "a_Color");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetAttribLocation");
        GLES20.glEnableVertexAttribArray(iGlGetAttribLocation);
        com.seewo.factoryaging.opengl3d.k.b.a("glEnableVertexAttribArray");
        cVar.H().position(0);
        GLES20.glVertexAttribPointer(iGlGetAttribLocation, 4, InvokeCmd.CMD_AUDIO_SET_FORCE_OUTPUT_DEVICE, false, 0, (Buffer) cVar.H());
        com.seewo.factoryaging.opengl3d.k.b.a("glVertexAttribPointer");
        return iGlGetAttribLocation;
    }

    private void l(float[] fArr) {
        GLES20.glUniform3f(GLES20.glGetUniformLocation(this.b, "u_LightPos"), fArr[0], fArr[1], fArr[2]);
    }

    private void m(float[] fArr) {
        int iGlGetUniformLocation = GLES20.glGetUniformLocation(this.b, "u_MVMatrix");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetUniformLocation");
        GLES20.glUniformMatrix4fv(iGlGetUniformLocation, 1, false, fArr, 0);
        com.seewo.factoryaging.opengl3d.k.b.a("glUniformMatrix4fv");
    }

    private void n(float[] fArr) {
        int iGlGetUniformLocation = GLES20.glGetUniformLocation(this.b, "u_MVPMatrix");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetUniformLocation");
        GLES20.glUniformMatrix4fv(iGlGetUniformLocation, 1, false, fArr, 0);
        com.seewo.factoryaging.opengl3d.k.b.a("glUniformMatrix4fv");
    }

    private int o(com.seewo.factoryaging.opengl3d.j.c cVar) {
        int iGlGetAttribLocation = GLES20.glGetAttribLocation(this.b, "a_Normal");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetAttribLocation");
        GLES20.glEnableVertexAttribArray(iGlGetAttribLocation);
        com.seewo.factoryaging.opengl3d.k.b.a("glEnableVertexAttribArray");
        FloatBuffer floatBufferI = cVar.I() != null ? cVar.I() : cVar.q();
        floatBufferI.position(0);
        GLES20.glVertexAttribPointer(iGlGetAttribLocation, 3, InvokeCmd.CMD_AUDIO_SET_FORCE_OUTPUT_DEVICE, false, 0, (Buffer) floatBufferI);
        return iGlGetAttribLocation;
    }

    private int p(com.seewo.factoryaging.opengl3d.j.c cVar) {
        int iGlGetAttribLocation = GLES20.glGetAttribLocation(this.b, "a_Position");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetAttribLocation");
        GLES20.glEnableVertexAttribArray(iGlGetAttribLocation);
        com.seewo.factoryaging.opengl3d.k.b.a("glEnableVertexAttribArray");
        FloatBuffer floatBufferF = cVar.F() != null ? cVar.F() : cVar.G();
        floatBufferF.position(0);
        GLES20.glVertexAttribPointer(iGlGetAttribLocation, 3, InvokeCmd.CMD_AUDIO_SET_FORCE_OUTPUT_DEVICE, false, 12, (Buffer) floatBufferF);
        com.seewo.factoryaging.opengl3d.k.b.a("glVertexAttribPointer");
        return iGlGetAttribLocation;
    }

    private int q(com.seewo.factoryaging.opengl3d.j.c cVar, int i2) {
        int iGlGetUniformLocation = GLES20.glGetUniformLocation(this.b, "u_Texture");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetUniformLocation");
        GLES20.glActiveTexture(33984);
        com.seewo.factoryaging.opengl3d.k.b.a("glActiveTexture");
        GLES20.glBindTexture(3553, i2);
        com.seewo.factoryaging.opengl3d.k.b.a("glBindTexture");
        GLES20.glUniform1i(iGlGetUniformLocation, 0);
        com.seewo.factoryaging.opengl3d.k.b.a("glUniform1i");
        int iGlGetAttribLocation = GLES20.glGetAttribLocation(this.b, "a_TexCoordinate");
        com.seewo.factoryaging.opengl3d.k.b.a("glGetAttribLocation");
        GLES20.glEnableVertexAttribArray(iGlGetAttribLocation);
        com.seewo.factoryaging.opengl3d.k.b.a("glEnableVertexAttribArray");
        cVar.C().position(0);
        GLES20.glVertexAttribPointer(iGlGetAttribLocation, 2, InvokeCmd.CMD_AUDIO_SET_FORCE_OUTPUT_DEVICE, false, 0, (Buffer) cVar.C());
        com.seewo.factoryaging.opengl3d.k.b.a("glVertexAttribPointer");
        return iGlGetAttribLocation;
    }

    private boolean r() {
        return this.a.contains("a_Color");
    }

    private boolean s() {
        return this.a.contains("u_LightPos") && this.a.contains("u_MVMatrix");
    }

    private boolean t() {
        return this.a.contains("u_MVMatrix");
    }

    private boolean u() {
        return this.a.contains("a_Normal");
    }

    private boolean v() {
        return this.a.contains("a_TexCoordinate");
    }

    private static void w(Set<String> set, String str, String str2) {
        if (str.contains(str2)) {
            set.add(str2);
        }
    }

    @Override // com.seewo.factoryaging.opengl3d.j.a
    public void a(com.seewo.factoryaging.opengl3d.j.c cVar, float[] fArr, float[] fArr2, int i2, float[] fArr3, float[] fArr4) {
        b(cVar, fArr, fArr2, cVar.e(), cVar.i(), i2, fArr3, fArr4);
    }

    @Override // com.seewo.factoryaging.opengl3d.j.a
    public void b(com.seewo.factoryaging.opengl3d.j.c cVar, float[] fArr, float[] fArr2, int i2, int i3, int i4, float[] fArr3, float[] fArr4) {
        int iK;
        GLES20.glUseProgram(this.b);
        float[] fArrG = g(f(cVar), fArr2);
        n(h(fArrG, fArr));
        int iP = p(cVar);
        int iO = u() ? o(cVar) : -1;
        if (r()) {
            iK = k(cVar);
        } else {
            i(cVar);
            iK = -1;
        }
        j(fArr4);
        int iQ = (i4 == -1 || !v()) ? -1 : q(cVar, i4);
        if (t()) {
            m(fArrG);
        }
        if (fArr3 != null && s()) {
            l(fArr3);
        }
        d(cVar, i2, i3);
        GLES20.glDisableVertexAttribArray(iP);
        if (iK != -1) {
            GLES20.glDisableVertexAttribArray(iK);
        }
        if (iO != -1) {
            GLES20.glDisableVertexAttribArray(iO);
        }
        if (iQ != -1) {
            GLES20.glDisableVertexAttribArray(iQ);
        }
    }

    @Override // com.seewo.factoryaging.opengl3d.j.a
    public void c(com.seewo.factoryaging.opengl3d.j.c cVar, float[] fArr, float[] fArr2, int i2, float[] fArr3) {
        b(cVar, fArr, fArr2, cVar.e(), cVar.i(), i2, fArr3, null);
    }
}
