|
|
@@ -18,13 +18,8 @@ package com.tencent.qgame.animplayer
|
|
|
import android.graphics.SurfaceTexture
|
|
|
import android.opengl.GLES11Ext
|
|
|
import android.opengl.GLES20
|
|
|
-import com.tencent.qgame.animplayer.util.GlFloatArray
|
|
|
-import com.tencent.qgame.animplayer.util.ShaderUtil
|
|
|
-import com.tencent.qgame.animplayer.util.TexCoordsUtil
|
|
|
-import com.tencent.qgame.animplayer.util.VertexUtil
|
|
|
-import java.nio.ByteBuffer
|
|
|
-import java.nio.ByteOrder
|
|
|
-import java.nio.ShortBuffer
|
|
|
+import android.util.Log
|
|
|
+import com.tencent.qgame.animplayer.util.*
|
|
|
|
|
|
class Render(surfaceTexture: SurfaceTexture): IRenderListener {
|
|
|
|
|
|
@@ -46,24 +41,53 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
|
|
|
private var aTextureAlphaLocation: Int = 0
|
|
|
private var aTextureRgbLocation: Int = 0
|
|
|
|
|
|
+ private var catchTextureId = -1
|
|
|
+
|
|
|
+ private var useFbo = true
|
|
|
+
|
|
|
+ private val catchBuf by lazy { CacheBuffer() }
|
|
|
+
|
|
|
+ private val mTextureCoors by lazy { floatArrayOf(
|
|
|
+ 0.0f, 0.0f,
|
|
|
+ 0.0f, 1.0f,
|
|
|
+ 1.0f, 0.0f,
|
|
|
+ 1.0f, 1.0f
|
|
|
+ ) }
|
|
|
+
|
|
|
init {
|
|
|
eglUtil.start(surfaceTexture)
|
|
|
initRender()
|
|
|
}
|
|
|
|
|
|
private fun setVertexBuf(config: AnimConfig) {
|
|
|
- vertexArray.setArray(VertexUtil.create(config.width, config.height, PointRect(0, 0, config.width, config.height), vertexArray.array))
|
|
|
+ val fArr = VertexUtil.create(config.width, config.height, PointRect(0, 0, config.width, config.height), vertexArray.array)
|
|
|
+ ALog.d(CacheBuffer.TAG, "setVertexArr: ${fArr.toList()}")
|
|
|
+
|
|
|
+ if (useFbo) {
|
|
|
+ catchBuf.setVertexArr(fArr)
|
|
|
+ }
|
|
|
+ vertexArray.setArray(fArr)
|
|
|
}
|
|
|
|
|
|
private fun setTexCoords(config: AnimConfig) {
|
|
|
- val alpha = TexCoordsUtil.create(config.videoWidth, config.videoHeight, config.alphaPointRect, alphaArray.array)
|
|
|
val rgb = TexCoordsUtil.create(config.videoWidth, config.videoHeight, config.rgbPointRect, rgbArray.array)
|
|
|
- alphaArray.setArray(alpha)
|
|
|
- rgbArray.setArray(rgb)
|
|
|
+ val alpha = TexCoordsUtil.create(config.videoWidth, config.videoHeight, config.alphaPointRect, alphaArray.array)
|
|
|
+ ALog.d(CacheBuffer.TAG, "setTexArr: texRgbArray: ${rgb.toList()}")
|
|
|
+ ALog.d(CacheBuffer.TAG, "setTexArr: texAlphaArray: ${alpha.toList()}")
|
|
|
+
|
|
|
+ if (useFbo) {
|
|
|
+ catchBuf.setTexArr(rgb, alpha)
|
|
|
+ catchBuf.genCatch(config.width, config.height)
|
|
|
+ rgbArray.setArray(mTextureCoors)
|
|
|
+ alphaArray.setArray(mTextureCoors)
|
|
|
+ } else {
|
|
|
+ rgbArray.setArray(rgb)
|
|
|
+ alphaArray.setArray(alpha)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun initRender() {
|
|
|
- shaderProgram = ShaderUtil.createProgram(RenderConstant.VERTEX_SHADER, RenderConstant.FRAGMENT_SHADER)
|
|
|
+ shaderProgram = ShaderUtil.createProgram(RenderConstant.VERTEX_SHADER, if (useFbo) RenderConstant.FRAGMENT_SHADER else RenderConstant.FRAGMENT_SHADER_OES)
|
|
|
uTextureLocation = GLES20.glGetUniformLocation(shaderProgram, "texture")
|
|
|
aPositionLocation = GLES20.glGetAttribLocation(shaderProgram, "vPosition")
|
|
|
aTextureAlphaLocation = GLES20.glGetAttribLocation(shaderProgram, "vTexCoordinateAlpha")
|
|
|
@@ -75,15 +99,29 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
|
|
|
GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR.toFloat())
|
|
|
GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE)
|
|
|
GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE)
|
|
|
+ GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_NONE)
|
|
|
+
|
|
|
+ if (useFbo) {
|
|
|
+ catchTextureId = catchBuf.init(genTexture[0])
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun renderFrame() {
|
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f)
|
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
|
|
|
if (surfaceSizeChanged && surfaceWidth>0 && surfaceHeight>0) {
|
|
|
+ ALog.d("renderFrame","surfaceWidth : $surfaceWidth, surfaceHeight : $surfaceHeight")
|
|
|
surfaceSizeChanged = false
|
|
|
GLES20.glViewport(0,0, surfaceWidth, surfaceHeight)
|
|
|
+ if (useFbo) {
|
|
|
+ catchBuf.genCatch(surfaceWidth, surfaceHeight)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ if (useFbo) {
|
|
|
+ catchBuf.draw()
|
|
|
+ }
|
|
|
+
|
|
|
draw()
|
|
|
}
|
|
|
|
|
|
@@ -114,7 +152,7 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
|
|
|
* 显示区域大小变化
|
|
|
*/
|
|
|
override fun updateViewPort(width: Int, height: Int) {
|
|
|
- if (width <=0 || height <=0) return
|
|
|
+ if (width <= 0 || height <= 0) return
|
|
|
surfaceSizeChanged = true
|
|
|
surfaceWidth = width
|
|
|
surfaceHeight = height
|
|
|
@@ -133,13 +171,17 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
|
|
|
|
|
|
private fun draw() {
|
|
|
GLES20.glUseProgram(shaderProgram)
|
|
|
- // 设置顶点坐标
|
|
|
- vertexArray.setVertexAttribPointer(aPositionLocation)
|
|
|
// 绑定纹理
|
|
|
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
|
|
|
- GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, genTexture[0])
|
|
|
+ if (useFbo) {
|
|
|
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, catchTextureId)
|
|
|
+ } else {
|
|
|
+ GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, genTexture[0])
|
|
|
+ }
|
|
|
GLES20.glUniform1i(uTextureLocation, 0)
|
|
|
|
|
|
+ // 设置顶点坐标
|
|
|
+ vertexArray.setVertexAttribPointer(aPositionLocation)
|
|
|
// 设置纹理坐标
|
|
|
// alpha 通道坐标
|
|
|
alphaArray.setVertexAttribPointer(aTextureAlphaLocation)
|
|
|
@@ -148,6 +190,12 @@ class Render(surfaceTexture: SurfaceTexture): IRenderListener {
|
|
|
|
|
|
// draw
|
|
|
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4)
|
|
|
+
|
|
|
+ if (useFbo) {
|
|
|
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, GLES20.GL_NONE)
|
|
|
+ } else {
|
|
|
+ GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_NONE)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|