Path: blob/main_old/src/tests/gl_tests/DifferentStencilMasksTest.cpp
1693 views
//1// Copyright 2015 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// DifferentStencilMasksTest:6// Tests the equality between stencilWriteMask and stencilBackWriteMask.7//89#include "test_utils/ANGLETest.h"10#include "test_utils/gl_raii.h"1112using namespace angle;1314namespace15{16class DifferentStencilMasksTest : public ANGLETest17{18protected:19DifferentStencilMasksTest() : mProgram(0)20{21setWindowWidth(128);22setWindowHeight(128);23setConfigRedBits(8);24setConfigGreenBits(8);25setConfigBlueBits(8);26setConfigAlphaBits(8);27setConfigDepthBits(24);28setConfigStencilBits(8);2930setWebGLCompatibilityEnabled(true);31}3233void testSetUp() override34{35mProgram = CompileProgram(essl1_shaders::vs::Zero(), essl1_shaders::fs::Blue());36ASSERT_NE(0u, mProgram);3738glEnable(GL_STENCIL_TEST);39ASSERT_GL_NO_ERROR();40}4142void testTearDown() override43{44glDisable(GL_STENCIL_TEST);45if (mProgram != 0)46glDeleteProgram(mProgram);47}4849GLuint mProgram;50};5152// Tests that effectively same front and back masks are legal.53TEST_P(DifferentStencilMasksTest, DrawWithSameEffectiveMask)54{55// 0x00ff and 0x01ff are effectively 0x00ff by being masked by the current stencil bits, 8.56glStencilMaskSeparate(GL_FRONT, 0x00ff);57glStencilMaskSeparate(GL_BACK, 0x01ff);5859glUseProgram(mProgram);6061glDrawArrays(GL_TRIANGLES, 0, 3);6263EXPECT_GL_NO_ERROR();64}6566// Tests that effectively different front and back masks are illegal.67TEST_P(DifferentStencilMasksTest, DrawWithDifferentMask)68{69// TODO(hqle): Make this test work for Metal. http://anglebug.com/413470ANGLE_SKIP_TEST_IF(IsMetal());7172glStencilMaskSeparate(GL_FRONT, 0x0001);73glStencilMaskSeparate(GL_BACK, 0x0002);7475glUseProgram(mProgram);7677glDrawArrays(GL_TRIANGLES, 0, 3);7879EXPECT_GL_ERROR(GL_INVALID_OPERATION);80}8182// Tests that effectively different front and back masks, without stencil bits, are legal.83TEST_P(DifferentStencilMasksTest, DrawWithDifferentMask_NoStencilBuffer)84{85GLTexture texture;86glBindTexture(GL_TEXTURE_2D, texture.get());87glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);8889GLFramebuffer framebuffer;90glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());91glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);9293glStencilMaskSeparate(GL_FRONT, 0x0001);94glStencilMaskSeparate(GL_BACK, 0x0002);9596glUseProgram(mProgram);9798glDrawArrays(GL_TRIANGLES, 0, 3);99100EXPECT_GL_NO_ERROR();101}102103// Use this to select which configurations (e.g. which renderer, which GLES major version) these104// tests should be run against.105ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(DifferentStencilMasksTest);106} // anonymous namespace107108109