50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package org.webrtc;
|
|
|
|
import android.opengl.GLES20;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.nio.FloatBuffer;
|
|
public class GlUtil {
|
|
|
|
public static class GlOutOfMemoryException extends RuntimeException {
|
|
public GlOutOfMemoryException(String str) {
|
|
super(str);
|
|
}
|
|
}
|
|
|
|
private GlUtil() {
|
|
}
|
|
|
|
public static void checkNoGLES2Error(String str) {
|
|
int glGetError = GLES20.glGetError();
|
|
if (glGetError == 0) {
|
|
return;
|
|
}
|
|
if (glGetError == 1285) {
|
|
throw new GlOutOfMemoryException(str);
|
|
}
|
|
throw new RuntimeException(str + ": GLES20 error: " + glGetError);
|
|
}
|
|
|
|
public static FloatBuffer createFloatBuffer(float[] fArr) {
|
|
ByteBuffer allocateDirect = ByteBuffer.allocateDirect(fArr.length * 4);
|
|
allocateDirect.order(ByteOrder.nativeOrder());
|
|
FloatBuffer asFloatBuffer = allocateDirect.asFloatBuffer();
|
|
asFloatBuffer.put(fArr);
|
|
asFloatBuffer.position(0);
|
|
return asFloatBuffer;
|
|
}
|
|
|
|
public static int generateTexture(int i) {
|
|
int[] iArr = new int[1];
|
|
GLES20.glGenTextures(1, iArr, 0);
|
|
int i2 = iArr[0];
|
|
GLES20.glBindTexture(i, i2);
|
|
GLES20.glTexParameterf(i, 10241, 9729.0f);
|
|
GLES20.glTexParameterf(i, 10240, 9729.0f);
|
|
GLES20.glTexParameterf(i, 10242, 33071.0f);
|
|
GLES20.glTexParameterf(i, 10243, 33071.0f);
|
|
checkNoGLES2Error("generateTexture");
|
|
return i2;
|
|
}
|
|
}
|