2016-11-07 17 views
0

MediaPlayerに接続したGLSurfaceViewにどのフラグメントシェーダを使用するかを示す整数がRecyclerViewに設定されています。私の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が、私はそれがために使用して、位置に応じて、必要なフラグメントシェーダが含まれているRAWファイルからの読み込み、前記要素をクリックすると、このコードは、トリガー既存のプログラムを削除して新しいプログラムを作成します。私はMediaPlayerがまだ動いている間にこれをやっています。私はこれを呼び出すとlogcatが私を与えた後

は、しかし、GLSurfaceViewはグリーン右のターン:

E/libEGL:なし現在のコンテキストでのOpenGL ES APIに呼び出します(スレッド毎に一度ログイン)

設定setEGLContextClientVersion(2)ネットはsetRenderer() has already been called in this threadなどです。

私の質問は:

  1. 私はその場でGLSurfaceView.Rendererのプログラムを変更することはできますか?
  2. できない場合は、レンダラー自身やレンダラーのフラグメントシェーダーを変更するのはどうですか?
  3. 上記が実現できない場合は、別のフラグメントシェーダーを使用して同様のレンダラーでGLSurfaceViewを再作成する必要がありますか?

答えて

0

私の質問のonFragmentShaderChanged()機能がEGLスレッド外で呼び出されました。

私はonDrawFrame()関数でプログラムを変更する必要があるという別の質問のおかげで、フィルタ位置整数変数の変更を監視し、変数が実際に変更されたときに新しいフラグメントシェーダでプログラムを作成しましたクリックで

関連する問題