Index: ui/gl/test/gl_image_test_template.h |
diff --git a/ui/gl/test/gl_image_test_template.h b/ui/gl/test/gl_image_test_template.h |
index fe333fa1997ca1a6f76f6c99144014c7ebbdfbb5..d8eb895467fa04bea23c5bdcc00b819a9c4cd6d4 100644 |
--- a/ui/gl/test/gl_image_test_template.h |
+++ b/ui/gl/test/gl_image_test_template.h |
@@ -34,62 +34,88 @@ |
namespace gl { |
namespace { |
+std::string GenerateShaderVersionString() { |
erikchen
2016/08/18 00:45:54
This function is never used.
Zhenyao Mo
2016/08/18 16:45:55
Done.
|
+ const GLVersionInfo* version_info = GLContext::GetCurrent()->GetVersionInfo(); |
+ return version_info->is_desktop_core_profile ? "#version 150" : ""; |
+} |
+ |
+GLuint LoadVertexShader() { |
+ bool is_desktop_core_profile = |
+ GLContext::GetCurrent()->GetVersionInfo()->is_desktop_core_profile; |
+ std::string vertex_shader = base::StringPrintf( |
+ "%s" |
+ "%s vec2 a_position;\n" |
+ "%s vec2 v_texCoord;\n" |
+ "void main() {\n" |
+ " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" |
+ " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" |
+ "}", |
+ is_desktop_core_profile ? "#version 150\n" : "", |
+ is_desktop_core_profile ? "in" : "attribute", |
+ is_desktop_core_profile ? "out" : "varying"); |
+ return GLHelper::LoadShader(GL_VERTEX_SHADER, vertex_shader.c_str()); |
+} |
// Compiles a fragment shader for sampling out of a texture of |size| bound to |
// |target| and checks for compilation errors. |
GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) { |
- // clang-format off |
- const char kFragmentShader[] = STRINGIZE( |
- uniform SamplerType a_texture; |
- varying vec2 v_texCoord; |
- void main() { |
- gl_FragColor = TextureLookup(a_texture, v_texCoord * TextureScale); |
- } |
- ); |
- const char kShaderFloatPrecision[] = STRINGIZE( |
- precision mediump float; |
- ); |
- // clang-format on |
- |
+ bool is_desktop_core_profile = |
+ GLContext::GetCurrent()->GetVersionInfo()->is_desktop_core_profile; |
bool is_gles = GLContext::GetCurrent()->GetVersionInfo()->is_es; |
+ |
+ std::string fragment_shader_main = base::StringPrintf( |
+ "uniform SamplerType a_texture;\n" |
+ "%s vec2 v_texCoord;\n" |
+ "%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.
|
+ "void main() {\n" |
+ " %s = TextureLookup(a_texture, v_texCoord * TextureScale);\n" |
+ "}", |
+ is_desktop_core_profile ? "in" : "varying", |
+ is_desktop_core_profile ? "out vec4 my_FragData;" : "", |
+ is_desktop_core_profile ? "my_FragData" : "gl_FragData[0]"); |
+ |
switch (target) { |
case GL_TEXTURE_2D: |
return GLHelper::LoadShader( |
GL_FRAGMENT_SHADER, |
- base::StringPrintf("%s\n" |
- "#define SamplerType sampler2D\n" |
- "#define TextureLookup texture2D\n" |
- "#define TextureScale vec2(1.0, 1.0)\n" |
- "%s", |
- is_gles ? kShaderFloatPrecision : "", |
- kFragmentShader) |
- .c_str()); |
+ base::StringPrintf( |
+ "%s" // version |
+ "%s" // precision |
+ "#define SamplerType sampler2D\n" |
+ "#define TextureLookup %s\n" |
+ "#define TextureScale vec2(1.0, 1.0)\n" |
+ "%s", |
+ is_desktop_core_profile ? "#version 150\n" : "", |
+ is_gles ? "precision mediump float\n" : "", |
+ is_desktop_core_profile ? "texture" : "texture2D", |
+ fragment_shader_main.c_str()).c_str()); |
case GL_TEXTURE_RECTANGLE_ARB: |
return GLHelper::LoadShader( |
GL_FRAGMENT_SHADER, |
- base::StringPrintf("#extension GL_ARB_texture_rectangle : require\n" |
- "%s\n" |
- "#define SamplerType sampler2DRect\n" |
- "#define TextureLookup texture2DRect\n" |
- "#define TextureScale vec2(%f, %f)\n" |
- "%s", |
- is_gles ? kShaderFloatPrecision : "", |
- static_cast<double>(size.width()), |
- static_cast<double>(size.height()), |
- kFragmentShader) |
- .c_str()); |
+ base::StringPrintf( |
+ "%s" // version |
+ "%s" // extension |
+ "#define SamplerType sampler2DRect\n" |
+ "#define TextureLookup %s\n" |
+ "#define TextureScale vec2(%f, %f)\n" |
+ "%s", |
+ is_desktop_core_profile ? "#version 150\n" : "", |
+ is_desktop_core_profile ? "" : |
+ "#extension GL_ARB_texture_rectangle : require\n", |
+ is_desktop_core_profile ? "texture" : "texture2DRect", |
+ static_cast<double>(size.width()), |
+ static_cast<double>(size.height()), |
+ fragment_shader_main.c_str()).c_str()); |
case GL_TEXTURE_EXTERNAL_OES: |
return GLHelper::LoadShader( |
GL_FRAGMENT_SHADER, |
- base::StringPrintf("#extension GL_OES_EGL_image_external : require\n" |
- "%s\n" |
- "#define SamplerType samplerExternalOES\n" |
- "#define TextureLookup texture2D\n" |
- "#define TextureScale vec2(1.0, 1.0)\n" |
- "%s", |
- is_gles ? kShaderFloatPrecision : "", |
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
|
- kFragmentShader) |
- .c_str()); |
+ base::StringPrintf( |
+ "#extension GL_OES_EGL_image_external : require\n" |
+ "#define SamplerType samplerExternalOES\n" |
+ "#define TextureLookup texture2D\n" |
+ "#define TextureScale vec2(1.0, 1.0)\n" |
+ "%s", |
+ fragment_shader_main.c_str()).c_str()); |
default: |
NOTREACHED(); |
return 0; |
@@ -99,24 +125,13 @@ GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) { |
// Draws texture bound to |target| of texture unit 0 to the currently bound |
// frame buffer. |
void DrawTextureQuad(GLenum target, const gfx::Size& size) { |
- // clang-format off |
- const char kVertexShader[] = STRINGIZE( |
- attribute vec2 a_position; |
- varying vec2 v_texCoord; |
- void main() { |
- gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); |
- v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5; |
- } |
- ); |
- // clang-format on |
- |
GLuint vao = 0; |
if (GLHelper::ShouldTestsUseVAOs()) { |
glGenVertexArraysOES(1, &vao); |
glBindVertexArrayOES(vao); |
} |
- GLuint vertex_shader = GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); |
+ GLuint vertex_shader = LoadVertexShader(); |
GLuint fragment_shader = LoadFragmentShader(target, size); |
GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader); |
EXPECT_NE(program, 0u); |