Use shader to calculate sample point

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
(cherry picked from commit 3d55f6adbf38215ce3c4e2986a2a2e8a91086f08)
diff --git a/external/openglcts/modules/common/glcNearestEdgeTests.cpp b/external/openglcts/modules/common/glcNearestEdgeTests.cpp
index 621a662..f9c754a 100644
--- a/external/openglcts/modules/common/glcNearestEdgeTests.cpp
+++ b/external/openglcts/modules/common/glcNearestEdgeTests.cpp
@@ -171,32 +171,44 @@
 		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};
@@ -301,8 +313,7 @@
 
 	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));
@@ -315,6 +326,11 @@
 	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(),