liballeg / allegro5

The official Allegro 5 git repository. Pull requests welcome!
https://liballeg.org
Other
1.88k stars 283 forks source link

Bitmap with depth buffer not being rendered to on Windows + nVidia #1167

Open fatcerberus opened 4 years ago

fatcerberus commented 4 years ago

Rendering to a bitmap with a depth buffer, with the depth test enabled, seems to fail on Windows machines with nVidia GPUs. I get a black image (or whatever the bitmap was cleared to beforehand). In my normal implemetation, the depth buffer is cleared to 1.0f before every frame, and the depth function in use is ALLEGRO_RENDER_LESS_EQUAL, though I've tested and it doesn't seem to work with any depth functions at all except for ALLEGRO_RENDER_ALWAYS, which is quite bizarre, so I'm really not sure what's going on here. It seems like it's just always failing the depth test no matter what.

fatcerberus commented 4 years ago

Intel graphics and AMD GPUs are fine. It's only nVidia GPUs this affects, and seemingly only on Windows. Note this is with the OpenGL backend.

fatcerberus commented 4 years ago

At first I thought this might be relevant:

https://www.khronos.org/opengl/wiki/Sampler_(GLSL)#Shadow_samplers

If a texture has a depth or depth-stencil image format and has the depth comparison activated, it cannot be used with a normal sampler. Attempting to do so results in undefined behavior. Such textures must be used with a shadow sampler. This type changes the texture lookup functions (see below), adding an additional component to the textures' usual texture coordinate vector. This extra value is used to compare against the value sampled from the texture.

But that actually isn't relevant here since the depth texture isn't what's being sampled, that's just an extra thing attached to the FBO. The shader only cares about the RGBA portion so the depth values don't even come into play there. This is quite a mystery.

SiegeLord commented 4 years ago

Is this fixed function or programmable pipeline?

fatcerberus commented 4 years ago

Programmable. Sorry, I thought that was obvious from my mention of shaders. 😃

fatcerberus commented 4 years ago

As a quick test, I commented out all calls to al_set_new_bitmap_depth() in my codebase and it's still refusing to render anything. I can only get it to render by either disabling ALLEGRO_DEPTH_TEST or setting the depth func to ALLEGRO_RENDER_ALWAYS.