blob: 9b93cc2f17b1763a6f8287e71bace38d2f80729c [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.
26void CreateMultiviewBackingTextures(GLenum multiviewLayout,
27 int viewWidth,
28 int height,
29 int numLayers,
30 std::vector<GLuint> colorTextures,
31 GLuint depthTexture,
32 GLuint depthStencilTexture);
33void CreateMultiviewBackingTextures(GLenum multiviewLayout,
34 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
42// textures they get attached to different color attachments starting from 0. If multiviewLayout is
43// GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, then the viewport offsets are set so that the views
44// are tightly packed inside the attachments.
45void AttachMultiviewTextures(GLenum target,
46 GLenum multiviewLayout,
47 int viewWidth,
48 int numViews,
49 int baseViewIndex,
50 std::vector<GLuint> colorTextures,
51 GLuint depthTexture,
52 GLuint depthStencilTexture);
53void AttachMultiviewTextures(GLenum target,
54 GLenum multiviewLayout,
55 int viewWidth,
56 int numViews,
57 int baseViewIndex,
58 GLuint colorTexture,
59 GLuint depthTexture,
60 GLuint depthStencilTexture);
61
Olli Etuahof26b27e2018-08-17 11:01:19 +030062struct MultiviewImplementationParams : public PlatformParameters
63{
64 MultiviewImplementationParams(GLint majorVersion,
65 GLint minorVersion,
66 bool forceUseGeometryShaderOnD3D,
67 const EGLPlatformParameters &eglPlatformParameters)
68 : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters),
69 mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D)
70 {
71 }
72 bool mForceUseGeometryShaderOnD3D;
73};
74std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params);
75
76MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion);
77MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion);
78MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion);
79
80class MultiviewTestBase : public ANGLETestBase
81{
82 protected:
83 MultiviewTestBase(const PlatformParameters &params) : ANGLETestBase(params)
84 {
85 setWindowWidth(128);
86 setWindowHeight(128);
87 setWebGLCompatibilityEnabled(true);
88 }
89 virtual ~MultiviewTestBase() {}
90
91 void MultiviewTestBaseSetUp()
92 {
93 ANGLETestBase::ANGLETestSetUp();
94
95 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
96 eglGetProcAddress("glRequestExtensionANGLE"));
97 }
98
99 void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); }
100
101 // Requests the ANGLE_multiview extension and returns true if the operation succeeds.
102 bool requestMultiviewExtension()
103 {
104 if (extensionRequestable("GL_ANGLE_multiview"))
105 {
106 glRequestExtensionANGLE("GL_ANGLE_multiview");
107 }
108
109 if (!extensionEnabled("GL_ANGLE_multiview"))
110 {
111 std::cout << "Test skipped due to missing GL_ANGLE_multiview." << std::endl;
112 return false;
113 }
114 return true;
115 }
116
117 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
118};
119
120// Base class for multiview tests that don't need specific helper functions.
121class MultiviewTest : public MultiviewTestBase,
122 public ::testing::TestWithParam<MultiviewImplementationParams>
123{
124 protected:
125 MultiviewTest() : MultiviewTestBase(GetParam()) {}
126 void SetUp() override { MultiviewTestBase::MultiviewTestBaseSetUp(); }
127 void TearDown() override { MultiviewTestBase::MultiviewTestBaseTearDown(); }
128
129 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) final;
130};
131
132} // namespace angle
133
134#endif // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_