2016-06-21 3 views
1

私はアンドロイドメディアプレーヤーアプリケーションを持っています。シェーダプログラム1を使用し、シェーダプログラム2を使用するオンスクリーンテクスチャ を持つFBOに付属するオフスクリーンテクスチャを使用しました。オフスクリーンテクスチャの表示を避ける

簡単にするため、shader1の出力は赤色と仮定します。 (R = 1)。私の2番目のシェーダは最初のシェーダからr値を読み込み、緑色を1にします。 したがって、実際にはr + g =黄色になるはずです。

私の問題は、最初の分割秒では、(オフスクリーンテクスチャから)赤い画面が表示され、突然黄色になります。私の実際のシナリオでは、最初の1秒間の赤は問題です。 それを解決することは可能ですか?

機能をOnSurfaceChanged:

// 1st texture: 

int[] textures = new int[1]; 
GLES20.glGenTextures(1, textures, 0); 
mTexture1 = textures[0]; 
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexture1); 

// 2nd texture 

int[] textures2d = new int[1]; 
GLES20.glGenTextures(1, textures2d, 0); 
mTexture2 = textures2d[0]; 
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture2); 

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 
       width, height, 0, GLES20.GL_RGBA, 
       GLES20.GL_UNSIGNED_BYTE, null); 

// FBO 
int handle2[] = { 0 }; 
GLES20.glGenFramebuffers(1, handle2, 0); 
mFrameBufferHandle2 = handle2[0]; 
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBufferHandle2); 

GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, 
       GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, 
       mTexture2, 0); 

surface1 = new SurfaceTexture(mTexture1); 
... pass it to mediaplayer 

機能onDrawFrame

GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); 

// Shader 1 
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBufferHandle2); 
GLES20.glViewport(0, 0, mViewportWidth, mViewportHeight); 
glUseProgram(shader1); 
..... 
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); 
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexture1); 
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 

// Shader 2 
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); 
GLES20.glViewport(0, 0, mViewportWidth, mViewportHeight); 
glUseProgram(shader2); 
... 
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); 
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture2); 
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 

答えて

0

GLES20.glBindFramebuffer(GLES20.GL_後

GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); 

を追加することによってそれを解決できますFRAMEBUFFER、0);

関連する問題