• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
54     glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8I, 64, 64);
55     if (getClientMajorVersion() < 3 || getClientMinorVersion() < 1)
56     {
57         ASSERT_GL_ERROR(GL_INVALID_OPERATION);
58     }
59     else
60     {
61         ASSERT_GL_NO_ERROR();
62 
63         GLint maxSamplesRGBA8I = 0;
64         glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8I, GL_SAMPLES, 1, &maxSamplesRGBA8I);
65         GLint maxIntegerSamples = 0;
66         glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &maxIntegerSamples);
67         ASSERT_GL_NO_ERROR();
68         EXPECT_GE(maxIntegerSamples, 1);
69 
70         glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamplesRGBA8I + 1, GL_RGBA8I, 64, 64);
71         ASSERT_GL_ERROR(GL_INVALID_OPERATION);
72         glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxIntegerSamples + 1, GL_RGBA8I, 64, 64);
73         ASSERT_GL_ERROR(GL_INVALID_OPERATION);
74     }
75 }
76 
77 // Ensure that the following spec language is correctly implemented:
78 //
79 //   the resulting value for RENDERBUFFER_SAMPLES is guaranteed to be greater than or equal to
80 //   samples and no more than the next larger sample count supported by the implementation.
81 //
82 // For example, if 2, 4, and 8 samples are supported, if 5 samples are requested, ANGLE will
83 // use 8 samples, and return 8 when GL_RENDERBUFFER_SAMPLES is queried.
TEST_P(RenderbufferMultisampleTest,OddSampleCount)84 TEST_P(RenderbufferMultisampleTest, OddSampleCount)
85 {
86     ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
87 
88     glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
89     ASSERT_GL_NO_ERROR();
90 
91     // Lookup the supported number of sample counts
92     GLint numSampleCounts = 0;
93     std::vector<GLint> sampleCounts;
94     GLsizei queryBufferSize = 1;
95     glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, queryBufferSize,
96                           &numSampleCounts);
97     ANGLE_SKIP_TEST_IF((numSampleCounts < 2));
98     sampleCounts.resize(numSampleCounts);
99     queryBufferSize = numSampleCounts;
100     glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_SAMPLES, queryBufferSize,
101                           sampleCounts.data());
102 
103     // Look for two sample counts that are not 1 apart (e.g. 2 and 4).  Request a sample count
104     // that's between those two samples counts (e.g. 3) and ensure that GL_RENDERBUFFER_SAMPLES
105     // is the higher number.
106     for (int i = 1; i < numSampleCounts; i++)
107     {
108         if (sampleCounts[i - 1] > (sampleCounts[i] + 1))
109         {
110             glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCounts[i] + 1, GL_RGBA8, 64,
111                                              64);
112             ASSERT_GL_NO_ERROR();
113             GLint renderbufferSamples = 0;
114             glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES,
115                                          &renderbufferSamples);
116             ASSERT_GL_NO_ERROR();
117             EXPECT_EQ(renderbufferSamples, sampleCounts[i - 1]);
118             break;
119         }
120     }
121 }
122 
123 ANGLE_INSTANTIATE_TEST_ES3_AND_ES31(RenderbufferMultisampleTest);
124 }  // namespace
125