blob: 13cf72769291ec1e5474d95e96729914b5e2a972 [file] [log] [blame]
Olli Etuahof26b27e2018-08-17 11:01:19 +03001//
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
15namespace angle
16{
Mingyu Huebab6702019-04-19 14:36:45 -070017enum ExtensionName
18{
19 multiview,
20 multiview2
21};
Olli Etuahof26b27e2018-08-17 11:01:19 +030022
23// Creates a simple program that passes through two-dimensional vertices and renders green
24// fragments.
Mingyu Huebab6702019-04-19 14:36:45 -070025GLuint CreateSimplePassthroughProgram(int numViews, ExtensionName multiviewExtension);
Olli Etuahof26b27e2018-08-17 11:01:19 +030026
Mingyu Hu7d64c482019-03-12 14:27:40 -070027// Create a 2D texture array to use for multiview rendering. Texture ids should be
Olli Etuahoa7b35c32018-08-21 16:32:24 +030028// created beforehand. If depthTexture or stencilTexture is 0, it will not be initialized.
Olli Etuaho2c8f0842018-09-12 14:44:55 +030029// If samples is 0, then non-multisampled textures are created. Otherwise multisampled textures are
30// created with the requested sample count.
Mingyu Hu7d64c482019-03-12 14:27:40 -070031void CreateMultiviewBackingTextures(int samples,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030032 int viewWidth,
33 int height,
34 int numLayers,
35 std::vector<GLuint> colorTextures,
36 GLuint depthTexture,
37 GLuint depthStencilTexture);
Mingyu Hu7d64c482019-03-12 14:27:40 -070038void CreateMultiviewBackingTextures(int samples,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030039 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
Mingyu Hu7d64c482019-03-12 14:27:40 -070047// textures they get attached to different color attachments starting from 0.
Olli Etuahoa7b35c32018-08-21 16:32:24 +030048void AttachMultiviewTextures(GLenum target,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030049 int viewWidth,
50 int numViews,
51 int baseViewIndex,
52 std::vector<GLuint> colorTextures,
53 GLuint depthTexture,
54 GLuint depthStencilTexture);
55void AttachMultiviewTextures(GLenum target,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030056 int viewWidth,
57 int numViews,
58 int baseViewIndex,
59 GLuint colorTexture,
60 GLuint depthTexture,
61 GLuint depthStencilTexture);
62
Olli Etuahof26b27e2018-08-17 11:01:19 +030063struct MultiviewImplementationParams : public PlatformParameters
64{
65 MultiviewImplementationParams(GLint majorVersion,
66 GLint minorVersion,
67 bool forceUseGeometryShaderOnD3D,
Mingyu Huebab6702019-04-19 14:36:45 -070068 const EGLPlatformParameters &eglPlatformParameters,
69 ExtensionName multiviewExtension)
Olli Etuahof26b27e2018-08-17 11:01:19 +030070 : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters),
Mingyu Huebab6702019-04-19 14:36:45 -070071 mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D),
72 mMultiviewExtension(multiviewExtension)
Jamie Madillb980c562018-11-27 11:34:27 -050073 {}
Olli Etuahof26b27e2018-08-17 11:01:19 +030074 bool mForceUseGeometryShaderOnD3D;
Mingyu Huebab6702019-04-19 14:36:45 -070075 ExtensionName mMultiviewExtension;
Olli Etuahof26b27e2018-08-17 11:01:19 +030076};
77std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params);
78
Mingyu Huebab6702019-04-19 14:36:45 -070079MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion,
80 GLint minorVersion,
81 ExtensionName multiviewExtension);
82MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion,
83 GLint minorVersion,
84 ExtensionName multiviewExtension);
85MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion,
86 GLint minorVersion,
87 ExtensionName multiviewExtension);
Olli Etuahof26b27e2018-08-17 11:01:19 +030088
89class MultiviewTestBase : public ANGLETestBase
90{
91 protected:
92 MultiviewTestBase(const PlatformParameters &params) : ANGLETestBase(params)
93 {
94 setWindowWidth(128);
95 setWindowHeight(128);
96 setWebGLCompatibilityEnabled(true);
97 }
98 virtual ~MultiviewTestBase() {}
99
100 void MultiviewTestBaseSetUp()
101 {
102 ANGLETestBase::ANGLETestSetUp();
103
104 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
105 eglGetProcAddress("glRequestExtensionANGLE"));
106 }
107
108 void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); }
109
Olli Etuahof26b27e2018-08-17 11:01:19 +0300110 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
111};
112
113// Base class for multiview tests that don't need specific helper functions.
114class MultiviewTest : public MultiviewTestBase,
115 public ::testing::TestWithParam<MultiviewImplementationParams>
116{
117 protected:
118 MultiviewTest() : MultiviewTestBase(GetParam()) {}
Olli Etuahof26b27e2018-08-17 11:01:19 +0300119
120 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) final;
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400121
122 virtual void testSetUp() {}
123 virtual void testTearDown() {}
124
Mingyu Huebab6702019-04-19 14:36:45 -0700125 // Requests the OVR_multiview(2) extension and returns true if the operation succeeds.
126 bool requestMultiviewExtension(bool requireMultiviewMultisample)
127 {
128 if (!EnsureGLExtensionEnabled(extensionName()))
129 {
130 std::cout << "Test skipped due to missing " << extensionName() << "." << std::endl;
131 return false;
132 }
133
134 if (requireMultiviewMultisample)
135 {
136 if (!EnsureGLExtensionEnabled("GL_OES_texture_storage_multisample_2d_array"))
137 {
138 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
139 << std::endl;
140 return false;
141 }
142
143 if (!EnsureGLExtensionEnabled("GL_ANGLE_multiview_multisample"))
144 {
145 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
146 << std::endl;
147 return false;
148 }
149 }
150 return true;
151 }
152
153 bool requestMultiviewExtension() { return requestMultiviewExtension(false); }
154
155 std::string extensionName()
156 {
157 switch (GetParam().mMultiviewExtension)
158 {
159 case multiview:
160 return "GL_OVR_multiview";
161 case multiview2:
162 return "GL_OVR_multiview2";
163 default:
164 // Ignore unknown.
165 return "";
166 }
167 }
168
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400169 private:
170 void SetUp() override
171 {
172 MultiviewTestBase::MultiviewTestBaseSetUp();
173 testSetUp();
174 }
175 void TearDown() override
176 {
177 testTearDown();
178 MultiviewTestBase::MultiviewTestBaseTearDown();
179 }
Olli Etuahof26b27e2018-08-17 11:01:19 +0300180};
181
182} // namespace angle
183
Mingyu Huebab6702019-04-19 14:36:45 -0700184#endif // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_