azurite-engine / Azurite

Azurite Game Engine is a 2D Java game engine built on top of LWJGL.
https://azurite-engine.github.io
MIT License
42 stars 20 forks source link

Apple Silicon - unit 2 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) #76

Open athaun opened 2 years ago

athaun commented 2 years ago

Warning when running some scenes on mac OS.

2022-02-18 22:22:23.705 java[64638:5363288] [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.
UNSUPPORTED (log once): POSSIBLE ISSUE: unit 1 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable

Reason for this is unknown right now, this issue is mostly a reminder for myself to debug it. Possibly a result of System.setProperty("java.awt.headless", "true"); on L. 139 in graphics.Window

heavyrain266 commented 2 years ago

You may want to try using java.awt.Toolkit.getDefaultToolkit(); before or after initializing glfw, this should remove this message.

athaun commented 2 years ago

That actually results in a black screen and the engine hanging. Interestingly, after researching the issue I found this: Someone who has the same error on apple silicon (which is also applicable to me).

Next I took a closer look at the shader itself. The texture samplers were stored in an array, which is a bit of a special case in GLSL, particularly when it comes to OpenGL 3. All accesses to the sampler array must use compile-time fixed indices. I was using a switch statement to branch out uses of every possible index, and this has been working fine on various OpenGL drivers so far. The shader was responding correctly to if statements, though, so eventually I decided to replace the switch statements with a series of ifs. Functionally these are supposed to be equivalent, but to my surprise it fixed the problem! from https://blog.dengine.net/2021/01/wonders-and-mysteries-of-the-m1/

I will investigate some more with a windows or linux machine to see if the error arises, if not, I will assume it is either mac OS and or m1 architecture specific. I will also see if using a if/else ladder resolves the issue.

athaun commented 2 years ago

Likely apple silicon image