kakashidinho / metalangle

MetalANGLE: OpenGL ES to Metal API translation layer
Other
459 stars 64 forks source link

pixelFormat failed assertion ONLY when running on simulators #68

Open lirbar opened 2 years ago

lirbar commented 2 years ago

MetalAngle is amazing work. Thank you so much Le Hoang Quyen!

We integrated MetalAngle and everything works great when running on devices. Tested on 15.1 of iOS, iPadOS, tvOS and macOS (using Mac Catalyst).

But when running on all corresponding simulators, we get the following error: MTLDebugValidateMTLPixelFormat:1433: failed assertion `pixelFormat (40) is not a valid MTLPixelFormat.'

on the first run of the following line: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _scalingTextureWidth, _scalingTextureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0); printOpenGLError();

We get The following similar error: MTLDebugValidateMTLPixelFormat:1433: failed assertion `pixelFormat (41) is not a valid MTLPixelFormat.

On the following line: GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GL_DYNAMIC_TEXTURE_WIDTH, GL_DYNAMIC_TEXTURE_WIDTH, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, dynamicTexturePixels));

As mentioned, these are ONLY when running on simulators.

kakashidinho commented 2 years ago

It looks like simulator doesn’t natively support 16 bits rgb format. I didn’t notice this before. Will have to do some 16->32 bits fallbacks for simulator. In the meantime you could try to use 32 bits rgb format if you detect you are on simulator as a workaround for now.

lirbar commented 2 years ago

Thanks! Is it a lot of work on your side ? Do you expect to have time for this in the near future ?

I am asking since I am not familiar enough with OpenGL/Metal code to do what you wrote. Replacing GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_SHORT_5_5_5_1 with GL_UNSIGNED_BYTE does produce an image - but the colors are all bad.

kakashidinho commented 2 years ago

Yes, It would require some works.

btw, if you change the type to GL_UNSIGNED_BYTE, you need to make sure input pixels (e.g. dynamicTexturePixels) are in 32 bits RGB/RGBA format as well.

lirbar commented 2 years ago

Thank! Hope you will find the time for this one...

Do you mean I should do the following conversion to my 16bit input pixels ? https://stackoverflow.com/a/8579650/14139949

kakashidinho commented 2 years ago

Thank! Hope you will find the time for this one...

Do you mean I should do the following conversion to my 16bit input pixels ? https://stackoverflow.com/a/8579650/14139949

Yes, normally MetalANGLE should do the conversion for you if the format fallback is implemented. However, it is not implemented yet for simulator. As a workaround for now, you could do it yourself on application layer (before passing to MetalANGLE's GL function)