本文介绍了GLConsumer已附加到新SurfaceTexture的上下文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在手动创建时,SurfaceTexture是否默认连接到GLContext?如果可以,怎么办?

Is SurfaceTexture attached to GLContext by default when created manually? If so, how?

这里是一个示例,我正在尝试创建自己的SurfaceTexture并将其设置为TextureView:

Here is an example, I'm trying to create my own SurfaceTexture and set it to TextureView:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView = (TextView) findViewById(R.id.version);
        TextureView textureView = (TextureView) findViewById(R.id.texture);

        int[] arr = new int[1];
        GLES20.glGenTextures(1, arr, 0);
        int texName = arr[1];

        SurfaceTexture surfaceTexture = new SurfaceTexture(texName);
        textureView.setSurfaceTexture(surfaceTexture);
    }
}

我不断得到:

还有一个例外:

在新创建的SurfaceTexture对象上调用detachFromGLContext可以解决问题,但是这很令人困惑,因为我可以确认在这种情况下从未调用过attachToGLContext.

Calling detachFromGLContext on newly created SurfaceTexture object solves the problem, but that's rather confusing as I can confirm that attachToGLContext is never called in this scenario.

P.S.我知道默认情况下TextureView具有它自己的SurfaceTexture.在这种情况下,我必须使用从SurfaceTexture扩展的自己的实现.

P.S. I know that TextureView has it's own SurfaceTexture by default. In this scenario I have to use own implementation that extends from SurfaceTexture.

推荐答案

在Android O中,有一个不会立即附加的新构造函数.听起来就是您想要的.正如您的自我回答所说,以前的构造函数会自动附加到当前线程的GL上下文中.

In Android O there is a new constructor which doesn't attach immediately. Sounds like that's what you want. As your self-answer says, the previous constructors automatically attach to the current thread's GL context.

这篇关于GLConsumer已附加到新SurfaceTexture的上下文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:58