blob: d3da6b7f4ed8eea9118d0b317ce73850edbe1ba8 [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
Olli Etuahoa7b35c32018-08-21 16:32:24 +030022// Create a set of textures to use for multiview rendering. If multiviewLayout is
23// GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, then 2D textures are created. If multiviewLayout is
24// GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, then 2D texture arrays are created. Texture ids should be
25// created beforehand. If depthTexture or stencilTexture is 0, it will not be initialized.
Olli Etuaho2c8f0842018-09-12 14:44:55 +030026// If samples is 0, then non-multisampled textures are created. Otherwise multisampled textures are
27// created with the requested sample count.
Olli Etuahoa7b35c32018-08-21 16:32:24 +030028void CreateMultiviewBackingTextures(GLenum multiviewLayout,
Olli Etuaho2c8f0842018-09-12 14:44:55 +030029 int samples,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030030 int viewWidth,
31 int height,
32 int numLayers,
33 std::vector<GLuint> colorTextures,
34 GLuint depthTexture,
35 GLuint depthStencilTexture);
36void CreateMultiviewBackingTextures(GLenum multiviewLayout,
Olli Etuaho2c8f0842018-09-12 14:44:55 +030037 int samples,
Olli Etuahoa7b35c32018-08-21 16:32:24 +030038 int viewWidth,
39 int height,
40 int numLayers,
41 GLuint colorTexture,
42 GLuint depthTexture,
43 GLuint depthStencilTexture);
44
45// Attach multiview textures to the framebuffer denoted by target. If there are multiple color
46// textures they get attached to different color attachments starting from 0. If multiviewLayout is
47// GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, then the viewport offsets are set so that the views
48// are tightly packed inside the attachments.
49void AttachMultiviewTextures(GLenum target,
50 GLenum multiviewLayout,
51 int viewWidth,
52 int numViews,
53 int baseViewIndex,
54 std::vector<GLuint> colorTextures,
55 GLuint depthTexture,
56 GLuint depthStencilTexture);
57void AttachMultiviewTextures(GLenum target,
58 GLenum multiviewLayout,
59 int viewWidth,
60 int numViews,
61 int baseViewIndex,
62 GLuint colorTexture,
63 GLuint depthTexture,
64 GLuint depthStencilTexture);
65
Olli Etuahof26b27e2018-08-17 11:01:19 +030066struct MultiviewImplementationParams : public PlatformParameters
67{
68 MultiviewImplementationParams(GLint majorVersion,
69 GLint minorVersion,
70 bool forceUseGeometryShaderOnD3D,
71 const EGLPlatformParameters &eglPlatformParameters)
72 : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters),
73 mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D)
Jamie Madillb980c562018-11-27 11:34:27 -050074 {}
Olli Etuahof26b27e2018-08-17 11:01:19 +030075 bool mForceUseGeometryShaderOnD3D;
76};
77std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params);
78
79MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion);
80MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion);
81MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion);
82
83class MultiviewTestBase : public ANGLETestBase
84{
85 protected:
86 MultiviewTestBase(const PlatformParameters &params) : ANGLETestBase(params)
87 {
88 setWindowWidth(128);
89 setWindowHeight(128);
90 setWebGLCompatibilityEnabled(true);
91 }
92 virtual ~MultiviewTestBase() {}
93
94 void MultiviewTestBaseSetUp()
95 {
96 ANGLETestBase::ANGLETestSetUp();
97
98 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
99 eglGetProcAddress("glRequestExtensionANGLE"));
100 }
101
102 void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); }
103
104 // Requests the ANGLE_multiview extension and returns true if the operation succeeds.
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300105 bool requestMultiviewExtension(bool requireMultiviewMultisample)
Olli Etuahof26b27e2018-08-17 11:01:19 +0300106 {
107 if (extensionRequestable("GL_ANGLE_multiview"))
108 {
109 glRequestExtensionANGLE("GL_ANGLE_multiview");
110 }
111
112 if (!extensionEnabled("GL_ANGLE_multiview"))
113 {
114 std::cout << "Test skipped due to missing GL_ANGLE_multiview." << std::endl;
115 return false;
116 }
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300117
118 if (requireMultiviewMultisample)
119 {
120 if (extensionRequestable("GL_OES_texture_storage_multisample_2d_array"))
121 {
122 glRequestExtensionANGLE("GL_OES_texture_storage_multisample_2d_array");
123 }
124 if (extensionRequestable("GL_ANGLE_multiview_multisample"))
125 {
126 glRequestExtensionANGLE("GL_ANGLE_multiview_multisample");
127 }
128
129 if (!extensionEnabled("GL_ANGLE_multiview_multisample"))
130 {
131 std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample."
132 << std::endl;
133 return false;
134 }
135 }
Olli Etuahof26b27e2018-08-17 11:01:19 +0300136 return true;
137 }
138
Olli Etuaho2c8f0842018-09-12 14:44:55 +0300139 bool requestMultiviewExtension() { return requestMultiviewExtension(false); }
140
Olli Etuahof26b27e2018-08-17 11:01:19 +0300141 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
142};
143
144// Base class for multiview tests that don't need specific helper functions.
145class MultiviewTest : public MultiviewTestBase,
146 public ::testing::TestWithParam<MultiviewImplementationParams>
147{
148 protected:
149 MultiviewTest() : MultiviewTestBase(GetParam()) {}
150 void SetUp() override { MultiviewTestBase::MultiviewTestBaseSetUp(); }
151 void TearDown() override { MultiviewTestBase::MultiviewTestBaseTearDown(); }
152
153 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) final;
154};
155
156} // namespace angle
157
158#endif // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_