Implement polygon offset in GL3 driver

This commit is contained in:
sfan5
2025-01-04 18:10:29 +01:00
parent 5b14c03301
commit 4774e65ed9
2 changed files with 12 additions and 6 deletions
irr
include
src/OpenGL

@ -304,11 +304,7 @@ public:
//! A constant z-buffer offset for a polygon/line/point
/** The range of the value is driver specific.
On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset.
On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer.
Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias.
Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/)
recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit). */
On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset. */
f32 PolygonOffsetDepthBias;
//! Variable Z-Buffer offset based on the slope of the polygon.

@ -1313,7 +1313,17 @@ void COpenGL3DriverBase::setBasicRenderStates(const SMaterial &material, const S
getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact));
}
// TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver.
// Polygon Offset
if (resetAllRenderStates ||
lastmaterial.PolygonOffsetDepthBias != material.PolygonOffsetDepthBias ||
lastmaterial.PolygonOffsetSlopeScale != material.PolygonOffsetSlopeScale) {
if (material.PolygonOffsetDepthBias || material.PolygonOffsetSlopeScale) {
GL.Enable(GL.POLYGON_OFFSET_FILL);
GL.PolygonOffset(material.PolygonOffsetSlopeScale, material.PolygonOffsetDepthBias);
} else {
GL.Disable(GL.POLYGON_OFFSET_FILL);
}
}
if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness)
GL.LineWidth(core::clamp(static_cast<GLfloat>(material.Thickness), DimAliasedLine[0], DimAliasedLine[1]));