Use shader to calculate sample point
authorleiche02 <ryan.chen@arm.com>
Wed, 11 Nov 2020 06:42:14 +0000 (14:42 +0800)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 3 Dec 2020 08:19:51 +0000 (03:19 -0500)
The test's sampling point is taking from interpolated varying, the inaccuracy
of interpolation may cause wrong sampling, use gl_FragCoord in fragment
shader to calcuate sample point directly.

Component: OpenGL

Affected tests: KHR-GLES32.core.nearest_edge.offset_*

VK-GL-CTS issue: 2651

Change-Id: Ib91595ca07a2b146059c51f2d68ebf086c10553c

external/openglcts/modules/common/glcNearestEdgeTests.cpp

index 14f63be..f5ddba0 100644 (file)
@@ -172,32 +172,44 @@ void NearestEdgeTestCase::init()
                TCU_THROW(NotSupportedError, "Render target size too small");
 
        m_vertShaderText =
-               "#version ${VERSION}\n"
-               "\n"
-               "in highp vec2 position;\n"
-               "in highp vec2 inTexCoord;\n"
-               "out highp vec2 commonTexCoord;\n"
-               "\n"
-               "void main()\n"
-               "{\n"
-               "    commonTexCoord = inTexCoord;\n"
-               "    gl_Position = vec4(position, 0.0, 1.0);\n"
-               "}\n"
-               ;
-
-       m_fragShaderText =
-               "#version ${VERSION}\n"
-               "\n"
-               "in highp vec2 commonTexCoord;\n"
-               "out highp vec4 fragColor;\n"
-               "\n"
-               "uniform highp sampler2D texSampler;\n"
-               "\n"
-               "void main()\n"
-               "{\n"
-               "    fragColor = texture(texSampler, commonTexCoord);\n"
-               "}\n"
-               "\n";
+        "#version ${VERSION}\n"
+        "\n"
+        "in highp vec2 position;\n"
+        "\n"
+        "void main()\n"
+        "{\n"
+        "    gl_Position = vec4(position, 0.0, 1.0);\n"
+        "}\n"
+        ;
+    m_fragShaderText =
+        "#version ${VERSION}\n"
+        "\n"
+        "precision highp float;\n"
+        "out highp vec4 fragColor;\n"
+        "\n"
+        "uniform highp sampler2D texSampler;\n"
+        "uniform int texOffset;\n"
+        "uniform float texWidth;\n"
+        "uniform float texHeight;\n"
+        "\n"
+        "void main()\n"
+        "{\n"
+        "    float texCoordX;\n"
+        "    float texCoordY;\n"
+        "    if(texOffset > 0)\n"
+        "    {\n"
+        "        texCoordX  = (gl_FragCoord.x + 0.499) / texWidth;\n "
+        "        texCoordY = (gl_FragCoord.y + 0.499) / texHeight;\n"
+        "    }\n"
+        "    else\n"
+        "    {\n"
+        "       texCoordX  = (gl_FragCoord.x - 0.499) / texWidth;\n"
+        "       texCoordY = (gl_FragCoord.y - 0.499) / texHeight;\n"
+        "    }\n"
+        "    vec2 sampleCoord = vec2(texCoordX, texCoordY);\n"
+        "    fragColor = texture(texSampler, sampleCoord);\n"
+        "}\n"
+        "\n";
 
        tcu::StringTemplate vertShaderTemplate{m_vertShaderText};
        tcu::StringTemplate fragShaderTemplate{m_fragShaderText};
@@ -303,8 +315,7 @@ void NearestEdgeTestCase::renderQuad ()
 
        const std::vector<glu::VertexArrayBinding> vertexArrays =
        {
-               glu::va::Float("position", 2, 4, 0, positions.data()),
-               glu::va::Float("inTexCoord", 2, 4, 0, texCoords.data())
+               glu::va::Float("position", 2, 4, 0, positions.data())
        };
 
        glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(m_vertShaderText, m_fragShaderText));
@@ -317,6 +328,11 @@ void NearestEdgeTestCase::renderQuad ()
        gl.uniform1i(gl.getUniformLocation(program.getProgram(), "texSampler"), 0);
        GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i failed");
 
+       gl.uniform1i(gl.getUniformLocation(program.getProgram(), "texOffset"),m_offsetSign);
+       gl.uniform1f(gl.getUniformLocation(program.getProgram(), "texWidth"), float(m_width));
+       gl.uniform1f(gl.getUniformLocation(program.getProgram(), "texHeight"), float(m_height));
+       GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i failed");
+
        gl.clear(GL_COLOR_BUFFER_BIT);
 
        glu::draw(renderContext, program.getProgram(),