Using SurfaceTexture in Android

后端 未结 4 607
遥遥无期
遥遥无期 2020-12-24 03:51

I want to play a video into an OpenGL texture on XOOM using Android 3.0. I have come across SurfaceTexture in the goole developer docs which has been added in API 11 http://

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 04:11

    Example code. This creates a new external texture suitable for use in a SurfaceTexture, then wraps it in said SurfaceTexture and passes it to the camera as a surface to write the preview into.

    int[] textures = new int[1];
    // generate one texture pointer and bind it as an external texture.
    GLES20.glGenTextures(1, textures, 0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    // No mip-mapping with camera source.
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            GL10.GL_TEXTURE_MIN_FILTER,
                            GL10.GL_LINEAR);        
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    // Clamp to edge is only option.
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    
    
    int texture_id = textures[0];
    SurfaceTexture mTexture = new SurfaceTexture(texture_id);
    mTexture.setOnFrameAvailableListener(this);
    
    Camera cam = Camera.open();
    cam.setPreviewTexture(mTexture);
    

    Note that if you render this object, you'll need to be careful: It's NOT a 2D texture, so it needs special treatment in the shader.

提交回复
热议问题