13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program EGL Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * --------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test EGL_SWAP_BEHAVIOR_PRESERVED_BIT. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglPreservingSwapTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuEgl.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeWindow.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUtil.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwDefs.hpp" 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace egl 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GLES2Program; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReferenceProgram; 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass PreservingSwapTest : public TestCase 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum DrawType 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAWTYPE_NONE = 0, 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAWTYPE_GLES2_CLEAR, 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAWTYPE_GLES2_RENDER 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest (EglTestContext& eglTestCtx, bool preserveColorbuffer, bool readPixelsBeforeSwap, DrawType preSwapDrawType, DrawType postSwapDrawType, const char* name, const char* description); 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~PreservingSwapTest (void); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_seed; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_preserveColorbuffer; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_readPixelsBeforeSwap; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const DrawType m_preSwapDrawType; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const DrawType m_postSwapDrawType; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry eglu::NativeWindow* m_window; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::egl::WindowSurface* m_eglSurface; 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGLConfig m_eglConfig; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::egl::Context* m_eglContext; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::Functions m_gl; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLES2Program* m_gles2Program; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceProgram* m_refProgram; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void initEGLSurface (EGLConfig config); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void initEGLContext (EGLConfig config); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GLES2Program 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLES2Program (const glw::Functions& gl); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~GLES2Program (void); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void render (int width, int height, float x1, float y1, float x2, float y2, PreservingSwapTest::DrawType drawType); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& m_gl; 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint m_glProgram; 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint m_coordLoc; 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint m_colorLoc; 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLES2Program& operator= (const GLES2Program&); 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLES2Program (const GLES2Program&); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLES2Program::GLES2Program (const glw::Functions& gl) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_gl (gl) 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glProgram (0) 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_coordLoc ((glw::GLuint)-1) 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_colorLoc ((glw::GLuint)-1) 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const vertexShaderSource = 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute mediump vec4 a_pos;\n" 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute mediump vec4 a_color;\n" 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main(void)\n" 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tv_color = a_color;\n" 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tgl_Position = a_pos;\n" 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}"; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const fragmentShaderSource = 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main(void)\n" 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tgl_FragColor = v_color;\n" 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}"; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint vtxShader = (glw::GLuint)-1; 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint fragShader = (glw::GLuint)-1; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vtxShader = m_gl.createShader(GL_VERTEX_SHADER); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fragShader = m_gl.createShader(GL_FRAGMENT_SHADER); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_glProgram = m_gl.createProgram(); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to create resources for shader program"); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.shaderSource(vtxShader, 1, &vertexShaderSource, DE_NULL); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.shaderSource(fragShader, 1, &fragmentShaderSource, DE_NULL); 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to set shader sources"); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.compileShader(vtxShader); 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.compileShader(fragShader); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Shader compilation failed"); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.attachShader(m_glProgram, vtxShader); 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.attachShader(m_glProgram, fragShader); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to attach shaders to program"); 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.linkProgram(m_glProgram); 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to link program"); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.deleteShader(fragShader); 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fragShader = (glw::GLuint)-1; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.deleteShader(vtxShader); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vtxShader = (glw::GLuint)-1; 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to delete shaders"); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_colorLoc = m_gl.getAttribLocation(m_glProgram, "a_color"); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_coordLoc = m_gl.getAttribLocation(m_glProgram, "a_pos"); 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to get attribute locations"); 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_colorLoc != (glw::GLuint)-1); 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_coordLoc != (glw::GLuint)-1); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (...) 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (vtxShader != (glw::GLuint)-1) 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.deleteShader(vtxShader); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (fragShader != (glw::GLuint)-1) 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.deleteShader(fragShader); 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glProgram != (glw::GLuint)-1) 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.deleteProgram(m_glProgram); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_glProgram = (glw::GLuint)-1; 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLES2Program::~GLES2Program (void) 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glProgram != (glw::GLuint)-1) 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.deleteProgram(m_glProgram); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GLES2Program::render (int width, int height, float x1, float y1, float x2, float y2, PreservingSwapTest::DrawType drawType) 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (drawType == PreservingSwapTest::DRAWTYPE_GLES2_RENDER) 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::GLfloat coords[] = 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x1, y1, 0.0f, 1.0f, 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x1, y2, 0.0f, 1.0f, 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x2, y2, 0.0f, 1.0f, 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x2, y2, 0.0f, 1.0f, 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x2, y1, 0.0f, 1.0f, 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x1, y1, 0.0f, 1.0f 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::GLubyte colors[] = 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 127, 127, 127, 255, 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 127, 127, 127, 255, 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 127, 127, 127, 255, 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 127, 127, 127, 255, 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 127, 127, 127, 255, 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 127, 127, 127, 255 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.useProgram(m_glProgram); 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed"); 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.enableVertexAttribArray(m_coordLoc); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.enableVertexAttribArray(m_colorLoc); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to enable attributes"); 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.vertexAttribPointer(m_coordLoc, 4, GL_FLOAT, GL_FALSE, 0, coords); 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.vertexAttribPointer(m_colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to set attribute pointers"); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.drawArrays(GL_TRIANGLES, 0, 6); 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "glDrawArrays() failed"); 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.disableVertexAttribArray(m_coordLoc); 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.disableVertexAttribArray(m_colorLoc); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to disable attributes"); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.useProgram(0); 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed"); 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (drawType == PreservingSwapTest::DRAWTYPE_GLES2_CLEAR) 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int ox = width/2; 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int oy = height/2; 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int px = width; 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int py = height; 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int x1i = (int)((px/2.0f) * x1 + ox); 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int y1i = (int)((py/2.0f) * y1 + oy); 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int x2i = (int)((px/2.0f) * x2 + ox); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int y2i = (int)((py/2.0f) * y2 + oy); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.enable(GL_SCISSOR_TEST); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.scissor(x1i, y1i, x2i-x1i, y2i-y1i); 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.clearColor(0.5f, 0.5f, 0.5f, 1.0f); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.clear(GL_COLOR_BUFFER_BIT); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gl.disable(GL_SCISSOR_TEST); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReferenceProgram 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceProgram (void); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ReferenceProgram (void); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void render (tcu::Surface* target, float x1, float y1, float x2, float y2, PreservingSwapTest::DrawType drawType); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceProgram (const ReferenceProgram&); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceProgram& operator= (const ReferenceProgram&); 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2883c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceProgram::ReferenceProgram (void) 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2923c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceProgram::~ReferenceProgram (void) 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceProgram::render (tcu::Surface* target, float x1, float y1, float x2, float y2, PreservingSwapTest::DrawType drawType) 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (drawType == PreservingSwapTest::DRAWTYPE_GLES2_RENDER || drawType == PreservingSwapTest::DRAWTYPE_GLES2_CLEAR) 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int ox = target->getWidth()/2; 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int oy = target->getHeight()/2; 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int px = target->getWidth(); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int py = target->getHeight(); 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int x1i = (int)((px/2.0) * x1 + ox); 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int y1i = (int)((py/2.0) * y1 + oy); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int x2i = (int)((px/2.0) * x2 + ox); 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int y2i = (int)((py/2.0) * y2 + oy); 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA color(127, 127, 127, 255); 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = y1i; y <= y2i; y++) 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = x1i; x <= x2i; x++) 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry target->setPixel(x, y, color); 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPreservingSwapTest::PreservingSwapTest (EglTestContext& eglTestCtx, bool preserveColorbuffer, bool readPixelsBeforeSwap, DrawType preSwapDrawType, DrawType postSwapDrawType, const char* name, const char* description) 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (eglTestCtx, name, description) 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_seed (deStringHash(name)) 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_preserveColorbuffer (preserveColorbuffer) 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_readPixelsBeforeSwap (readPixelsBeforeSwap) 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_preSwapDrawType (preSwapDrawType) 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_postSwapDrawType (postSwapDrawType) 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_window (DE_NULL) 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_eglSurface (DE_NULL) 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_eglContext (DE_NULL) 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_gles2Program (DE_NULL) 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refProgram (DE_NULL) 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3393c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPreservingSwapTest::~PreservingSwapTest (void) 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3443c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLConfig getEGLConfig (tcu::egl::Display& eglDisplay, bool preserveColorbuffer) 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<EGLConfig> configs; 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const EGLint attribList[] = 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGL_SURFACE_TYPE, EGL_WINDOW_BIT | (preserveColorbuffer ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0), 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGL_NONE 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry eglDisplay.chooseConfig(attribList, configs); 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (configs.size() == 0) 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return DE_NULL; 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return configs[0]; 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearColorScreen(const glw::Functions& gl, float red, float green, float blue, float alpha) 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearColor(red, green, blue, alpha); 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear(GL_COLOR_BUFFER_BIT); 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearColorReference(tcu::Surface* ref, float red, float green, float blue, float alpha) 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clear(ref->getAccess(), tcu::Vec4(red, green, blue, alpha)); 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid readPixels (const glw::Functions& gl, tcu::Surface* screen) 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen->getAccess().getDataPtr()); 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PreservingSwapTest::initEGLSurface (EGLConfig config) 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_window = m_eglTestCtx.createNativeWindow(m_eglTestCtx.getDisplay().getEGLDisplay(), config, DE_NULL, 480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())); 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglSurface = new tcu::egl::WindowSurface(m_eglTestCtx.getDisplay(), eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_window, m_eglTestCtx.getDisplay().getEGLDisplay(), config, DE_NULL)); 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PreservingSwapTest::initEGLContext (EGLConfig config) 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const EGLint attribList[] = 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGL_CONTEXT_CLIENT_VERSION, 2, 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGL_NONE 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglContext = new tcu::egl::Context(m_eglTestCtx.getDisplay(), config, attribList, EGL_OPENGL_ES_API); 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PreservingSwapTest::init (void) 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglConfig = getEGLConfig(m_eglTestCtx.getDisplay(), m_preserveColorbuffer); 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_eglConfig == DE_NULL) 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("No supported config found", "", __FILE__, __LINE__); 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry initEGLSurface(m_eglConfig); 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry initEGLContext(m_eglConfig); 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglContext->makeCurrent(*m_eglSurface, *m_eglSurface); 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglTestCtx.getGLFunctions(m_gl, glu::ApiType::es(2,0)); 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gles2Program = new GLES2Program(m_gl); 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refProgram = new ReferenceProgram(); 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PreservingSwapTest::deinit (void) 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_refProgram; 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refProgram = DE_NULL; 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_gles2Program; 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gles2Program = DE_NULL; 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_eglContext; 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglContext = DE_NULL; 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_eglSurface; 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglSurface = DE_NULL; 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_window; 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_window = DE_NULL; 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool compareToReference (tcu::TestLog& log, const char* name, const char* description, const tcu::Surface& reference, const tcu::Surface& screen, int x, int y, int width, int height) 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::fuzzyCompare(log, name, description, reference.getSubAccess(x, y, width, height), screen.getSubAccess(x, y, width, height), 0.05f, tcu::COMPARE_LOG_RESULT); 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool comparePreAndPostSwapFramebuffers (tcu::TestLog& log, const tcu::Surface& preSwap, const tcu::Surface& postSwap) 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::pixelThresholdCompare(log, "Pre- / Post framebuffer compare", "Compare pre- and post-swap framebuffers", preSwap, postSwap, tcu::RGBA(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT); 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4413c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult PreservingSwapTest::iterate (void) 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestLog& log = m_testCtx.getLog(); 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd(m_seed); 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int width = m_eglSurface->getWidth(); 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int height = m_eglSurface->getHeight(); 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float clearRed = rnd.getFloat(); 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float clearGreen = rnd.getFloat(); 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float clearBlue = rnd.getFloat(); 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float clearAlpha = 1.0f; 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float preSwapX1 = -0.9f * rnd.getFloat(); 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float preSwapY1 = -0.9f * rnd.getFloat(); 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float preSwapX2 = 0.9f * rnd.getFloat(); 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float preSwapY2 = 0.9f * rnd.getFloat(); 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float postSwapX1 = -0.9f * rnd.getFloat(); 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float postSwapY1 = -0.9f * rnd.getFloat(); 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float postSwapX2 = 0.9f * rnd.getFloat(); 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float postSwapY2 = 0.9f * rnd.getFloat(); 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface postSwapFramebufferReference(width, height); 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface preSwapFramebufferReference(width, height); 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface postSwapFramebuffer(width, height); 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface preSwapFramebuffer(width, height); 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preserveColorbuffer) 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglSurface->setAttribute(EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglContext->makeCurrent(*m_eglSurface, *m_eglSurface); 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearColorScreen(m_gl, clearRed, clearGreen, clearBlue, clearAlpha); 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_readPixelsBeforeSwap) 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearColorReference(&preSwapFramebufferReference, clearRed, clearGreen, clearBlue, clearAlpha); 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearColorReference(&postSwapFramebufferReference, clearRed, clearGreen, clearBlue, clearAlpha); 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preSwapDrawType != DRAWTYPE_NONE) 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gles2Program->render(width, height, preSwapX1, preSwapY1, preSwapX2, preSwapY2, m_preSwapDrawType); 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refProgram->render(&postSwapFramebufferReference, preSwapX1, preSwapY1, preSwapX2, preSwapY2, m_preSwapDrawType); 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_readPixelsBeforeSwap) 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preSwapDrawType != DRAWTYPE_NONE) 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refProgram->render(&preSwapFramebufferReference, preSwapX1, preSwapY1, preSwapX2, preSwapY2, m_preSwapDrawType); 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readPixels(m_gl, &preSwapFramebuffer); 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_eglSurface->swapBuffers(); 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_postSwapDrawType != DRAWTYPE_NONE) 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refProgram->render(&postSwapFramebufferReference, postSwapX1, postSwapY1, postSwapX2, postSwapY2, m_postSwapDrawType); 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_gles2Program->render(width, height, postSwapX1, postSwapY1, postSwapX2, postSwapY2, m_postSwapDrawType); 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readPixels(m_gl, &postSwapFramebuffer); 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk = true; 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preserveColorbuffer) 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_readPixelsBeforeSwap) 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = isOk && compareToReference(log, "Compare pre-swap framebuffer to reference", "Compare pre-swap framebuffer to reference", preSwapFramebufferReference, preSwapFramebuffer, 0, 0, width, height); 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = isOk && compareToReference(log, "Compare post-swap framebuffer to reference", "Compare post-swap framebuffer to reference", postSwapFramebufferReference, postSwapFramebuffer, 0, 0, width, height); 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_readPixelsBeforeSwap && m_postSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE) 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = isOk && comparePreAndPostSwapFramebuffers(log, preSwapFramebuffer, postSwapFramebuffer); 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int ox = width/2; 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int oy = height/2; 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int px = width; 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int py = height; 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int x1i = (int)((px/2.0f) * postSwapX1 + ox); 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int y1i = (int)((py/2.0f) * postSwapY1 + oy); 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int x2i = (int)((px/2.0f) * postSwapX2 + ox); 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int y2i = (int)((py/2.0f) * postSwapY2 + oy); 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_readPixelsBeforeSwap) 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = isOk && compareToReference(log, "Compare pre-swap framebuffer to reference", "Compare pre-swap framebuffer to reference", preSwapFramebufferReference, preSwapFramebuffer, 0, 0, width, height); 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_postSwapDrawType != DRAWTYPE_NONE); 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = isOk && compareToReference(log, "Compare valid are of post-swap framebuffer to reference", "Compare valid area of post-swap framebuffer to reference", postSwapFramebufferReference, postSwapFramebuffer, x1i, y1i, x2i - x1i, y2i - y1i); 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (isOk) 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring generateTestName (PreservingSwapTest::DrawType preSwapDrawType, PreservingSwapTest::DrawType postSwapDrawType) 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (preSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE && postSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE) 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "no_draw"; 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (preSwapDrawType) 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case PreservingSwapTest::DRAWTYPE_NONE: 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Do nothing 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case PreservingSwapTest::DRAWTYPE_GLES2_RENDER: 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "pre_render"; 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case PreservingSwapTest::DRAWTYPE_GLES2_CLEAR: 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "pre_clear"; 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (preSwapDrawType != PreservingSwapTest::DRAWTYPE_NONE && postSwapDrawType != PreservingSwapTest::DRAWTYPE_NONE) 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "_"; 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (postSwapDrawType) 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case PreservingSwapTest::DRAWTYPE_NONE: 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Do nothing 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case PreservingSwapTest::DRAWTYPE_GLES2_RENDER: 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "post_render"; 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case PreservingSwapTest::DRAWTYPE_GLES2_CLEAR: 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "post_clear"; 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return stream.str(); 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6003c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPreservingSwapTests::PreservingSwapTests (EglTestContext& eglTestCtx) 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(eglTestCtx, "preserve_swap", "Color buffer preserving swap tests") 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PreservingSwapTests::init (void) 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const PreservingSwapTest::DrawType preSwapDrawTypes[] = 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest::DRAWTYPE_NONE, 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest::DRAWTYPE_GLES2_CLEAR, 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest::DRAWTYPE_GLES2_RENDER 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const PreservingSwapTest::DrawType postSwapDrawTypes[] = 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest::DRAWTYPE_NONE, 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest::DRAWTYPE_GLES2_CLEAR, 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PreservingSwapTest::DRAWTYPE_GLES2_RENDER 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int preserveNdx = 0; preserveNdx < 2; preserveNdx++) 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool preserve = (preserveNdx == 0); 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const preserveGroup = new TestCaseGroup(m_eglTestCtx, (preserve ? "preserve" : "no_preserve"), ""); 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int readPixelsNdx = 0; readPixelsNdx < 2; readPixelsNdx++) 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool readPixelsBeforeSwap = (readPixelsNdx == 1); 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const readPixelsBeforeSwapGroup = new TestCaseGroup(m_eglTestCtx, (readPixelsBeforeSwap ? "read_before_swap" : "no_read_before_swap"), ""); 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int preSwapDrawTypeNdx = 0; preSwapDrawTypeNdx < DE_LENGTH_OF_ARRAY(preSwapDrawTypes); preSwapDrawTypeNdx++) 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const PreservingSwapTest::DrawType preSwapDrawType = preSwapDrawTypes[preSwapDrawTypeNdx]; 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int postSwapDrawTypeNdx = 0; postSwapDrawTypeNdx < DE_LENGTH_OF_ARRAY(postSwapDrawTypes); postSwapDrawTypeNdx++) 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const PreservingSwapTest::DrawType postSwapDrawType = postSwapDrawTypes[postSwapDrawTypeNdx]; 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // If not preserving and rendering after swap, then there is nothing to verify 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!preserve && postSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE) 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = generateTestName(preSwapDrawType, postSwapDrawType); 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readPixelsBeforeSwapGroup->addChild(new PreservingSwapTest(m_eglTestCtx, preserve, readPixelsBeforeSwap, preSwapDrawType, postSwapDrawType, name.c_str(), "")); 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry preserveGroup->addChild(readPixelsBeforeSwapGroup); 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(preserveGroup); 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 658