Browse Source

fix: fbo透明度重复问题

jeofferyli 4 years ago
parent
commit
b429072d8e

+ 1 - 11
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/CacheBuffer.kt

@@ -1,18 +1,8 @@
 package com.tencent.qgame.animplayer
 
-import android.graphics.Bitmap
 import android.opengl.GLES11Ext
 import android.opengl.GLES20
-import android.os.Environment
-import android.util.Log
 import com.tencent.qgame.animplayer.util.*
-import android.util.DisplayMetrics
-
-import android.view.WindowManager
-import java.io.BufferedOutputStream
-import java.io.FileOutputStream
-import java.io.IOException
-import java.nio.ByteBuffer
 
 
 /**
@@ -73,7 +63,7 @@ class CacheBuffer {
         }
         this.textureId = textureId
 
-        shaderProgram = ShaderUtil.createProgram(RenderConstant.VERTEX_SHADER, RenderConstant.FBO_FRAGMENT_SHADER)
+        shaderProgram = ShaderUtil.createProgram(RenderConstant.VERTEX_SHADER_ALPHA, RenderConstant.FRAGMENT_SHADER_ALPHA)
         uTextureLocation = GLES20.glGetUniformLocation(shaderProgram, "texture")
         aPositionLocation = GLES20.glGetAttribLocation(shaderProgram, "vPosition")
         aTextureAlphaLocation = GLES20.glGetAttribLocation(shaderProgram, "vTexCoordinateAlpha")

+ 2 - 0
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/HardDecoder.kt

@@ -83,8 +83,10 @@ class HardDecoder(player: AnimPlayer) : Decoder(player), SurfaceTexture.OnFrameA
             try {
                 glTexture?.apply {
                     updateTexImage()
+
                     render?.renderFrame()
                     player.pluginManager.onRendering()
+
                     render?.swapBuffers()
                 }
             } catch (e: Throwable) {

+ 3 - 5
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/Render.kt

@@ -18,7 +18,6 @@ package com.tencent.qgame.animplayer
 import android.graphics.SurfaceTexture
 import android.opengl.GLES11Ext
 import android.opengl.GLES20
-import android.util.Log
 import com.tencent.qgame.animplayer.util.*
 
 class Render(surfaceTexture: SurfaceTexture): IRenderListener {
@@ -79,7 +78,6 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
         if (useFbo) {
             catchBuf.setTexArr(rgb, alpha)
             rgbArray.setArray(mTextureCoors)
-            alphaArray.setArray(mTextureCoors)
         } else {
             rgbArray.setArray(rgb)
             alphaArray.setArray(alpha)
@@ -87,7 +85,7 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
     }
 
     override fun initRender() {
-        shaderProgram = ShaderUtil.createProgram(RenderConstant.VERTEX_SHADER, if (useFbo) RenderConstant.FRAGMENT_SHADER else RenderConstant.FRAGMENT_SHADER_OES)
+        shaderProgram = ShaderUtil.createProgram(RenderConstant.VERTEX_SHADER_ALPHA, if (useFbo) RenderConstant.FRAGMENT_SHADER else RenderConstant.FRAGMENT_SHADER_ALPHA)
         uTextureLocation = GLES20.glGetUniformLocation(shaderProgram, "texture")
         aPositionLocation = GLES20.glGetAttribLocation(shaderProgram, "vPosition")
         aTextureAlphaLocation = GLES20.glGetAttribLocation(shaderProgram, "vTexCoordinateAlpha")
@@ -119,7 +117,7 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
         }
 
         // todo 测试用,记得删
-        updateSave2BitmapIndex()
+//        updateSave2BitmapIndex()
 
         if (useFbo) {
             catchBuf.draw()
@@ -139,7 +137,7 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
         eglUtil.release()
 
         // todo 测试用,记得删
-        resetSave2Bitmap()
+//        resetSave2Bitmap()
     }
 
     override fun releaseTexture() {

+ 3 - 16
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/RenderConstant.kt

@@ -18,7 +18,7 @@ package com.tencent.qgame.animplayer
 
 object RenderConstant {
 
-    const val VERTEX_SHADER = "attribute vec4 vPosition;\n" +
+    const val VERTEX_SHADER_ALPHA = "attribute vec4 vPosition;\n" +
             "attribute vec4 vTexCoordinateAlpha;\n" +
             "attribute vec4 vTexCoordinateRgb;\n" +
             "varying vec2 v_TexCoordinateAlpha;\n" +
@@ -30,7 +30,7 @@ object RenderConstant {
             "    gl_Position = vPosition;\n" +
             "}"
 
-    const val FRAGMENT_SHADER_OES = "#extension GL_OES_EGL_image_external : require\n" +
+    const val FRAGMENT_SHADER_ALPHA = "#extension GL_OES_EGL_image_external : require\n" +
             "precision mediump float;\n" +
             "uniform samplerExternalOES texture;\n" +
             "varying vec2 v_TexCoordinateAlpha;\n" +
@@ -45,24 +45,11 @@ object RenderConstant {
     const val FRAGMENT_SHADER = "#extension GL_OES_EGL_image_external : require\n" +
             "precision mediump float;\n" +
             "uniform sampler2D texture;\n" +
-            "varying vec2 v_TexCoordinateAlpha;\n" +
             "varying vec2 v_TexCoordinateRgb;\n" +
             "\n" +
             "void main () {\n" +
-            "    vec4 alphaColor = texture2D(texture, v_TexCoordinateAlpha);\n" +
             "    vec4 rgbColor = texture2D(texture, v_TexCoordinateRgb);\n" +
-            "    gl_FragColor = vec4(rgbColor.r, rgbColor.g, rgbColor.b, alphaColor);\n" +
+            "    gl_FragColor = vec4(rgbColor.r, rgbColor.g, rgbColor.b, rgbColor.a);\n" +
             "}"
 
-    const val FBO_FRAGMENT_SHADER = "#extension GL_OES_EGL_image_external : require\n" +
-            "precision mediump float;\n" +
-            "uniform samplerExternalOES texture;\n" +
-            "varying vec2 v_TexCoordinateAlpha;\n" +
-            "varying vec2 v_TexCoordinateRgb;\n" +
-            "\n" +
-            "void main () {\n" +
-            "    vec4 alphaColor = texture2D(texture, v_TexCoordinateAlpha);\n" +
-            "    vec4 rgbColor = texture2D(texture, v_TexCoordinateRgb);\n" +
-            "    gl_FragColor = vec4(rgbColor.r, rgbColor.g, rgbColor.b, alphaColor);\n" +
-            "}"
 }