1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Polygon offset tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fPolygonOffsetTests.hpp"
25 #include "deStringUtil.hpp"
26 #include "deRandom.hpp"
27 #include "gluContextInfo.hpp"
28 #include "gluRenderContext.hpp"
29 #include "gluShaderProgram.hpp"
30 #include "gluPixelTransfer.hpp"
31 #include "gluStrUtil.hpp"
32 #include "glwEnums.hpp"
33 #include "glwDefs.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestContext.hpp"
36 #include "tcuTestLog.hpp"
37 #include "tcuTextureUtil.hpp"
38 #include "tcuRenderTarget.hpp"
39 #include "tcuVectorUtil.hpp"
40 #include "rrRenderer.hpp"
41 #include "rrFragmentOperations.hpp"
43 #include "sglrReferenceContext.hpp"
48 using namespace glw; // GLint and other GL types
59 const char* s_shaderSourceVertex = "attribute highp vec4 a_position;\n"
60 "attribute highp vec4 a_color;\n"
61 "varying mediump vec4 v_color;\n"
64 " gl_Position = a_position;\n"
65 " v_color = a_color;\n"
67 const char* s_shaderSourceFragment = "varying mediump vec4 v_color;\n"
70 " gl_FragColor = v_color;\n"
73 static const tcu::Vec4 MASK_COLOR_OK = tcu::Vec4(0.0f, 0.1f, 0.0f, 1.0f);
74 static const tcu::Vec4 MASK_COLOR_DEV = tcu::Vec4(0.8f, 0.5f, 0.0f, 1.0f);
75 static const tcu::Vec4 MASK_COLOR_FAIL = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
77 inline bool compareThreshold (const tcu::IVec4& a, const tcu::IVec4& b, const tcu::IVec4& threshold)
79 return tcu::boolAll(tcu::lessThanEqual(tcu::abs(a - b), threshold));
82 /*--------------------------------------------------------------------*//*!
83 * \brief Pixelwise comparison of two images.
84 * \note copied & modified from glsRasterizationTests
86 * Kernel radius defines maximum allowed distance. If radius is 0, only
87 * perfect match is allowed. Radius of 1 gives a 3x3 kernel.
89 * Return values: -1 = Perfect match
90 * 0 = Deviation within kernel
91 * >0 = Number of faulty pixels
92 *//*--------------------------------------------------------------------*/
93 int compareImages (tcu::TestLog& log, glu::RenderContext& renderCtx, const tcu::ConstPixelBufferAccess& test, const tcu::ConstPixelBufferAccess& ref, const tcu::PixelBufferAccess& diffMask, int radius)
95 const int height = test.getHeight();
96 const int width = test.getWidth();
97 const int colorThreshold = 128;
98 const tcu::RGBA formatThreshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold();
99 const tcu::IVec4 threshold = tcu::IVec4(colorThreshold, colorThreshold, colorThreshold, formatThreshold.getAlpha() > 0 ? colorThreshold : 0)
100 + tcu::IVec4(formatThreshold.getRed(), formatThreshold.getGreen(), formatThreshold.getBlue(), formatThreshold.getAlpha());
102 int deviatingPixels = 0;
103 int faultyPixels = 0;
104 int compareFailed = -1;
106 tcu::clear(diffMask, MASK_COLOR_OK);
108 for (int y = 0; y < height; y++)
110 for (int x = 0; x < width; x++)
112 const tcu::IVec4 cRef = ref.getPixelInt(x, y);
114 // Pixelwise match, no deviation or fault
116 const tcu::IVec4 cTest = test.getPixelInt(x, y);
117 if (compareThreshold(cRef, cTest, threshold))
121 // If not, search within kernel radius
123 const int kYmin = deMax32(y - radius, 0);
124 const int kYmax = deMin32(y + radius, height-1);
125 const int kXmin = deMax32(x - radius, 0);
126 const int kXmax = deMin32(x + radius, width-1);
129 for (int kY = kYmin; kY <= kYmax; kY++)
130 for (int kX = kXmin; kX <= kXmax; kX++)
132 const tcu::IVec4 cTest = test.getPixelInt(kX, kY);
133 if (compareThreshold(cRef, cTest, threshold))
137 if (found) // The pixel is deviating if the color is found inside the kernel
139 diffMask.setPixel(MASK_COLOR_DEV, x, y);
140 if (compareFailed == -1)
147 diffMask.setPixel(MASK_COLOR_FAIL, x, y);
148 faultyPixels++; // The pixel is faulty if the color is not found
153 log << tcu::TestLog::Message << faultyPixels << " faulty pixel(s) found." << tcu::TestLog::EndMessage;
155 return (compareFailed == 1 ? faultyPixels : compareFailed);
158 void verifyImages (tcu::TestLog& log, tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const tcu::ConstPixelBufferAccess& testImage, const tcu::ConstPixelBufferAccess& referenceImage)
162 const int kernelRadius = 1;
163 const int faultyPixelLimit = 20;
165 tcu::Surface diffMask (testImage.getWidth(), testImage.getHeight());
167 faultyPixels = compareImages(log, renderCtx, referenceImage, testImage, diffMask.getAccess(), kernelRadius);
169 if (faultyPixels > faultyPixelLimit)
171 log << TestLog::ImageSet("Images", "Image comparison");
172 log << TestLog::Image("Test image", "Test image", testImage);
173 log << TestLog::Image("Reference image", "Reference image", referenceImage);
174 log << TestLog::Image("Difference mask", "Difference mask", diffMask.getAccess());
175 log << TestLog::EndImageSet;
177 log << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
178 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
182 void verifyError (tcu::TestContext& testCtx, const glw::Functions& gl, GLenum expected)
184 deUint32 got = gl.getError();
187 testCtx.getLog() << tcu::TestLog::Message << "// ERROR: expected " << glu::getErrorStr(expected) << "; got " << glu::getErrorStr(got) << tcu::TestLog::EndMessage;
188 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
189 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
193 void checkCanvasSize (int width, int height, int minWidth, int minHeight)
195 if (width < minWidth || height < minHeight)
196 throw tcu::NotSupportedError(std::string("Render context size must be at least ") + de::toString(minWidth) + "x" + de::toString(minWidth));
199 class PositionColorShader : public sglr::ShaderProgram
207 PositionColorShader (void);
208 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
209 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
212 PositionColorShader::PositionColorShader (void)
213 : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
214 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
215 << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
216 << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
217 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
218 << sglr::pdec::VertexSource(s_shaderSourceVertex)
219 << sglr::pdec::FragmentSource(s_shaderSourceFragment))
223 void PositionColorShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
225 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
227 const int positionAttrLoc = 0;
228 const int colorAttrLoc = 1;
230 rr::VertexPacket& packet = *packets[packetNdx];
232 // Transform to position
233 packet.position = rr::readVertexAttribFloat(inputs[positionAttrLoc], packet.instanceNdx, packet.vertexNdx);
236 packet.outputs[VARYINGLOC_COLOR] = rr::readVertexAttribFloat(inputs[colorAttrLoc], packet.instanceNdx, packet.vertexNdx);
240 void PositionColorShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
242 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
244 rr::FragmentPacket& packet = packets[packetNdx];
246 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
247 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readTriangleVarying<float>(packet, context, VARYINGLOC_COLOR, fragNdx));
251 // PolygonOffsetTestCase
253 class PolygonOffsetTestCase : public TestCase
256 PolygonOffsetTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName, int canvasSize);
258 virtual void testPolygonOffset (void) = DE_NULL;
259 IterateResult iterate (void);
262 const GLenum m_internalFormat;
263 const char* m_internalFormatName;
264 const int m_targetSize;
267 PolygonOffsetTestCase::PolygonOffsetTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName, int canvasSize)
268 : TestCase (context, name, description)
269 , m_internalFormat (internalFormat)
270 , m_internalFormatName (internalFormatName)
271 , m_targetSize (canvasSize)
275 PolygonOffsetTestCase::IterateResult PolygonOffsetTestCase::iterate (void)
277 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
278 m_testCtx.getLog() << tcu::TestLog::Message << "Testing PolygonOffset with " << m_internalFormatName << " depth buffer." << tcu::TestLog::EndMessage;
280 if (m_internalFormat == 0)
282 // default framebuffer
283 const int width = m_context.getRenderTarget().getWidth();
284 const int height = m_context.getRenderTarget().getHeight();
286 checkCanvasSize(width, height, m_targetSize, m_targetSize);
288 if (m_context.getRenderTarget().getDepthBits() == 0)
289 throw tcu::NotSupportedError("polygon offset tests require depth buffer");
295 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
297 // framebuffer object
298 GLuint colorRboId = 0;
299 GLuint depthRboId = 0;
303 gl.genRenderbuffers(1, &colorRboId);
304 gl.bindRenderbuffer(GL_RENDERBUFFER, colorRboId);
305 gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, m_targetSize, m_targetSize);
306 verifyError(m_testCtx, gl, GL_NO_ERROR);
308 gl.genRenderbuffers(1, &depthRboId);
309 gl.bindRenderbuffer(GL_RENDERBUFFER, depthRboId);
310 gl.renderbufferStorage(GL_RENDERBUFFER, m_internalFormat, m_targetSize, m_targetSize);
311 verifyError(m_testCtx, gl, GL_NO_ERROR);
313 gl.genFramebuffers(1, &fboId);
314 gl.bindFramebuffer(GL_FRAMEBUFFER, fboId);
315 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRboId);
316 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRboId);
317 verifyError(m_testCtx, gl, GL_NO_ERROR);
319 fboComplete = gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
324 gl.deleteFramebuffers(1, &fboId);
325 gl.deleteRenderbuffers(1, &depthRboId);
326 gl.deleteRenderbuffers(1, &colorRboId);
329 throw tcu::NotSupportedError("could not create fbo for testing.");
337 class UsageTestCase : public PolygonOffsetTestCase
340 UsageTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
342 void testPolygonOffset (void);
345 UsageTestCase::UsageTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
346 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
350 void UsageTestCase::testPolygonOffset (void)
354 const tcu::Vec4 triangle[] =
356 tcu::Vec4(-1, 1, 0, 1),
357 tcu::Vec4( 1, 1, 0, 1),
358 tcu::Vec4( 1, -1, 0, 1),
361 tcu::TestLog& log = m_testCtx.getLog();
362 tcu::Surface testImage (m_targetSize, m_targetSize);
363 tcu::Surface referenceImage (m_targetSize, m_targetSize);
367 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
368 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
369 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
370 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
375 TCU_FAIL("Shader compile failed.");
378 gl.clearColor (0, 0, 0, 1);
379 gl.clearDepthf (1.0f);
380 gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
381 gl.viewport (0, 0, m_targetSize, m_targetSize);
382 gl.useProgram (program.getProgram());
383 gl.enable (GL_DEPTH_TEST);
384 gl.depthFunc (GL_LEQUAL); // make test pass if polygon offset doesn't do anything. It has its own test case. This test is only for to detect always-on cases.
386 log << TestLog::Message << "DepthFunc = GL_LEQUAL" << TestLog::EndMessage;
388 gl.enableVertexAttribArray (positionLoc);
389 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangle);
391 //draw back (offset disabled)
393 log << TestLog::Message << "Draw bottom-right. Color = White.\tState: PolygonOffset(0, -2), POLYGON_OFFSET_FILL disabled." << TestLog::EndMessage;
395 gl.polygonOffset (0, -2);
396 gl.disable (GL_POLYGON_OFFSET_FILL);
397 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
398 gl.drawArrays (GL_TRIANGLES, 0, 3);
402 log << TestLog::Message << "Draw bottom-right. Color = Red.\tState: PolygonOffset(0, -1), POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
404 gl.polygonOffset (0, -1);
405 gl.enable (GL_POLYGON_OFFSET_FILL);
406 gl.vertexAttrib4f (colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
407 gl.drawArrays (GL_TRIANGLES, 0, 3);
409 gl.disableVertexAttribArray (positionLoc);
413 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
416 // render reference image
418 rr::Renderer referenceRenderer;
419 rr::VertexAttrib attribs[2];
420 rr::RenderState state((rr::ViewportState)(rr::WindowRectangle(0, 0, m_targetSize, m_targetSize)));
422 PositionColorShader program;
424 attribs[0].type = rr::VERTEXATTRIBTYPE_FLOAT;
426 attribs[0].stride = 0;
427 attribs[0].instanceDivisor = 0;
428 attribs[0].pointer = triangle;
430 attribs[1].type = rr::VERTEXATTRIBTYPE_DONT_CARE;
431 attribs[1].generic = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
433 tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
435 log << TestLog::Message << "Expecting: Bottom-right = Red." << TestLog::EndMessage;
437 referenceRenderer.draw(
440 rr::RenderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(referenceImage.getAccess())),
441 rr::Program(program.getVertexShader(), program.getFragmentShader()),
444 rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, 3, 0)));
448 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
451 // UsageDisplacementTestCase
453 class UsageDisplacementTestCase : public PolygonOffsetTestCase
456 UsageDisplacementTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
459 tcu::Vec4 genRandomVec4 (de::Random& rnd) const;
460 void testPolygonOffset (void);
463 UsageDisplacementTestCase::UsageDisplacementTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
464 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
468 tcu::Vec4 UsageDisplacementTestCase::genRandomVec4 (de::Random& rnd) const
470 // generater triangle endpoint with following properties
471 // 1) it will not be clipped
472 // 2) it is not near either far or near plane to prevent possible problems related to depth clamping
473 // => w >= 1.0 and z in (-0.9, 0.9) range
476 retVal.x() = rnd.getFloat(-1, 1);
477 retVal.y() = rnd.getFloat(-1, 1);
478 retVal.z() = rnd.getFloat(-0.9f, 0.9f);
479 retVal.w() = 1.0f + rnd.getFloat();
484 void UsageDisplacementTestCase::testPolygonOffset (void)
488 de::Random rnd (0xdec0de);
489 tcu::TestLog& log = m_testCtx.getLog();
490 tcu::Surface testImage (m_targetSize, m_targetSize);
491 tcu::Surface referenceImage (m_targetSize, m_targetSize);
495 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
496 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
497 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
498 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
499 const int numIterations = 40;
504 TCU_FAIL("Shader compile failed.");
507 gl.clearColor (0, 0, 0, 1);
508 gl.clearDepthf (1.0f);
509 gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
510 gl.viewport (0, 0, m_targetSize, m_targetSize);
511 gl.useProgram (program.getProgram());
512 gl.enable (GL_DEPTH_TEST);
513 gl.enable (GL_POLYGON_OFFSET_FILL);
514 gl.enableVertexAttribArray (positionLoc);
515 gl.vertexAttrib4f (colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
517 log << TestLog::Message << "Framebuffer cleared, clear color = Black." << TestLog::EndMessage;
518 log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
520 // draw colorless (mask = 0,0,0) triangle at random* location, set offset and render green triangle with depthfunc = equal
521 // *) w >= 1.0 and z in (-1, 1) range
522 for (int iterationNdx = 0; iterationNdx < numIterations; ++iterationNdx)
524 const bool offsetDirection = rnd.getBool();
525 const float offset = offsetDirection ? -1.0f : 1.0f;
526 tcu::Vec4 triangle[3];
528 for (int vertexNdx = 0; vertexNdx < DE_LENGTH_OF_ARRAY(triangle); ++vertexNdx)
529 triangle[vertexNdx] = genRandomVec4(rnd);
531 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangle);
533 log << TestLog::Message << "Setup triangle with random coordinates:" << TestLog::EndMessage;
534 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangle); ++ndx)
535 log << TestLog::Message
536 << "\tx=" << triangle[ndx].x()
537 << "\ty=" << triangle[ndx].y()
538 << "\tz=" << triangle[ndx].z()
539 << "\tw=" << triangle[ndx].w()
540 << TestLog::EndMessage;
542 log << TestLog::Message << "Draw colorless triangle.\tState: DepthFunc = GL_ALWAYS, PolygonOffset(0, 0)." << TestLog::EndMessage;
544 gl.depthFunc (GL_ALWAYS);
545 gl.polygonOffset (0, 0);
546 gl.colorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
547 gl.drawArrays (GL_TRIANGLES, 0, 3);
549 // all fragments should have different Z => DepthFunc == GL_EQUAL fails with every fragment
551 log << TestLog::Message << "Draw green triangle.\tState: DepthFunc = GL_EQUAL, PolygonOffset(0, " << offset << ")." << TestLog::EndMessage;
553 gl.depthFunc (GL_EQUAL);
554 gl.polygonOffset (0, offset);
555 gl.colorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
556 gl.drawArrays (GL_TRIANGLES, 0, 3);
558 log << TestLog::Message << TestLog::EndMessage; // empty line for clarity
561 gl.disableVertexAttribArray (positionLoc);
565 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
568 // render reference image
569 log << TestLog::Message << "Expecting black framebuffer." << TestLog::EndMessage;
570 tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
573 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
576 // UsagePositiveNegativeTestCase
578 class UsagePositiveNegativeTestCase : public PolygonOffsetTestCase
581 UsagePositiveNegativeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
583 void testPolygonOffset (void);
586 UsagePositiveNegativeTestCase::UsagePositiveNegativeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
587 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
591 void UsagePositiveNegativeTestCase::testPolygonOffset (void)
595 const tcu::Vec4 triangleBottomRight[] =
597 tcu::Vec4(-1, 1, 0, 1),
598 tcu::Vec4( 1, 1, 0, 1),
599 tcu::Vec4( 1, -1, 0, 1),
601 const tcu::Vec4 triangleTopLeft[] =
603 tcu::Vec4(-1, -1, 0, 1),
604 tcu::Vec4(-1, 1, 0, 1),
605 tcu::Vec4( 1, -1, 0, 1),
608 tcu::TestLog& log = m_testCtx.getLog();
609 tcu::Surface testImage (m_targetSize, m_targetSize);
610 tcu::Surface referenceImage (m_targetSize, m_targetSize);
614 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
615 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
616 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
617 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
622 TCU_FAIL("Shader compile failed.");
625 gl.clearColor (0, 0, 0, 1);
626 gl.clearDepthf (1.0f);
627 gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
628 gl.viewport (0, 0, m_targetSize, m_targetSize);
629 gl.depthFunc (GL_LESS);
630 gl.useProgram (program.getProgram());
631 gl.enable (GL_DEPTH_TEST);
632 gl.enable (GL_POLYGON_OFFSET_FILL);
633 gl.enableVertexAttribArray (positionLoc);
635 log << TestLog::Message << "DepthFunc = GL_LESS." << TestLog::EndMessage;
636 log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
638 //draw top left (negative offset test)
640 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleTopLeft);
642 log << TestLog::Message << "Draw top-left. Color = White.\tState: PolygonOffset(0, 0)." << TestLog::EndMessage;
644 gl.polygonOffset (0, 0);
645 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
646 gl.drawArrays (GL_TRIANGLES, 0, 3);
648 log << TestLog::Message << "Draw top-left. Color = Green.\tState: PolygonOffset(0, -1)." << TestLog::EndMessage;
650 gl.polygonOffset (0, -1);
651 gl.vertexAttrib4f (colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
652 gl.drawArrays (GL_TRIANGLES, 0, 3);
655 //draw bottom right (positive offset test)
657 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleBottomRight);
659 log << TestLog::Message << "Draw bottom-right. Color = White.\tState: PolygonOffset(0, 1)." << TestLog::EndMessage;
661 gl.polygonOffset (0, 1);
662 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
663 gl.drawArrays (GL_TRIANGLES, 0, 3);
665 log << TestLog::Message << "Draw bottom-right. Color = Yellow.\tState: PolygonOffset(0, 0)." << TestLog::EndMessage;
667 gl.polygonOffset (0, 0);
668 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 0.0f, 1.0f);
669 gl.drawArrays (GL_TRIANGLES, 0, 3);
672 gl.disableVertexAttribArray (positionLoc);
676 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
679 // render reference image
681 rr::Renderer referenceRenderer;
682 rr::VertexAttrib attribs[2];
683 rr::RenderState state((rr::ViewportState)(rr::WindowRectangle(0, 0, m_targetSize, m_targetSize)));
685 PositionColorShader program;
687 attribs[0].type = rr::VERTEXATTRIBTYPE_FLOAT;
689 attribs[0].stride = 0;
690 attribs[0].instanceDivisor = 0;
691 attribs[0].pointer = triangleTopLeft;
693 attribs[1].type = rr::VERTEXATTRIBTYPE_DONT_CARE;
694 attribs[1].generic = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
696 tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
698 log << TestLog::Message << "Expecting: Top-left = Green, Bottom-right = Yellow." << TestLog::EndMessage;
700 referenceRenderer.draw(
703 rr::RenderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(referenceImage.getAccess())),
704 rr::Program(program.getVertexShader(), program.getFragmentShader()),
707 rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, 3, 0)));
709 attribs[0].pointer = triangleBottomRight;
710 attribs[1].generic = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
712 referenceRenderer.draw(
715 rr::RenderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(referenceImage.getAccess())),
716 rr::Program(program.getVertexShader(), program.getFragmentShader()),
719 rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, 3, 0)));
723 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
726 // ResultClampingTestCase
728 class ResultClampingTestCase : public PolygonOffsetTestCase
731 ResultClampingTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
733 void testPolygonOffset (void);
736 ResultClampingTestCase::ResultClampingTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
737 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
741 void ResultClampingTestCase::testPolygonOffset (void)
745 const tcu::Vec4 triangleBottomRight[] =
747 tcu::Vec4(-1, 1, 1, 1),
748 tcu::Vec4( 1, 1, 1, 1),
749 tcu::Vec4( 1, -1, 1, 1),
751 const tcu::Vec4 triangleTopLeft[] =
753 tcu::Vec4(-1, -1, -1, 1),
754 tcu::Vec4(-1, 1, -1, 1),
755 tcu::Vec4( 1, -1, -1, 1),
758 tcu::TestLog& log = m_testCtx.getLog();
759 tcu::Surface testImage (m_targetSize, m_targetSize);
760 tcu::Surface referenceImage (m_targetSize, m_targetSize);
764 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
765 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
766 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
767 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
772 TCU_FAIL("Shader compile failed.");
775 gl.clearColor (0, 0, 0, 1);
776 gl.clearDepthf (1.0f);
777 gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
778 gl.viewport (0, 0, m_targetSize, m_targetSize);
779 gl.useProgram (program.getProgram());
780 gl.enable (GL_DEPTH_TEST);
781 gl.enable (GL_POLYGON_OFFSET_FILL);
782 gl.enableVertexAttribArray (positionLoc);
784 log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
786 //draw bottom right (far)
788 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleBottomRight);
790 log << TestLog::Message << "Draw bottom-right. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 8), Polygon Z = 1.0. (Result depth should clamp to 1.0)." << TestLog::EndMessage;
792 gl.depthFunc (GL_ALWAYS);
793 gl.polygonOffset (0, 8);
794 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
795 gl.drawArrays (GL_TRIANGLES, 0, 3);
797 log << TestLog::Message << "Draw bottom-right. Color = Red.\tState: DepthFunc = GREATER, PolygonOffset(0, 9), Polygon Z = 1.0. (Result depth should clamp to 1.0 too)" << TestLog::EndMessage;
799 gl.depthFunc (GL_GREATER);
800 gl.polygonOffset (0, 9);
801 gl.vertexAttrib4f (colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
802 gl.drawArrays (GL_TRIANGLES, 0, 3);
805 //draw top left (near)
807 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleTopLeft);
809 log << TestLog::Message << "Draw top-left. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, -8), Polygon Z = -1.0. (Result depth should clamp to -1.0)" << TestLog::EndMessage;
811 gl.depthFunc (GL_ALWAYS);
812 gl.polygonOffset (0, -8);
813 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
814 gl.drawArrays (GL_TRIANGLES, 0, 3);
816 log << TestLog::Message << "Draw top-left. Color = Yellow.\tState: DepthFunc = LESS, PolygonOffset(0, -9), Polygon Z = -1.0. (Result depth should clamp to -1.0 too)." << TestLog::EndMessage;
818 gl.depthFunc (GL_LESS);
819 gl.polygonOffset (0, -9);
820 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 0.0f, 1.0f);
821 gl.drawArrays (GL_TRIANGLES, 0, 3);
824 gl.disableVertexAttribArray (positionLoc);
828 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
831 // render reference image
832 log << TestLog::Message << "Expecting: Top-left = White, Bottom-right = White." << TestLog::EndMessage;
833 tcu::clear(referenceImage.getAccess(), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
836 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
839 // UsageSlopeTestCase
841 class UsageSlopeTestCase : public PolygonOffsetTestCase
844 UsageSlopeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
846 void testPolygonOffset (void);
849 UsageSlopeTestCase::UsageSlopeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
850 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
854 void UsageSlopeTestCase::testPolygonOffset (void)
858 const tcu::Vec4 triangleBottomRight[] =
860 tcu::Vec4(-1, 1, 0.0f, 1),
861 tcu::Vec4( 1, 1, 0.9f, 1),
862 tcu::Vec4( 1, -1, 0.9f, 1),
864 const tcu::Vec4 triangleTopLeft[] =
866 tcu::Vec4(-1, -1, -0.9f, 1),
867 tcu::Vec4(-1, 1, 0.9f, 1),
868 tcu::Vec4( 1, -1, 0.0f, 1),
871 tcu::TestLog& log = m_testCtx.getLog();
872 tcu::Surface testImage (m_targetSize, m_targetSize);
873 tcu::Surface referenceImage (m_targetSize, m_targetSize);
877 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
878 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
879 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
880 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
885 TCU_FAIL("Shader compile failed.");
888 gl.clearColor (0, 0, 0, 1);
889 gl.clearDepthf (1.0f);
890 gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
891 gl.viewport (0, 0, m_targetSize, m_targetSize);
892 gl.useProgram (program.getProgram());
893 gl.enable (GL_DEPTH_TEST);
894 gl.enable (GL_POLYGON_OFFSET_FILL);
895 gl.enableVertexAttribArray (positionLoc);
897 log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
899 //draw top left (negative offset test)
901 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleTopLeft);
903 log << TestLog::Message << "Draw top-left. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 0)." << TestLog::EndMessage;
905 gl.depthFunc (GL_ALWAYS);
906 gl.polygonOffset (0, 0);
907 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
908 gl.drawArrays (GL_TRIANGLES, 0, 3);
910 log << TestLog::Message << "Draw top-left. Color = Green.\tState: DepthFunc = LESS, PolygonOffset(-1, 0)." << TestLog::EndMessage;
912 gl.depthFunc (GL_LESS);
913 gl.polygonOffset (-1, 0);
914 gl.vertexAttrib4f (colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
915 gl.drawArrays (GL_TRIANGLES, 0, 3);
918 //draw bottom right (positive offset test)
920 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleBottomRight);
922 log << TestLog::Message << "Draw bottom-right. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 0)." << TestLog::EndMessage;
924 gl.depthFunc (GL_ALWAYS);
925 gl.polygonOffset (0, 0);
926 gl.vertexAttrib4f (colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
927 gl.drawArrays (GL_TRIANGLES, 0, 3);
929 log << TestLog::Message << "Draw bottom-right. Color = Green.\tState: DepthFunc = GREATER, PolygonOffset(1, 0)." << TestLog::EndMessage;
931 gl.depthFunc (GL_GREATER);
932 gl.polygonOffset (1, 0);
933 gl.vertexAttrib4f (colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
934 gl.drawArrays (GL_TRIANGLES, 0, 3);
937 gl.disableVertexAttribArray (positionLoc);
941 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
944 // render reference image
945 log << TestLog::Message << "Expecting: Top-left = Green, Bottom-right = Green." << TestLog::EndMessage;
946 tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
949 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
954 class ZeroSlopeTestCase : public PolygonOffsetTestCase
957 ZeroSlopeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
959 void testPolygonOffset (void);
962 ZeroSlopeTestCase::ZeroSlopeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
963 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
967 void ZeroSlopeTestCase::testPolygonOffset (void)
971 const tcu::Vec4 triangle[] =
973 tcu::Vec4(-0.4f, 0.4f, 0.0f, 1.0f),
974 tcu::Vec4(-0.8f, -0.5f, 0.0f, 1.0f),
975 tcu::Vec4( 0.7f, 0.2f, 0.0f, 1.0f),
978 tcu::TestLog& log = m_testCtx.getLog();
979 tcu::Surface testImage (m_targetSize, m_targetSize);
980 tcu::Surface referenceImage (m_targetSize, m_targetSize);
983 log << TestLog::Message << "Setup triangle with coordinates:" << TestLog::EndMessage;
984 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangle); ++ndx)
985 log << TestLog::Message
986 << "\tx=" << triangle[ndx].x()
987 << "\ty=" << triangle[ndx].y()
988 << "\tz=" << triangle[ndx].z()
989 << "\tw=" << triangle[ndx].w()
990 << TestLog::EndMessage;
994 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
995 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
996 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
997 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
1002 TCU_FAIL("Shader compile failed.");
1005 gl.clearColor (0, 0, 0, 1);
1006 gl.clearDepthf (1.0f);
1007 gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1008 gl.viewport (0, 0, m_targetSize, m_targetSize);
1009 gl.useProgram (program.getProgram());
1010 gl.enable (GL_DEPTH_TEST);
1011 gl.enable (GL_POLYGON_OFFSET_FILL);
1012 gl.enableVertexAttribArray (positionLoc);
1014 log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
1017 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangle);
1019 log << TestLog::Message << "Draw triangle. Color = Red.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 0)." << TestLog::EndMessage;
1021 gl.depthFunc (GL_ALWAYS);
1022 gl.polygonOffset (0, 0);
1023 gl.vertexAttrib4f (colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
1024 gl.drawArrays (GL_TRIANGLES, 0, 3);
1026 log << TestLog::Message << "Draw triangle. Color = Black.\tState: DepthFunc = EQUAL, PolygonOffset(4, 0)." << TestLog::EndMessage;
1028 gl.depthFunc (GL_EQUAL);
1029 gl.polygonOffset (4, 0); // triangle slope == 0
1030 gl.vertexAttrib4f (colorLoc, 0.0f, 0.0f, 0.0f, 1.0f);
1031 gl.drawArrays (GL_TRIANGLES, 0, 3);
1034 gl.disableVertexAttribArray (positionLoc);
1038 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
1041 // render reference image
1042 log << TestLog::Message << "Expecting black triangle." << TestLog::EndMessage;
1043 tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1046 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
1051 class OneSlopeTestCase : public PolygonOffsetTestCase
1054 OneSlopeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName);
1056 void testPolygonOffset (void);
1059 OneSlopeTestCase::OneSlopeTestCase (Context& context, const char* name, const char* description, GLenum internalFormat, const char* internalFormatName)
1060 : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
1064 void OneSlopeTestCase::testPolygonOffset (void)
1069 * setup vertices subject to following properties
1077 const float cornerDepth = float(m_targetSize);
1078 const tcu::Vec4 triangles[2][3] =
1081 tcu::Vec4(-1, -1, -cornerDepth, 1),
1082 tcu::Vec4(-1, 1, -cornerDepth, 1),
1083 tcu::Vec4( 1, -1, cornerDepth, 1),
1086 tcu::Vec4(-1, 1, cornerDepth, 1),
1087 tcu::Vec4( 1, 1, cornerDepth, 1),
1088 tcu::Vec4( 1, -1, -cornerDepth, 1),
1092 tcu::TestLog& log = m_testCtx.getLog();
1093 tcu::Surface testImage (m_targetSize, m_targetSize);
1094 tcu::Surface referenceImage (m_targetSize, m_targetSize);
1096 // log triangle info
1097 log << TestLog::Message << "Setup triangle0 coordinates: (slope in window coordinates = 1.0)" << TestLog::EndMessage;
1098 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangles[0]); ++ndx)
1099 log << TestLog::Message
1100 << "\tx=" << triangles[0][ndx].x()
1101 << "\ty=" << triangles[0][ndx].y()
1102 << "\tz=" << triangles[0][ndx].z()
1103 << "\tw=" << triangles[0][ndx].w()
1104 << TestLog::EndMessage;
1105 log << TestLog::Message << "Setup triangle1 coordinates: (slope in window coordinates = 1.0)" << TestLog::EndMessage;
1106 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangles[1]); ++ndx)
1107 log << TestLog::Message
1108 << "\tx=" << triangles[1][ndx].x()
1109 << "\ty=" << triangles[1][ndx].y()
1110 << "\tz=" << triangles[1][ndx].z()
1111 << "\tw=" << triangles[1][ndx].w()
1112 << TestLog::EndMessage;
1114 // render test image
1116 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1117 const glu::ShaderProgram program (m_context.getRenderContext(), glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
1118 const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
1119 const GLint colorLoc = gl.getAttribLocation(program.getProgram(), "a_color");
1121 if (!program.isOk())
1124 TCU_FAIL("Shader compile failed.");
1127 gl.clearColor (0, 0, 0, 1);
1128 gl.clear (GL_COLOR_BUFFER_BIT);
1129 gl.viewport (0, 0, m_targetSize, m_targetSize);
1130 gl.useProgram (program.getProgram());
1131 gl.enable (GL_DEPTH_TEST);
1132 gl.enable (GL_POLYGON_OFFSET_FILL);
1133 gl.enableVertexAttribArray (positionLoc);
1135 log << TestLog::Message << "Framebuffer cleared, clear color = Black." << TestLog::EndMessage;
1136 log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
1138 // top left (positive offset)
1140 log << TestLog::Message << "Clear depth to 1.0." << TestLog::EndMessage;
1142 gl.clearDepthf (1.0f); // far
1143 gl.clear (GL_DEPTH_BUFFER_BIT);
1145 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangles[0]);
1147 log << TestLog::Message << "Draw triangle0. Color = Red.\tState: DepthFunc = NOTEQUAL, PolygonOffset(10, 0). (Result depth should clamp to 1.0)." << TestLog::EndMessage;
1149 gl.polygonOffset (10, 0); // clamps any depth on the triangle to 1
1150 gl.depthFunc (GL_NOTEQUAL);
1151 gl.vertexAttrib4f (colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
1152 gl.drawArrays (GL_TRIANGLES, 0, 3);
1154 // bottom right (negative offset)
1156 log << TestLog::Message << "Clear depth to 0.0." << TestLog::EndMessage;
1158 gl.clearDepthf (0.0f); // far
1159 gl.clear (GL_DEPTH_BUFFER_BIT);
1161 gl.vertexAttribPointer (positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangles[1]);
1163 log << TestLog::Message << "Draw triangle1. Color = Green.\tState: DepthFunc = NOTEQUAL, PolygonOffset(-10, 0). (Result depth should clamp to 0.0)." << TestLog::EndMessage;
1165 gl.polygonOffset (-10, 0); // clamps depth to 0
1166 gl.depthFunc (GL_NOTEQUAL);
1167 gl.vertexAttrib4f (colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
1168 gl.drawArrays (GL_TRIANGLES, 0, 3);
1171 gl.disableVertexAttribArray (positionLoc);
1175 glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
1178 // render reference image
1179 log << TestLog::Message << "Expecting black framebuffer." << TestLog::EndMessage;
1180 tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1183 verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
1188 PolygonOffsetTests::PolygonOffsetTests (Context& context)
1189 : TestCaseGroup(context, "polygon_offset", "Polygon offset tests")
1193 PolygonOffsetTests::~PolygonOffsetTests (void)
1197 void PolygonOffsetTests::init (void)
1199 const struct DepthBufferFormat
1204 TYPE_FLOATING_POINT,
1208 GLenum internalFormat;
1210 BufferType floatingPoint;
1214 { 0, 0, DepthBufferFormat::TYPE_UNKNOWN, "default" },
1215 { GL_DEPTH_COMPONENT16, 16, DepthBufferFormat::TYPE_FIXED_POINT, "fixed16" },
1218 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthFormats); ++ndx)
1220 const DepthBufferFormat& format = depthFormats[ndx];
1223 addChild(new UsageTestCase(m_context, (std::string(format.name) + "_enable").c_str(), "test enable GL_POLYGON_OFFSET_FILL", format.internalFormat, format.name));
1225 // Really moves the polygons ?
1226 addChild(new UsageDisplacementTestCase(m_context, (std::string(format.name) + "_displacement_with_units").c_str(), "test polygon offset", format.internalFormat, format.name));
1228 // Really moves the polygons to right direction ?
1229 addChild(new UsagePositiveNegativeTestCase(m_context, (std::string(format.name) + "_render_with_units").c_str(), "test polygon offset", format.internalFormat, format.name));
1231 // Is total result clamped to [0,1] like promised?
1232 addChild(new ResultClampingTestCase(m_context, (std::string(format.name) + "_result_depth_clamp").c_str(), "test polygon offset clamping", format.internalFormat, format.name));
1234 // Slope really moves the polygon?
1235 addChild(new UsageSlopeTestCase(m_context, (std::string(format.name) + "_render_with_factor").c_str(), "test polygon offset factor", format.internalFormat, format.name));
1237 // Factor with zero slope
1238 addChild(new ZeroSlopeTestCase(m_context, (std::string(format.name) + "_factor_0_slope").c_str(), "test polygon offset factor", format.internalFormat, format.name));
1240 // Factor with 1.0 slope
1241 addChild(new OneSlopeTestCase(m_context, (std::string(format.name) + "_factor_1_slope").c_str(), "test polygon offset factor", format.internalFormat, format.name));