Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame^] | 1 | // |
| 2 | // Copyright 2017 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 | // Multiview draw tests: |
| 7 | // Test issuing multiview Draw* commands. |
| 8 | // |
| 9 | |
| 10 | #include "test_utils/ANGLETest.h" |
| 11 | #include "test_utils/gl_raii.h" |
| 12 | |
| 13 | using namespace angle; |
| 14 | |
| 15 | class MultiviewDrawTest : public ANGLETest |
| 16 | { |
| 17 | protected: |
| 18 | MultiviewDrawTest() |
| 19 | { |
| 20 | setWindowWidth(128); |
| 21 | setWindowHeight(128); |
| 22 | setWebGLCompatibilityEnabled(true); |
| 23 | } |
| 24 | |
| 25 | void SetUp() override |
| 26 | { |
| 27 | ANGLETest::SetUp(); |
| 28 | |
| 29 | glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>( |
| 30 | eglGetProcAddress("glRequestExtensionANGLE")); |
| 31 | } |
| 32 | |
| 33 | // Requests the ANGLE_multiview extension and returns true if the operation succeeds. |
| 34 | bool requestMultiviewExtension() |
| 35 | { |
| 36 | if (extensionRequestable("GL_ANGLE_multiview")) |
| 37 | { |
| 38 | glRequestExtensionANGLE("GL_ANGLE_multiview"); |
| 39 | } |
| 40 | |
| 41 | if (!extensionEnabled("GL_ANGLE_multiview")) |
| 42 | { |
| 43 | std::cout << "Test skipped due to missing GL_ANGLE_multiview." << std::endl; |
| 44 | return false; |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr; |
| 50 | }; |
| 51 | |
| 52 | // The test verifies that glDraw*Indirect: |
| 53 | // 1) generates an INVALID_OPERATION error if the number of views in the draw framebuffer is greater |
| 54 | // than 1. |
| 55 | // 2) does not generate any error if the draw framebuffer has exactly 1 view. |
| 56 | TEST_P(MultiviewDrawTest, IndirectDraw) |
| 57 | { |
| 58 | if (!requestMultiviewExtension()) |
| 59 | { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | GLTexture tex2d; |
| 64 | glBindTexture(GL_TEXTURE_2D, tex2d); |
| 65 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 66 | |
| 67 | const GLint viewportOffsets[4] = {0, 0, 2, 0}; |
| 68 | ASSERT_GL_NO_ERROR(); |
| 69 | |
| 70 | const std::string fsSource = |
| 71 | "#version 300 es\n" |
| 72 | "#extension GL_OVR_multiview : require\n" |
| 73 | "precision mediump float;\n" |
| 74 | "void main()\n" |
| 75 | "{}\n"; |
| 76 | |
| 77 | GLVertexArray vao; |
| 78 | glBindVertexArray(vao); |
| 79 | |
| 80 | const float kVertexData[3] = {0.0f}; |
| 81 | const unsigned int kIndices[3] = {0u, 1u, 2u}; |
| 82 | |
| 83 | GLBuffer vbo; |
| 84 | glBindBuffer(GL_ARRAY_BUFFER, vbo); |
| 85 | glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3u, &kVertexData[0], GL_STATIC_DRAW); |
| 86 | ASSERT_GL_NO_ERROR(); |
| 87 | |
| 88 | GLBuffer ibo; |
| 89 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); |
| 90 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * 3, &kIndices[0], GL_STATIC_DRAW); |
| 91 | ASSERT_GL_NO_ERROR(); |
| 92 | |
| 93 | GLBuffer commandBuffer; |
| 94 | glBindBuffer(GL_DRAW_INDIRECT_BUFFER, commandBuffer); |
| 95 | const GLuint commandData[] = {1u, 1u, 0u, 0u, 0u}; |
| 96 | glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(GLuint) * 5u, &commandData[0], GL_STATIC_DRAW); |
| 97 | ASSERT_GL_NO_ERROR(); |
| 98 | |
| 99 | GLFramebuffer framebuffer; |
| 100 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 101 | |
| 102 | // Check for a GL_INVALID_OPERATION error with the framebuffer having 2 views. |
| 103 | { |
| 104 | const std::string &vsSource = |
| 105 | "#version 300 es\n" |
| 106 | "#extension GL_OVR_multiview : require\n" |
| 107 | "layout(num_views = 2) in;\n" |
| 108 | "void main()\n" |
| 109 | "{}\n"; |
| 110 | ANGLE_GL_PROGRAM(program, vsSource, fsSource); |
| 111 | glUseProgram(program); |
| 112 | |
| 113 | glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex2d, 0, |
| 114 | 2, &viewportOffsets[0]); |
| 115 | |
| 116 | glDrawArraysIndirect(GL_TRIANGLES, nullptr); |
| 117 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 118 | |
| 119 | glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr); |
| 120 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 121 | } |
| 122 | |
| 123 | // Check that no errors are generated if the number of views is 1. |
| 124 | { |
| 125 | const std::string &vsSource = |
| 126 | "#version 300 es\n" |
| 127 | "#extension GL_OVR_multiview : require\n" |
| 128 | "layout(num_views = 1) in;\n" |
| 129 | "void main()\n" |
| 130 | "{}\n"; |
| 131 | ANGLE_GL_PROGRAM(program, vsSource, fsSource); |
| 132 | glUseProgram(program); |
| 133 | |
| 134 | glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex2d, 0, |
| 135 | 1, &viewportOffsets[0]); |
| 136 | |
| 137 | glDrawArraysIndirect(GL_TRIANGLES, nullptr); |
| 138 | EXPECT_GL_NO_ERROR(); |
| 139 | |
| 140 | glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr); |
| 141 | EXPECT_GL_NO_ERROR(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | ANGLE_INSTANTIATE_TEST(MultiviewDrawTest, ES31_OPENGL()); |