1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL (ES) 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 GLES Scissor tests
22 *//*--------------------------------------------------------------------*/
24 #include "glsScissorTests.hpp"
25 #include "glsTextureTestUtil.hpp"
28 #include "deRandom.hpp"
29 #include "deUniquePtr.hpp"
31 #include "tcuTestCase.hpp"
32 #include "tcuImageCompare.hpp"
33 #include "tcuVector.hpp"
34 #include "tcuVectorUtil.hpp"
35 #include "tcuTexture.hpp"
36 #include "tcuStringTemplate.hpp"
38 #include "gluStrUtil.hpp"
39 #include "gluDrawUtil.hpp"
40 #include "gluPixelTransfer.hpp"
41 #include "gluObjectWrapper.hpp"
43 #include "glwEnums.hpp"
44 #include "glwFunctions.hpp"
57 using namespace ScissorTestInternal;
58 using namespace glw; // GL types
60 using tcu::ConstPixelBufferAccess;
61 using tcu::PixelBufferAccess;
72 void drawQuad (const glw::Functions& gl, deUint32 program, const Vec3& p0, const Vec3& p1)
75 const float hz = (p0.z() + p1.z()) * 0.5f;
76 const float position[] =
78 p0.x(), p0.y(), p0.z(), 1.0f,
79 p0.x(), p1.y(), hz, 1.0f,
80 p1.x(), p0.y(), hz, 1.0f,
81 p1.x(), p1.y(), p1.z(), 1.0f
84 const deUint16 indices[] = { 0, 1, 2, 2, 1, 3 };
86 const deInt32 posLoc = gl.getAttribLocation(program, "a_position");
88 gl.useProgram(program);
89 gl.enableVertexAttribArray(posLoc);
90 gl.vertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &position[0]);
92 gl.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_SHORT, &indices[0]);
94 gl.disableVertexAttribArray(posLoc);
98 void drawPrimitives (const glw::Functions& gl, deUint32 program, const deUint32 type, const vector<float>& vertices, const vector<deUint16>& indices)
100 const deInt32 posLoc = gl.getAttribLocation(program, "a_position");
102 TCU_CHECK(posLoc >= 0);
104 gl.useProgram(program);
105 gl.enableVertexAttribArray(posLoc);
106 gl.vertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &vertices[0]);
108 gl.drawElements(type, GLsizei(indices.size()), GL_UNSIGNED_SHORT, &indices[0]);
110 gl.disableVertexAttribArray(posLoc);
114 void clearEdges (const tcu::PixelBufferAccess& access, const T& color, const IVec4& scissorArea)
116 for (int y = 0; y < access.getHeight(); y++)
117 for (int x = 0; x < access.getWidth(); x++)
119 if (y < scissorArea.y() ||
120 y >= scissorArea.y() + scissorArea.w() ||
121 x < scissorArea.x() ||
122 x >= scissorArea.x()+ scissorArea.z())
123 access.setPixel(color, x, y);
127 glu::ProgramSources genShaders(glu::GLSLVersion version)
129 const string vtxSource = "${VERSION}\n"
130 "${IN} highp vec4 a_position;\n"
132 " gl_Position = a_position;\n"
135 const string frgSource = "${VERSION}\n"
137 "uniform highp vec4 u_color;\n"
139 " ${OUTPUT} = u_color;\n"
142 map<string, string> params;
146 case glu::GLSL_VERSION_100_ES:
147 params["VERSION"] = "#version 100";
148 params["IN"] = "attribute";
149 params["OUT_DECL"] = "";
150 params["OUTPUT"] = "gl_FragColor";
153 case glu::GLSL_VERSION_300_ES:
154 case glu::GLSL_VERSION_310_ES: // Assumed to support 3.0
155 params["VERSION"] = "#version 300 es";
157 params["OUT_DECL"] = "out mediump vec4 f_color;\n";
158 params["OUTPUT"] = "f_color";
162 DE_FATAL("Unsupported version");
165 return glu::makeVtxFragSources(tcu::StringTemplate(vtxSource).specialize(params), tcu::StringTemplate(frgSource).specialize(params));
168 // Wrapper class, provides iterator & reporting logic
169 class ScissorCase : public tcu::TestCase
172 ScissorCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char *name, const char* desc, const Vec4& scissorArea);
173 virtual ~ScissorCase (void) {}
175 virtual IterateResult iterate (void);
178 virtual void render (GLuint program, const IVec4& viewport) const = 0;
180 glu::RenderContext& m_renderCtx;
181 const Vec4 m_scissorArea;
184 ScissorCase::ScissorCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char *name, const char* desc, const Vec4& scissorArea)
185 : TestCase (testCtx, name, desc)
186 , m_renderCtx (renderCtx)
187 , m_scissorArea (scissorArea)
191 ScissorCase::IterateResult ScissorCase::iterate (void)
193 using TextureTestUtil::RandomViewport;
195 const glw::Functions& gl = m_renderCtx.getFunctions();
196 TestLog& log = m_testCtx.getLog();
197 const tcu::PixelFormat renderFormat = m_renderCtx.getRenderTarget().getPixelFormat();
198 const tcu::Vec4 threshold = 0.02f * UVec4(1u << de::max(0, 8 - renderFormat.redBits),
199 1u << de::max(0, 8 - renderFormat.greenBits),
200 1u << de::max(0, 8 - renderFormat.blueBits),
201 1u << de::max(0, 8 - renderFormat.alphaBits)).asFloat();
202 const glu::ShaderProgram shader (m_renderCtx, genShaders(glu::getContextTypeGLSLVersion(m_renderCtx.getType())));
204 const RandomViewport viewport (m_renderCtx.getRenderTarget(), 256, 256, deStringHash(getName()));
205 const IVec4 relScissorArea (int(m_scissorArea.x() * (float)viewport.width),
206 int(m_scissorArea.y() * (float)viewport.height),
207 int(m_scissorArea.z() * (float)viewport.width),
208 int(m_scissorArea.w() * (float)viewport.height));
209 const IVec4 absScissorArea (relScissorArea.x() + viewport.x,
210 relScissorArea.y() + viewport.y,
214 tcu::Surface refImage (viewport.width, viewport.height);
215 tcu::Surface resImage (viewport.width, viewport.height);
220 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Shader compile/link failed");
224 log << TestLog::Message << "Viewport area is " << IVec4(viewport.x, viewport.y, viewport.width, viewport.height) << TestLog::EndMessage;
225 log << TestLog::Message << "Scissor area is " << absScissorArea << TestLog::EndMessage;
227 // Render reference (no scissors)
229 log << TestLog::Message << "Rendering reference (scissors disabled)" << TestLog::EndMessage;
231 gl.useProgram(shader.getProgram());
232 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
234 gl.clearColor(0.125f, 0.25f, 0.5f, 1.0f);
235 gl.clearDepthf(1.0f);
237 gl.disable(GL_DEPTH_TEST);
238 gl.disable(GL_STENCIL_TEST);
239 gl.disable(GL_SCISSOR_TEST);
240 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
242 render(shader.getProgram(), IVec4(viewport.x, viewport.y, viewport.width, viewport.height));
244 glu::readPixels(m_renderCtx, viewport.x, viewport.y, refImage.getAccess());
245 GLU_CHECK_ERROR(gl.getError());
248 // Render result (scissors)
250 log << TestLog::Message << "Rendering result (scissors enabled)" << TestLog::EndMessage;
252 gl.useProgram(shader.getProgram());
253 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
255 gl.clearColor(0.125f, 0.25f, 0.5f, 1.0f);
256 gl.clearDepthf(1.0f);
258 gl.disable(GL_DEPTH_TEST);
259 gl.disable(GL_STENCIL_TEST);
260 gl.disable(GL_SCISSOR_TEST);
261 gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
263 gl.scissor(absScissorArea.x(), absScissorArea.y(), absScissorArea.z(), absScissorArea.w());
264 gl.enable(GL_SCISSOR_TEST);
266 render(shader.getProgram(), IVec4(viewport.x, viewport.y, viewport.width, viewport.height));
268 glu::readPixels(m_renderCtx, viewport.x, viewport.y, resImage.getAccess());
269 GLU_CHECK_ERROR(gl.getError());
272 // Manual 'scissors' for reference image
273 log << TestLog::Message << "Clearing area outside scissor area from reference" << TestLog::EndMessage;
274 clearEdges(refImage.getAccess(), IVec4(32, 64, 128, 255), relScissorArea);
276 if (tcu::floatThresholdCompare(log, "ComparisonResult", "Image comparison result", refImage.getAccess(), resImage.getAccess(), threshold, tcu::COMPARE_LOG_RESULT))
277 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
279 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
284 // Tests scissoring with multiple primitive types
285 class ScissorPrimitiveCase : public ScissorCase
288 ScissorPrimitiveCase (tcu::TestContext& testCtx,
289 glu::RenderContext& renderCtx,
292 const Vec4& scissorArea,
293 const Vec4& renderArea,
296 virtual ~ScissorPrimitiveCase (void){}
299 virtual void render (GLuint program, const IVec4& viewport) const;
302 const Vec4 m_renderArea;
303 const PrimitiveType m_primitiveType;
304 const int m_primitiveCount;
307 ScissorPrimitiveCase::ScissorPrimitiveCase (tcu::TestContext& testCtx,
308 glu::RenderContext& renderCtx,
311 const Vec4& scissorArea,
312 const Vec4& renderArea,
315 : ScissorCase (testCtx, renderCtx, name, desc, scissorArea)
316 , m_renderArea (renderArea)
317 , m_primitiveType (type)
318 , m_primitiveCount (primitiveCount)
322 void ScissorPrimitiveCase::render (GLuint program, const IVec4&) const
324 const glw::Functions& gl = m_renderCtx.getFunctions();
325 const Vec4 white (1.0f, 1.0f, 1.0f, 1.0);
326 const Vec4 primitiveArea (m_renderArea.x()*2.0f-1.0f,
327 m_renderArea.x()*2.0f-1.0f,
328 m_renderArea.z()*2.0f,
329 m_renderArea.w()*2.0f);
331 static const float quadPositions[] =
338 static const float triPositions[] =
344 static const float linePositions[] =
349 static const float pointPosition[] =
354 const float* positionSet[] = { pointPosition, linePositions, triPositions, quadPositions };
355 const int vertexCountSet[]= { 1, 2, 3, 4 };
356 const int indexCountSet[] = { 1, 2, 3, 6 };
358 const deUint16 baseIndices[] = { 0, 1, 2, 2, 1, 3 };
359 const float* basePositions = positionSet[m_primitiveType];
360 const int vertexCount = vertexCountSet[m_primitiveType];
361 const int indexCount = indexCountSet[m_primitiveType];
363 const float scale = 1.44f/deFloatSqrt(float(m_primitiveCount)*2.0f); // Magic value to roughly fill the render area with primitives at a readable density
364 vector<float> positions (4*vertexCount*m_primitiveCount);
365 vector<deUint16> indices (indexCount*m_primitiveCount);
366 de::Random rng (1234);
368 for (int primNdx = 0; primNdx < m_primitiveCount; primNdx++)
370 const float dx = m_primitiveCount>1 ? rng.getFloat() : 0.0f;
371 const float dy = m_primitiveCount>1 ? rng.getFloat() : 0.0f;
373 for (int vertNdx = 0; vertNdx < vertexCount; vertNdx++)
375 const int ndx = primNdx*4*vertexCount + vertNdx*4;
376 positions[ndx+0] = (basePositions[vertNdx*2 + 0]*scale + dx)*primitiveArea.z() + primitiveArea.x();
377 positions[ndx+1] = (basePositions[vertNdx*2 + 1]*scale + dy)*primitiveArea.w() + primitiveArea.y();
378 positions[ndx+2] = 0.2f;
379 positions[ndx+3] = 1.0f;
382 for (int ndx = 0; ndx < indexCount; ndx++)
383 indices[primNdx*indexCount + ndx] = (deUint16)(baseIndices[ndx] + primNdx*vertexCount);
386 gl.uniform4fv(gl.getUniformLocation(program, "u_color"), 1, white.m_data);
388 switch (m_primitiveType)
390 case TRIANGLE: drawPrimitives(gl, program, GL_TRIANGLES, positions, indices); break;
391 case LINE: drawPrimitives(gl, program, GL_LINES, positions, indices); break;
392 case POINT: drawPrimitives(gl, program, GL_POINTS, positions, indices); break;
393 default: DE_ASSERT(false); break;
397 // Test effect of scissor on default framebuffer clears
398 class ScissorClearCase : public ScissorCase
401 ScissorClearCase (tcu::TestContext& testCtx,
402 glu::RenderContext& renderCtx,
405 const Vec4& scissorArea,
407 virtual ~ScissorClearCase (void) {}
409 virtual void init (void);
412 virtual void render (GLuint program, const IVec4& viewport) const;
415 const deUint32 m_clearMode; //!< Combination of the flags accepted by glClear
418 ScissorClearCase::ScissorClearCase (tcu::TestContext& testCtx,
419 glu::RenderContext& renderCtx,
422 const Vec4& scissorArea,
424 : ScissorCase (testCtx, renderCtx, name, desc, scissorArea)
425 , m_clearMode (clearMode)
429 void ScissorClearCase::init (void)
431 if ((m_clearMode & GL_DEPTH_BUFFER_BIT) && m_renderCtx.getRenderTarget().getDepthBits() == 0)
432 throw tcu::NotSupportedError("Cannot clear depth; no depth buffer present", "", __FILE__, __LINE__);
433 else if ((m_clearMode & GL_STENCIL_BUFFER_BIT) && m_renderCtx.getRenderTarget().getStencilBits() == 0)
434 throw tcu::NotSupportedError("Cannot clear stencil; no stencil buffer present", "", __FILE__, __LINE__);
437 void ScissorClearCase::render (GLuint program, const IVec4&) const
439 const glw::Functions& gl = m_renderCtx.getFunctions();
440 const Vec4 white (1.0f, 1.0f, 1.0f, 1.0);
442 gl.clearColor(0.6f, 0.1f, 0.1f, 1.0);
443 gl.clearDepthf(0.0f);
445 if (m_clearMode & GL_DEPTH_BUFFER_BIT)
447 gl.enable(GL_DEPTH_TEST);
448 gl.depthFunc(GL_GREATER);
451 if (m_clearMode & GL_STENCIL_BUFFER_BIT)
453 gl.clearStencil(123);
454 gl.enable(GL_STENCIL_TEST);
455 gl.stencilFunc(GL_EQUAL, 123, ~0u);
458 if (m_clearMode & GL_COLOR_BUFFER_BIT)
459 gl.clearColor(0.1f, 0.6f, 0.1f, 1.0);
461 gl.clear(m_clearMode);
462 gl.disable(GL_SCISSOR_TEST);
464 gl.uniform4fv(gl.getUniformLocation(program, "u_color"), 1, white.getPtr());
466 if (!(m_clearMode & GL_COLOR_BUFFER_BIT))
467 drawQuad(gl, program, Vec3(-1.0f, -1.0f, 0.5f), Vec3(1.0f, 1.0f, 0.5f));
469 gl.disable(GL_DEPTH_TEST);
470 gl.disable(GL_STENCIL_TEST);
473 class FramebufferBlitCase : public ScissorCase
476 FramebufferBlitCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* desc, const Vec4& scissorArea);
477 virtual ~FramebufferBlitCase (void) {}
479 virtual void init (void);
480 virtual void deinit (void);
483 typedef de::MovePtr<glu::Framebuffer> FramebufferP;
487 virtual void render (GLuint program, const IVec4& viewport) const;
492 FramebufferBlitCase::FramebufferBlitCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* desc, const Vec4& scissorArea)
493 : ScissorCase(testCtx, renderCtx, name, desc, scissorArea)
497 void FramebufferBlitCase::init (void)
499 if (m_renderCtx.getRenderTarget().getNumSamples())
500 throw tcu::NotSupportedError("Cannot blit to multisampled framebuffer", "", __FILE__, __LINE__);
502 const glw::Functions& gl = m_renderCtx.getFunctions();
503 const glu::Renderbuffer colorbuf (gl);
504 const tcu::Vec4 clearColor (1.0f, 0.5, 0.125f, 1.0f);
506 m_fbo = FramebufferP(new glu::Framebuffer(gl));
508 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, **m_fbo);
510 gl.bindRenderbuffer(GL_RENDERBUFFER, *colorbuf);
511 gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, SIZE, SIZE);
512 gl.framebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, *colorbuf);
514 gl.clearBufferfv(GL_COLOR, 0, clearColor.getPtr());
515 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_renderCtx.getDefaultFramebuffer());
518 void FramebufferBlitCase::deinit (void)
523 void FramebufferBlitCase::render(GLuint program, const IVec4& viewport) const
525 const glw::Functions& gl = m_renderCtx.getFunctions();
527 const int width = viewport.z();
528 const int height = viewport.w();
529 const deInt32 defaultFramebuffer = m_renderCtx.getDefaultFramebuffer();
533 // blit to default framebuffer
534 gl.bindFramebuffer(GL_READ_FRAMEBUFFER, **m_fbo);
535 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, defaultFramebuffer);
537 gl.blitFramebuffer(0, 0, SIZE, SIZE, viewport.x(), viewport.y(), viewport.x() + width, viewport.y() + height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
539 gl.bindFramebuffer(GL_READ_FRAMEBUFFER, defaultFramebuffer);
544 tcu::TextureFormat texFmt;
550 enum Type {FLOAT, INT, UINT};
561 Color(const float f_[4]) : type(FLOAT) { f[0] = f_[0]; f[1] = f_[1]; f[2] = f_[2]; f[3] = f_[3]; }
562 Color(const deInt32 i_[4]) : type(INT) { i[0] = i_[0]; i[1] = i_[1]; i[2] = i_[2]; i[3] = i_[3]; }
563 Color(const deUint32 u_[4]) : type(UINT) { u[0] = u_[0]; u[1] = u_[1]; u[2] = u_[2]; u[3] = u_[3]; }
566 class FramebufferClearCase : public tcu::TestCase
569 FramebufferClearCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* desc, ClearType clearType);
570 virtual ~FramebufferClearCase (void) {}
572 virtual IterateResult iterate (void);
575 static void clearBuffers (const glw::Functions& gl, Color color, float depth, int stencil);
576 static Color getBaseColor (const BufferFmtDesc& bufferFmt);
577 static Color getMainColor (const BufferFmtDesc& bufferFmt);
578 static BufferFmtDesc getBufferFormat (ClearType type);
580 virtual void render (GLuint program) const;
582 glu::RenderContext& m_renderCtx;
583 const ClearType m_clearType;
586 FramebufferClearCase::FramebufferClearCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* desc, ClearType clearType)
587 : tcu::TestCase (testCtx, name, desc)
588 , m_renderCtx (renderCtx)
589 , m_clearType (clearType)
593 void FramebufferClearCase::clearBuffers (const glw::Functions& gl, Color color, float depth, int stencil)
597 case Color::FLOAT: gl.clearBufferfv (GL_COLOR, 0, color.f); break;
598 case Color::INT: gl.clearBufferiv (GL_COLOR, 0, color.i); break;
599 case Color::UINT: gl.clearBufferuiv(GL_COLOR, 0, color.u); break;
604 gl.clearBufferfv(GL_DEPTH, 0, &depth);
605 gl.clearBufferiv(GL_STENCIL, 0, &stencil);
608 FramebufferClearCase::IterateResult FramebufferClearCase::iterate (void)
610 TestLog& log = m_testCtx.getLog();
611 const glw::Functions& gl = m_renderCtx.getFunctions();
612 const glu::ShaderProgram shader (m_renderCtx, genShaders(glu::getContextTypeGLSLVersion(m_renderCtx.getType())));
614 const glu::Framebuffer fbo (gl);
615 const glu::Renderbuffer colorbuf (gl);
616 const glu::Renderbuffer depthbuf (gl);
618 const BufferFmtDesc bufferFmt = getBufferFormat(m_clearType);
619 const Color baseColor = getBaseColor(bufferFmt);
621 const int width = 64;
622 const int height = 64;
624 const IVec4 scissorArea (8, 8, 48, 48);
626 vector<deUint8> refData (width*height*bufferFmt.texFmt.getPixelSize());
627 vector<deUint8> resData (width*height*bufferFmt.texFmt.getPixelSize());
629 tcu::PixelBufferAccess refAccess (bufferFmt.texFmt, width, height, 1, &refData[0]);
630 tcu::PixelBufferAccess resAccess (bufferFmt.texFmt, width, height, 1, &resData[0]);
635 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Shader compile/link failed");
639 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
640 gl.bindFramebuffer(GL_READ_FRAMEBUFFER, *fbo);
643 gl.bindRenderbuffer(GL_RENDERBUFFER, *colorbuf);
644 gl.renderbufferStorage(GL_RENDERBUFFER, bufferFmt.colorFmt, width, height);
645 gl.framebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, *colorbuf);
648 gl.bindRenderbuffer(GL_RENDERBUFFER, *depthbuf);
649 gl.renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
650 gl.framebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, *depthbuf);
652 log << TestLog::Message << "Scissor area is " << scissorArea << TestLog::EndMessage;
656 log << TestLog::Message << "Rendering reference (scissors disabled)" << TestLog::EndMessage;
658 gl.useProgram(shader.getProgram());
659 gl.viewport(0, 0, width, height);
661 gl.disable(GL_DEPTH_TEST);
662 gl.disable(GL_STENCIL_TEST);
663 gl.disable(GL_SCISSOR_TEST);
665 clearBuffers(gl, baseColor, 1.0f, 0);
667 render(shader.getProgram());
669 glu::readPixels(m_renderCtx, 0, 0, refAccess);
670 GLU_CHECK_ERROR(gl.getError());
675 log << TestLog::Message << "Rendering result (scissors enabled)" << TestLog::EndMessage;
677 gl.useProgram(shader.getProgram());
678 gl.viewport(0, 0, width, height);
680 gl.disable(GL_DEPTH_TEST);
681 gl.disable(GL_STENCIL_TEST);
682 gl.disable(GL_SCISSOR_TEST);
684 clearBuffers(gl, baseColor, 1.0f, 0);
686 gl.enable(GL_SCISSOR_TEST);
687 gl.scissor(scissorArea.x(), scissorArea.y(), scissorArea.z(), scissorArea.w());
689 render(shader.getProgram());
691 glu::readPixels(m_renderCtx, 0, 0, resAccess);
692 GLU_CHECK_ERROR(gl.getError());
696 bool resultOk = false;
698 switch (baseColor.type)
701 clearEdges(refAccess, Vec4(baseColor.f[0], baseColor.f[1], baseColor.f[2], baseColor.f[3]), scissorArea);
702 resultOk = tcu::floatThresholdCompare(log, "ComparisonResult", "Image comparison result", refAccess, resAccess, Vec4(0.02f, 0.02f, 0.02f, 0.02f), tcu::COMPARE_LOG_RESULT);
706 clearEdges(refAccess, IVec4(baseColor.i[0], baseColor.i[1], baseColor.i[2], baseColor.i[3]), scissorArea);
707 resultOk = tcu::intThresholdCompare(log, "ComparisonResult", "Image comparison result", refAccess, resAccess, UVec4(2, 2, 2, 2), tcu::COMPARE_LOG_RESULT);
711 clearEdges(refAccess, UVec4(baseColor.u[0], baseColor.u[1], baseColor.u[2], baseColor.u[3]), scissorArea);
712 resultOk = tcu::intThresholdCompare(log, "ComparisonResult", "Image comparison result", refAccess, resAccess, UVec4(2, 2, 2, 2), tcu::COMPARE_LOG_RESULT);
717 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
719 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
725 Color FramebufferClearCase::getBaseColor (const BufferFmtDesc& bufferFmt)
727 const float f[4] = {0.125f, 0.25f, 0.5f, 1.0f};
728 const deInt32 i[4] = {0, 0, 0, 0};
729 const deUint32 u[4] = {0, 0, 0, 0};
731 switch(bufferFmt.colorFmt)
733 case GL_RGBA8: return Color(f);
734 case GL_RGBA8I: return Color(i);
735 case GL_RGBA8UI: return Color(u);
743 Color FramebufferClearCase::getMainColor (const BufferFmtDesc& bufferFmt)
745 const float f[4] = {1.0f, 1.0f, 0.5f, 1.0f};
746 const deInt32 i[4] = {127, -127, 0, 127};
747 const deUint32 u[4] = {255, 255, 0, 255};
749 switch(bufferFmt.colorFmt)
751 case GL_RGBA8: return Color(f);
752 case GL_RGBA8I: return Color(i);
753 case GL_RGBA8UI: return Color(u);
761 BufferFmtDesc FramebufferClearCase::getBufferFormat (ClearType type)
763 BufferFmtDesc retval;
767 case CLEAR_COLOR_FLOAT:
768 retval.colorFmt = GL_RGBA16F;
769 retval.texFmt = tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::HALF_FLOAT);
770 DE_FATAL("Floating point clear not implemented");// \todo [2014-1-23 otto] pixel read format & type, nothing guaranteed, need extension...
773 case CLEAR_COLOR_INT:
774 retval.colorFmt = GL_RGBA8I;
775 retval.texFmt = tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::SIGNED_INT32);
778 case CLEAR_COLOR_UINT:
779 retval.colorFmt = GL_RGBA8UI;
780 retval.texFmt = tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32);
784 retval.colorFmt = GL_RGBA8;
785 retval.texFmt = tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
792 void FramebufferClearCase::render (GLuint program) const
794 const glw::Functions& gl = m_renderCtx.getFunctions();
796 const BufferFmtDesc bufferFmt = getBufferFormat(m_clearType);
797 const Color clearColor = getMainColor(bufferFmt);
799 const int clearStencil = 123;
800 const float clearDepth = 0.5f;
804 case CLEAR_COLOR_FIXED: gl.clearBufferfv (GL_COLOR, 0, clearColor.f); break;
805 case CLEAR_COLOR_FLOAT: gl.clearBufferfv (GL_COLOR, 0, clearColor.f); break;
806 case CLEAR_COLOR_INT: gl.clearBufferiv (GL_COLOR, 0, clearColor.i); break;
807 case CLEAR_COLOR_UINT: gl.clearBufferuiv(GL_COLOR, 0, clearColor.u); break;
808 case CLEAR_DEPTH: gl.clearBufferfv (GL_DEPTH, 0, &clearDepth); break;
809 case CLEAR_STENCIL: gl.clearBufferiv (GL_STENCIL, 0, &clearStencil); break;
810 case CLEAR_DEPTH_STENCIL: gl.clearBufferfi (GL_DEPTH_STENCIL, 0, clearDepth, clearStencil); break;
816 const bool useDepth = (m_clearType == CLEAR_DEPTH || m_clearType == CLEAR_DEPTH_STENCIL);
817 const bool useStencil = (m_clearType == CLEAR_STENCIL || m_clearType == CLEAR_DEPTH_STENCIL);
819 // Render something to expose changes to depth/stencil buffer
820 if (useDepth || useStencil)
823 gl.enable(GL_DEPTH_TEST);
826 gl.enable(GL_STENCIL_TEST);
828 gl.stencilFunc(GL_EQUAL, clearStencil, ~0u);
829 gl.depthFunc(GL_GREATER);
830 gl.disable(GL_SCISSOR_TEST);
832 gl.uniform4fv(gl.getUniformLocation(program, "u_color"), 1, clearColor.f);
833 drawQuad(gl, program, tcu::Vec3(-1.0f, -1.0f, 0.6f), tcu::Vec3(1.0f, 1.0f, 0.6f));
839 namespace ScissorTestInternal
842 tcu::TestNode* createPrimitiveTest (tcu::TestContext& testCtx,
843 glu::RenderContext& renderCtx,
846 const Vec4& scissorArea,
847 const Vec4& renderArea,
851 return new ScissorPrimitiveCase(testCtx, renderCtx, name, desc, scissorArea, renderArea, type, primitiveCount);
854 tcu::TestNode* createClearTest (tcu::TestContext& testCtx,
855 glu::RenderContext& renderCtx,
858 const Vec4& scissorArea,
861 return new ScissorClearCase(testCtx, renderCtx, name, desc, scissorArea, clearMode);
864 tcu::TestNode* createFramebufferClearTest (tcu::TestContext& testCtx,
865 glu::RenderContext& renderCtx,
870 return new FramebufferClearCase(testCtx, renderCtx, name, desc, clearType);
873 tcu::TestNode* createFramebufferBlitTest (tcu::TestContext& testCtx,
874 glu::RenderContext& renderCtx,
877 const Vec4& scissorArea)
879 return new FramebufferBlitCase(testCtx, renderCtx, name, desc, scissorArea);
882 } // ScissorTestInternal