blob: ef83da697ef8d375907566df4cf21cc9c0c56eaa [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{
17
18// Creates a simple program that passes through two-dimensional vertices and renders green
19// fragments.
20GLuint CreateSimplePassthroughProgram(int numViews);
21
Mingyu Hu7d64c482019-03-12 14:27:40 -070022// Create a 2D texture array to use for multiview rendering. Texture ids should be
Olli Etuahoa7b35c32018-08-21 16:32:24 +030023// created beforehand. If depthTexture or stencilTexture is 0, it will not be initialized.
Olli Etuaho2c8f0842018-09-12 14:44:55 +030024// If samples is 0, then non-multisampled textures are created. Otherwise multisampled textures are
25// created with the requested sample count.
Mingyu Hu7d64c482019-03-12 14:27:40 -070026void CreateMultiviewBackingTextures(int samples,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030027 int viewWidth,
28 int height,
29 int numLayers,
30 std::vector<GLuint> colorTextures,
31 GLuint depthTexture,
32 GLuint depthStencilTexture);
Mingyu Hu7d64c482019-03-12 14:27:40 -070033void CreateMultiviewBackingTextures(int samples,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030034 int viewWidth,
35 int height,
36 int numLayers,
37 GLuint colorTexture,
38 GLuint depthTexture,
39 GLuint depthStencilTexture);
40
41// Attach multiview textures to the framebuffer denoted by target. If there are multiple color
Mingyu Hu7d64c482019-03-12 14:27:40 -070042// textures they get attached to different color attachments starting from 0.
Olli Etuahoa7b35c32018-08-21 16:32:24 +030043void AttachMultiviewTextures(GLenum target,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030044 int viewWidth,
45 int numViews,
46 int baseViewIndex,
47 std::vector<GLuint> colorTextures,
48 GLuint depthTexture,
49 GLuint depthStencilTexture);
50void AttachMultiviewTextures(GLenum target,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030051 int viewWidth,
52 int numViews,
53 int baseViewIndex,
54 GLuint colorTexture,
55 GLuint depthTexture,
56 GLuint depthStencilTexture);
57
Olli Etuahof26b27e2018-08-17 11:01:19 +030058struct MultiviewImplementationParams : public PlatformParameters
59{
60 MultiviewImplementationParams(GLint majorVersion,
61 GLint minorVersion,
62 bool forceUseGeometryShaderOnD3D,
63 const EGLPlatformParameters &eglPlatformParameters)
64 : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters),
65 mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D)
Jamie Madillb980c562018-11-27 11:34:27 -050066 {}
Olli Etuahof26b27e2018-08-17 11:01:19 +030067 bool mForceUseGeometryShaderOnD3D;
68};
69std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params);
70
71MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion);
72MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion);
73MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion);
74
75class MultiviewTestBase : public ANGLETestBase
76{
77 protected:
78 MultiviewTestBase(const PlatformParameters &params) : ANGLETestBase(params)
79 {
80 setWindowWidth(128);
81 setWindowHeight(128);
82 setWebGLCompatibilityEnabled(true);
83 }
84 virtual ~MultiviewTestBase() {}
85
86 void MultiviewTestBaseSetUp()
87 {
88 ANGLETestBase::ANGLETestSetUp();
89
90 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
91 eglGetProcAddress("glRequestExtensionANGLE"));
92 }
93
94 void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); }
95
Mingyu Hu7d64c482019-03-12 14:27:40 -070096 // Requests the OVR_multiview2 extension and returns true if the operation succeeds.
Olli Etuaho2c8f0842018-09-12 14:44:55 +030097 bool requestMultiviewExtension(bool requireMultiviewMultisample)
Olli Etuahof26b27e2018-08-17 11:01:19 +030098 {
Jamie Madillb8149072019-04-30 16:14:44 -040099 if (IsGLExtensionRequestable("GL_OVR_multiview2"))
Olli Etuahof26b27e2018-08-17 11:01:19 +0300100 {
Mingyu Hu7d64c482019-03-12 14:27:40 -0700101 glRequestExtensionANGLE("GL_OVR_multiview2");
Olli Etuahof26b27e2018-08-17 11:01:19 +0300102 }
103
Jamie Madillb8149072019-04-30 16:14:44 -0400104 if (!IsGLExtensionEnabled("GL_OVR_multiview2"))
Olli Etuahof26b27e2018-08-17 11:01:19 +0300105 {
Mingyu Hu7d64c482019-03-12 14:27:40 -0700106 std::cout << "Test skipped due to missing GL_OVR_multiview2." << std::endl;
Olli Etuahof26b27e2018-08-17 11:01:19 +0300107 return false;
108 }
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300109
110 if (requireMultiviewMultisample)
111 {
Jamie Madillb8149072019-04-30 16:14:44 -0400112 if (IsGLExtensionRequestable("GL_OES_texture_storage_multisample_2d_array"))
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300113 {
114 glRequestExtensionANGLE("GL_OES_texture_storage_multisample_2d_array");
115 }
Jamie Madillb8149072019-04-30 16:14:44 -0400116 if (IsGLExtensionRequestable("GL_ANGLE_multiview_multisample"))
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300117 {
118 glRequestExtensionANGLE("GL_ANGLE_multiview_multisample");
119 }
120
Jamie Madillb8149072019-04-30 16:14:44 -0400121 if (!IsGLExtensionEnabled("GL_ANGLE_multiview_multisample"))
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300122 {
123 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
124 << std::endl;
125 return false;
126 }
127 }
Olli Etuahof26b27e2018-08-17 11:01:19 +0300128 return true;
129 }
130
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300131 bool requestMultiviewExtension() { return requestMultiviewExtension(false); }
132
Olli Etuahof26b27e2018-08-17 11:01:19 +0300133 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
134};
135
136// Base class for multiview tests that don't need specific helper functions.
137class MultiviewTest : public MultiviewTestBase,
138 public ::testing::TestWithParam<MultiviewImplementationParams>
139{
140 protected:
141 MultiviewTest() : MultiviewTestBase(GetParam()) {}
Olli Etuahof26b27e2018-08-17 11:01:19 +0300142
143 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) final;
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400144
145 virtual void testSetUp() {}
146 virtual void testTearDown() {}
147
148 private:
149 void SetUp() override
150 {
151 MultiviewTestBase::MultiviewTestBaseSetUp();
152 testSetUp();
153 }
154 void TearDown() override
155 {
156 testTearDown();
157 MultiviewTestBase::MultiviewTestBaseTearDown();
158 }
Olli Etuahof26b27e2018-08-17 11:01:19 +0300159};
160
161} // namespace angle
162
163#endif // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_