Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public static native void init(

public static native void setClearColorValue(float r, float g, float b, float a);

public static native boolean isSRGBTextureFormat(int textureFormat);

public static native void surfaceDestroyed(Surface surface);

public static class RenderSessionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL10;

/// Simple view that sets up a GLES 2.0 rendering context
Expand All @@ -39,6 +40,8 @@ public SampleView(
// Set the view to be transluscent since we provide an alpha channel below.
this.getHolder().setFormat(PixelFormat.TRANSLUCENT);

setEGLWindowSurfaceFactory(new SurfaceFactory(SampleLib.isSRGBTextureFormat(swapchainColorTextureFormat)));

setEGLConfigChooser(new ConfigChooser(backendVersion));

setRenderer(new Renderer(context, backendVersion, swapchainColorTextureFormat));
Expand Down Expand Up @@ -112,6 +115,33 @@ private static void checkEglError(String prompt, EGL10 egl) {
}
}

private static class SurfaceFactory implements GLSurfaceView.EGLWindowSurfaceFactory{
final int EGL_GL_COLORSPACE_KHR = 0x309D;
final int EGL_GL_COLORSPACE_SRGB_KHR = 0x3089;
final int EGL_GL_COLORSPACE_LINEAR_KHR = 0x308A;

private boolean mIsSRGBColorSpace;

SurfaceFactory(boolean isSRGB){
mIsSRGBColorSpace = isSRGB;
}

@Override
public EGLSurface createWindowSurface(EGL10 egl10, EGLDisplay eglDisplay, EGLConfig eglConfig, Object nativeWindow) {
int[] configAttribs = {
EGL_GL_COLORSPACE_KHR , (mIsSRGBColorSpace ? EGL_GL_COLORSPACE_SRGB_KHR : EGL_GL_COLORSPACE_LINEAR_KHR),
EGL10.EGL_NONE
};

return egl10.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, configAttribs);
}

@Override
public void destroySurface(EGL10 egl10, EGLDisplay eglDisplay, EGLSurface eglSurface) {
egl10.eglDestroySurface(eglDisplay, eglSurface);
}
}

/// Config chooser: handles specifying the requirements for the EGL config and choosing the
// correct one.
private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser {
Expand Down
11 changes: 11 additions & 0 deletions shell/android/jni/Jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ JNIEXPORT void JNICALL Java_com_facebook_igl_shell_SampleLib_setClearColorValue(
jfloat g,
jfloat b,
jfloat a);

JNIEXPORT bool JNICALL Java_com_facebook_igl_shell_SampleLib_isSRGBTextureFormat(JNIEnv* env,
jobject obj,
int textureFormat);

};

JNIEXPORT jobjectArray JNICALL
Expand Down Expand Up @@ -365,4 +370,10 @@ JNIEXPORT void JNICALL Java_com_facebook_igl_shell_SampleLib_setClearColorValue(
renderers[*activeRendererIndex]->setClearColorValue(r, g, b, a);
}

JNIEXPORT bool JNICALL Java_com_facebook_igl_shell_SampleLib_isSRGBTextureFormat(JNIEnv* env,
jobject obj,
int textureFormat){
return textureFormat == (int)igl::TextureFormat::RGBA_SRGB || textureFormat == (int)igl::TextureFormat::BGRA_SRGB;
}

} // namespace igl::samples