• 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 // MultiviewTest:
7 //   Implementation of helpers for multiview testing.
8 //
9 
10 #ifndef ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_
11 #define ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_
12 
13 #include "test_utils/ANGLETest.h"
14 
15 namespace angle
16 {
17 enum ExtensionName
18 {
19     multiview,
20     multiview2
21 };
22 
23 // Creates a simple program that passes through two-dimensional vertices and renders green
24 // fragments.
25 GLuint CreateSimplePassthroughProgram(int numViews, ExtensionName multiviewExtension);
26 
27 // Create a 2D texture array to use for multiview rendering. Texture ids should be
28 // created beforehand. If depthTexture or stencilTexture is 0, it will not be initialized.
29 // If samples is 0, then non-multisampled textures are created. Otherwise multisampled textures are
30 // created with the requested sample count.
31 void CreateMultiviewBackingTextures(int samples,
32                                     int viewWidth,
33                                     int height,
34                                     int numLayers,
35                                     std::vector<GLuint> colorTextures,
36                                     GLuint depthTexture,
37                                     GLuint depthStencilTexture);
38 void CreateMultiviewBackingTextures(int samples,
39                                     int viewWidth,
40                                     int height,
41                                     int numLayers,
42                                     GLuint colorTexture,
43                                     GLuint depthTexture,
44                                     GLuint depthStencilTexture);
45 
46 // Attach multiview textures to the framebuffer denoted by target. If there are multiple color
47 // textures they get attached to different color attachments starting from 0.
48 void AttachMultiviewTextures(GLenum target,
49                              int viewWidth,
50                              int numViews,
51                              int baseViewIndex,
52                              std::vector<GLuint> colorTextures,
53                              GLuint depthTexture,
54                              GLuint depthStencilTexture);
55 void AttachMultiviewTextures(GLenum target,
56                              int viewWidth,
57                              int numViews,
58                              int baseViewIndex,
59                              GLuint colorTexture,
60                              GLuint depthTexture,
61                              GLuint depthStencilTexture);
62 
63 struct MultiviewImplementationParams : public PlatformParameters
64 {
MultiviewImplementationParamsMultiviewImplementationParams65     MultiviewImplementationParams(GLint majorVersion,
66                                   GLint minorVersion,
67                                   const EGLPlatformParameters &eglPlatformParameters,
68                                   ExtensionName multiviewExtension)
69         : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters),
70           mMultiviewExtension(multiviewExtension)
71     {}
72     ExtensionName mMultiviewExtension;
73 };
74 std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params);
75 
76 MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion,
77                                                  GLint minorVersion,
78                                                  ExtensionName multiviewExtension);
79 MultiviewImplementationParams VertexShaderVulkan(GLint majorVersion,
80                                                  GLint minorVersion,
81                                                  ExtensionName multiviewExtension);
82 MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion,
83                                                 GLint minorVersion,
84                                                 ExtensionName multiviewExtension);
85 MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion,
86                                               GLint minorVersion,
87                                               ExtensionName multiviewExtension);
88 
89 class MultiviewTestBase : public ANGLETestBase
90 {
91   protected:
MultiviewTestBase(const PlatformParameters & params)92     MultiviewTestBase(const PlatformParameters &params) : ANGLETestBase(params)
93     {
94         setWindowWidth(128);
95         setWindowHeight(128);
96         setWebGLCompatibilityEnabled(true);
97     }
~MultiviewTestBase()98     virtual ~MultiviewTestBase() {}
99 
MultiviewTestBaseSetUp()100     void MultiviewTestBaseSetUp() { ANGLETestBase::ANGLETestSetUp(); }
101 
MultiviewTestBaseTearDown()102     void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); }
103 };
104 
105 // Base class for multiview tests that don't need specific helper functions.
106 class MultiviewTest : public MultiviewTestBase,
107                       public ::testing::TestWithParam<MultiviewImplementationParams>
108 {
109   protected:
MultiviewTest()110     MultiviewTest() : MultiviewTestBase(GetParam()) {}
111 
testSetUp()112     virtual void testSetUp() {}
testTearDown()113     virtual void testTearDown() {}
114 
115     // Requests the OVR_multiview(2) extension and returns true if the operation succeeds.
requestMultiviewExtension(bool requireMultiviewMultisample)116     bool requestMultiviewExtension(bool requireMultiviewMultisample)
117     {
118         if (!EnsureGLExtensionEnabled(extensionName()))
119         {
120             std::cout << "Test skipped due to missing " << extensionName() << "." << std::endl;
121             return false;
122         }
123 
124         if (requireMultiviewMultisample)
125         {
126             if (!EnsureGLExtensionEnabled("GL_OES_texture_storage_multisample_2d_array"))
127             {
128                 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
129                           << std::endl;
130                 return false;
131             }
132 
133             if (!EnsureGLExtensionEnabled("GL_ANGLE_multiview_multisample"))
134             {
135                 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
136                           << std::endl;
137                 return false;
138             }
139         }
140         return true;
141     }
142 
requestMultiviewExtension()143     bool requestMultiviewExtension() { return requestMultiviewExtension(false); }
144 
extensionName()145     std::string extensionName()
146     {
147         switch (GetParam().mMultiviewExtension)
148         {
149             case multiview:
150                 return "GL_OVR_multiview";
151             case multiview2:
152                 return "GL_OVR_multiview2";
153             default:
154                 // Ignore unknown.
155                 return "";
156         }
157     }
158 
159   private:
SetUp()160     void SetUp() override
161     {
162         MultiviewTestBase::MultiviewTestBaseSetUp();
163         testSetUp();
164     }
TearDown()165     void TearDown() override
166     {
167         testTearDown();
168         MultiviewTestBase::MultiviewTestBaseTearDown();
169     }
170 };
171 
172 }  // namespace angle
173 
174 #endif  // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_
175