Hash :
bf5e9dbc
Author :
Date :
2023-03-09T00:00:00
GL: Reset clip origin before scissored clears Clip origin must not affect scissor box but some drivers flip it for clear operations. Added capture/replay support for ClipControl. Bug: angleproject:8066 Change-Id: I9292cb4945b49c56c80da4c5813e89df3453b6b6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4328267 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
//
// Copyright 2023 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Test cases for GL_EXT_clip_control
// These tests complement dEQP-GLES2.functional.clip_control.*
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
#include "util/test_utils.h"
using namespace angle;
class ClipControlTest : public ANGLETest<>
{
protected:
static const int w = 64;
static const int h = 64;
ClipControlTest()
{
setWindowWidth(w);
setWindowHeight(h);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
setExtensionsEnabled(false);
}
};
// Test state queries and updates
TEST_P(ClipControlTest, StateQuery)
{
// Queries with the extension disabled
GLint clipOrigin = -1;
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
EXPECT_EQ(clipOrigin, -1);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
GLint clipDepthMode = -1;
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_EQ(clipDepthMode, -1);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// Command with the extension disabled
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
ASSERT_GL_NO_ERROR();
// Default state with the extension enabled
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_LOWER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_NEGATIVE_ONE_TO_ONE_EXT, clipDepthMode);
ASSERT_GL_NO_ERROR();
// Check valid state updates
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_LOWER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_NEGATIVE_ONE_TO_ONE_EXT, clipDepthMode);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_LOWER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_ZERO_TO_ONE_EXT, clipDepthMode);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_UPPER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_NEGATIVE_ONE_TO_ONE_EXT, clipDepthMode);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_UPPER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_ZERO_TO_ONE_EXT, clipDepthMode);
ASSERT_GL_NO_ERROR();
// Check invalid state updates
glClipControlEXT(GL_LOWER_LEFT_EXT, 0);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
glClipControlEXT(0, GL_NEGATIVE_ONE_TO_ONE_EXT);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// Invalid command does not change the state
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_UPPER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_ZERO_TO_ONE_EXT, clipDepthMode);
ASSERT_GL_NO_ERROR();
}
// Test that clip origin does not affect scissored clears
TEST_P(ClipControlTest, OriginScissorClear)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
auto test = [&](std::string name, bool useES3) {
// Start with lower-left
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
// Make a draw call without color writes to sync the state
glColorMask(false, false, false, false);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
glColorMask(true, true, true, true);
// Clear to red
glDisable(GL_SCISSOR_TEST);
if (useES3)
{
float color[4] = {1.0, 0.0, 0.0, 1.0};
glClearBufferfv(GL_COLOR, 0, color);
}
else
{
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
// Flip the clip origin
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
// Make a draw call without color writes to sync the state
glColorMask(false, false, false, false);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
glColorMask(true, true, true, true);
// Clear lower half to green
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w, h / 2);
if (useES3)
{
float color[4] = {0.0, 1.0, 0.0, 1.0};
glClearBufferfv(GL_COLOR, 0, color);
}
else
{
glClearColor(0.0, 1.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0.5 * w, 0.25 * h, GLColor::green) << name;
EXPECT_PIXEL_COLOR_EQ(0.5 * w, 0.75 * h, GLColor::red) << name;
};
test("Default framebuffer", getClientMajorVersion() > 2);
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_rgb8_rgba8"));
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
test("User framebuffer", getClientMajorVersion() > 2);
}
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ClipControlTest);