Path: blob/main_old/src/tests/gl_tests/ContextNoErrorTest.cpp
1693 views
//1// Copyright 2020 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ContextNoErrorTest:6// Tests pertaining to GL_KHR_no_error7//89#include <gtest/gtest.h>1011#include "common/platform.h"12#include "test_utils/ANGLETest.h"13#include "test_utils/gl_raii.h"1415using namespace angle;1617class ContextNoErrorTest : public ANGLETest18{19protected:20ContextNoErrorTest() : mNaughtyTexture(0) { setNoErrorEnabled(true); }2122void testTearDown() override23{24if (mNaughtyTexture != 0)25{26glDeleteTextures(1, &mNaughtyTexture);27}28}2930void bindNaughtyTexture()31{32glGenTextures(1, &mNaughtyTexture);33ASSERT_GL_NO_ERROR();34glBindTexture(GL_TEXTURE_CUBE_MAP, mNaughtyTexture);35ASSERT_GL_NO_ERROR();3637// mNaughtyTexture should now be a GL_TEXTURE_CUBE_MAP texture, so rebinding it to38// GL_TEXTURE_2D is an error39glBindTexture(GL_TEXTURE_2D, mNaughtyTexture);40}4142GLuint mNaughtyTexture;43};4445class ContextNoErrorTest31 : public ContextNoErrorTest46{47protected:48~ContextNoErrorTest31()49{50glDeleteProgram(mVertProg);51glDeleteProgram(mFragProg);52glDeleteProgramPipelines(1, &mPipeline);53}5455void bindProgramPipeline(const GLchar *vertString, const GLchar *fragString);56void drawQuadWithPPO(const std::string &positionAttribName,57const GLfloat positionAttribZ,58const GLfloat positionAttribXYScale);5960GLuint mVertProg;61GLuint mFragProg;62GLuint mPipeline;63};6465void ContextNoErrorTest31::bindProgramPipeline(const GLchar *vertString, const GLchar *fragString)66{67mVertProg = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &vertString);68ASSERT_NE(mVertProg, 0u);69mFragProg = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &fragString);70ASSERT_NE(mFragProg, 0u);7172// Generate a program pipeline and attach the programs to their respective stages73glGenProgramPipelines(1, &mPipeline);74EXPECT_GL_NO_ERROR();75glUseProgramStages(mPipeline, GL_VERTEX_SHADER_BIT, mVertProg);76EXPECT_GL_NO_ERROR();77glUseProgramStages(mPipeline, GL_FRAGMENT_SHADER_BIT, mFragProg);78EXPECT_GL_NO_ERROR();79glBindProgramPipeline(mPipeline);80EXPECT_GL_NO_ERROR();81}8283void ContextNoErrorTest31::drawQuadWithPPO(const std::string &positionAttribName,84const GLfloat positionAttribZ,85const GLfloat positionAttribXYScale)86{87glUseProgram(0);8889std::array<Vector3, 6> quadVertices = ANGLETestBase::GetQuadVertices();9091for (Vector3 &vertex : quadVertices)92{93vertex.x() *= positionAttribXYScale;94vertex.y() *= positionAttribXYScale;95vertex.z() = positionAttribZ;96}9798GLint positionLocation = glGetAttribLocation(mVertProg, positionAttribName.c_str());99100glBindBuffer(GL_ARRAY_BUFFER, 0);101glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());102glEnableVertexAttribArray(positionLocation);103104glDrawArrays(GL_TRIANGLES, 0, 6);105106glDisableVertexAttribArray(positionLocation);107glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);108}109110// Tests that error reporting is suppressed when GL_KHR_no_error is enabled111TEST_P(ContextNoErrorTest, NoError)112{113ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_no_error"));114115bindNaughtyTexture();116EXPECT_GL_NO_ERROR();117}118119// Test glDetachShader to make sure it resolves linking with a no error context and doesn't assert120TEST_P(ContextNoErrorTest, DetachAfterLink)121{122ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_no_error"));123124GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Simple());125GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl1_shaders::fs::Red());126GLuint program = glCreateProgram();127glAttachShader(program, vs);128glAttachShader(program, fs);129glLinkProgram(program);130131glDetachShader(program, vs);132glDetachShader(program, fs);133134glDeleteShader(vs);135glDeleteShader(fs);136glDeleteProgram(program);137EXPECT_GL_NO_ERROR();138}139140// Tests that we can draw with a program pipeline when GL_KHR_no_error is enabled.141TEST_P(ContextNoErrorTest31, DrawWithPPO)142{143ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_no_error"));144145// Only the Vulkan backend supports PPOs146ANGLE_SKIP_TEST_IF(!IsVulkan());147148// TODO(http://anglebug.com/5102): Linking PPOs is currently done during draw call validation,149// so drawing with a PPO fails without validation enabled.150ANGLE_SKIP_TEST_IF(IsGLExtensionEnabled("GL_KHR_no_error"));151152// Create two separable program objects from a153// single source string respectively (vertSrc and fragSrc)154const GLchar *vertString = essl31_shaders::vs::Simple();155const GLchar *fragString = essl31_shaders::fs::Red();156157bindProgramPipeline(vertString, fragString);158159drawQuadWithPPO("a_position", 0.5f, 1.0f);160ASSERT_GL_NO_ERROR();161EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);162}163164// Tests that an incorrect enum to GetInteger does not cause an application crash.165TEST_P(ContextNoErrorTest, InvalidGetIntegerDoesNotCrash)166{167ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_no_error"));168169GLint value = 1;170glGetIntegerv(GL_TEXTURE_2D, &value);171EXPECT_GL_NO_ERROR();172EXPECT_EQ(value, 1);173}174175ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ContextNoErrorTest);176177GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ContextNoErrorTest31);178ANGLE_INSTANTIATE_TEST_ES31(ContextNoErrorTest31);179180181