Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [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 | |
| 7 | // GeometryShaderTest.cpp : Tests of the implementation of geometry shader |
| 8 | |
| 9 | #include "test_utils/ANGLETest.h" |
| 10 | |
| 11 | using namespace angle; |
| 12 | |
| 13 | namespace |
| 14 | { |
| 15 | |
| 16 | class GeometryShaderTest : public ANGLETest |
| 17 | { |
| 18 | }; |
| 19 | |
| 20 | class GeometryShaderTestES3 : public ANGLETest |
| 21 | { |
| 22 | }; |
| 23 | |
| 24 | // Verify that Geometry Shader cannot be created in an OpenGL ES 3.0 context. |
| 25 | TEST_P(GeometryShaderTestES3, CreateGeometryShaderInES3) |
| 26 | { |
| 27 | EXPECT_TRUE(!extensionEnabled("GL_EXT_geometry_shader")); |
| 28 | GLuint geometryShader = glCreateShader(GL_GEOMETRY_SHADER_EXT); |
| 29 | EXPECT_EQ(0u, geometryShader); |
| 30 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 31 | } |
| 32 | |
| 33 | // Verify that Geometry Shader can be created and attached to a program. |
| 34 | TEST_P(GeometryShaderTest, CreateAndAttachGeometryShader) |
| 35 | { |
| 36 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); |
| 37 | |
| 38 | const std::string &geometryShaderSource = |
| 39 | R"(#version 310 es |
| 40 | #extension GL_EXT_geometry_shader : require |
| 41 | layout (invocations = 3, triangles) in; |
| 42 | layout (triangle_strip, max_vertices = 3) out; |
| 43 | in vec4 texcoord[]; |
| 44 | out vec4 o_texcoord; |
| 45 | void main() |
| 46 | { |
| 47 | int n; |
| 48 | for (n = 0; n < gl_in.length(); n++) |
| 49 | { |
| 50 | gl_Position = gl_in[n].gl_Position; |
| 51 | gl_Layer = gl_InvocationID; |
| 52 | o_texcoord = texcoord[n]; |
| 53 | EmitVertex(); |
| 54 | } |
| 55 | EndPrimitive(); |
| 56 | })"; |
| 57 | |
| 58 | GLuint geometryShader = CompileShader(GL_GEOMETRY_SHADER_EXT, geometryShaderSource); |
| 59 | |
| 60 | EXPECT_NE(0u, geometryShader); |
| 61 | |
| 62 | GLuint programID = glCreateProgram(); |
| 63 | glAttachShader(programID, geometryShader); |
| 64 | |
| 65 | glDetachShader(programID, geometryShader); |
| 66 | glDeleteShader(geometryShader); |
| 67 | glDeleteProgram(programID); |
| 68 | |
| 69 | EXPECT_GL_NO_ERROR(); |
| 70 | } |
| 71 | |
| 72 | ANGLE_INSTANTIATE_TEST(GeometryShaderTestES3, ES3_OPENGL(), ES3_OPENGLES(), ES3_D3D11()); |
| 73 | ANGLE_INSTANTIATE_TEST(GeometryShaderTest, ES31_OPENGL(), ES31_OPENGLES(), ES31_D3D11()); |
| 74 | } |