1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // RenderbufferMultisampleTest: Tests of multisampled renderbuffer
8
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11
12 using namespace angle;
13
14 namespace
15 {
16
17 class RenderbufferMultisampleTest : public ANGLETest
18 {
19 protected:
RenderbufferMultisampleTest()20 RenderbufferMultisampleTest()
21 {
22 setWindowWidth(64);
23 setWindowHeight(64);
24 setConfigRedBits(8);
25 setConfigGreenBits(8);
26 setConfigBlueBits(8);
27 setConfigAlphaBits(8);
28 }
29
testSetUp()30 void testSetUp() override
31 {
32 glGenRenderbuffers(1, &mRenderbuffer);
33
34 ASSERT_GL_NO_ERROR();
35 }
36
testTearDown()37 void testTearDown() override
38 {
39 glDeleteRenderbuffers(1, &mRenderbuffer);
40 mRenderbuffer = 0;
41 }
42
43 GLuint mRenderbuffer = 0;
44 };
45
46 // In GLES 3.0, if internalformat is integer (signed or unsigned), to allocate multisample
47 // renderbuffer storage for that internalformat is not supported. An INVALID_OPERATION is
48 // generated. In GLES 3.1, it is OK to allocate multisample renderbuffer storage for interger
49 // internalformat, but the max samples should be less than MAX_INTEGER_SAMPLES.
50 // MAX_INTEGER_SAMPLES should be at least 1.
TEST_P(RenderbufferMultisampleTest,IntegerInternalformat)51 TEST_P(RenderbufferMultisampleTest, IntegerInternalformat)
52 {
53 // Fixed in recent mesa. http://crbug.com/1071142
54 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && (IsIntel() || IsAMD()));
55
56 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
57 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8I, 64, 64);
58 if (getClientMajorVersion() < 3 || getClientMinorVersion() < 1)
59 {
60 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
61 }
62 else
63 {
64 ASSERT_GL_NO_ERROR();
65
66 GLint maxSamplesRGBA8I = 0;
67 glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8I, GL_SAMPLES, 1, &maxSamplesRGBA8I);
68 GLint maxIntegerSamples = 0;
69 glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &maxIntegerSamples);
70 ASSERT_GL_NO_ERROR();
71 EXPECT_GE(maxIntegerSamples, 1);
72
73 glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamplesRGBA8I + 1, GL_RGBA8I, 64, 64);
74 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
75 glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxIntegerSamples + 1, GL_RGBA8I, 64, 64);
76 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
77 }
78 }
79
80 // Ensure that the following spec language is correctly implemented:
81 //
82 // the resulting value for RENDERBUFFER_SAMPLES is guaranteed to be greater than or equal to
83 // samples and no more than the next larger sample count supported by the implementation.
84 //
85 // For example, if 2, 4, and 8 samples are supported, if 5 samples are requested, ANGLE will
86 // use 8 samples, and return 8 when GL_RENDERBUFFER_SAMPLES is queried.
TEST_P(RenderbufferMultisampleTest,OddSampleCount)87 TEST_P(RenderbufferMultisampleTest, OddSampleCount)
88 {
89 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
90
91 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
92 ASSERT_GL_NO_ERROR();
93
94 // Lookup the supported number of sample counts
95 GLint numSampleCounts = 0;
96 std::vector<GLint> sampleCounts;
97 GLsizei queryBufferSize = 1;
98 glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, queryBufferSize,
99 &numSampleCounts);
100 ANGLE_SKIP_TEST_IF((numSampleCounts < 2));
101 sampleCounts.resize(numSampleCounts);
102 queryBufferSize = numSampleCounts;
103 glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_SAMPLES, queryBufferSize,
104 sampleCounts.data());
105
106 // Look for two sample counts that are not 1 apart (e.g. 2 and 4). Request a sample count
107 // that's between those two samples counts (e.g. 3) and ensure that GL_RENDERBUFFER_SAMPLES
108 // is the higher number.
109 for (int i = 1; i < numSampleCounts; i++)
110 {
111 if (sampleCounts[i - 1] > (sampleCounts[i] + 1))
112 {
113 glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCounts[i] + 1, GL_RGBA8, 64,
114 64);
115 ASSERT_GL_NO_ERROR();
116 GLint renderbufferSamples = 0;
117 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES,
118 &renderbufferSamples);
119 ASSERT_GL_NO_ERROR();
120 EXPECT_EQ(renderbufferSamples, sampleCounts[i - 1]);
121 break;
122 }
123 }
124 }
125
126 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RenderbufferMultisampleTest);
127 ANGLE_INSTANTIATE_TEST_ES3_AND_ES31(RenderbufferMultisampleTest);
128 } // namespace
129