Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 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 | |
| 18 | // Creates a simple program that passes through two-dimensional vertices and renders green |
| 19 | // fragments. |
| 20 | GLuint CreateSimplePassthroughProgram(int numViews); |
| 21 | |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame^] | 22 | // 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. |
| 26 | void CreateMultiviewBackingTextures(GLenum multiviewLayout, |
| 27 | int viewWidth, |
| 28 | int height, |
| 29 | int numLayers, |
| 30 | std::vector<GLuint> colorTextures, |
| 31 | GLuint depthTexture, |
| 32 | GLuint depthStencilTexture); |
| 33 | void 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. |
| 45 | void 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); |
| 53 | void 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 Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 62 | struct 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 | }; |
| 74 | std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams ¶ms); |
| 75 | |
| 76 | MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion); |
| 77 | MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion); |
| 78 | MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion); |
| 79 | |
| 80 | class MultiviewTestBase : public ANGLETestBase |
| 81 | { |
| 82 | protected: |
| 83 | MultiviewTestBase(const PlatformParameters ¶ms) : 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. |
| 121 | class 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_ |