OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file defines tests that implementations of GLImage should pass in order | 5 // This file defines tests that implementations of GLImage should pass in order |
6 // to be conformant. | 6 // to be conformant. |
7 | 7 |
8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "ui/gl/init/gl_factory.h" | 27 #include "ui/gl/init/gl_factory.h" |
28 #include "ui/gl/test/gl_image_test_support.h" | 28 #include "ui/gl/test/gl_image_test_support.h" |
29 #include "ui/gl/test/gl_test_helper.h" | 29 #include "ui/gl/test/gl_test_helper.h" |
30 | 30 |
31 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
32 #include "base/mac/mac_util.h" | 32 #include "base/mac/mac_util.h" |
33 #endif | 33 #endif |
34 | 34 |
35 namespace gl { | 35 namespace gl { |
36 namespace { | 36 namespace { |
37 std::string GenerateShaderVersionString() { | |
erikchen
2016/08/18 00:45:54
This function is never used.
Zhenyao Mo
2016/08/18 16:45:55
Done.
| |
38 const GLVersionInfo* version_info = GLContext::GetCurrent()->GetVersionInfo(); | |
39 return version_info->is_desktop_core_profile ? "#version 150" : ""; | |
40 } | |
41 | |
42 GLuint LoadVertexShader() { | |
43 bool is_desktop_core_profile = | |
44 GLContext::GetCurrent()->GetVersionInfo()->is_desktop_core_profile; | |
45 std::string vertex_shader = base::StringPrintf( | |
46 "%s" | |
47 "%s vec2 a_position;\n" | |
48 "%s vec2 v_texCoord;\n" | |
49 "void main() {\n" | |
50 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" | |
51 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" | |
52 "}", | |
53 is_desktop_core_profile ? "#version 150\n" : "", | |
54 is_desktop_core_profile ? "in" : "attribute", | |
55 is_desktop_core_profile ? "out" : "varying"); | |
56 return GLHelper::LoadShader(GL_VERTEX_SHADER, vertex_shader.c_str()); | |
57 } | |
37 | 58 |
38 // Compiles a fragment shader for sampling out of a texture of |size| bound to | 59 // Compiles a fragment shader for sampling out of a texture of |size| bound to |
39 // |target| and checks for compilation errors. | 60 // |target| and checks for compilation errors. |
40 GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) { | 61 GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) { |
41 // clang-format off | 62 bool is_desktop_core_profile = |
42 const char kFragmentShader[] = STRINGIZE( | 63 GLContext::GetCurrent()->GetVersionInfo()->is_desktop_core_profile; |
43 uniform SamplerType a_texture; | 64 bool is_gles = GLContext::GetCurrent()->GetVersionInfo()->is_es; |
44 varying vec2 v_texCoord; | |
45 void main() { | |
46 gl_FragColor = TextureLookup(a_texture, v_texCoord * TextureScale); | |
47 } | |
48 ); | |
49 const char kShaderFloatPrecision[] = STRINGIZE( | |
50 precision mediump float; | |
51 ); | |
52 // clang-format on | |
53 | 65 |
54 bool is_gles = GLContext::GetCurrent()->GetVersionInfo()->is_es; | 66 std::string fragment_shader_main = base::StringPrintf( |
67 "uniform SamplerType a_texture;\n" | |
68 "%s vec2 v_texCoord;\n" | |
69 "%s\n" | |
erikchen
2016/08/18 00:45:54
to match LoadVertexShader, can you move the "\n" i
Zhenyao Mo
2016/08/18 16:45:55
Done.
| |
70 "void main() {\n" | |
71 " %s = TextureLookup(a_texture, v_texCoord * TextureScale);\n" | |
72 "}", | |
73 is_desktop_core_profile ? "in" : "varying", | |
74 is_desktop_core_profile ? "out vec4 my_FragData;" : "", | |
75 is_desktop_core_profile ? "my_FragData" : "gl_FragData[0]"); | |
76 | |
55 switch (target) { | 77 switch (target) { |
56 case GL_TEXTURE_2D: | 78 case GL_TEXTURE_2D: |
57 return GLHelper::LoadShader( | 79 return GLHelper::LoadShader( |
58 GL_FRAGMENT_SHADER, | 80 GL_FRAGMENT_SHADER, |
59 base::StringPrintf("%s\n" | 81 base::StringPrintf( |
60 "#define SamplerType sampler2D\n" | 82 "%s" // version |
61 "#define TextureLookup texture2D\n" | 83 "%s" // precision |
62 "#define TextureScale vec2(1.0, 1.0)\n" | 84 "#define SamplerType sampler2D\n" |
63 "%s", | 85 "#define TextureLookup %s\n" |
64 is_gles ? kShaderFloatPrecision : "", | 86 "#define TextureScale vec2(1.0, 1.0)\n" |
65 kFragmentShader) | 87 "%s", |
66 .c_str()); | 88 is_desktop_core_profile ? "#version 150\n" : "", |
89 is_gles ? "precision mediump float\n" : "", | |
90 is_desktop_core_profile ? "texture" : "texture2D", | |
91 fragment_shader_main.c_str()).c_str()); | |
67 case GL_TEXTURE_RECTANGLE_ARB: | 92 case GL_TEXTURE_RECTANGLE_ARB: |
68 return GLHelper::LoadShader( | 93 return GLHelper::LoadShader( |
69 GL_FRAGMENT_SHADER, | 94 GL_FRAGMENT_SHADER, |
70 base::StringPrintf("#extension GL_ARB_texture_rectangle : require\n" | 95 base::StringPrintf( |
71 "%s\n" | 96 "%s" // version |
72 "#define SamplerType sampler2DRect\n" | 97 "%s" // extension |
73 "#define TextureLookup texture2DRect\n" | 98 "#define SamplerType sampler2DRect\n" |
74 "#define TextureScale vec2(%f, %f)\n" | 99 "#define TextureLookup %s\n" |
75 "%s", | 100 "#define TextureScale vec2(%f, %f)\n" |
76 is_gles ? kShaderFloatPrecision : "", | 101 "%s", |
77 static_cast<double>(size.width()), | 102 is_desktop_core_profile ? "#version 150\n" : "", |
78 static_cast<double>(size.height()), | 103 is_desktop_core_profile ? "" : |
79 kFragmentShader) | 104 "#extension GL_ARB_texture_rectangle : require\n", |
80 .c_str()); | 105 is_desktop_core_profile ? "texture" : "texture2DRect", |
106 static_cast<double>(size.width()), | |
107 static_cast<double>(size.height()), | |
108 fragment_shader_main.c_str()).c_str()); | |
81 case GL_TEXTURE_EXTERNAL_OES: | 109 case GL_TEXTURE_EXTERNAL_OES: |
82 return GLHelper::LoadShader( | 110 return GLHelper::LoadShader( |
83 GL_FRAGMENT_SHADER, | 111 GL_FRAGMENT_SHADER, |
84 base::StringPrintf("#extension GL_OES_EGL_image_external : require\n" | 112 base::StringPrintf( |
85 "%s\n" | 113 "#extension GL_OES_EGL_image_external : require\n" |
86 "#define SamplerType samplerExternalOES\n" | 114 "#define SamplerType samplerExternalOES\n" |
87 "#define TextureLookup texture2D\n" | 115 "#define TextureLookup texture2D\n" |
88 "#define TextureScale vec2(1.0, 1.0)\n" | 116 "#define TextureScale vec2(1.0, 1.0)\n" |
89 "%s", | 117 "%s", |
90 is_gles ? kShaderFloatPrecision : "", | 118 fragment_shader_main.c_str()).c_str()); |
erikchen
2016/08/18 00:45:54
is_gles will always evaluate to false in this case
Zhenyao Mo
2016/08/18 00:56:51
As far as I know there is no ES drivers on Mac. I
| |
91 kFragmentShader) | |
92 .c_str()); | |
93 default: | 119 default: |
94 NOTREACHED(); | 120 NOTREACHED(); |
95 return 0; | 121 return 0; |
96 } | 122 } |
97 } | 123 } |
98 | 124 |
99 // Draws texture bound to |target| of texture unit 0 to the currently bound | 125 // Draws texture bound to |target| of texture unit 0 to the currently bound |
100 // frame buffer. | 126 // frame buffer. |
101 void DrawTextureQuad(GLenum target, const gfx::Size& size) { | 127 void DrawTextureQuad(GLenum target, const gfx::Size& size) { |
102 // clang-format off | |
103 const char kVertexShader[] = STRINGIZE( | |
104 attribute vec2 a_position; | |
105 varying vec2 v_texCoord; | |
106 void main() { | |
107 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); | |
108 v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5; | |
109 } | |
110 ); | |
111 // clang-format on | |
112 | |
113 GLuint vao = 0; | 128 GLuint vao = 0; |
114 if (GLHelper::ShouldTestsUseVAOs()) { | 129 if (GLHelper::ShouldTestsUseVAOs()) { |
115 glGenVertexArraysOES(1, &vao); | 130 glGenVertexArraysOES(1, &vao); |
116 glBindVertexArrayOES(vao); | 131 glBindVertexArrayOES(vao); |
117 } | 132 } |
118 | 133 |
119 GLuint vertex_shader = GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); | 134 GLuint vertex_shader = LoadVertexShader(); |
120 GLuint fragment_shader = LoadFragmentShader(target, size); | 135 GLuint fragment_shader = LoadFragmentShader(target, size); |
121 GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader); | 136 GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader); |
122 EXPECT_NE(program, 0u); | 137 EXPECT_NE(program, 0u); |
123 glUseProgram(program); | 138 glUseProgram(program); |
124 | 139 |
125 GLint sampler_location = glGetUniformLocation(program, "a_texture"); | 140 GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
126 ASSERT_NE(sampler_location, -1); | 141 ASSERT_NE(sampler_location, -1); |
127 glUniform1i(sampler_location, 0); | 142 glUniform1i(sampler_location, 0); |
128 | 143 |
129 GLuint vertex_buffer = GLHelper::SetupQuadVertexBuffer(); | 144 GLuint vertex_buffer = GLHelper::SetupQuadVertexBuffer(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 image->Destroy(true /* have_context */); | 372 image->Destroy(true /* have_context */); |
358 } | 373 } |
359 | 374 |
360 // The GLImageCopyTest test case verifies that the GLImage implementation | 375 // The GLImageCopyTest test case verifies that the GLImage implementation |
361 // handles CopyTexImage correctly. | 376 // handles CopyTexImage correctly. |
362 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); | 377 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
363 | 378 |
364 } // namespace gl | 379 } // namespace gl |
365 | 380 |
366 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 381 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
OLD | NEW |