我有一個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
,然後使用不同的片元着色器?