discord-jadx/app/src/main/java/org/webrtc/GlShader.java

121 lines
4.5 KiB
Java

package org.webrtc;
import android.opengl.GLES20;
import b.d.b.a.a;
import java.nio.Buffer;
import java.nio.FloatBuffer;
/* loaded from: classes3.dex */
public class GlShader {
private static final String TAG = "GlShader";
private int program;
public GlShader(String str, String str2) {
int compileShader = compileShader(35633, str);
int compileShader2 = compileShader(35632, str2);
int glCreateProgram = GLES20.glCreateProgram();
this.program = glCreateProgram;
if (glCreateProgram != 0) {
GLES20.glAttachShader(glCreateProgram, compileShader);
GLES20.glAttachShader(this.program, compileShader2);
GLES20.glLinkProgram(this.program);
int[] iArr = {0};
GLES20.glGetProgramiv(this.program, 35714, iArr, 0);
if (iArr[0] == 1) {
GLES20.glDeleteShader(compileShader);
GLES20.glDeleteShader(compileShader2);
GlUtil.checkNoGLES2Error("Creating GlShader");
return;
}
StringBuilder R = a.R("Could not link program: ");
R.append(GLES20.glGetProgramInfoLog(this.program));
Logging.e(TAG, R.toString());
throw new RuntimeException(GLES20.glGetProgramInfoLog(this.program));
}
StringBuilder R2 = a.R("glCreateProgram() failed. GLES20 error: ");
R2.append(GLES20.glGetError());
throw new RuntimeException(R2.toString());
}
private static int compileShader(int i, String str) {
int glCreateShader = GLES20.glCreateShader(i);
if (glCreateShader != 0) {
GLES20.glShaderSource(glCreateShader, str);
GLES20.glCompileShader(glCreateShader);
int[] iArr = {0};
GLES20.glGetShaderiv(glCreateShader, 35713, iArr, 0);
if (iArr[0] == 1) {
GlUtil.checkNoGLES2Error("compileShader");
return glCreateShader;
}
StringBuilder R = a.R("Compile error ");
R.append(GLES20.glGetShaderInfoLog(glCreateShader));
R.append(" in shader:\n");
R.append(str);
Logging.e(TAG, R.toString());
throw new RuntimeException(GLES20.glGetShaderInfoLog(glCreateShader));
}
StringBuilder R2 = a.R("glCreateShader() failed. GLES20 error: ");
R2.append(GLES20.glGetError());
throw new RuntimeException(R2.toString());
}
public int getAttribLocation(String str) {
int i = this.program;
if (i != -1) {
int glGetAttribLocation = GLES20.glGetAttribLocation(i, str);
if (glGetAttribLocation >= 0) {
return glGetAttribLocation;
}
throw new RuntimeException(a.w("Could not locate '", str, "' in program"));
}
throw new RuntimeException("The program has been released");
}
public int getUniformLocation(String str) {
int i = this.program;
if (i != -1) {
int glGetUniformLocation = GLES20.glGetUniformLocation(i, str);
if (glGetUniformLocation >= 0) {
return glGetUniformLocation;
}
throw new RuntimeException(a.w("Could not locate uniform '", str, "' in program"));
}
throw new RuntimeException("The program has been released");
}
public void release() {
Logging.d(TAG, "Deleting shader.");
int i = this.program;
if (i != -1) {
GLES20.glDeleteProgram(i);
this.program = -1;
}
}
public void setVertexAttribArray(String str, int i, int i2, FloatBuffer floatBuffer) {
if (this.program != -1) {
int attribLocation = getAttribLocation(str);
GLES20.glEnableVertexAttribArray(attribLocation);
GLES20.glVertexAttribPointer(attribLocation, i, 5126, false, i2, (Buffer) floatBuffer);
GlUtil.checkNoGLES2Error("setVertexAttribArray");
return;
}
throw new RuntimeException("The program has been released");
}
public void setVertexAttribArray(String str, int i, FloatBuffer floatBuffer) {
setVertexAttribArray(str, i, 0, floatBuffer);
}
public void useProgram() {
if (this.program != -1) {
synchronized (EglBase.lock) {
GLES20.glUseProgram(this.program);
}
GlUtil.checkNoGLES2Error("glUseProgram");
return;
}
throw new RuntimeException("The program has been released");
}
}