TheDoktor said:
Here is my projection matrix setting code. It's based on some of the PVR sample code.
<snip>
that's the canonical gl projection when it comes to depth, nothing extraordinary there.
I call it using:
PVRTMatrixPerspectiveFovRHF(40.0f,(F32)screen.width/(F32)screen.height,gl.znear,gl.zfar);
glScalef(1,-1,-1); // Model view matrix is LHF
ok, the canonical gl proj matrix expects a right-handed model-view, which it then flips the handedness of by flipping the z axis - native gl clipping space is left-handed and +z points away from the viewer. by making your model-view's z opposite to the norm, while preserving the original z-axis negation in the projection matrix, you effectively invert the order of your depth ranger, ergo, depth buffer (read further below).
where:
screen.width = 1280
screen.height = 768
gl.znear = 0.2f;
gl.far = 2500.0f;
btw, znear is generally too small. if your scene is depth-precision-sensitive that could cause issues. try adjusting it to something at least a unit big.
Other things of note:
glDepthRangef(gl.zfar,gl.znear);
glClearDepthf(0.0f);
glDepthFunc(GL_GEQUAL);
so here you'd need to either invert the depth compare function, of flip the znear/zfar mapping to the depth range. of course, clear depth should be fixed accordinly.
apropos, the depthRange function provides the mapping of NDC coords to depth-buffer. that means it takes the -1..1 NDC depth and maps that somewhere in the 0..1 range of the depth buffer, which is what the function params signify; those are automatically clamped to 0..1. so your gl.zfar an gl.znear end up as 1.f and .2f, respectively - that's another issue you have there.
As far as depth buffer precision is concerned as far as I know SGX uses 32 bit floating point in all cases as it doesn't actually have a depth buffer but it's tile sorting algorithms use 32 bit floats.
I don't do any sorting myself, I just throw everthing in the scenegraph that hasn't been frustrum culled at the SGX.
that high-precision tile's depth should still get exported to an external depth buffer if needed, which buffer could later participate in occlusion tests. or at least that's what previous pvr generations have allowed. but given you don't do anything fancy with your scene, you should indeed be on the vanilla path.
ed: post-morning-coffee edit. hope now it's more readable.