Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

vinsentli
Copy link
Contributor

@vinsentli vinsentli commented Nov 15, 2024

image

@@ -100,6 +100,16 @@ void TinyRenderer::init(AAssetManager* mgr,
vulkan::VulkanContextConfig config;
config.terminateOnValidationError = true;
config.requestedSwapChainTextureFormat = swapchainColorTextureFormat;
switch (swapchainColorTextureFormat) {
Copy link
Contributor

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

@vinsentli
Copy link
Contributor Author

@francoiscoulombe You can check out these screenshots

Header Header Header
OpenGL BGRA_SRGB & RGBA_UNorm8 Vulkan before : BGRA_SRGB Vulkan now :RGBA_UNorm8
d380a7a8db98d5eb675b3037d8d6a7e0_compress a6d1473835817baceee6782fdc9a7b36_compress 1d3f677a388fb1b63d7f76706b030e94_compress

@francoiscoulombe
Copy link
Contributor

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

@francoiscoulombe
Copy link
Contributor

to verify set your display into srgb profile and sample the pixel to compare with the value written on the image.
image

@vinsentli
Copy link
Contributor Author

Indeed, the color in the middle image is correct.

@vinsentli
Copy link
Contributor Author

I will continue researching the reasons behind the incorrect colors in OpenGL.

@vinsentli vinsentli closed this Nov 15, 2024
@vinsentli
Copy link
Contributor Author

@francoiscoulombe I have resolved it.
image

@francoiscoulombe
Copy link
Contributor

What was it?

@vinsentli
Copy link
Contributor Author

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);
    }
  }

@francoiscoulombe
Copy link
Contributor

Sweet!
on Vulkan, you only need the colorspace extension to do a color space that is not nonlinear srgb. (Like pass through)

nonlinear srgb “should” work pretty much everywhere nowadays.

@vinsentli
Copy link
Contributor Author

That's correct.

@vinsentli
Copy link
Contributor Author

vinsentli commented Nov 16, 2024

@francoiscoulombe @corporateshark
After the pull request #199 is merged, I will create a new pull request based on the latest OpenGL SampleView to fix the colorspace issue in OpenGL.

@francoiscoulombe
Copy link
Contributor

I’ll take a look first thing on monday

thanks for doing this

@vinsentli vinsentli reopened this Nov 20, 2024
@vinsentli vinsentli marked this pull request as draft November 20, 2024 01:32
@vinsentli vinsentli changed the title igl | shell | Fix color is inconsist between opengl and vulkan. igl | android | Support sRGB framebuffer on OpenGLES. Nov 20, 2024
@vinsentli vinsentli marked this pull request as ready for review November 20, 2024 02:14
@vinsentli
Copy link
Contributor Author

@francoiscoulombe
I have already updated the code.

@facebook-github-bot
Copy link
Contributor

@corporateshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@francoiscoulombe
Copy link
Contributor

sorry for the delay, I had some fire to extinguish

promise I'll try this out today

@francoiscoulombe
Copy link
Contributor

using this code, opengl is still dark.

am i missing something?

@vinsentli
Copy link
Contributor Author

The prerequisite is that the device needs to support the EGL_KHR_gl_colorspace extension.
Screenshot_20241121_212217.jpg

@francoiscoulombe
Copy link
Contributor

you're right... surprisingly, my s22 doesn't seem to have that extension.

gonna try on a different phone

@francoiscoulombe
Copy link
Contributor

my pixel definitely has the extension and it still shows dark

@vinsentli
Copy link
Contributor Author

Please check the format of the swapchain is SRGB.

@francoiscoulombe
Copy link
Contributor

i even hardcoded srgb color format in a few places where it was set to unorm8 but unfortunately i'm still getting dark colors

@vinsentli
Copy link
Contributor Author

add a breakpoint in java createWindowSurface,check the final congfig attribute is EGL_GL_COLORSPACE_SRGB_KHR

@francoiscoulombe
Copy link
Contributor

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?
how are you running this?

@corporateshark
Copy link
Contributor

@francoiscoulombe The files inbuild/android/app/src/main/java/com/facebook/igl/sample are CMake-only. It can be you are using a completely different code path.

@francoiscoulombe
Copy link
Contributor

francoiscoulombe commented Nov 21, 2024

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

@francoiscoulombe
Copy link
Contributor

francoiscoulombe commented Nov 21, 2024

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

@facebook-github-bot
Copy link
Contributor

@corporateshark merged this pull request in b36a432.

@vinsentli vinsentli deleted the vulkan_color_space branch November 21, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants