我有一个RecyclerView
填充了整数,指向我用于连接到GLSurfaceView
的{{1}}的片段着色器。在我的MediaPlayer
中,我输入了以下代码:
GLSurfaceView.Renderer
当我单击所述public void onFragmentShaderChanged(int filterPosition)
{
mFragmentShader = VideoUtils.getFragmentShader(mContext, filterPosition);
GLES20.glDeleteProgram(mProgram);
mProgram = createProgram(mVertexShader, VideoUtils.getFragmentShader(mContext, filterPosition));
if (mProgram == 0) {
return;
}
maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
checkGlError("glGetAttribLocation aPosition");
if (maPositionHandle == -1) {
throw new RuntimeException("Could not get attrib location for aPosition");
}
maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
checkGlError("glGetAttribLocation aTextureCoord");
if (maTextureHandle == -1) {
throw new RuntimeException("Could not get attrib location for aTextureCoord");
}
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
checkGlError("glGetUniformLocation uMVPMatrix");
if (muMVPMatrixHandle == -1) {
throw new RuntimeException("Could not get attrib location for uMVPMatrix");
}
muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
checkGlError("glGetUniformLocation uSTMatrix");
if (muSTMatrixHandle == -1) {
throw new RuntimeException("Could not get attrib location for uSTMatrix");
}
}
的元素时,触发此代码,从包含我需要的片段着色器的原始文件中读取,具体取决于位置,然后使用它删除现有程序并创建新程序。我在RecyclerView
仍然在运行时这样做。
然而,当我调用它时,GLSurfaceView在logcat给我后立即变为绿色:
E / libEGL:调用没有当前上下文的OpenGL ES API(每个线程记录一次)
设置MediaPlayer
让我setEGLContextClientVersion(2)
或类似的东西。
我的问题:
setRenderer() has already been called in this thread
的程序吗?GLSurfaceView.Renderer
?答案 0 :(得分:0)
原来我的问题中的onFragmentShaderChanged()
函数是在EGL线程之外调用的。
感谢fadden在另一个问题中的答案,我必须在onDrawFrame()函数中更改程序,我观察了过滤器位置整数变量的变化,并在变量真正改变时用新的片段着色器创建程序点击。