OpenSWE1R / openswe1r

An Open-Source port of the 1999 Game "Star Wars Episode 1: Racer"
https://openswe1r.github.io/
GNU General Public License v2.0
313 stars 26 forks source link

Implement Z-buffer #94

Closed JayFoxRox closed 6 years ago

JayFoxRox commented 6 years ago

This implements all functionality to get working depth-testing.

First , the hardware capabilities for filling Z-buffers will be reported with this change. This is the feature the game will test to enable the Z-buffer clearing. Furthermore, the reported Z-Buffer precision was reduced to 16 bits to make synchronization with OpenGL easier. This will be important in a later change when Z-buffer readback is implemented, but we might as well do it now. (The internal Z-buffer precision might be higher, but emulated 16 bit is fine for now)

Then actual Z-clearing (or depth filling / clearing) is implemented. This currently assumes that the game always sets the maximum Z value, which is 0xFFFF for our 16 bit Z-buffer. This will be improved in the future if necessary (to support other clear values).

Now that Z-clearing is functional, we can turn on Z-buffering by synchronizing OpenGL and the emulated D3D states. As a hack, we always assume the LEQUAL comparison. More states will be added when they are encountered. We also have to lazily synchronize the glDepthMask because we always have to enable depth writes for the Z-clear from the previous commit.

Note that color clearing and fog are still not implemented, so there'll still be a lot of graphical glitches on some maps (mostly related to distant objects).

Screenshots:

(I'll probably merge this in a day or so but I might not get around to doing it too soon, as I'm busy setting up a CLA)