-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
igl | android | Support sRGB framebuffer on OpenGLES. #207
Conversation
vinsentli
commented
Nov 15, 2024
•
edited
Loading
edited
shell/android/jni/TinyRenderer.cpp
Outdated
@@ -100,6 +100,16 @@ void TinyRenderer::init(AAssetManager* mgr, | |||
vulkan::VulkanContextConfig config; | |||
config.terminateOnValidationError = true; | |||
config.requestedSwapChainTextureFormat = swapchainColorTextureFormat; | |||
switch (swapchainColorTextureFormat) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, while I believe you that you get different results, why do you feel this is the right fix?
can you provide screenshots of the differences just to make sure that we’re talking about the same thing?
the sRGB frame buffer might not be very well tested on Android phones
@francoiscoulombe You can check out these screenshots
|
thanks for the screenshots. for what it's worth, the center one is the correct colors I don't know why sending a BGRA_SRGB to OpenGL ES isn't resulting in an image that is more like the center one. I'm more worried about the swapchain color space changes which are separate from this |
Indeed, the color in the middle image is correct. |
I will continue researching the reasons behind the incorrect colors in OpenGL. |
@francoiscoulombe I have resolved it. |
What was it? |
We need create a sRGB surface in GLSurfaceView. The prerequisite is that the device needs to support the EGL_KHR_gl_colorspace extension. setEGLWindowSurfaceFactory(new SurfaceFactory(getHolder()));
private static class SurfaceFactory implements GLSurfaceView.EGLWindowSurfaceFactory{
private SurfaceHolder surfaceHolder_;
public SurfaceFactory(SurfaceHolder surfaceHolder){
surfaceHolder_ = surfaceHolder;
}
final int EGL_GL_COLORSPACE_KHR = 0x309D;
final int EGL_GL_COLORSPACE_SRGB_KHR = 0x3089;
final int EGL_GL_COLORSPACE_LINEAR_KHR = 0x308A;
final int[] configAttribs = {
EGL_GL_COLORSPACE_KHR ,EGL_GL_COLORSPACE_SRGB_KHR,
EGL10.EGL_NONE
};
@Override
public EGLSurface createWindowSurface(EGL10 egl10, EGLDisplay eglDisplay, EGLConfig eglConfig, Object o) {
return egl10.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceHolder_, configAttribs);
}
@Override
public void destroySurface(EGL10 egl10, EGLDisplay eglDisplay, EGLSurface eglSurface) {
egl10.eglDestroySurface(eglDisplay, eglSurface);
}
} |
Sweet! nonlinear srgb “should” work pretty much everywhere nowadays. |
That's correct. |
@francoiscoulombe @corporateshark |
I’ll take a look first thing on monday thanks for doing this |
@francoiscoulombe |
@corporateshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
sorry for the delay, I had some fire to extinguish promise I'll try this out today |
using this code, opengl is still dark. am i missing something? |
you're right... surprisingly, my s22 doesn't seem to have that extension. gonna try on a different phone |
my pixel definitely has the extension and it still shows dark |
Please check the format of the swapchain is SRGB. |
i even hardcoded srgb color format in a few places where it was set to unorm8 but unfortunately i'm still getting dark colors |
add a breakpoint in java createWindowSurface,check the final congfig attribute is EGL_GL_COLORSPACE_SRGB_KHR |
i'm not setup with a java debugger but i'm adding logs and they're not coming out either something's wrong with my setup or something is missing. I'm also not building this using cmake. maybe i should try to replicate your setup? |
@francoiscoulombe The files in |
i just saw this. your changes were only done to the files inside the build folder and that's the not the files that i'm using lol i couldn't understand why my C++ log was coming out but not the java one |
alright, got it. it works now that i use the right java code. sorry for all the confusion, i didn't know we had this duplication i'll take care of propagating the changes |
@corporateshark merged this pull request in b36a432. |