I’m rendering video using
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
decodedFrame.width[j],
decodedFrame.height[j],
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
null);
I was using GL_RED
in place of GL_LUMINANCE
because I thougth that, since im using OpenGL #version 320 es
in my shader, I need to use OpenGL 3.x commands like GL_RED. But GL_RED wont work, only GL_LUMINANCE does.
Here’s how I’m creating the context:
eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed");
}
int[] version = new int[2];
if (!egl.eglInitialize(eglDisplay, version)) {
throw new RuntimeException("eglInitialize failed");
}
EGLConfig eglConfig = chooseEglConfig();
eglContext = createContext(egl, eglDisplay, eglConfig);
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceTexture, null);
if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException("GL Error: " + GLUtils.getEGLErrorString(egl.eglGetError()));
}
if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
throw new RuntimeException("GL make current error: " + GLUtils.getEGLErrorString(egl.eglGetError()));
}
private EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
int[] attribList = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL10.EGL_NONE};
return egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attribList);
}
private EGLConfig chooseEglConfig() {
int[] configsCount = new int[1];
EGLConfig[] configs = new EGLConfig[1];
int[] configSpec = getConfig();
if (!egl.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
throw new IllegalArgumentException("Failed to choose config: " + GLUtils.getEGLErrorString(egl.eglGetError()));
} else if (configsCount[0] > 0) {
return configs[0];
}
return null;
}
As you can see Im using EGL_CONTEXT_CLIENT_VERSION
, 3
I also imported everything from GLES30:
import static android.opengl.GLES30.GL_TRIANGLE_STRIP;
import static android.opengl.GLES30.glDrawArrays;
import static android.opengl.GLES30.GL_CLAMP_TO_EDGE;
import static android.opengl.GLES30.GL_LINEAR;
import static android.opengl.GLES30.GL_STREAM_DRAW;
import static android.opengl.GLES30.GL_TEXTURE0;
import static android.opengl.GLES30.GL_TEXTURE_2D;
import static android.opengl.GLES30.GL_TEXTURE_MAG_FILTER;
import static android.opengl.GLES30.GL_TEXTURE_MIN_FILTER;
import static android.opengl.GLES30.GL_TEXTURE_WRAP_S;
import static android.opengl.GLES30.GL_TEXTURE_WRAP_T;
import static android.opengl.GLES30.glActiveTexture;
import static android.opengl.GLES30.glBindBuffer;
import static android.opengl.GLES30.glBindTexture;
import static android.opengl.GLES30.glBufferData;
import static android.opengl.GLES30.glBufferSubData;
import static android.opengl.GLES30.glGenBuffers;
import static android.opengl.GLES30.glGenTextures;
import static android.opengl.GLES30.glGetUniformLocation;
import static android.opengl.GLES30.glTexImage2D;
import static android.opengl.GLES30.glTexParameteri;
import static android.opengl.GLES30.glTexSubImage2D;
import static android.opengl.GLES30.glUniform1f;
import static android.opengl.GLES30.glUniform1i;
import static android.opengl.GLES30.GL_PIXEL_UNPACK_BUFFER;
But I needed to import GL_LUMINANCE
from GLES20 for it to work
So why do I need to use GL_LUMINANCE
?