我有一个RecyclerView
填充整数,指向我使用哪个片段着色器为GLSurfaceView
我连接到MediaPlayer
。在我GLSurfaceView.Renderer
,我把下面的代码: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
的元素,从包含我需要根据位置的片段着色器的原始文件读取,然后用它来删除现有程序并创建一个新程序。在MediaPlayer
仍在运行时,我正在执行此操作。
当我打电话这一点,但是,GLSurfaceView变绿权logcat的给了我后:
E/libEGL:打电话的OpenGL ES API没有当前上下文(每个线程记录一次)
设置setEGLContextClientVersion(2)
网我setRenderer() has already been called in this thread
或类似的东西。
我的问题:
- 我可以改变对飞
GLSurfaceView.Renderer
的计划? - 如果我不能,那么更改渲染器本身,甚至更改渲染器的片段着色器如何?
- 如果上述方法不可行,我是否应该使用类似的渲染器重新创建
GLSurfaceView
,然后使用不同的片元着色器?