Skip to content

Commit

Permalink
【igl nanovg part-1】shell | Android OpenGLES SampleView introduce new …
Browse files Browse the repository at this point in the history
…param : enableStencilBuffer (#215)

Summary:
This is a prerequisite pull request for igl nanovg(#213).

Pull Request resolved: #215

Reviewed By: dmannemela

Differential Revision: D67834361

Pulled By: corporateshark

fbshipit-source-id: 414f2fc60f56de57fb6b703a89a7cb979ab4db31
  • Loading branch information
vinsentli authored and facebook-github-bot committed Jan 7, 2025
1 parent b383064 commit a458777
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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));
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down
28 changes: 24 additions & 4 deletions shell/android/java/com/facebook/igl/sample/SampleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit a458777

Please sign in to comment.