Is SurfaceTexture
attached to GLContext
by default when created manually? If so, how?
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);
}
}
I'm constantly getting:
E/GLConsumer: [unnamed-29058-0] attachToContext: GLConsumer is already attached to a context
And the exception:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.dkarmazin.openglesversion, PID: 29058 java.lang.RuntimeException: Error during attachToGLContext (see logcat for details) at android.graphics.SurfaceTexture.attachToGLContext(SurfaceTexture.java:215) at android.view.GLES20TextureLayer.setSurfaceTexture(GLES20TextureLayer.java:86) at android.view.HardwareRenderer$Gl20Renderer.setSurfaceTexture(HardwareRenderer.java:2228) at android.view.TextureView.getHardwareLayer(TextureView.java:401) at android.view.View.getDisplayList(View.java:13443) at android.view.View.getDisplayList(View.java:13519) at android.view.View.draw(View.java:14297) at android.view.ViewGroup.drawChild(ViewGroup.java:3115) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2952) at android.view.View.getDisplayList(View.java:13472) at android.view.View.getDisplayList(View.java:13519) at android.view.View.draw(View.java:14297) at android.view.ViewGroup.drawChild(ViewGroup.java:3115) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2952) at android.view.View.draw(View.java:14583) at android.widget.FrameLayout.draw(FrameLayout.java:472) at android.view.View.getDisplayList(View.java:13477) at android.view.View.getDisplayList(View.java:13519) at android.view.View.draw(View.java:14297) at android.view.ViewGroup.drawChild(ViewGroup.java:3115) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2952) at android.view.View.draw(View.java:14583) at android.support.v7.widget.ActionBarOverlayLayout.draw(ActionBarOverlayLayout.java:444) at android.view.View.getDisplayList(View.java:13477) at android.view.View.getDisplayList(View.java:13519) at android.view.View.draw(View.java:14297) at android.view.ViewGroup.drawChild(ViewGroup.java:3115) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2952) at android.view.View.getDisplayList(View.java:13472) at android.view.View.getDisplayList(View.java:13519) at android.view.View.draw(View.java:14297) at android.view.ViewGroup.drawChild(ViewGroup.java:3115) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2952) at android.view.View.getDisplayList(View.java:13472) at android.view.View.getDisplayList(View.java:13519) at android.view.View.draw(View.java:14297) at android.view.ViewGroup.drawChild(ViewGroup.java:3115) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2952) at android.view.View.draw(View.java:14583) at android.widget.FrameLayout.draw(FrameLayout.java:472) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2326) at android.view.View.getDisplayList(View.java:13477) at android.view.View.getDisplayList(View.java:13519) at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1577) at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2530) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2402) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2019) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1079) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5948) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5102) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)
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. I know that TextureView
has it's own SurfaceTexture
by default. In this scenario I have to use own implementation that extends from SurfaceTexture
.