Fix PolygonOffsetClampMinMax test fail when using 24bit depth buffer
authorAlex Lan <alex.lan@arm.com>
Wed, 26 Oct 2022 14:01:29 +0000 (22:01 +0800)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Wed, 26 Oct 2022 20:44:12 +0000 (20:44 +0000)
If using 24bit depth buffer to implement GL_DEPTH_COMPONENT16,
the polygon-offset value generated by glPolygonOffset isn't larger
or smaller than clamp value specified by glPolygonOffsetClampEXT.
So adjust units value based on depth buffer bits when calling
glPolygonOffset/glPolygonOffsetClampEXT.

Affects:
KHR-GLES31.core.polygon_offset_clamp.*

Components: OpenGL
Change-Id: If7a5da4b7b62d2a590ac03ad92832d0daf3e5f47

external/openglcts/modules/common/glcPolygonOffsetClampTests.cpp

index ba5ae72..d896474 100644 (file)
@@ -355,6 +355,12 @@ void PolygonOffsetClampValueTestCaseBase::test(const glw::Functions& gl)
        gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
        GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer");
 
+       /* Calculate number of depth units from depth bits. */
+       GLint depth_bits = 0;
+       gl.getIntegerv(GL_DEPTH_BITS, &depth_bits);
+       float num_units = (float)(1 << depth_bits);
+       GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv");
+
        bool result = true;
        for (GLuint i = 0; i < m_testValues.size(); ++i)
        {
@@ -383,7 +389,7 @@ void PolygonOffsetClampValueTestCaseBase::test(const glw::Functions& gl)
                gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
                GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer");
 
-               gl.polygonOffset(m_testValues[i].factor, m_testValues[i].units);
+               gl.polygonOffset(m_testValues[i].factor, m_testValues[i].units * num_units);
                GLU_EXPECT_NO_ERROR(gl.getError(), "glPolygonOffset");
 
                gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -408,7 +414,7 @@ void PolygonOffsetClampValueTestCaseBase::test(const glw::Functions& gl)
                gl.enable(GL_POLYGON_OFFSET_FILL);
                GLU_EXPECT_NO_ERROR(gl.getError(), "glEnable");
 
-               gl.polygonOffsetClamp(m_testValues[i].factor, m_testValues[i].units, m_testValues[i].clamp);
+               gl.polygonOffsetClamp(m_testValues[i].factor, m_testValues[i].units * num_units, m_testValues[i].clamp);
                GLU_EXPECT_NO_ERROR(gl.getError(), "glPolygonOffsetClamp");
 
                gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -514,8 +520,8 @@ void PolygonOffsetClampMinMaxTestCase::init()
        PolygonOffsetClampValueTestCaseBase::init();
 
        m_testValues.clear();
-       m_testValues.push_back(PolygonOffsetClampValues(0.0f, -1000.0f, -0.0001f)); // Min offset case
-       m_testValues.push_back(PolygonOffsetClampValues(0.0f, 1000.0f, 0.0001f));   // Max offset case
+       m_testValues.push_back(PolygonOffsetClampValues(0.0f, -1000.0f / 65536.0f, -0.0001f)); // Min offset case
+       m_testValues.push_back(PolygonOffsetClampValues(0.0f, 1000.0f / 65536.0f, 0.0001f));   // Max offset case
 }
 
 /** Verification method that determines if depth values are as expected
@@ -581,10 +587,10 @@ void PolygonOffsetClampZeroInfinityTestCase::init()
        PolygonOffsetClampValueTestCaseBase::init();
 
        m_testValues.clear();
-       m_testValues.push_back(PolygonOffsetClampValues(0.0f, -1000.0f, 0.0f));          // Min offset, zero clamp case
-       m_testValues.push_back(PolygonOffsetClampValues(0.0f, -1000.0f, -INFINITY)); // Min Offset, infinity clamp case
-       m_testValues.push_back(PolygonOffsetClampValues(0.0f, 1000.0f, 0.0f));           // Max offset, zero clamp case
-       m_testValues.push_back(PolygonOffsetClampValues(0.0f, 1000.0f, INFINITY));   // Max Offset, infinity clamp case
+       m_testValues.push_back(PolygonOffsetClampValues(0.0f, -1000.0f / 65536.0f, 0.0f));               // Min offset, zero clamp case
+       m_testValues.push_back(PolygonOffsetClampValues(0.0f, -1000.0f / 65536.0f, -INFINITY)); // Min Offset, infinity clamp case
+       m_testValues.push_back(PolygonOffsetClampValues(0.0f, 1000.0f / 65536.0f, 0.0f));                // Max offset, zero clamp case
+       m_testValues.push_back(PolygonOffsetClampValues(0.0f, 1000.0f / 65536.0f, INFINITY));   // Max Offset, infinity clamp case
 }
 
 bool PolygonOffsetClampZeroInfinityTestCase::verify(GLuint caseNo, GLfloat depth, GLfloat offsetDepth,