119 lines
4.5 KiB
Java
119 lines
4.5 KiB
Java
package org.webrtc;
|
|
|
|
import android.opengl.GLES20;
|
|
import c.d.b.a.a;
|
|
import java.nio.Buffer;
|
|
import java.nio.FloatBuffer;
|
|
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 K = a.K("Could not link program: ");
|
|
K.append(GLES20.glGetProgramInfoLog(this.program));
|
|
Logging.e("GlShader", K.toString());
|
|
throw new RuntimeException(GLES20.glGetProgramInfoLog(this.program));
|
|
}
|
|
StringBuilder K2 = a.K("glCreateProgram() failed. GLES20 error: ");
|
|
K2.append(GLES20.glGetError());
|
|
throw new RuntimeException(K2.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 K = a.K("Compile error ");
|
|
K.append(GLES20.glGetShaderInfoLog(glCreateShader));
|
|
K.append(" in shader:\n");
|
|
K.append(str);
|
|
Logging.e("GlShader", K.toString());
|
|
throw new RuntimeException(GLES20.glGetShaderInfoLog(glCreateShader));
|
|
}
|
|
StringBuilder K2 = a.K("glCreateShader() failed. GLES20 error: ");
|
|
K2.append(GLES20.glGetError());
|
|
throw new RuntimeException(K2.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.t("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.t("Could not locate uniform '", str, "' in program"));
|
|
}
|
|
throw new RuntimeException("The program has been released");
|
|
}
|
|
|
|
public void release() {
|
|
Logging.d("GlShader", "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");
|
|
}
|
|
}
|