From a4587770e2b5085c91efb250659009b3c15d1f71 Mon Sep 17 00:00:00 2001 From: vinsentli Date: Mon, 6 Jan 2025 19:44:00 -0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90igl=20nanovg=20part-1=E3=80=91shell=20?= =?UTF-8?q?|=20Android=20OpenGLES=20SampleView=20introduce=20new=20param?= =?UTF-8?q?=20:=20enableStencilBuffer=20(#215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This is a prerequisite pull request for igl nanovg(https://github.com/facebook/igl/pull/213). Pull Request resolved: https://github.com/facebook/igl/pull/215 Reviewed By: dmannemela Differential Revision: D67834361 Pulled By: corporateshark fbshipit-source-id: 414f2fc60f56de57fb6b703a89a7cb979ab4db31 --- .../facebook/igl/sample/SampleActivity.java | 7 ++++- .../com/facebook/igl/sample/SampleView.java | 27 ++++++++++++++++-- .../facebook/igl/sample/SampleActivity.java | 7 ++++- .../com/facebook/igl/sample/SampleView.java | 28 ++++++++++++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/build/android/app/src/main/java/com/facebook/igl/sample/SampleActivity.java b/build/android/app/src/main/java/com/facebook/igl/sample/SampleActivity.java index 822ed8fede..fd8c399d56 100644 --- a/build/android/app/src/main/java/com/facebook/igl/sample/SampleActivity.java +++ b/build/android/app/src/main/java/com/facebook/igl/sample/SampleActivity.java @@ -33,6 +33,8 @@ public class SampleActivity extends Activity implements View.OnClickListener { private final int selectedTabColor = Color.BLUE; private final int unSelectedTabColor = Color.GRAY; + protected boolean mEnableStencilBuffer = false; + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -69,7 +71,10 @@ protected void onCreate(Bundle icicle) { } else if (mConfigs[i].version.flavor == SampleLib.BackendFlavor.OpenGL_ES) { backendView = new SampleView( - getApplication(), mConfigs[i].version, mConfigs[i].swapchainColorTextureFormat); + getApplication(), + mConfigs[i].version, + mConfigs[i].swapchainColorTextureFormat, + mEnableStencilBuffer); ((SampleView) backendView).onPause(); } diff --git a/build/android/app/src/main/java/com/facebook/igl/sample/SampleView.java b/build/android/app/src/main/java/com/facebook/igl/sample/SampleView.java index 7d0a4d800e..77f87cdfe1 100644 --- a/build/android/app/src/main/java/com/facebook/igl/sample/SampleView.java +++ b/build/android/app/src/main/java/com/facebook/igl/sample/SampleView.java @@ -29,9 +29,26 @@ public class SampleView extends GLSurfaceView { private float lastTouchY = 0.0f; public SampleView( - Context context, SampleLib.BackendVersion backendVersion, int swapchainColorTextureFormat) { + Context context, + SampleLib.BackendVersion backendVersion, + int swapchainColorTextureFormat, + boolean enableStencilBuffer) { + super(context); + init(context, backendVersion, swapchainColorTextureFormat, enableStencilBuffer); + } + public SampleView( + Context context, SampleLib.BackendVersion backendVersion, int swapchainColorTextureFormat) { super(context); + init(context, backendVersion, swapchainColorTextureFormat, false); + } + + private void init( + Context context, + SampleLib.BackendVersion backendVersion, + int swapchainColorTextureFormat, + boolean enableStencilBuffer) { + // Uncomment to attach debugging // android.os.Debug.waitForDebugger(); @@ -43,7 +60,7 @@ public SampleView( setEGLWindowSurfaceFactory( new SurfaceFactory(SampleLib.isSRGBTextureFormat(swapchainColorTextureFormat))); - setEGLConfigChooser(new ConfigChooser(backendVersion)); + setEGLConfigChooser(new ConfigChooser(backendVersion, enableStencilBuffer)); setRenderer(new Renderer(context, backendVersion, swapchainColorTextureFormat)); } @@ -155,8 +172,11 @@ private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser { private final SampleLib.BackendVersion mBackendVersion; - public ConfigChooser(SampleLib.BackendVersion version) { + private boolean mEnableStencilBuffer = false; + + public ConfigChooser(SampleLib.BackendVersion version, boolean enableStencilBuffer) { mBackendVersion = version; + mEnableStencilBuffer = enableStencilBuffer; } public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { @@ -169,6 +189,7 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16, + EGL10.EGL_STENCIL_SIZE, mEnableStencilBuffer ? 8 : 0, EGL10.EGL_RENDERABLE_TYPE, (mBackendVersion.majorVersion == (byte) 3) ? EGL15.EGL_OPENGL_ES3_BIT diff --git a/shell/android/java/com/facebook/igl/sample/SampleActivity.java b/shell/android/java/com/facebook/igl/sample/SampleActivity.java index 822ed8fede..fd8c399d56 100644 --- a/shell/android/java/com/facebook/igl/sample/SampleActivity.java +++ b/shell/android/java/com/facebook/igl/sample/SampleActivity.java @@ -33,6 +33,8 @@ public class SampleActivity extends Activity implements View.OnClickListener { private final int selectedTabColor = Color.BLUE; private final int unSelectedTabColor = Color.GRAY; + protected boolean mEnableStencilBuffer = false; + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -69,7 +71,10 @@ protected void onCreate(Bundle icicle) { } else if (mConfigs[i].version.flavor == SampleLib.BackendFlavor.OpenGL_ES) { backendView = new SampleView( - getApplication(), mConfigs[i].version, mConfigs[i].swapchainColorTextureFormat); + getApplication(), + mConfigs[i].version, + mConfigs[i].swapchainColorTextureFormat, + mEnableStencilBuffer); ((SampleView) backendView).onPause(); } diff --git a/shell/android/java/com/facebook/igl/sample/SampleView.java b/shell/android/java/com/facebook/igl/sample/SampleView.java index 61a3d124cf..bd4b818964 100644 --- a/shell/android/java/com/facebook/igl/sample/SampleView.java +++ b/shell/android/java/com/facebook/igl/sample/SampleView.java @@ -31,9 +31,26 @@ public class SampleView extends GLSurfaceView { private CountDownLatch renderSessionInitLatch = new CountDownLatch(1); public SampleView( - Context context, SampleLib.BackendVersion backendVersion, int swapchainColorTextureFormat) { + Context context, + SampleLib.BackendVersion backendVersion, + int swapchainColorTextureFormat, + boolean enableStencilBuffer) { + super(context); + init(context, backendVersion, swapchainColorTextureFormat, enableStencilBuffer); + } + public SampleView( + Context context, SampleLib.BackendVersion backendVersion, int swapchainColorTextureFormat) { super(context); + init(context, backendVersion, swapchainColorTextureFormat, false); + } + + private void init( + Context context, + SampleLib.BackendVersion backendVersion, + int swapchainColorTextureFormat, + boolean enableStencilBuffer) { + // Uncomment to attach debugging // android.os.Debug.waitForDebugger(); @@ -45,7 +62,7 @@ public SampleView( setEGLWindowSurfaceFactory( new SurfaceFactory(SampleLib.isSRGBTextureFormat(swapchainColorTextureFormat))); - setEGLConfigChooser(new ConfigChooser(backendVersion)); + setEGLConfigChooser(new ConfigChooser(backendVersion, enableStencilBuffer)); setRenderer( new Renderer(context, backendVersion, swapchainColorTextureFormat, renderSessionInitLatch)); @@ -141,7 +158,6 @@ private static class SurfaceFactory implements GLSurfaceView.EGLWindowSurfaceFac @Override public EGLSurface createWindowSurface( EGL10 egl10, EGLDisplay eglDisplay, EGLConfig eglConfig, Object nativeWindow) { - String eglExtensionString = egl10.eglQueryString(eglDisplay, egl10.EGL_EXTENSIONS); if (!eglExtensionString.contains("EGL_KHR_gl_colorspace")) { return egl10.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, null); @@ -167,8 +183,11 @@ private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser { private final SampleLib.BackendVersion mBackendVersion; - public ConfigChooser(SampleLib.BackendVersion version) { + private boolean mEnableStencilBuffer = false; + + public ConfigChooser(SampleLib.BackendVersion version, boolean enableStencilBuffer) { mBackendVersion = version; + mEnableStencilBuffer = enableStencilBuffer; } public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { @@ -181,6 +200,7 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16, + EGL10.EGL_STENCIL_SIZE, mEnableStencilBuffer ? 8 : 0, EGL10.EGL_RENDERABLE_TYPE, (mBackendVersion.majorVersion == (byte) 3) ? EGL15.EGL_OPENGL_ES3_BIT