Setting depth testing and writing correctly.

# Description:
Setting depth testing and writing correctly.
We've been getting away with avoiding this for a while because things either restore the correct state or we're just lucky but recent work exposes where it gets left in the wrong state.

#2528, #2525 and #2527 will all need or include these changes.