• 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                                   bool forceUseGeometryShaderOnD3D,
68                                   const EGLPlatformParameters &eglPlatformParameters,
69                                   ExtensionName multiviewExtension)
70         : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters),
71           mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D),
72           mMultiviewExtension(multiviewExtension)
73     {}
74     bool mForceUseGeometryShaderOnD3D;
75     ExtensionName mMultiviewExtension;
76 };
77 std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params);
78 
79 MultiviewImplementationParams VertexShaderOpenGL(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 
112     void overrideWorkaroundsD3D(FeaturesD3D *features) final;
113 
testSetUp()114     virtual void testSetUp() {}
testTearDown()115     virtual void testTearDown() {}
116 
117     // Requests the OVR_multiview(2) extension and returns true if the operation succeeds.
requestMultiviewExtension(bool requireMultiviewMultisample)118     bool requestMultiviewExtension(bool requireMultiviewMultisample)
119     {
120         if (!EnsureGLExtensionEnabled(extensionName()))
121         {
122             std::cout << "Test skipped due to missing " << extensionName() << "." << std::endl;
123             return false;
124         }
125 
126         if (requireMultiviewMultisample)
127         {
128             if (!EnsureGLExtensionEnabled("GL_OES_texture_storage_multisample_2d_array"))
129             {
130                 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
131                           << std::endl;
132                 return false;
133             }
134 
135             if (!EnsureGLExtensionEnabled("GL_ANGLE_multiview_multisample"))
136             {
137                 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
138                           << std::endl;
139                 return false;
140             }
141         }
142         return true;
143     }
144 
requestMultiviewExtension()145     bool requestMultiviewExtension() { return requestMultiviewExtension(false); }
146 
extensionName()147     std::string extensionName()
148     {
149         switch (GetParam().mMultiviewExtension)
150         {
151             case multiview:
152                 return "GL_OVR_multiview";
153             case multiview2:
154                 return "GL_OVR_multiview2";
155             default:
156                 // Ignore unknown.
157                 return "";
158         }
159     }
160 
161   private:
SetUp()162     void SetUp() override
163     {
164         MultiviewTestBase::MultiviewTestBaseSetUp();
165         testSetUp();
166     }
TearDown()167     void TearDown() override
168     {
169         testTearDown();
170         MultiviewTestBase::MultiviewTestBaseTearDown();
171     }
172 };
173 
174 }  // namespace angle
175 
176 #endif  // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_